Ejemplo n.º 1
0
  /**
   * Update the speed of each particle
   *
   * @throws JMException
   */
  private void computeSpeed(int iter, int miter) throws JMException, IOException {
    double r1, r2, W, C1, C2;
    double wmax, wmin, deltaMax, deltaMin;
    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 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_, // [var],
                deltaMin_, // [var],
                var,
                i);
      }
    }
  } // computeSpeed
Ejemplo n.º 2
0
  /**
   * Runs of the SMPSO algorithm.
   *
   * @return a <code>SolutionSet</code> that is a set of non dominated solutions as a result of the
   *     algorithm execution
   * @throws JMException
   */
  public SolutionSet execute() throws JMException, ClassNotFoundException {
    initParams();
    success_ = false;
    // ->Step 1 (and 3) Create the initial population and evaluate
    for (int i = 0; i < swarmSize_; i++) {
      Solution particle = new Solution(problem_);
      particles_.add(particle);
      parallelEvaluator_.addSolutionForEvaluation(particle);
    }

    parallelEvaluator_.parallelEvaluation();

    // -> Step2. Initialize the speed_ of each particle to 0
    for (int i = 0; i < swarmSize_; i++) {
      for (int j = 0; j < problem_.getNumberOfVariables(); j++) {
        speed_[i][j] = 0.0;
      }
    }

    // Step4 and 5
    for (int i = 0; i < particles_.size(); i++) {
      Solution particle = new Solution(particles_.get(i));
      leaders_.add(particle);
    }

    // -> Step 6. Initialize the memory of each particle
    for (int i = 0; i < particles_.size(); i++) {
      Solution particle = new Solution(particles_.get(i));
      best_[i] = particle;
    }

    // Crowding the leaders_
    distance_.crowdingDistanceAssignment(leaders_, problem_.getNumberOfObjectives());

    // -> Step 7. Iterations ..
    while (iteration_ < maxIterations_) {

      try {
        // Compute the speed_
        computeSpeed(iteration_, maxIterations_);
      } catch (IOException ex) {
        Logger.getLogger(SMPSODDSteadyState.class.getName()).log(Level.SEVERE, null, ex);
      }

      // Compute the new positions for the particles_
      computeNewPositions();

      // Mutate the particles_
      mopsoMutation(iteration_, maxIterations_);

      for (int i = 0; i < particles_.size(); i++) {
        Solution particle = particles_.get(i);
        parallelEvaluator_.addSolutionForEvaluation(particle);
      }

      parallelEvaluator_.parallelEvaluation();

      // Actualize the archive
      for (int i = 0; i < particles_.size(); i++) {
        Solution particle = new Solution(particles_.get(i));
        leaders_.add(particle);
      }

      // Actualize the memory of this particle
      for (int i = 0; i < particles_.size(); i++) {
        int flag = dominance_.compare(particles_.get(i), best_[i]);
        if (flag != 1) { // the new particle is best_ than the older remeber
          Solution particle = new Solution(particles_.get(i));
          best_[i] = particle;
        }
      }

      // Assign crowding distance to the leaders_
      distance_.crowdingDistanceAssignment(leaders_, problem_.getNumberOfObjectives());
      iteration_++;
    }

    parallelEvaluator_.stopEvaluator();
    return this.leaders_;
  } // execute