Example #1
0
/**
 * Evaluates a solution
 * @param solution The solution to evaluate
 */
void DTLZ7::evaluate(Solution *solution) {
	XReal * vars = new XReal(solution);
  double g = 0.0;

  int k = numberOfVariables_ - numberOfObjectives_ + 1;
  double alpha = 100.0;

  for (int i = 0; i < numberOfVariables_; i++)
    x_[i] = vars->getValue(i);

  for (int i = numberOfVariables_ - k; i < numberOfVariables_; i++)
    g += x_[i] ;

  g = 1 + (9.0 * g)/k ;


  for (int i = 0; i < numberOfObjectives_ - 1; i++)
    fx_[i] = x_[i] ;

  double h = 0.0 ;
  for (int i = 0; i < numberOfObjectives_ - 1; i++){
    h+=(fx_[i]/(1.0+g))*(1 + sin(3.0*M_PI*fx_[i])) ;
  } //for

  h = numberOfObjectives_ - h ;

  fx_[numberOfObjectives_ - 1] = (1+g)*h ;

  for (int i = 0; i < numberOfObjectives_; i++)
    solution->setObjective(i, fx_[i]);

	delete vars ;
} // evaluate
/**
 * Perform the mutation operation
 * @param probability Mutation probability
 * @param solution The solution to mutate
 */
void * PolynomialMutation::doMutation(double probability, Solution *solution) {
    double rnd, delta1, delta2, mut_pow, deltaq;
    double y, yl, yu, val, xy;
    XReal * x = new XReal(solution);

    for (int var=0; var < solution->getNumberOfVariables(); var++) {
        if (PseudoRandom::randDouble() <= probability) {
            y  = x->getValue(var);
            yl = x->getLowerBound(var);
            yu = x->getUpperBound(var);
            delta1 = (y-yl)/(yu-yl);
            delta2 = (yu-y)/(yu-yl);
            rnd = PseudoRandom::randDouble();
            mut_pow = 1.0/(distributionIndex_+1.0);
            if (rnd <= 0.5) {
                xy     = 1.0-delta1;
                val    = 2.0*rnd+(1.0-2.0*rnd)*(pow(xy,(eta_m_+1.0)));
                deltaq = pow(val,mut_pow) - 1.0;
            } else {
                xy     = 1.0-delta2;
                val    = 2.0*(1.0-rnd)+2.0*(rnd-0.5)*(pow(xy,(eta_m_+1.0)));
                deltaq = 1.0 - (pow(val,mut_pow));
            }
            y = y + deltaq*(yu-yl);
            if (y<yl)
                y = yl;
            if (y>yu)
                y = yu;
            x->setValue(var, y);
        }
    } // for

    delete x;

} // doMutation
Example #3
0
/**
 * Evaluates a solution
 * @param solution The solution to evaluate
 */
void DTLZ4::evaluate(Solution *solution) {
	XReal * vars = new XReal(solution);

  int k = numberOfVariables_ - numberOfObjectives_ + 1;
  double alpha = 100.0;

  for (int i = 0; i < numberOfVariables_; i++)
    x_[i] = vars->getValue(i);

  double g = 0.0;
  for (int i = numberOfVariables_ - k; i < numberOfVariables_; i++)
    g += (x_[i] - 0.5)*(x_[i] - 0.5);

  for (int i = 0; i < numberOfObjectives_; i++)
    fx_[i] = 1.0 + g;

  for (int i = 0; i < numberOfObjectives_; i++) {
    for (int j = 0; j < numberOfObjectives_ - (i + 1); j++)
      fx_[i] *= cos(pow(x_[j],alpha)*(PI/2.0));
      if (i != 0){
        int aux = numberOfObjectives_ - (i + 1);
        fx_[i] *= sin(pow(x_[aux],alpha)*(PI/2.0));
      } //if
  } // for

  for (int i = 0; i < numberOfObjectives_; i++)
    solution->setObjective(i, fx_[i]);

	delete vars ;
} // evaluate
Example #4
0
/**
 * Evaluates a solution
 * @param solution The solution to evaluate
 */
void ZDT1::evaluate(Solution *solution) {
	XReal * x = new XReal(solution);

	fx_[0] = x->getValue(0) ;
  double g = evalG(x) ;
  double h = evalH(fx_[0], g) ;
	fx_[1] = h * g ;

	solution->setObjective(0,fx_[0]);
	solution->setObjective(1,fx_[1]);

	delete x ;
} // evaluate
Example #5
0
/**
 * Evaluates a solution
 * @param solution The solution to evaluate
 */
