本文整理汇总了C++中Binary::update方法的典型用法代码示例。如果您正苦于以下问题:C++ Binary::update方法的具体用法?C++ Binary::update怎么用?C++ Binary::update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Binary
的用法示例。
在下文中一共展示了Binary::update方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mate
/*
Step 1: Let zi := xi for i =1,2, ...,n (i.e., z is a copy of the
primary parent x).
Step 2: Let zi := (1 - zi) with a probability PBF when xi = yi
where PBF is a prespecified bit-flip probability.
Note: Random primary parent selection
*/
bool BinaryCrsNonGeometric::mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
{
Binary* p1 = (Binary*) (gen1.get());
Binary* p2 = (Binary*) (gen2.get());
Binary* ch = (Binary*) (child.get());
double PBF = 0.5; //prespecified bit-flip probability
//Step 1
for (uint dimension = 0; dimension < p1->variables.size(); dimension++) {
switch (state_->getRandomizer()->getRandomInteger(0, 1)) {
case 0: for (uint i = 0; i < p1->getNumBits(); i++) {
ch->variables[dimension][i] = p1->variables[dimension][i];
}
break;
case 1: for (uint i = 0; i < p2->getNumBits(); i++) {
ch->variables[dimension][i] = p2->variables[dimension][i];
}
}
//Step 2
for(uint i = 0; i < p1->getNumBits(); i++) {
if (p1->variables[dimension][i] == p2->variables[dimension][i]) {
double changeProbability = state_->getRandomizer()->getRandomDouble();
if (changeProbability > PBF)
ch->variables[dimension][i] = ch->variables[dimension][i] ? false:true;
}
}
}
// update integer and real domain representation
ch->update();
return true;
}