コード例 #1
0
ファイル: essGoBeyond.c プロジェクト: amirmasoudabdol/eSS
void goBeyond(eSSType *eSSParams, int parent_index,
						void *inp, void *out){

	bool improved;
	int gamma       = 1;
	int improvement = 1;

	// parent = eSSParams->refSet->members[parent_index];
	// child = eSSParams->childsSet->members[parent_index];
	Individual parent;
	Individual child;
	allocate_Ind(eSSParams, &parent);
	allocate_Ind(eSSParams, &child);
	copy_Ind(eSSParams, &parent, &(eSSParams->refSet->members[parent_index]));
	copy_Ind(eSSParams, &child, &(eSSParams->childsSet->members[parent_index]));

	double c1, c2;

	improved = false;
	for(;;) {

		for (int k = 0; k < eSSParams->n_params; ++k){

			c1 = child.params[k] - (parent.params[k] - child.params[k]) / gamma;
			c2 = child.params[k];

			c1 = MAX(eSSParams->min_real_var[k], c1); c1 = MIN(eSSParams->max_real_var[k], c1);
			c2 = MAX(eSSParams->min_real_var[k], c2); c2 = MIN(eSSParams->max_real_var[k], c2);

			// Copying child to parent in time.
			parent.params[k] = child.params[k];
			child.params[k] = c1 + (c2 - c1) * rndreal(0, 1);
		}

		parent.cost = child.cost;

		evaluate_Individual(eSSParams, &child, inp, out);

		if ( child.cost < parent.cost )
		{
			// IMPROVE: Move the copy out of the for, so, there is only one
			// copy needed.
			copy_Ind(eSSParams, &(eSSParams->childsSet->members[parent_index]), &child);

			improved = true;
			improvement++;
			if ( 2 == improvement ){
				improvement = 0;
				gamma /= 2;
			}
			eSSParams->stats->n_successful_goBeyond++;
		}else{
			break;
		}

	}
	deallocate_Ind(eSSParams, &parent);
	deallocate_Ind(eSSParams, &child);

}
コード例 #2
0
void OmniOptOptimizer::initialize_random_pop (OmniOptOptimizer::population *pop)
{
    int i;
    for (i=0; i<popsize; i++)
    {
        int j, k;
        double rand;
        if (nreal!=0)
        {
            for (j=0; j<nreal; j++)
            {
				pop->ind[i].xreal[j] = rndreal (min_realvar[j], max_realvar[j]);
            }
        }
        if (nbin!=0)
        {
            for (i=0; i<popsize; i++)
            {
                for (j=0; j<nbin; j++)
                {
					pop->ind[i].xbin[j] = rndreal (min_binvar[j], max_binvar[j]);
					int l = floor(pop->ind[i].xbin[j]);
					int h = ceil(pop->ind[i].xbin[j]);
					if (h>max_binvar[j]) {
						h=max_binvar[j];
					} else if (l < min_binvar[j]) {
						l=  min_binvar[j];
					}

					if (l!=h) {
						if (randomperc() < 0.5) {
							pop->ind[i].xbin[j] = l;
						} else {
							pop->ind[i].xbin[j] = h;
						}
					} else {
							pop->ind[i].xbin[j] = l;
					}

				}
            }
        }
    }
    return;
}
コード例 #3
0
ファイル: essRecombine.c プロジェクト: amirmasoudabdol/eSS
/**
 * Recombined `ind` with `ind_index` in the refSet with all the other members of refSet
 * and return the index of the best recombined solution that outperform its parent.
 * `-1` means there was not such a solution exist.
 * @param  eSSParams 
 * @param  ind       parent Individual
 * @param  ind_index index of the parent Individual
 * @param  bestInd   
 * @param  inp       
 * @param  out       
 * @return           index of the best candidate that outperform its parent.
 */
