mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-09 13:40:46 +01:00
Hadrons: genetic pair selection based on exponential probability
This commit is contained in:
parent
59aae5f5ec
commit
01f00385a4
@ -212,28 +212,23 @@ typename GeneticScheduler<T>::GenePair GeneticScheduler<T>::selectPair(void)
|
|||||||
std::vector<double> prob;
|
std::vector<double> prob;
|
||||||
unsigned int ind;
|
unsigned int ind;
|
||||||
Gene *p1, *p2;
|
Gene *p1, *p2;
|
||||||
|
const double max = population_.rbegin()->first;
|
||||||
|
|
||||||
|
|
||||||
for (auto &c: population_)
|
for (auto &c: population_)
|
||||||
{
|
{
|
||||||
prob.push_back(1./c.first);
|
prob.push_back(std::exp((c.first-1.)/max));
|
||||||
}
|
}
|
||||||
do
|
std::discrete_distribution<unsigned int> dis1(prob.begin(), prob.end());
|
||||||
{
|
auto rIt = population_.begin();
|
||||||
double probCpy;
|
ind = dis1(gen_);
|
||||||
|
std::advance(rIt, ind);
|
||||||
std::discrete_distribution<unsigned int> dis1(prob.begin(), prob.end());
|
p1 = &(rIt->second);
|
||||||
auto rIt = population_.begin();
|
prob[ind] = 0.;
|
||||||
ind = dis1(gen_);
|
std::discrete_distribution<unsigned int> dis2(prob.begin(), prob.end());
|
||||||
std::advance(rIt, ind);
|
rIt = population_.begin();
|
||||||
p1 = &(rIt->second);
|
std::advance(rIt, dis2(gen_));
|
||||||
probCpy = prob[ind];
|
p2 = &(rIt->second);
|
||||||
prob[ind] = 0.;
|
|
||||||
std::discrete_distribution<unsigned int> dis2(prob.begin(), prob.end());
|
|
||||||
rIt = population_.begin();
|
|
||||||
std::advance(rIt, dis2(gen_));
|
|
||||||
p2 = &(rIt->second);
|
|
||||||
prob[ind] = probCpy;
|
|
||||||
} while (p1 == p2);
|
|
||||||
|
|
||||||
return std::make_pair(p1, p2);
|
return std::make_pair(p1, p2);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user