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


C++ Velocity::push_back方法代码示例

本文整理汇总了C++中Velocity::push_back方法的典型用法代码示例。如果您正苦于以下问题:C++ Velocity::push_back方法的具体用法?C++ Velocity::push_back怎么用?C++ Velocity::push_back使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Velocity的用法示例。


在下文中一共展示了Velocity::push_back方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getRandomVelocity

    Velocity Solver::getRandomVelocity()
    {
        Velocity velocity;

        for (int i = 0; i < currentProblem->n; ++i) {
            double randomVariable = getRandomDoubleValue(0.0, 1.0);

            velocity.push_back(randomVariable);
        }

        return velocity;
    }
开发者ID:JeGa,项目名称:mknap_pso,代码行数:12,代码来源:Solver.cpp

示例2: findSolution

    void Solver::findSolution()
    {
        for (auto &i : swarm.getParticles()) {
            Velocity newVelocity;
            Solution newPosition;

            /**
             * Iterate through all dimensions of a Solution/position
             * to calculate the new velocity and update the position.
             *
             * j = dimension
             */
            for (int j = 0; j < currentProblem->n; ++j) {
                int currentPositionD = i.getPosition().at(j);
                double currentVelocityD = i.getVelocity().at(j);

                int pBestD = i.getBestPosition().at(j);
                int gBestD = swarm.getBestPosition().at(j);

                int randomParticleNumber = getRandomIntegerValue(0, 1);
                int randomGlobalNumber = getRandomIntegerValue(0, 1);

                double newVelocityD = parameters.getInertiaWeight() * currentVelocityD +
                                      parameters.getConstant1() * randomParticleNumber * (pBestD - currentPositionD) +
                                      parameters.getConstant2() * randomGlobalNumber * (gBestD - currentPositionD);

                if (newVelocityD > parameters.getVMax())
                    newVelocityD = parameters.getVMax();
                else if (newVelocityD < -parameters.getVMax())
                    newVelocityD = -parameters.getVMax();

                int newPositionD = updateStrategy->updatePosition(currentPositionD, newVelocityD);

                newVelocity.push_back(newVelocityD);
                newPosition.push_back(newPositionD);
            }

            i.setVelocity(newVelocity);
            i.setPosition(newPosition);

            int pBestTmp = calculateProfit(i.getPosition());
            pBestTmp -= calculatePenalty(i.getPosition(), pBestTmp);

            // Update pBest and gBest position/solution
            if (pBestTmp > i.getBestValue()) {
                i.setBestPositionAndValue(i.getPosition(), pBestTmp);

                if (pBestTmp > swarm.getBestValue())
                    swarm.setBestPositionAndValue(i.getPosition(), pBestTmp);
            }
        }
    }
开发者ID:JeGa,项目名称:mknap_pso,代码行数:52,代码来源:Solver.cpp


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