Exemple #1
0
/**
 * Update the speed of each particle
 */
void SMPSOhv::computeSpeed(int iter, int miter) {
  double r1, r2, W, C1, C2;
  double wmax, wmin;
  XReal *bestGlobal;

  for (int i = 0; i < swarmSize; i++) {
    XReal *particle     = new XReal(particles->get(i));
    XReal *bestParticle = new XReal(best[i]);

    //Select a global best for calculate the speed of particle i, bestGlobal
    Solution *one, *two;
    int pos1 = PseudoRandom::randInt(0,leaders->size()-1);

    //int pos1 = PseudoRandom::randInt(0,leaders->size()-1);
    int pos2 = PseudoRandom::randInt(0,leaders->size()-1);
    one = leaders->get(pos1);
    two = leaders->get(pos2);

    if (crowdingDistanceComparator->compare(one,two) < 1) {
      bestGlobal = new XReal(one);
    } else {
      bestGlobal = new XReal(two);
    }

    //Params for velocity equation
    r1 = PseudoRandom::randDouble(r1Min, r1Max);
    r2 = PseudoRandom::randDouble(r2Min, r2Max);
    C1 = PseudoRandom::randDouble(C1Min, C1Max);
    C2 = PseudoRandom::randDouble(C2Min, C2Max);
    W  = PseudoRandom::randDouble(WMin, WMax);

    wmax = WMax;
    wmin = WMin;

    for (int var = 0; var < particle->getNumberOfDecisionVariables(); var++) {
      //Computing the velocity of this particle
      speed[i][var] = velocityConstriction(constrictionCoefficient(C1, C2) *
                  (inertiaWeight(iter, miter, wmax, wmin) *
                      speed[i][var] +
                      C1 * r1 * (bestParticle->getValue(var) -
                          particle->getValue(var)) +
                          C2 * r2 * (bestGlobal->getValue(var) -
                              particle->getValue(var))), deltaMax,
                              deltaMin,
                              var,
                              i);
    }
    delete bestGlobal;
    delete particle;
    delete bestParticle;
  }
} // computeSpeed
Exemple #2
0
/**
 * Update the speed of each particle
 */
void PSO::computeSpeed(int iter, int miter) {
  double r1, r2;
  //double W ;
  double C1, C2;
  double wmax, wmin, deltaMax, deltaMin;
  XReal * bestGlobal;

  bestGlobal = new XReal(globalBest_) ;

  for (int i = 0; i < particlesSize_; i++) {
    XReal * particle = new XReal(particles_->get(i)) ;
    XReal * bestParticle = new XReal(localBest_[i]) ;

    //int bestIndividual = findBestSolution_->execute(particles_) ;

    C1Max_ = 2.5;
    C1Min_ = 1.5;
    C2Max_ = 2.5;
    C2Min_ = 1.5;

    r1 = PseudoRandom::randDouble(r1Min_, r1Max_);
    r2 = PseudoRandom::randDouble(r2Min_, r2Max_);
    C1 = PseudoRandom::randDouble(C1Min_, C1Max_);
    C2 = PseudoRandom::randDouble(C2Min_, C2Max_);
    //W =  PseudoRandom.randDouble(WMin_, WMax_);
    //

    WMax_ = 0.9;
    WMin_ = 0.9;
    ChVel1_ = 1.0;
    ChVel2_ = 1.0;

    C1 = 2.5;
    C2 = 1.5;

    wmax = WMax_;
    wmin = WMin_;
/*
    for (int var = 0; var < particle.size(); var++) {
      //Computing the velocity of this particle
      speed_[i][var] = velocityConstriction(constrictionCoefficient(C1, C2) *
        (inertiaWeight(iter, miter, wmax, wmin) *
        speed_[i][var] +
        C1 * r1 * (bestParticle.getValue(var) - particle.getValue(var)) +
        C2 * r2 * (bestGlobal.getValue(var) -
        particle.getValue(var))), deltaMax_,
        deltaMin_, //[var],
        var,
        i);
    }
*/
    C1 = 1.5;
    C2 = 1.5;
    double W = 0.9;
    for (int var = 0; var < particle->size(); var++) {
      //Computing the velocity of this particle
      speed_[i][var] = inertiaWeight(iter, miter, wmax, wmin) * speed_[i][var] +
        C1 * r1 * (bestParticle->getValue(var) - particle->getValue(var)) +
        C2 * r2 * (bestGlobal->getValue(var) - particle->getValue(var)) ;
    }

    delete particle;
    delete bestParticle;

  }

  delete bestGlobal;

} // computeSpeed