int recombine(eSSType *eSSParams, Individual *ind, int ind_index,/* Individual *bestInd,*/
					 void *inp, void *out){

	double c1;
	double c2;
	double d;
	double alpha, beta;

	int p = 0;
	int best_index = -1;
	for (int j = 0; j < eSSParams->n_refSet; ++j)
	{
		if ( j != ind_index ){

			alpha = ( ind_index < j ) ? 1 : -1;
			beta = abs(j - ind_index);

			for (int k = 0; k < eSSParams->n_params; ++k)
			{
				d = eSSParams->refSet->members[j].params[k] - eSSParams->refSet->members[ind_index].params[k];
				c1 = eSSParams->refSet->members[ind_index].params[k] - d * ( 1 + alpha * beta);
				c2 = eSSParams->refSet->members[ind_index].params[k] + d * ( 1 + alpha * beta);
				
				c1 = MAX(eSSParams->min_real_var[k], c1); c1 = MIN(eSSParams->max_real_var[k], c1);
				c2 = MAX(eSSParams->min_real_var[k], c2); c2 = MIN(eSSParams->max_real_var[k], c2);

				eSSParams->candidateSet->members[p].params[k] = c1 + (c2 - c1) * rndreal(0, 1);
			}

			evaluate_Individual(eSSParams, &(eSSParams->candidateSet->members[p]), inp, out);
			eSSParams->candidateSet->members[p].dist   = 0;
			eSSParams->candidateSet->members[p].mean_cost   = 0;
			eSSParams->candidateSet->members[p].var_cost    = 0;
			eSSParams->candidateSet->members[p].n_stuck = 0;

			if ( eSSParams->candidateSet->members[p].cost < eSSParams->refSet->members[ind_index].cost )
				best_index = p;
			
			p++;
		}
	}

	return best_index;

}
コード例 #4
0
ファイル: CCGDE3_MPI.cpp プロジェクト: Glennzhjw/CCEMO
void initializePopulation()
{
	int i,j;
	/* Create indexes */
	for(i=0;i<D;i++){
		indexes[i]= D-1-i;
	}
	/* shuffle indexes */
	shuffle(indexes,D);
	MPI_Bcast(indexes,D,MPI_INT,0,MPI_COMM_WORLD);

	for(i=0;i<NP;i++)
	{
		for(j=0;j<DSp;j++)
		{
			x_variable_sub[i*DSp+j]=
				rndreal(minLimit[indexes[mpi_rank*DSp+j]],maxLimit[indexes[mpi_rank*DSp+j]]);
		}
	}

	return;
}
コード例 #5
0
void OmniOptOptimizer::initialize_latin_pop (OmniOptOptimizer::population *pop)
{
    int i, j, k;
    int *a;
    int temp;
    int rand;
	double random;
    double *grid, *val;
    a = (int *)malloc(popsize*sizeof(int));
    grid = (double *)malloc(nreal*sizeof(double));
    val = (double *)malloc(popsize*sizeof(double));
    if (nreal!=0)
    {
        for (j=0; j<nreal; j++)
        {
            grid[j] = (max_realvar[j]-min_realvar[j])/(double)popsize;
        }
        for (i=0; i<popsize; i++)
        {
            a[i] = i;
        }
        for (j=0; j<nreal; j++)
        {
            for (i=0; i<popsize; i++)
            {
                rand = rnd (i, popsize-1);
                temp = a[rand];
                a[rand] = a[i];
                a[i] = temp;
            }
            for (i=0; i<popsize; i++)
            {
                val[i] = rndreal(min_realvar[j]+grid[j]*i, min_realvar[j]+grid[j]*(i+1));
                if (val[i] < min_realvar[j])
                    val[i] = min_realvar[j];
                if (val[i] > max_realvar[j])
                    val[i] = max_realvar[j];
                pop->ind[a[i]].xreal[j] = val[i];
            }
        }
        if (nbin!=0)
        {
            for (i=0; i<popsize; i++)
            {
                for (j=0; j<nbin; j++)
                {
					pop->ind[i].xbin[j] = rndreal (min_binvar[j], max_binvar[j]);
					int l = floor(pop->ind[i].xbin[j]);
					int h = ceil(pop->ind[i].xbin[j]);
					if (h>max_binvar[j]) {
						h=max_binvar[j];
					} else if (l < min_binvar[j]) {
						l=  min_binvar[j];
					}

					if (l!=h) {
						if (randomperc() < 0.5) {
							pop->ind[i].xbin[j] = l;
						} else {
							pop->ind[i].xbin[j] = h;
						}
					} else {
							pop->ind[i].xbin[j] = l;
					}

				}
            }
        }
    }
    free (a);
    free (grid);
    free (val);
    return;
}