Ejemplo n.º 1
0
void mutate(unsigned int t) /* Mutacion de PArticulas MOPSO */
{
	unsigned int i;
	int dimension = 0;
	double minvalue[maxvar], maxvalue[maxvar], minvaluetemp, maxvaluetemp, range;
	double valtemp = 0;
	get_ranges(minvalue,maxvalue);
	for(i=0; i < popsize; i++)
	{
		if(flip(pow(1.0-(double)t / (maxgen * pMut),1.5)))
		{
			dimension = RandomInt(0,maxvar-1);
			range =(maxvalue[dimension] - minvalue[dimension]) * pow(1.0 - (double)t / (maxgen * pMut),1.5) / 2;
			valtemp = RandomDouble(range, -range);
			if(popVar[i][dimension] - range < minvalue[dimension])
				minvaluetemp = minvalue[dimension];
			else
				minvaluetemp = popVar[i][dimension] - range;
			if(popVar[i][dimension] + range > maxvalue[dimension])
				maxvaluetemp = maxvalue[dimension];
			else
				maxvaluetemp = popVar[i][dimension] + range;
			popVar[i][dimension] = RandomDouble(minvaluetemp, maxvaluetemp);
		}
	}
}
Ejemplo n.º 2
0
vec Genetic::Crossing(vec mother, vec father) { //берем среднее по каждой из координат
	vec child;
	for (int i = 0; i < N; i++) {
		if (mother.variable[i] < father.variable[i])
			child.variable[i] = RandomDouble(mother.variable[i], father.variable[i]);
		else
			child.variable[i] = RandomDouble(father.variable[i], mother.variable[i]);
	}
	return child;
}
Ejemplo n.º 3
0
void Simulator::burn(Paper& p)
{
    int rmin = 0;
    int cmin = 0;
    int rmax = p.rows - 1;
    int cmax = p.columns - 1;
    float k = 0.4;
    float left = 0, right = 0, top = 0, bottom = 0, self = 0, Tnew = 0, rowid = 0, columnid =0;
    
    
    for (int i = 1; i< p.particleCount;i++)
    {
        
        self = p.paperParticles[i].temperature;
        Tnew = p.paperParticles[i].temperature;
        rowid = i%p.rows;
        columnid = i/p.columns;
        if (columnid != cmin)
        {
            left = p.paperParticles[i-(p.rows)].temperature;
            Tnew = Tnew + ((k + RandomDouble(-0.1, 0.1)) * (left -self));
        }
        if (columnid != cmax)
        {
            right = p.paperParticles[i+(p.rows)].temperature;
            Tnew = Tnew + ((k + RandomDouble(-0.1, 0.1)) * (right - self));
            
        }
        if (rowid != rmin)
        {
            top = p.paperParticles[i -1].temperature;
            Tnew = Tnew + ((k + RandomDouble(-0.1, 0.1)) * (top - self));
            
        }
        if (rowid != rmax)
        {
            bottom = p.paperParticles[i +1].temperature;
            Tnew = Tnew + ((k + RandomDouble(-0.1, 0.1)) *(bottom - self));
        }
        
        p.paperParticles[i].temperature = Tnew;
        
    }
    
    p.drawPaper();
    p.drawMesh();
    
}
Ejemplo n.º 4
0
double slave_psgold(double shift, double scale, int seed, int stream)
{
     int i;
     double currgcv, bestgcv, bestlambda = 0;
     
     struct SP_1D  * best_sp;       
     best_sp = spline_1d_copy(sp_psgold);

     RandomInitialise(stream, stream+1, seed);

     lambda_psgold = exp(RandomDouble(MIN_LOG_LAMBDA_PSGOLD,
                     MAX_LOG_LAMBDA_PSGOLD)); 
     bestgcv = INFINITY;
     sp_1d_set_knots(sp_psgold, 0., 1.);
     sp_1d_set_knots(best_sp, 0., 1.);

     for (i = 0; i < NUMBER_LOOPS_PSGOLD; i++)
     {
          currgcv = lambda_loop_psgold(shift, scale);
          if (currgcv < bestgcv)
          {
              bestlambda = lambda_psgold;
              bestgcv = currgcv;
          }
          currgcv = knot_loop_psgold(shift, scale);
          if (currgcv < bestgcv)
          {
              free_SP_1D(best_sp);
              best_sp = spline_1d_copy(sp_psgold);
              bestgcv = currgcv;
          }
     }

     return bestlambda;
}
Ejemplo n.º 5
0
void compute_velocity() /* Calcular la nueva velocidad de cada particula en la poblacion */
{
	unsigned int i, j, gBest, top;
    compute_hvContribution();
    top = (unsigned int)((nondomCtr-1) * 0.05);
	for(i = 0; i < popsize; i++)
	{
	    gBest = RandomInt(0,top);
		for(j = 0; j < maxvar; j++)
			velocity[i][j] = 0.4 * velocity[i][j] + 1.0 * RandomDouble(0.0, 1.0) * (pbestsVar[i][j] - popVar[i][j]) + 1.0 * RandomDouble(0.0, 1.0) * (archiveVar[gBest][j] - popVar[i][j]);
            /* W* Vi + C1  * RandomDouble(0.0, 1.0) * (pBest - Xi) + C2  * RandomDouble(0.0, 1.0) * (gBest  -  Xi) */
	}
}
Ejemplo n.º 6
0
int Parameters::SetParams(const GeneralGamlConfig& conf, const HKYData& data_in)	{
	// general config
	strncpy(datafname, conf.datafname.c_str(), 80);
	strncpy(ofprefix, conf.ofprefix.c_str(), 80);
	if (conf.streefname.length() == 0)
		strcpy(startfname, "random");
	else
		strncpy(startfname, conf.streefname.c_str(), 84);
	
	constraintFile = conf.constraintfile;

	logEvery = conf.logevery;
	saveEvery = conf.saveevery;

	nindivs = RandomInt(conf.min_nindivs, conf.max_nindivs);
	stopgen = conf.stopgen;
	stoptime = conf.stoptime;
	meanBrlenMuts = RandomDouble(conf.minBrlenMuts, conf.maxBrlenMuts);
	holdover = conf.holdover;
	gammaShapeBrlen = conf.gammaShapeBrlen;
	gammaShapeModel = conf.gammaShapeBrlen;
	selectionIntensity=conf.selectionIntensity;
	holdoverPenalty=conf.holdoverPenalty;
	treeRejectionThreshold = conf.treeRejectionThreshold;

	// construct other settings from the previous ones
	sprintf(logfname, "%s.log", ofprefix);
	sprintf(gnufname, "%s.gnu", ofprefix);
	sprintf(treefname, "%s.best.tre", ofprefix);
	sprintf(statefname, "%s.gml", ofprefix);

	// now the random seedSetParams
	if(conf.randseed < 1)
		randomSeed = RandomInt(1, 1000);
	else randomSeed=conf.randseed;
	rnd.set_seed(randomSeed);

	// finally set the data pointer
	data = const_cast<HKYData*>(&data_in);
	
	return 0;
}
Ejemplo n.º 7
0
uint32 CalculateDamage( Unit* pAttacker, Unit* pVictim, uint32 weapon_damage_type, uint64 spellgroup, SpellEntry* ability ) // spellid is used only for 2-3 spells, that have AP bonus
{
    //TODO: Some awesome formula to determine how much damage to deal
    //consider this is melee damage
    // weapon_damage_type: 0 = melee, 1 = offhand(dualwield), 2 = ranged

    // Attack Power increases your base damage-per-second (DPS) by 1 for every 14 attack power.
    // (c) wowwiki

    //type of this UNIT_FIELD_ATTACK_POWER_MODS is unknown, not even uint32 disabled for now.

    uint32 offset;
    Item *it = NULL;

    if(pAttacker->disarmed && pAttacker->IsPlayer())
    {
        offset=UNIT_FIELD_MINDAMAGE;
        it = static_cast< Player* >(pAttacker)->GetItemInterface()->GetInventoryItem(EQUIPMENT_SLOT_MAINHAND);
    }
    else if( weapon_damage_type == MELEE )
        offset = UNIT_FIELD_MINDAMAGE;
    else if( weapon_damage_type == OFFHAND )
        offset = UNIT_FIELD_MINOFFHANDDAMAGE;
    else  // weapon_damage_type == RANGED
        offset = UNIT_FIELD_MINRANGEDDAMAGE;

    float min_damage = pAttacker->GetFloatValue(offset);
    float max_damage = pAttacker->GetFloatValue(offset+1);
    if(it)
    {
        min_damage -= it->GetProto()->Damage[0].Min;
        max_damage -= it->GetProto()->Damage[0].Max;
    }

    float ap = 0;
    float bonus;
    float wspeed;

    if(offset == UNIT_FIELD_MINRANGEDDAMAGE)
    {
        //starting from base attack power then we apply mods on it
        //ap += pAttacker->GetRAP();
        ap += pVictim->RAPvModifier;

        if(!pVictim->IsPlayer() && ((Creature*)pVictim)->GetCreatureInfo())
        {
            uint32 creatType = ((Creature*)pVictim)->GetCreatureInfo()->Type;
            ap += (float)pAttacker->CreatureRangedAttackPowerMod[creatType];

            if(pAttacker->IsPlayer())
            {
                min_damage = (min_damage + static_cast< Player* >(pAttacker)->IncreaseDamageByType[creatType]) * (1 + static_cast< Player* >(pAttacker)->IncreaseDamageByTypePCT[creatType]);
                max_damage = (max_damage + static_cast< Player* >(pAttacker)->IncreaseDamageByType[creatType]) * (1 + static_cast< Player* >(pAttacker)->IncreaseDamageByTypePCT[creatType]);
            }
        }

        if(pAttacker->IsPlayer())
        {
            if(!pAttacker->disarmed)
            {
                Item *it = static_cast< Player* >(pAttacker)->GetItemInterface()->GetInventoryItem(EQUIPMENT_SLOT_RANGED);
                if(it)
                    wspeed = (float)it->GetProto()->Delay;
                else
                    wspeed = 2000;
            }
            else
                wspeed = (float)pAttacker->GetUInt32Value(UNIT_FIELD_RANGEDATTACKTIME);
        }
        else
        {
            wspeed = (float)pAttacker->GetUInt32Value(UNIT_FIELD_BASEATTACKTIME);
        }

        //ranged weapon normalization.
        if(pAttacker->IsPlayer() && ability)
        {
            if(ability->Effect[0] == SPELL_EFFECT_DUMMYMELEE || ability->Effect[1] == SPELL_EFFECT_DUMMYMELEE || ability->Effect[2] == SPELL_EFFECT_DUMMYMELEE)
            {
                wspeed = 2800;
            }
        }

        //Weapon speed constant in feral forms
        if(pAttacker->IsPlayer())
        {
            if(static_cast< Player* >(pAttacker)->IsInFeralForm())
            {
                uint8 ss = static_cast< Player* >(pAttacker)->GetShapeShift();

                if(ss == FORM_CAT)
                    wspeed = 1000.0;
                else if(ss == FORM_DIREBEAR || ss == FORM_BEAR)
                    wspeed = 2500.0;
            }
        }

        bonus = (wspeed-pAttacker->GetUInt32Value(UNIT_FIELD_RANGEDATTACKTIME))/14000.0f*ap;
        min_damage += bonus;
        max_damage += bonus;
    }
    else
    {
        //MinD = AP(28AS-(WS/7))-MaxD
        //starting from base attack power then we apply mods on it
        //ap += pAttacker->GetAP();
        ap += pVictim->APvModifier;

        if(!pVictim->IsPlayer() && ((Creature*)pVictim)->GetCreatureInfo())
        {
            uint32 creatType = ((Creature*)pVictim)->GetCreatureInfo()->Type;
            ap += (float)pAttacker->CreatureAttackPowerMod[creatType];

            if(pAttacker->IsPlayer())
            {
                min_damage = (min_damage + static_cast< Player* >(pAttacker)->IncreaseDamageByType[creatType]) * (1 + static_cast< Player* >(pAttacker)->IncreaseDamageByTypePCT[creatType]);
                max_damage = (max_damage + static_cast< Player* >(pAttacker)->IncreaseDamageByType[creatType]) * (1 + static_cast< Player* >(pAttacker)->IncreaseDamageByTypePCT[creatType]);
            }
        }

        if(pAttacker->IsPlayer())
        {
            if(!pAttacker->disarmed)
            {
                Item *it = static_cast< Player* >(pAttacker)->GetItemInterface()->GetInventoryItem(EQUIPMENT_SLOT_MAINHAND);

                if(it)
                    wspeed = (float)it->GetProto()->Delay;
                else
                    wspeed = 2000;
            }
            else
                wspeed = (float)pAttacker->GetUInt32Value(UNIT_FIELD_BASEATTACKTIME);

            if(spellgroup)
            {
                int32 apall = pAttacker->GetAP();
                int32 apb=0;
                SM_FIValue(pAttacker->SM_PAPBonus,&apb,spellgroup);

                if(apb)
                    ap += apall*((float)apb/100);
                else
                    ap = float(apall);
            }
        }
        else
        {
            wspeed = (float)pAttacker->GetUInt32Value(UNIT_FIELD_BASEATTACKTIME);
        }

        //Normalized weapon damage checks.
        if(pAttacker->IsPlayer() && ability)
        {
            if(ability->Effect[0] == SPELL_EFFECT_DUMMYMELEE || ability->Effect[1] == SPELL_EFFECT_DUMMYMELEE || ability->Effect[2] == SPELL_EFFECT_DUMMYMELEE)
            {
                it = static_cast< Player* >(pAttacker)->GetItemInterface()->GetInventoryItem(EQUIPMENT_SLOT_MAINHAND);

                if(it)
                {
                    if(it->GetProto()->Class == 2) //weapon
                    {
                        if(it->GetProto()->InventoryType == INVTYPE_2HWEAPON) wspeed = 3300;
                        else if(it->GetProto()->SubClass == 15) wspeed = 1700;
                        else wspeed = 2400;
                    }
                }
            }
        }

        //Weapon speed constant in feral forms
        if(pAttacker->IsPlayer())
        {
            if(static_cast< Player* >(pAttacker)->IsInFeralForm())
            {
                uint8 ss = static_cast< Player* >(pAttacker)->GetShapeShift();

                if(ss == FORM_CAT)
                    wspeed = 1000.0;
                else if(ss == FORM_DIREBEAR || ss == FORM_BEAR)
                    wspeed = 2500.0;
            }
        }

        if (offset == UNIT_FIELD_MINDAMAGE)
            bonus = (wspeed-pAttacker->GetUInt32Value(UNIT_FIELD_BASEATTACKTIME))/14000.0f*ap;
        else
            bonus = (wspeed-pAttacker->GetUInt32Value(UNIT_FIELD_BASEATTACKTIME_01))/14000.0f*ap;
        min_damage += bonus;
        max_damage += bonus;
    }
    float diff = fabs(max_damage - min_damage);
    float result = min_damage;

    if(diff >= 1)
        result += float(RandomDouble(diff));

    if(result >= 0)
    {
        if( pAttacker->IsPlayer() && ((Player*)pAttacker)->m_outStealthDamageBonusTimer )
        {
            if( (uint32)UNIXTIME >= ((Player*)pAttacker)->m_outStealthDamageBonusTimer )
                ((Player*)pAttacker)->m_outStealthDamageBonusTimer = 0;
            else
                result *= ((float(((Player*)pAttacker)->m_outStealthDamageBonusPct) / 100.0f) + 1.0f);
        }

        return FL2UINT(result);
    }

    return 0;
}
Ejemplo n.º 8
0
void Buddhabrot::DrawFrame(cv::Mat frame)
{





    double pointX = px.Get(), pointY = py.Get();
    double scale = s.Get();

    double frameRatio = (double)width / (double)height;

    double cwidth = 0, cheight = 0;

    cwidth = 3.0 * scale;
    cheight =  cwidth / frameRatio;

    double minRe, maxRe;
    double minIm, maxIm;

    minRe = pointX - cwidth / 2.0;
    maxRe = pointX + cwidth / 2.0;

    minIm = pointY - cheight / 2.0;
    maxIm = pointY + cheight / 2.0;


    unsigned int maxIterations = max_iter.Get();

    //std::cout<<"minRe: "<<minRe<<"; maxRe: "<<maxRe<<std::endl;
    //std::cout<<"minIm: "<<minIm<<"; maxIm: "<<maxIm<<std::endl;


    bool classic = false;

    double radius = r.Get();

    if(coloring == "classic")
        classic = true;

    bool black_hole = true;

    double xxx = 0;

     int points = calc_points.Get();//;50000000
     // radius = 2;


     double odl_x = (maxRe - minRe) / width;
     double odl_y = (maxIm - minIm) / height;


     double **licznik = new double*[width];
     for(int x = 0 ; x < width; x++)
     {
         licznik[x] = new double[height];
         for(int y = 0; y < height; y++)
         {
             licznik[x][y] = 0;
         }
     }

     double * offRe = new double[maxIterations];
     double * offIm = new double[maxIterations];

     WriteProcessInfo();

    double d2 = 1.0 / (double) points;

    for(int po = 0; po < points; po++)
    {

        //coal++;
       // if(coal >  koks)
       // {

            //std::cout<<(double)po/(double)points*100<<" %"<<std::endl;
            //coal = 0;
       // }
        double pRe = RandomDouble(minRe, maxRe);
        double pIm = RandomDouble(minIm, maxIm);

         double cIm = pIm;//maxIm - (double)y*(double)(  (maxIm-minIm)/(height-1) );
         double cRe = pRe;//minRe + (double)x*(double)  (  (maxRe-minRe)/(width-1) );

         double zRe = 0;
         double zIm = 0;

         double abs2;
         bool hop = true;



         int nnn = 0;
         for(int i = 0; i < maxIterations ; i++)
         {
             nnn = i;

             // normalnie
             double zIm2 = zIm*zIm;
             zIm = 2 * zRe*zIm + cIm;
             zRe = zRe*zRe - zIm2 + cRe;

             //abs = sqrt( zRe*zRe + zIm*zIm );
             abs2 = zRe*zRe + zIm*zIm ;

             offRe[i] = zRe;
             offIm[i] = zIm;

             if(abs2 > radius*radius) //4
             {
                 hop = false;
                 break;
             }
         }

         double *tmpx = new double;
         double *tmpy = new double;

       if(hop == false)
       {
           for(int i = 0; i < nnn; i++)
           {

               double x = offRe[i];
               double y = offIm[i];

               int xx, yy;

               modf((x - minRe) / odl_x , tmpx);

               xx = (*tmpx) ;

               modf((y - minIm) / odl_y, tmpy);
               yy = (*tmpy) ;
              // std::cout<<"#       SONDA( "<<*tmpx<<", "<<*tmpy<<");"<<std::endl;
               double errorx = (x - minRe) / odl_x - xx;
               double errory = (y - minIm) / odl_y - yy;
//log2( (licznik[x][y] - mini) / (maxi - mini)) ;
               //std::cout<<"SONDA( "<<xx<<", "<<yy<<");"<<std::endl;
               if(xx < width && yy < height)
                   licznik[xx][yy] +=  ( ( 1 - errorx) * (1 - errory))   ;
               if(xx +1< width && yy < height)
                   licznik[xx+1][yy] += ( ( 1 - errorx) * (errory));
               if(xx < width && yy+1 < height)
                   licznik[xx][yy+1] += ( (  errorx) * (1 - errory));
               if(xx + 1 < width && yy + 1< height)
                   licznik[xx+1][yy+1] += (  (  errorx) * ( errory));

            //   licznik[xx][yy] = log2( licznik[xx][yy]) / log2(i+2);
             //  licznik[xx+1][yy] = log2( licznik[xx+1][yy]) / log2(i+2);
              // licznik[xx][yy+1] = log2( licznik[xx][yy+1]) / log2(i+2);
              // licznik[xx+1][yy+1] = log2( licznik[xx+1][yy+1]) / log2(i+2);
           }

       }


       if(filetype == "image")
       {
           ReadProcessInfo(d2);
           WriteProcessInfo();
       }

   }
   //std::cout<<"cześć 2."; int kro= 0;
  // std::cin>>kro;

   long double  maxi = 0, mini= 0, sumi = 0;
   for(int y = 0; y < height; ++y)
   {
       for(int x = 0; x < width; ++x)
       {
           if(licznik[x][y] < mini)
               mini = licznik[x][y];
           if(licznik[x][y] > maxi)
               maxi = licznik[x][y];
           sumi += licznik[x][y];
       }
   }
   sumi /= height * width; // śrendia




//    Argument<double> color_r ;
//    Argument<double> color_g ;
//    Argument<double> color_b;

//    for(int i = 0; i < 100 ;i++)
//    {
//        double p = (double) i / 100.0;
//        color_r.Set(Key<double>( 255.0 * p, p));
//        color_g.Set(Key<double>( 255.0 * p , p));
//        color_b.Set(Key<double>( 255.0*log(p) / log(100), p));
//    }


       Argument<double> color_r ;// = c_r;
       Argument<double> color_g ;// = c_g;
       Argument<double> color_b  ;//= c_b;

       unsigned int color_level_num = 100;
       for(unsigned int i = 0 ; i <= color_level_num; i++)
       {
           double p = (double) i / (double) color_level_num;


           //color_r.Set(Key<double>( c_r.GetAbsolute(p) *   log(i) / log(color_level_num), p ));
           //color_g.Set(Key<double>( c_g.GetAbsolute(p) *    log(i) / log(color_level_num), p ));
           //color_b.Set(Key<double>( c_b.GetAbsolute(p) *    log(i) / log(color_level_num) , p ));



// TO JEST BARADZO WAŻNE
            color_r.Set(Key<double>( 255.0 *   p, p ));
           color_g.Set(Key<double>( 255.0 *    p, p ));
           color_b.Set(Key<double>( 255.0 *    log(i) / log(color_level_num) , p ));

       }

   color_r.Prepare();
   color_g.Prepare();
   color_b.Prepare();



   std::cout<<mini<<" > "<<maxi<<std::endl;
   for(int y = 0; y < height; ++y)
   {
       for(int x = 0; x < width; ++x)
       {



              //abs = licznik;



             //  m =0.5+ 0.5* sin (  nnn -   (  log2 (  abs ) / log2(radius)      ))  ;
                //m =0.5+ 0.5* sin (  nnn - log (  abs )  );




           // !!! 2 *
           double m = 2 * (licznik[x][y]-mini) / (maxi - mini);





          /*
           double m = 0;
           if(licznik[x][y] < sumi)
           {
               m = (licznik[x][y]-mini) / (sumi - mini);
           } else
           {
                m = (licznik[x][y]-sumi) / (maxi - sumi);
           }
               */


           //
          // std::cout<<"SONDA( "<<x<<", "<<y<<") = "<<m<<std::endl;
                frame.data[frame.step*y + frame.channels()* x + 0] = color_b.GetAbsolute(m);
                frame.data[frame.step*y + frame.channels()* x +1] = color_g.GetAbsolute(m);
                frame.data[frame.step*y + frame.channels()* x + 2] = color_r.GetAbsolute(m);

       }
   }
  // std::cout<<"XXX: "<<xxx<<std::endl;


}
Ejemplo n.º 9
0
void initialize_pop() /* Iniciando la poblacion */
{
	unsigned int i, j;
	switch(function)
	{
		case 100: /* Kita */
			for(i=0; i < popsize; i++)
				for(j =0; j < maxvar; j++)
					popVar[i][j] = RandomDouble(0.0, 7.0);
			break;
		case 200: /* Kursawe */
			for(i=0; i < popsize; i++)
				for(j =0; j < maxvar; j++)
					popVar[i][j] = RandomDouble(-5.0, 5.0);
			break;
		case 300: /* Deb 1 */
			for(i=0; i < popsize; i++)
				for(j =0; j < maxvar; j++)
					popVar[i][j] = RandomDouble(0.1, 0.8191);
			break;
        case 350: /* Deb 2 */
			for(i=0; i < popsize; i++)
				for(j =0; j < maxvar; j++)
					popVar[i][j] = RandomDouble(0.0, 1.0);// 0.8191);
			break;
        case 400: /* Deb 3 */
			for(i=0; i < popsize; i++)
				for(j =0; j < maxvar; j++)
					popVar[i][j] = RandomDouble(0.0, 1.0);
			break;
        case 450: /* Fonseca 2 */
			for(i=0; i < popsize; i++)
				for(j =0; j < maxvar; j++)
					popVar[i][j] = RandomDouble(-4.0, 4.0);
			break;

		case 500: /* DTLZ6 */
			for(i=0; i < popsize; i++)
				for(j =0; j < maxvar; j++)
					popVar[i][j] = RandomDouble(0.0, 1.0);
			break;
        case 600: /* zdt1 */
			for(i=0; i < popsize; i++)
				for(j =0; j < maxvar; j++)
					popVar[i][j] = RandomDouble(-0.0, 1.0);
			break;
        case 605: /* zdt2 */
			for(i=0; i < popsize; i++)
				for(j =0; j < maxvar; j++)
					popVar[i][j] = RandomDouble(0.0, 1.0);
			break;
        case 610: /* zdt3 */
			for(i=0; i < popsize; i++)
				for(j =0; j < maxvar; j++)
					popVar[i][j] = RandomDouble(0.0, 1.0);
			break;
        case 615: /* zdt4 */
			for(i=0; i < popsize; i++)
			{
			    popVar[i][0] = RandomDouble(0.0, 1.0);
			    for(j =1; j < maxvar; j++)
					popVar[i][j] = RandomDouble(-5.0, 5.0);
			}
			break;
        case 620: /* zdt6 */
			for(i=0; i < popsize; i++)
				for(j =0; j < maxvar; j++)
					popVar[i][j] = RandomDouble(0.0, 1.0);
			break;
        case 700: /* dtlz1 */
			for(i=0; i < popsize; i++)
				for(j =0; j < maxvar; j++)
					popVar[i][j] = RandomDouble(0.0, 1.0);
			break;
        case 705: /* dtlz2 */
			for(i=0; i < popsize; i++)
				for(j =0; j < maxvar; j++)
					popVar[i][j] = RandomDouble(0.0, 1.0);
			break;
        case 710: /* dtlz3 */
			for(i=0; i < popsize; i++)
				for(j =0; j < maxvar; j++)
					popVar[i][j] = RandomDouble(0.0, 1.0);
			break;
        case 715: /* dtlz4 */
			for(i=0; i < popsize; i++)
				for(j =0; j < maxvar; j++)
					popVar[i][j] = RandomDouble(0.0, 1.0);
			break;
        case 720: /* dtlz5 */
			for(i=0; i < popsize; i++)
				for(j =0; j < maxvar; j++)
					popVar[i][j] = RandomDouble(0.0, 1.0);
			break;
        case 725: /* dtlz6 */
			for(i=0; i < popsize; i++)
				for(j =0; j < maxvar; j++)
					popVar[i][j] = RandomDouble(0.0, 1.0);
			break;
        case 730: /* dtlz7 */
			for(i=0; i < popsize; i++)
				for(j =0; j < maxvar; j++)
					popVar[i][j] = RandomDouble(0.0, 1.0);
			break;
    /** Agregar maa aqui ***/
	}
}
Ejemplo n.º 10
0
int main(int argc, char *argv[]) {
   char fileName[255];
   FILE *exampleIn, *names;
   ExampleSpecPtr es;
   ExamplePtr e;
   FILE *outputData, *outputTest = NULL;

   _processArgs(argc, argv);

   /* set up the random seed */
   RandomInit();
   if(gSeed != -1) {
      RandomSeed(gSeed);
   }

   /* read the spec file */
   sprintf(fileName, "%s/%s.names", gSourceDirectory, gFileStem);
   /* TODO check that the file exists */
   es = ExampleSpecRead(fileName);
   DebugError(es == 0, "Unable to open the .names file");

   if(!gStdout) {
      /* TODO check that the target directory exists */
      sprintf(fileName, "%s/%s.data", gTargetDirectory, gOutputStem);
      outputData = fopen(fileName, "w");
      DebugError(outputData == 0, "Unable to open output files.");
   } else {
      outputData = stdout;
   }

   if(gOutputTest) {
      /* TODO check that the target directory exists */
      sprintf(fileName, "%s/%s.test", gTargetDirectory, gOutputStem);
      outputTest = fopen(fileName, "w");
      DebugError(outputData == 0, "Unable to open test data output files.");
   }

   if(!gStdin) {
      sprintf(fileName, "%s/%s.data", gSourceDirectory, gFileStem);
      exampleIn = fopen(fileName, "r");
      DebugError(exampleIn == 0, "Unable to open .data file");
   } else {
      exampleIn = stdin;
   }

   e = ExampleRead(exampleIn, es);
   while(e != 0) {
      if(gSamplePercent >= RandomDouble()) {
         ExampleWrite(e, outputData);
      } else if(gOutputTest) {
         ExampleWrite(e, outputTest);
      }

      ExampleFree(e);
      e = ExampleRead(exampleIn, es);
   }
   fclose(exampleIn);


   fclose(outputData);

   /* output the names file */
   /* TODO check that the target directory exists */
   sprintf(fileName, "%s/%s.names", gTargetDirectory, gOutputStem);
   names = fopen(fileName, "w");
   DebugError(names == 0, "Unable to open target names file for output.");

   ExampleSpecWrite(es, names);
   fclose(names);

   return 0;
}
Ejemplo n.º 11
0
double Random::RandomDouble(double x, double y)
{
	return x + (y - x) * RandomDouble();
}
Ejemplo n.º 12
0
uint32 CalculateDamage( UnitPointer pAttacker, UnitPointer pVictim, uint32 weapon_damage_type, SpellEntry* ability ) // spellid is used only for 2-3 spells, that have AP bonus
{
	//TODO: Some awesome formula to determine how much damage to deal
	//consider this is melee damage
	// weapon_damage_type: 0 = melee, 1 = offhand(dualwield), 2 = ranged

	// Attack Power increases your base damage-per-second (DPS) by 1 for every 14 attack power.
	// (c) wowwiki

	//type of this UNIT_FIELD_ATTACK_POWER_MODS is unknown, not even uint32 disabled for now.

	uint32 offset;
	ItemPointer it = NULLITEM;

	if(pAttacker->disarmed && pAttacker->IsPlayer())
	{
		offset=UNIT_FIELD_MINDAMAGE;
		it = TO_PLAYER(pAttacker)->GetItemInterface()->GetInventoryItem(EQUIPMENT_SLOT_MAINHAND);
	}
	else if( weapon_damage_type == MELEE )
		offset = UNIT_FIELD_MINDAMAGE;
	else if( weapon_damage_type == OFFHAND )
		offset = UNIT_FIELD_MINOFFHANDDAMAGE;
	else  // weapon_damage_type == RANGED
		offset = UNIT_FIELD_MINRANGEDDAMAGE;

	float min_damage = pAttacker->GetFloatValue(offset);
	float max_damage = pAttacker->GetFloatValue(offset+1);
	if(it)
	{
		min_damage -= it->GetProto()->Damage[0].Min;
		max_damage -= it->GetProto()->Damage[0].Max;
	}

	float ap = 0;
	float bonus;
	float wspeed;
	float appbonuspct = 1.0f;
	ItemPointer BonusItem = NULLITEM;
	if( pAttacker->IsPlayer() && weapon_damage_type == MELEE )
	{
		BonusItem = TO_PLAYER(pAttacker)->GetItemInterface()->GetInventoryItem(EQUIPMENT_SLOT_MAINHAND);
	}
	else if(pAttacker->IsPlayer() && weapon_damage_type == OFFHAND )
	{
		BonusItem = TO_PLAYER(pAttacker)->GetItemInterface()->GetInventoryItem(EQUIPMENT_SLOT_OFFHAND);
	}
	else if(pAttacker->IsPlayer() && weapon_damage_type == RANGED )
	{
		BonusItem = TO_PLAYER(pAttacker)->GetItemInterface()->GetInventoryItem(EQUIPMENT_SLOT_RANGED);
	}

	if( pAttacker->IsPlayer() && BonusItem )
	{
		appbonuspct = TO_PLAYER(pAttacker)->m_WeaponSubClassDamagePct[ BonusItem->GetProto()->SubClass  ];
	}

	if(offset == UNIT_FIELD_MINRANGEDDAMAGE)
	{
		//starting from base attack power then we apply mods on it
		//ap += pAttacker->GetRAP();
		ap += pVictim->RAPvModifier;

		if(!pVictim->IsPlayer() && TO_CREATURE(pVictim)->GetCreatureName())
		{
			uint32 creatType = TO_CREATURE(pVictim)->GetCreatureName()->Type;
			ap += (float)pAttacker->CreatureRangedAttackPowerMod[creatType];

			if(pAttacker->IsPlayer())
			{
				min_damage = (min_damage + TO_PLAYER(pAttacker)->IncreaseDamageByType[creatType]) * (1 + TO_PLAYER(pAttacker)->IncreaseDamageByTypePCT[creatType]);
				max_damage = (max_damage + TO_PLAYER(pAttacker)->IncreaseDamageByType[creatType]) * (1 + TO_PLAYER(pAttacker)->IncreaseDamageByTypePCT[creatType]);
			}
		}

		if(pAttacker->IsPlayer())
		{
			if(!pAttacker->disarmed)
			{
				ItemPointer it = TO_PLAYER(pAttacker)->GetItemInterface()->GetInventoryItem(EQUIPMENT_SLOT_RANGED);
				if(it)
				{
					wspeed = (float)it->GetProto()->Delay;
				}
				else
					wspeed = 2000;
			}
			else
				wspeed = (float)pAttacker->GetUInt32Value(UNIT_FIELD_RANGEDATTACKTIME);
		}
		else
		{
			wspeed = (float)pAttacker->GetUInt32Value(UNIT_FIELD_BASEATTACKTIME);
		}

		//ranged weapon normalization.
		if(pAttacker->IsPlayer() && ability)
		{
			if(ability->Effect[0] == SPELL_EFFECT_DUMMYMELEE || ability->Effect[1] == SPELL_EFFECT_DUMMYMELEE || ability->Effect[2] == SPELL_EFFECT_DUMMYMELEE)
			{
				wspeed = 2800;
			}
		}

		//Weapon speed constant in feral forms
		if(pAttacker->IsPlayer())
		{
			if(TO_PLAYER(pAttacker)->IsInFeralForm())
			{
				uint8 ss = TO_PLAYER(pAttacker)->GetShapeShift();

				if(ss == FORM_CAT)
					wspeed = 1000.0;
				else if(ss == FORM_DIREBEAR || ss == FORM_BEAR)
					wspeed = 2500.0;
			}
		}

		bonus = (wspeed-pAttacker->GetUInt32Value(UNIT_FIELD_RANGEDATTACKTIME))/14000.0f*ap;
		min_damage += bonus;
		max_damage += bonus;
	}
	else
	{
		//MinD = AP(28AS-(WS/7))-MaxD
		//starting from base attack power then we apply mods on it
		//ap += pAttacker->GetAP();
		ap += pVictim->APvModifier;

		if(!pVictim->IsPlayer() && TO_CREATURE(pVictim)->GetCreatureName())
		{
			uint32 creatType = TO_CREATURE(pVictim)->GetCreatureName()->Type;
			ap += (float)pAttacker->CreatureAttackPowerMod[creatType];

			if(pAttacker->IsPlayer())
			{
				min_damage = (min_damage + TO_PLAYER(pAttacker)->IncreaseDamageByType[creatType]) * (1 + TO_PLAYER(pAttacker)->IncreaseDamageByTypePCT[creatType]);
				max_damage = (max_damage + TO_PLAYER(pAttacker)->IncreaseDamageByType[creatType]) * (1 + TO_PLAYER(pAttacker)->IncreaseDamageByTypePCT[creatType]);
			}
		}

		if(pAttacker->IsPlayer())
		{
			if(!pAttacker->disarmed)
			{
				ItemPointer it = TO_PLAYER(pAttacker)->GetItemInterface()->GetInventoryItem(EQUIPMENT_SLOT_MAINHAND);

				if(it)
					wspeed = (float)it->GetProto()->Delay;
				else
					wspeed = 2000;
			}
			else
				wspeed = (float)pAttacker->GetUInt32Value(UNIT_FIELD_BASEATTACKTIME);

			if(ability && ability->SpellGroupType)
			{
				int32 apall = pAttacker->GetAP();
				/* this spell modifier doesn't exist. also need to clear up how the AP is used here
				int32 apb=0;
				SM_FIValue(pAttacker->SM[SMT_ATTACK_POWER_BONUS][1],&apb,ability->SpellGroupType);

				if(apb)
					ap += apall*((float)apb/100);
				else*/
					ap = float(apall);
			}
		}
		else
		{
			wspeed = (float)pAttacker->GetUInt32Value(UNIT_FIELD_BASEATTACKTIME);
		}

		//Normalized weapon damage checks.
		if(pAttacker->IsPlayer() && ability)
		{
			if(ability->Effect[0] == SPELL_EFFECT_DUMMYMELEE || ability->Effect[1] == SPELL_EFFECT_DUMMYMELEE || ability->Effect[2] == SPELL_EFFECT_DUMMYMELEE)
			{
				it = TO_PLAYER(pAttacker)->GetItemInterface()->GetInventoryItem(EQUIPMENT_SLOT_MAINHAND);

				if(it)
				{
					if(it->GetProto()->Class == ITEM_CLASS_WEAPON) //weapon
					{
						if(it->GetProto()->InventoryType == INVTYPE_2HWEAPON) wspeed = 3300;
						else if(it->GetProto()->SubClass == 15) wspeed = 1700;
						else wspeed = 2400;
					}
				}
			}
		}

		//Weapon speed constant in feral forms
		if(pAttacker->IsPlayer())
		{
			if(TO_PLAYER(pAttacker)->IsInFeralForm())
			{
				uint8 ss = TO_PLAYER(pAttacker)->GetShapeShift();

				if(ss == FORM_CAT)
					wspeed = 1000.0;
				else if(ss == FORM_DIREBEAR || ss == FORM_BEAR)
					wspeed = 2500.0;
			}
		}

		if (offset == UNIT_FIELD_MINDAMAGE)
			bonus = (wspeed-pAttacker->GetUInt32Value(UNIT_FIELD_BASEATTACKTIME))/14000.0f*ap;
		else if( offset == UNIT_FIELD_MINOFFHANDDAMAGE )
			bonus = (wspeed-pAttacker->GetUInt32Value(UNIT_FIELD_BASEATTACKTIME + 1)) / 14000.0f*ap;
		else
			bonus = (wspeed-pAttacker->GetUInt32Value(UNIT_FIELD_RANGEDATTACKTIME))/14000.0f*ap;
		min_damage += bonus;
		max_damage += bonus;
	}

	float diff = fabs(max_damage - min_damage);
	float result = min_damage;

	if(diff >= 1)
		result += float(RandomDouble(diff));

	if(result >= 0)
	{
		return FL2UINT(result * appbonuspct);
	}

	return 0;
}
Ejemplo n.º 13
0
double lambda_loop_psgold(double shift, double scale)
{
int i, j;

double glob_min_gcv, loc_min_gcv, currgcv;
double loc_best_lambda = 0, glob_best_lambda = 0;
double oldgcv, a, b;

glob_min_gcv = INFINITY;

for (j = 0; j < NUMBER_LAMBDA_LOOPS_PSGOLD; j++)
{
     loc_min_gcv = INFINITY;
     for (i = 0; i < NUMBER_LAMBDA_ITER_PSGOLD; i++)
     {
          lambda_psgold = exp(RandomDouble(MIN_LOG_LAMBDA_PSGOLD, MAX_LOG_LAMBDA_PSGOLD)); 
          currgcv = gcv_fit(dat_psgold, sp_psgold, lambda_psgold, MIN_SPACE_PSGOLD);
          if (currgcv < loc_min_gcv)
          {
              loc_best_lambda = lambda_psgold;
              loc_min_gcv = currgcv;
          }
      }

      lambda_psgold = loc_best_lambda;
      currgcv = loc_min_gcv;
      get_pen_1D_spline(dat_psgold, sp_psgold, lambda_psgold);

      if (currgcv < glob_min_gcv)
      {
          glob_best_lambda = lambda_psgold;
          glob_min_gcv = currgcv;
      }

      for(i=0; i<99; i++)
      {
          oldgcv = currgcv;
          a = log(lambda_psgold) + log(LAMBDA_MULT_PSGOLD);
          b = log(lambda_psgold) - log(LAMBDA_MULT_PSGOLD); 
          lambda_psgold = exp(fminbr(a, b, flambda_psgold, LAMBDA_TOL_PSGOLD));
          currgcv = gcv_fit( dat_psgold, sp_psgold, lambda_psgold, MIN_SPACE_PSGOLD );
          if( fabs( (currgcv-oldgcv)/(oldgcv + .0001) ) < .0001 )
	         break;
      }	

      currgcv = gcv_fit(dat_psgold, sp_psgold, lambda_psgold, MIN_SPACE_PSGOLD );

      if (currgcv < glob_min_gcv)
      {
          glob_best_lambda = lambda_psgold;
          glob_min_gcv = currgcv;
      }

}  /* end j loop */

lambda_psgold = glob_best_lambda;
currgcv = gcv_fit(dat_psgold, sp_psgold, lambda_psgold, MIN_SPACE_PSGOLD);

/* printf("The overall best GCV is %e\n", currgcv);
printf("The value of lambda is %e \n", lambda_psgold*pow(scale, 2*sp_psgold->order-2));
for(i=0; i< sp_psgold->n + sp_psgold->order; i++)
      printf("%f ", shift + scale * sp_psgold->knot[i]);
printf("\n\n"); */

return currgcv;
}