Beispiel #1
0
void Raw::onBotnetcmd(const char *from, const char *cmd)
{
    char arg[2][MAX_LEN], *text;

    str2words(arg[0], cmd, 2, MAX_LEN, 0);

    if(!strcasecmp(arg[1], "raw"))
    {
        text=srewind(cmd, 2);

        if(text && *text)
        {
            if(penalty<10)
            {
                net.irc.send(text, NULL);
                penalty+=calculatePenalty(text);
            }

            else
                net.sendOwner(arg[0], "[raw] Penalty is too high. Please wait a while and try again.", NULL);
        }

        else
            net.sendOwner(arg[0], "[raw] Syntax: .bc ", (const char*) config.handle, " raw <text>", NULL);
    }
}
Beispiel #2
0
    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);
            }
        }
    }
Beispiel #3
0
    void Solver::initializeParticles()
    {
        // Initialize the swarms best position with the lowest value.

        for (auto &i : swarm.getParticles()) {
            Solution position = getRandomSolution();
            Velocity velocity = getRandomVelocity();

            i.setPosition(position);
            i.setVelocity(velocity);

            // Fitness value / Profit of the solution/position.
            int profit = calculateProfit(position);
            profit -= calculatePenalty(position, profit);

            i.setBestPositionAndValue(position, profit);

            // Check if this solution is better than the global solution.
            if (!swarm.isGBestInitialized())
                swarm.setBestPositionAndValue(position, profit);
            else if (profit > swarm.getBestValue())
                swarm.setBestPositionAndValue(position, profit);
        }
    }