tools/vcachetuner.cpp
// https://en.wikipedia.org/wiki/Differential_evolution
// Good Parameters for Differential Evolution. Magnus Erik Hvass Pedersen, 2010
en.wikipedia.org/wiki/Differential_evolution
Good Parameters for Differential Evolution. Magnus Erik Hvass Pedersen, 2010
en . wikipedia . org / wiki / Differential_evolution Good Parameters for Differential Evolution . Magnus Erik Hvass Pedersen 2010
std::pair<State, float> genN(std::vector<State>& seed, const std::vector<Mesh>& meshes, float crossover = 0.8803f, float weight = 0.4717f)
{
	std::vector<State> result(seed.size());
	for (size_t i = 0; i < seed.size(); ++i)
	{
		for (;;)
		{
			int a = rand32() % seed.size();
			int b = rand32() % seed.size();
			int c = rand32() % seed.size();
			if (a == b || a == c || b == c || a == int(i) || b == int(i) || c == int(i))
				continue;
			int rc = rand32() % kCacheSizeMax;
			int rl = rand32() % kValenceMax;
			for (int j = 0; j < kCacheSizeMax; ++j)
			{
				float r = rand01();
				if (r < crossover || j == rc)
					result[i].cache[j] = std::max(0.f, std::min(1.f, seed[a].cache[j] + weight * (seed[b].cache[j] - seed[c].cache[j])));
				else
					result[i].cache[j] = seed[i].cache[j];
			}
			for (int j = 0; j < kValenceMax; ++j)
			{
				float r = rand01();
				if (r < crossover || j == rl)
					result[i].live[j] = std::max(0.f, std::min(1.f, seed[a].live[j] + weight * (seed[b].live[j] - seed[c].live[j])));
				else
					result[i].live[j] = seed[i].live[j];
			}
			break;
		}
	}
	#pragma omp parallel for
	for (size_t i = 0; i < seed.size(); ++i)
	{
		result[i].fitness = fitness_score(result[i], meshes);
	}
	State best = {};
	float bestfit = 0;
	for (size_t i = 0; i < seed.size(); ++i)
	{
		if (result[i].fitness > seed[i].fitness)
			seed[i] = result[i];
		if (seed[i].fitness > bestfit)
		{
			best = seed[i];
			bestfit = seed[i].fitness;
		}
	}
	return std::make_pair(best, bestfit);
}
std :: pair < State , float > genN ( std :: vector < State > & seed , const std :: vector < Mesh > & meshes , float crossover = 0.8803f , float weight = 0.4717f ) { std :: vector < State > result ( seed . size ( ) ) ; for ( size_t i = 0 ; i < seed . size ( ) ; ++ i ) { for ( ; ; ) { int a = rand32 ( ) % seed . size ( ) ; int b = rand32 ( ) % seed . size ( ) ; int c = rand32 ( ) % seed . size ( ) ; if ( a == b || a == c || b == c || a == int ( i ) || b == int ( i ) || c == int ( i ) ) continue ; int rc = rand32 ( ) % kCacheSizeMax ; int rl = rand32 ( ) % kValenceMax ; for ( int j = 0 ; j < kCacheSizeMax ; ++ j ) { float r = rand01 ( ) ; if ( r < crossover || j == rc ) result [ i ] . cache [ j ] = std :: max ( 0.f , std :: min ( 1.f , seed [ a ] . cache [ j ] + weight * ( seed [ b ] . cache [ j ] - seed [ c ] . cache [ j ] ) ) ) ; else result [ i ] . cache [ j ] = seed [ i ] . cache [ j ] ; } for ( int j = 0 ; j < kValenceMax ; ++ j ) { float r = rand01 ( ) ; if ( r < crossover || j == rl ) result [ i ] . live [ j ] = std :: max ( 0.f , std :: min ( 1.f , seed [ a ] . live [ j ] + weight * ( seed [ b ] . live [ j ] - seed [ c ] . live [ j ] ) ) ) ; else result [ i ] . live [ j ] = seed [ i ] . live [ j ] ; } break ; } } #pragma  omp parallel for for ( size_t i = 0 ; i < seed . size ( ) ; ++ i ) { result [ i ] . fitness = fitness_score ( result [ i ] , meshes ) ; } State best = { } ; float bestfit = 0 ; for ( size_t i = 0 ; i < seed . size ( ) ; ++ i ) { if ( result [ i ] . fitness > seed [ i ] . fitness ) seed [ i ] = result [ i ] ; if ( seed [ i ] . fitness > bestfit ) { best = seed [ i ] ; bestfit = seed [ i ] . fitness ; } } return std :: make_pair ( best , bestfit ) ; }
https://en.wikipedia.org/wiki/Differential_evolution
Good Parameters for Differential Evolution.
https : // en . wikipedia . org / wiki / Differential_evolution Good Parameters for Differential Evolution .