本文整理汇总了C++中TPoint::Augment方法的典型用法代码示例。如果您正苦于以下问题:C++ TPoint::Augment方法的具体用法?C++ TPoint::Augment怎么用?C++ TPoint::Augment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TPoint
的用法示例。
在下文中一共展示了TPoint::Augment方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetRandomWeightVector
template < class TProblemSolution > void TPMA < TProblemSolution >::Run()
{
// Callback function
this->Start();
this->MainPopulation.DeleteAll();
this->pNondominatedSet->DeleteAll();
this->FindInitialPopulation();
// Callback function
this->InitialPopulationFound();
MainPopulationSize = this->MainPopulation.size() * this->TempPopulationSize;
// Main loop
unsigned int Iteration = 0;
do
{
// Draw at random new weight vector
this->WeightVector = GetRandomWeightVector();
// Rescale the weight vector
this->WeightVector.Rescale(this->pNondominatedSet->ApproximateIdealPoint,
this->pNondominatedSet->ApproximateNadirPoint);
// Calculate reference point
TPoint TempReferencePoint = this->pNondominatedSet->ApproximateIdealPoint;
TempReferencePoint.Augment(this->pNondominatedSet->ApproximateIdealPoint,
this->pNondominatedSet->ApproximateNadirPoint);
// Find two different solutions for recombination
int TournamentSize = (int) floor(3.0 * this->MainPopulation.size() / (this->TempPopulationSize + 1) + 0.5);
// Parent 1 - the best solution in tournament
// Parent 2 - the second best solution in tournament
TProblemSolution *Parent1 = (TProblemSolution *) this->MainPopulation[rand() % this->MainPopulation.size()];
TProblemSolution *Parent2;
do
{
Parent2 = (TProblemSolution *) this->MainPopulation[rand() % this->MainPopulation.size()];
} while (Parent1 == Parent2);
Parent1->SetScalarizingFunctionType(this->ScalarizingFunctionType);
Parent1->ScalarizingFunctionValue = Parent1->ScalarizingFunction(TempReferencePoint, this->WeightVector);
Parent2->SetScalarizingFunctionType(this->ScalarizingFunctionType);
Parent2->ScalarizingFunctionValue = Parent2->ScalarizingFunction(TempReferencePoint, this->WeightVector);
// Perform tournament
int i;
for (i = 2; i < TournamentSize; i++)
{
TProblemSolution *Challenger =
(TProblemSolution *) this->MainPopulation[rand() % this->MainPopulation.size()];
Challenger->SetScalarizingFunctionType(this->ScalarizingFunctionType);
Challenger->ScalarizingFunctionValue =
Challenger->ScalarizingFunction(TempReferencePoint, this->WeightVector);
if (Challenger->ScalarizingFunctionValue < Parent1->ScalarizingFunctionValue)
{
Parent2 = Parent1;
Parent1 = Challenger;
} else if ((Challenger->ScalarizingFunctionValue < Parent2->ScalarizingFunctionValue)
&& (Parent1 != Challenger))
{
Parent2 = Challenger;
}
}
// Generate new solution by recombination
TListSet < TProblemSolution > TempNondominatedSet;
TProblemSolution *Solution = new TProblemSolution(*Parent1, *Parent2,
this->ScalarizingFunctionType, TempReferencePoint, this->WeightVector, TempNondominatedSet);
// Update the nondominated set
bool bAdded = this->pNondominatedSet->Update(*Solution);
bool bAddedSet = this->pNondominatedSet->Update(TempNondominatedSet);
bAdded = bAdded || bAddedSet;
Solution->ScalarizingFunctionValue = Solution->ScalarizingFunction(TempReferencePoint, this->WeightVector);
bool bBetter = Solution->ScalarizingFunctionValue < Parent2->ScalarizingFunctionValue;
if (bAdded)
{
// Callback function
this->NewNondominatedSolutionFound();
}
// If the new solution is nondominated or better than
// the worst solution in the current population
// Add it to the main population
if (bAdded || bBetter)
{
this->MainPopulation.push_back(Solution);
if (this->MainPopulation.size() > MainPopulationSize)
{
delete((TProblemSolution *) this->MainPopulation[0]);
this->MainPopulation.erase(this->MainPopulation.begin());
}
} else
delete Solution;
// Callback function
//.........这里部分代码省略.........