Beispiel #1
0
int is_link(int now,int from,int to)
{
	int i;
	double t1,t2,t3,t4;
	double tmp_x_now;
	double *indiv1=(double *)malloc(nreal*sizeof(double));
	double *indiv2=(double *)malloc(nreal*sizeof(double));
	for(i=0;i<nreal;i++)
	{
		indiv2[i]=indiv1[i]=low+(high-low)*rand()/RAND_MAX;//low+(high-low)*rand()/RAND_MAX;
	}
	tmp_x_now = low+(high-low)*rand()/RAND_MAX;
	t1 = calc_benchmark_func(indiv1);
	indiv1[now] = tmp_x_now;
	t3 = calc_benchmark_func(indiv1);

	for(i=from;i<to;i++)
	{
		indiv2[i]=low+(high-low)*rand()/RAND_MAX;/*(high-low)*rand()/RAND_MAX; */
	}
	t2 = calc_benchmark_func(indiv2);
	indiv2[now]=tmp_x_now;
	t4 = calc_benchmark_func(indiv2);
	fes+=4;
	free(indiv1);
	free(indiv2);
	/*	printf("%.8f %d %d %d\n",ttt,now,from,to); */
	if(fabs(fabs(t3-t1)-fabs(t4-t2)) > 1.0E-4)
	{
		return 1;
	}
	return 0;
}
Beispiel #2
0
double FloatGA::evaluate( Sprng *sprng_stream, double *temp )
{
  if ( this->fitness != -INF )
    return this->fitness;

  return ( this->fitness =
      -( calc_benchmark_func( sprng_stream, genome, temp ) ) );
}
Beispiel #3
0
void optimization ()
{

	int i,k,t,s,id;
	int count = 0;
	int generation;
	int candidate;

	popInit();

	generation = 0;
	t = s = 0;
	id = -1;
	/*
	printf("NP=%d\n", NP);

	printf("%.8e\n", bestFit);
	*/

	while (fes <= maxFes)
	{	
		/*		for (id = 0; id < GID; ++id) */
		{
			for(candidate = 0; candidate < NP; candidate++)
			{
				for(k = 1; k <= 2; ++k)
				{
					AHDE(candidate,k,id);
					trivalFit = calc_benchmark_func(popTrival);
					//				printf("trivalFit = %lf\n",trivalFit);
					++fes;
					if(trivalFit < popFit[candidate])
					{
						popFit[candidate] = trivalFit;
						for(i = 0; i < nreal; ++i)
						{
							if(groupID[i] == id)
								population[candidate][i] = popTrival[i];		
						}

						if (trivalFit < bestFit)
						{
							bestFit= trivalFit;
							for(i = 0; i < nreal; ++i)
							{
								bestFitVec[i] = popTrival[i];		
							}
						}
						//					printf("t = %d\n", ++t);
						/*					record(fes,fp); */
						break;
					}
					else
					{
						for(i = 0; i < nreal; ++i)
						{
							population[NP+count][i] = popTrival[i];	
						}
						count = (count+1)%NA;
						/*					record(fes,fp); */
						//					printf("s = %d\n", ++s);
					}
				}
			}
		}
//		printf("%d: %.8e\n",++generation, bestFit);
	}
}