当前位置: 首页>>代码示例>>C++>>正文


C++ TPoint::Augment方法代码示例

本文整理汇总了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
//.........这里部分代码省略.........
开发者ID:derino,项目名称:maponoc,代码行数:101,代码来源:pma.cpp


注:本文中的TPoint::Augment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。