void ZDT6::evaluate(Solution *solution) {
    XReal * x = new XReal(solution);

    double x1 = x->getValue(0) ;
    fx_[0] = 1.0 - exp(-4.0*x1) * pow(sin(6.0*PI*x1), 6.0) ;
    double g = evalG(x) ;
    double h = evalH(fx_[0], g) ;
    fx_[1] = h * g ;

    solution->setObjective(0,fx_[0]);
    solution->setObjective(1,fx_[1]);

    delete x ;
} // evaluate
Example #6
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
Example #7
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_) ;

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

    wmax = WMax_;
    wmin = WMin_;
    
    for (int var = 0; var < particle->size(); var++) {
      //Computing the velocity of this particle
      speed_[i][var] = constrictionCoefficient(C1, C2) *
        (speed_[i][var] +
        C1 * r1 * (bestParticle->getValue(var) - particle->getValue(var)) +
        C2 * r2 * (bestGlobal->getValue(var) - particle->getValue(var)));
    }

    /*
    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
Example #8
0
void LZ09_F1::evaluate(Solution * solution) {
    XReal * vars = new XReal(solution);

    vector<double> * x = new vector<double>(numberOfVariables_) ;
    vector<double> * y = new vector<double>(numberOfObjectives_);

    for (int i = 0; i < numberOfVariables_; i++) {
        x->at(i) = vars->getValue(i);
    } // for
    for (int i = 0; i < numberOfObjectives_; i++) {
        y->at(i) = 0.0 ;
    } // for

    LZ09_->objective(x, y) ;

    for (int i = 0; i < numberOfObjectives_; i++)
        solution->setObjective(i, y->at(i));

    delete x;
    delete y;
    delete vars;
}
Example #9
0
/**
 * Evaluates a solution
 * @param solution The solution to evaluate
 */
void DTLZ5::evaluate(Solution *solution) {
	XReal * vars = new XReal(solution);
  double g = 0.0;

  int k = numberOfVariables_ - numberOfObjectives_ + 1;
  double alpha = 100.0;

  for (int i = 0; i < numberOfVariables_; i++)
    x_[i] = vars->getValue(i);

  for (int i = numberOfVariables_ - k; i < numberOfVariables_; i++)
    g += (x_[i] - 0.5)*(x_[i] - 0.5);

  double t = M_PI  / (4.0 * (1.0 + g));

  theta_[0] = x_[0] * M_PI / 2.0;
  for (int i = 1; i < (numberOfObjectives_-1); i++)
    theta_[i] = t * (1.0 + 2.0 * g * x_[i]);

  for (int i = 0; i < numberOfObjectives_; i++)
    fx_[i] = 1.0 + g;

  for (int i = 0; i < numberOfObjectives_; i++){
    for (int j = 0; j < numberOfObjectives_ - (i + 1); j++)
      fx_[i] *= cos(theta_[j]);
      if (i != 0){
        int aux = numberOfObjectives_ - (i + 1);
        fx_[i] *= sin(theta_[aux]);
      } // if
  } //for

  for (int i = 0; i < numberOfObjectives_; i++)
    solution->setObjective(i, fx_[i]);

	delete vars ;
} // evaluate
Example #10
0
/**
 * Update the position of each particle
 */
void SMPSOhv::computeNewPositions() {

  for (int i = 0; i < swarmSize; i++) {
    XReal * particle = new XReal(particles->get(i));
    for (int var = 0; var < particle->getNumberOfDecisionVariables(); var++) {
      particle->setValue(var, particle->getValue(var) + speed[i][var]);

      if (particle->getValue(var) < problem_->getLowerLimit(var)) {
        particle->setValue(var, problem_->getLowerLimit(var));
        speed[i][var] = speed[i][var] * ChVel1;
      }
      if (particle->getValue(var) > problem_->getUpperLimit(var)){
        particle->setValue(var, problem_->getUpperLimit(var));
        speed[i][var] = speed[i][var] * ChVel2;
      }
    }
    delete particle;
  }

} // computeNewPositions
Example #11
0
File: PSO.cpp Project: wkoder/mocde
/**
 * Update the position of each particle
 */
void PSO::computeNewPositions() {
  for (int i = 0; i < particlesSize_; i++) {
    //Variable ** particle = particles_->get(i)->getDecisionVariables();
    XReal * particle = new XReal(particles_->get(i)) ;
    //particle->move(speed_[i]);
    for (int var = 0; var < particle->size(); var++) {
      particle->setValue(var, particle->getValue(var) +  speed_[i][var]) ;

      if (particle->getValue(var) < problem_->getLowerLimit(var)) {
        particle->setValue(var, problem_->getLowerLimit(var));
        speed_[i][var] = speed_[i][var] * ChVel1_; //
      }
      if (particle->getValue(var) > problem_->getUpperLimit(var)) {
        particle->setValue(var, problem_->getUpperLimit(var));
        speed_[i][var] = speed_[i][var] * ChVel2_; //
      }

    }
    delete particle;
  }
} // computeNewPositions