Пример #1
0
 /**
  * Constructor. Creates a new instance of Spea2Fitness for a given <code>SolutionSet</code>.
  *
  * @param solutionSet The <code>SolutionSet</code>
  */
 public Spea2Fitness(SolutionSet solutionSet) {
   distance = distance_.distanceMatrix(solutionSet);
   solutionSet_ = solutionSet;
   for (int i = 0; i < solutionSet_.size(); i++) {
     solutionSet_.get(i).setLocation(i);
   } // for
 } // Spea2Fitness
  /**
   * Performs the operation
   *
   * @param object Object representing a SolutionSet.
   * @return the best solution found
   */
  public Object execute(Object object) {
    SolutionSet solutionSet = (SolutionSet) object;

    if (solutionSet.size() == 0) {
      return null;
    }
    int worstSolution;

    worstSolution = 0;

    for (int i = 1; i < solutionSet.size(); i++) {
      if (comparator_.compare(solutionSet.get(i), solutionSet.get(worstSolution)) > 0)
        worstSolution = i;
    } // for

    return worstSolution;
  } // Execute
Пример #3
0
  /**
   * Performs the operation
   *
   * @param object Object representing a SolutionSet.
   * @return the best solution found
   */
  public Object execute(Object object, CITO_CAITO problem) {
    SolutionSet solutionSet = (SolutionSet) object;

    if (solutionSet.size() == 0) {
      return null;
    }
    int bestSolution;

    bestSolution = 0;

    for (int i = 1; i < solutionSet.size(); i++) {
      if (comparator_.compare(solutionSet.get(i), solutionSet.get(bestSolution)) < 0)
        bestSolution = i;
    } // for

    return bestSolution;
  } // Execute
Пример #4
0
  /**
   * Assigns crowding distances to all solutions in a <code>SolutionSet</code>.
   *
   * @param solutionSet The <code>SolutionSet</code>.
   * @param nObjs Number of objectives.
   */
  public void crowdingDistanceAssignment(SolutionSet solutionSet, int nObjs) {
    int size = solutionSet.size();

    if (size == 0) return;

    if (size == 1) {
      solutionSet.get(0).setCrowdingDistance(Double.POSITIVE_INFINITY);
      return;
    } // if

    if (size == 2) {
      solutionSet.get(0).setCrowdingDistance(Double.POSITIVE_INFINITY);
      solutionSet.get(1).setCrowdingDistance(Double.POSITIVE_INFINITY);
      return;
    } // if

    // Use a new SolutionSet to evite alter original solutionSet
    SolutionSet front = new SolutionSet(size);
    for (int i = 0; i < size; i++) {
      front.add(solutionSet.get(i));
    }

    for (int i = 0; i < size; i++) front.get(i).setCrowdingDistance(0.0);

    double objetiveMaxn;
    double objetiveMinn;
    double distance;

    for (int i = 0; i < nObjs; i++) {
      // Sort the population by Obj n
      front.sort(new ObjectiveComparator(i));
      objetiveMinn = front.get(0).getObjective(i);
      objetiveMaxn = front.get(front.size() - 1).getObjective(i);

      // Set de crowding distance
      front.get(0).setCrowdingDistance(Double.POSITIVE_INFINITY);
      front.get(size - 1).setCrowdingDistance(Double.POSITIVE_INFINITY);

      for (int j = 1; j < size - 1; j++) {
        distance = front.get(j + 1).getObjective(i) - front.get(j - 1).getObjective(i);
        distance = distance / (objetiveMaxn - objetiveMinn);
        distance += front.get(j).getCrowdingDistance();
        front.get(j).setCrowdingDistance(distance);
      } // for
    } // for
  } // crowdingDistanceAssing
Пример #5
0
  protected void addRankedSolutionsToPopulation(Ranking ranking, int rank) throws JMetalException {
    SolutionSet front;

    front = ranking.getSubfront(rank);

    for (int i = 0; i < front.size(); i++) {
      population.add(front.get(i));
    }
  }
Пример #6
0
  /**
   * Returns a matrix with distances between solutions in a <code>SolutionSet</code>.
   *
   * @param solutionSet The <code>SolutionSet</code>.
   * @return a matrix with distances.
   */
  public double[][] distanceMatrix(SolutionSet solutionSet) {
    Solution solutionI, solutionJ;

    // The matrix of distances
    double[][] distance = new double[solutionSet.size()][solutionSet.size()];
    // -> Calculate the distances
    for (int i = 0; i < solutionSet.size(); i++) {
      distance[i][i] = 0.0;
      solutionI = solutionSet.get(i);
      for (int j = i + 1; j < solutionSet.size(); j++) {
        solutionJ = solutionSet.get(j);
        distance[i][j] = this.distanceBetweenObjectives(solutionI, solutionJ);
        distance[j][i] = distance[i][j];
      } // for
    } // for

    // ->Return the matrix of distances
    return distance;
  } // distanceMatrix
Пример #7
0
  protected void addLastRankedSolutions(Ranking ranking, int rank) throws JMetalException {
    SolutionSet currentRankedFront = ranking.getSubfront(rank);

    currentRankedFront.sort(new CrowdingComparator());

    int i = 0;
    while (population.size() < populationSize) {
      population.add(currentRankedFront.get(i));
      i++;
    }
  }
Пример #8
0
 /**
  * Apply a mutation operator to some particles in the swarm
  *
  * @throws jmetal.util.JMException
  */
 private void mopsoMutation(int actualIteration, int totalIterations) throws JMException {
   for (int i = 0; i < particles_.size(); i++) {
     if ((i % 6) == 0) polynomialMutation_.execute(particles_.get(i));
     // if (i % 3 == 0) { //particles_ mutated with a non-uniform mutation %3
     //  nonUniformMutation_.execute(particles_.get(i));
     // } else if (i % 3 == 1) { //particles_ mutated with a uniform mutation operator
     //  uniformMutation_.execute(particles_.get(i));
     // } else //particles_ without mutation
     // ;
   }
 } // mopsoMutation
Пример #9
0
  /**
   * Returns the minimum distance from a <code>Solution</code> to a <code>
   * SolutionSet according to the variable values</code>.
   *
   * @param solution The <code>Solution</code>.
   * @param solutionSet The <code>SolutionSet</code>.
   * @return The minimum distance between solution and the set.
   * @throws JMException
   */
  public double distanceToSolutionSetInSolutionSpace(Solution solution, SolutionSet solutionSet)
      throws JMException {
    // At start point the distance is the max
    double distance = Double.MAX_VALUE;

    // found the min distance respect to population
    for (int i = 0; i < solutionSet.size(); i++) {
      double aux = this.distanceBetweenSolutions(solution, solutionSet.get(i));
      if (aux < distance) distance = aux;
    } // for

    // ->Return the best distance
    return distance;
  } // distanceToSolutionSetInSolutionSpace
Пример #10
0
  /** Assigns fitness for all the solutions. */
  public void fitnessAssign() {
    double[] strength = new double[solutionSet_.size()];
    double[] rawFitness = new double[solutionSet_.size()];
    double kDistance;

    // Calculate the strength value
    // strength(i) = |{j | j <- SolutionSet and i dominate j}|
    for (int i = 0; i < solutionSet_.size(); i++) {
      for (int j = 0; j < solutionSet_.size(); j++) {
        if (dominance_.compare(solutionSet_.get(i), solutionSet_.get(j)) == -1) {
          strength[i] += 1.0;
        } // if
      } // for
    } // for

    // Calculate the raw fitness
    // rawFitness(i) = |{sum strenght(j) | j <- SolutionSet and j dominate i}|
    for (int i = 0; i < solutionSet_.size(); i++) {
      for (int j = 0; j < solutionSet_.size(); j++) {
        if (dominance_.compare(solutionSet_.get(i), solutionSet_.get(j)) == 1) {
          rawFitness[i] += strength[j];
        } // if
      } // for
    } // for

    // Add the distance to the k-th individual. In the reference paper of SPEA2,
    // k = sqrt(population.size()), but a value of k = 1 recommended. See
    // http://www.tik.ee.ethz.ch/pisa/selectors/spea2/spea2_documentation.txt
    int k = 1;
    for (int i = 0; i < distance.length; i++) {
      Arrays.sort(distance[i]);
      kDistance = 1.0 / (distance[i][k] + 2.0); // Calcule de D(i) distance
      // population.get(i).setFitness(rawFitness[i]);
      solutionSet_.get(i).setFitness(rawFitness[i] + kDistance);
    } // for
  } // fitnessAsign
Пример #11
0
  protected SolutionSet evaluatePopulation(SolutionSet population) throws JMetalException {
    evaluations += population.size();

    return evaluator.evaluate(population, problem);
  }
  /**
   * Runs of the Spea2 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 {
    int populationSize, archiveSize, maxEvaluations, evaluations;
    Operator crossoverOperator, mutationOperator, selectionOperator;
    SolutionSet solutionSet, archive, offSpringSolutionSet;

    // Read the params
    populationSize = ((Integer) getInputParameter("populationSize")).intValue();
    archiveSize = ((Integer) getInputParameter("archiveSize")).intValue();
    maxEvaluations = ((Integer) getInputParameter("maxEvaluations")).intValue();

    // Read the operators
    crossoverOperator = operators_.get("crossover");
    mutationOperator = operators_.get("mutation");
    selectionOperator = operators_.get("selection");

    // Initialize the variables
    solutionSet = new SolutionSet(populationSize);
    archive = new SolutionSet(archiveSize);
    evaluations = 0;

    // -> Create the initial solutionSet
    Solution newSolution;
    for (int i = 0; i < populationSize; i++) {
      newSolution = new Solution(problem_);
      problem_.evaluate(newSolution);
      problem_.evaluateConstraints(newSolution);
      evaluations++;
      solutionSet.add(newSolution);
    }

    while (evaluations < maxEvaluations) {
      SolutionSet union = ((SolutionSet) solutionSet).union(archive);
      Spea2Fitness spea = new Spea2Fitness(union);
      spea.fitnessAssign();
      archive = spea.environmentalSelection(archiveSize);
      // Create a new offspringPopulation
      offSpringSolutionSet = new SolutionSet(populationSize);
      Solution[] parents = new Solution[2];
      while (offSpringSolutionSet.size() < populationSize) {
        int j = 0;
        do {
          j++;
          parents[0] = (Solution) selectionOperator.execute(archive);
        } while (j < SPEA2.TOURNAMENTS_ROUNDS); // do-while
        int k = 0;
        do {
          k++;
          parents[1] = (Solution) selectionOperator.execute(archive);
        } while (k < SPEA2.TOURNAMENTS_ROUNDS); // do-while

        // make the crossover
        Solution[] offSpring = (Solution[]) crossoverOperator.execute(parents);
        mutationOperator.execute(offSpring[0]);
        problem_.evaluate(offSpring[0]);
        problem_.evaluateConstraints(offSpring[0]);
        offSpringSolutionSet.add(offSpring[0]);
        evaluations++;
      } // while
      // End Create a offSpring solutionSet
      solutionSet = offSpringSolutionSet;
    } // while

    Ranking ranking = new Ranking(archive);
    return ranking.getSubfront(0);
  } // execute
Пример #13
0
  /** @param args the command line arguments -- modelname, alg_name, evaluation_times, [runid] */
  public static void main(String[] args) throws Exception {

    try {
      String name = args[0];
      URL location = Main.class.getProtectionDomain().getCodeSource().getLocation();
      String loc = location.toString();
      String project_path =
          loc.substring(5, loc.lastIndexOf("SPL/")) + "SPL/"; // with '/' at the end
      String fm = project_path + "dimacs_data/" + name + ".dimacs";
      String augment = fm + ".augment";
      String dead = fm + ".dead";
      String mandatory = fm + ".mandatory";
      String seed = fm + ".richseed";
      String opfile = fm + ".sipop";

      Problem p = new ProductLineProblem(fm, augment, mandatory, dead, seed);
      //            Problem p = new ProductLineProblemNovelPrep(fm, augment, mandatory, dead, seed,
      // opfile);
      //            GroupedProblem.grouping((ProductLineProblem) p, 100); System.exit(0);
      Algorithm a;
      int evaluation_times = Integer.parseInt(args[2]);
      String alg_name = args[1];
      String runid = "";
      if (args.length >= 4) {
        runid = args[3];
      }

      switch (alg_name) {
        case "IBEA":
          a = new SPL_SettingsIBEA(p).configureICSE2013(evaluation_times);
          break;
        case "SIPIBEA":
          a = new SPL_SettingsIBEA(p).configureSIPIBEA(evaluation_times);
          break;
        case "SPEA2":
          a = new SPL_SettingsEMOs(p).configureSPEA2(evaluation_times);
          break;
        case "NSGA2":
          a = new SPL_SettingsEMOs(p).configureNSGA2(evaluation_times);
          break;
        case "IBEASEED":
          a = new SPL_SettingsIBEA(p).configureIBEASEED(evaluation_times);
          break;
        case "SATIBEA":
          // a = new SPL_SettingsIBEA(p).configureICSE15(1000, fm, ((ProductLineProblem)
          // p).getNumFeatures(),
          // ((ProductLineProblem) p).getConstraints());
          a =
              new SPL_SettingsIBEA(p)
                  .configureSATIBEA(
                      evaluation_times,
                      fm,
                      ((ProductLineProblem) p).getNumFeatures(),
                      ((ProductLineProblem) p).getConstraints());
          break;
        default:
          a = new SPL_SettingsIBEA(p).configureICSE2013(evaluation_times);
      }

      long start = System.currentTimeMillis();
      SolutionSet pop = a.execute();
      float total_time = (System.currentTimeMillis() - start) / 1000.0f;

      String file_tag =
          name + "_" + alg_name + '_' + evaluation_times / 1000 + "k_" + runid + ".txt";
      String file_path = project_path + "j_res/" + file_tag;
      File file = new File(file_path);

      if (!file.exists()) {
        file.createNewFile();
      }

      FileWriter fw = new FileWriter(file.getAbsoluteFile());
      BufferedWriter bw = new BufferedWriter(fw);

      for (int i = 0; i < pop.size(); i++) {
        Variable v = pop.get(i).getDecisionVariables()[0];
        bw.write((Binary) v + "\n");
        System.out.println("Conf" + (i + 1) + ": " + (Binary) v + " ");
      }

      bw.write("~~~\n");

      for (int i = 0; i < pop.size(); i++) {
        Variable v = pop.get(i).getDecisionVariables()[0];
        for (int j = 0; j < pop.get(i).getNumberOfObjectives(); j++) {
          bw.write(pop.get(i).getObjective(j) + " ");
          System.out.print(pop.get(i).getObjective(j) + " ");
        }
        bw.write("\n");
        System.out.println("");
      }

      System.out.println(total_time);
      bw.write("~~~\n" + total_time + "\n");

      bw.close();
      fw.close();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #14
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 jmetal.util.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_);
      problem_.evaluate(particle);
      problem_.evaluateConstraints(particle);
      particles_.add(particle);
    }

    // -> 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(SMPSO.class.getName()).log(Level.SEVERE, null, ex);
      }

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

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

      // Evaluate the new particles_ in new positions
      for (int i = 0; i < particles_.size(); i++) {
        Solution particle = particles_.get(i);
        problem_.evaluate(particle);
        problem_.evaluateConstraints(particle);
      }

      // 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_++;
      /*
            if ((iteration_ % 1) == 0) {
              leaders_.printObjectivesOfValidSolutionsToFile("FUNV"+iteration_) ;
              leaders_.printObjectivesToFile("FUN"+iteration_) ;
              leaders_.printVariablesToFile("VAR"+iteration_) ;
            }
      */
    }
    // leaders_.printObjectivesOfValidSolutionsToFile("FUNV.SMPSO") ;
    leaders_.printFeasibleFUN("FUN_SMPSO");

    return this.leaders_;
  } // execute
Пример #15
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;
    globalBest_ =  null ;
    //->Step 1 (and 3) Create the initial population and evaluate
    for (int i = 0; i < particlesSize_; i++) {
      Solution particle = new Solution(problem_);
      problem_.evaluate(particle);
      evaluations_ ++ ;
      particles_.add(particle);
      if ((globalBest_ == null) || (particle.getObjective(0) < globalBest_.getObjective(0)))
        globalBest_ = new Solution(particle) ;
    }

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

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

    //-> Step 7. Iterations ..        
    while (iteration_ < maxIterations_) {
      int bestIndividual = (Integer)findBestSolution_.execute(particles_) ;
      try {
        //Compute the speed_
        computeSpeed(iteration_, maxIterations_);
      } catch (IOException ex) {
        Logger.getLogger(PSO.class.getName()).log(Level.SEVERE, null, ex);
      }

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

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

      //Evaluate the new particles_ in new positions
      evaluations_ += particles_.size();
      finish {		// 
    	  async {
    		  for (int i = 0; i < particles_.size(); i++) {
    			  evaluate_parallel_internal(i);
    		  }
    	  }
      }

      //Actualize the memory of this particle
      for (int i = 0; i < particles_.size(); i++) {
        //int flag = comparator_.compare(particles_.get(i), localBest_[i]);
        //if (flag < 0) { // the new particle is best_ than the older remember        
      	if ((particles_.get(i).getObjective(0) < localBest_[i].getObjective(0))) {
          Solution particle = new Solution(particles_.get(i));
          localBest_[i] = particle;
        } // if
      	if ((particles_.get(i).getObjective(0) < globalBest_.getObjective(0))) {
          Solution particle = new Solution(particles_.get(i));
          globalBest_ = particle;
        } // if
      	
      }
      iteration_++;
    }
    
    // Return a population with the best individual
    SolutionSet resultPopulation = new SolutionSet(1) ;
    resultPopulation.add(particles_.get((Integer)findBestSolution_.execute(particles_))) ;
    
    return resultPopulation ;
  } // execute
Пример #16
0
 protected boolean populationIsNotFull() {
   return population.size() < populationSize;
 }
Пример #17
0
  /**
   * Gets 'size' elements from a population of more than 'size' elements using for this de
   * enviromentalSelection truncation
   *
   * @param size The number of elements to get.
   */
  public SolutionSet environmentalSelection(int size) {

    if (solutionSet_.size() < size) {
      size = solutionSet_.size();
    }

    // Create a new auxiliar population for no alter the original population
    SolutionSet aux = new SolutionSet(solutionSet_.size());

    int i = 0;
    while (i < solutionSet_.size()) {
      if (solutionSet_.get(i).getFitness() < 1.0) {
        aux.add(solutionSet_.get(i));
        solutionSet_.remove(i);
      } else {
        i++;
      } // if
    } // while

    if (aux.size() < size) {
      Comparator comparator = new FitnessComparator();
      solutionSet_.sort(comparator);
      int remain = size - aux.size();
      for (i = 0; i < remain; i++) {
        aux.add(solutionSet_.get(i));
      }
      return aux;
    } else if (aux.size() == size) {
      return aux;
    }

    double[][] distance = distance_.distanceMatrix(aux);
    List<List<DistanceNode>> distanceList = new LinkedList<List<DistanceNode>>();
    for (int pos = 0; pos < aux.size(); pos++) {
      aux.get(pos).setLocation(pos);
      List<DistanceNode> distanceNodeList = new ArrayList<DistanceNode>();
      for (int ref = 0; ref < aux.size(); ref++) {
        if (pos != ref) {
          distanceNodeList.add(new DistanceNode(distance[pos][ref], ref));
        } // if
      } // for
      distanceList.add(distanceNodeList);
    } // for

    for (int q = 0; q < distanceList.size(); q++) {
      Collections.sort(distanceList.get(q), distanceNodeComparator);
    } // for

    while (aux.size() > size) {
      double minDistance = Double.MAX_VALUE;
      int toRemove = 0;
      i = 0;
      Iterator<List<DistanceNode>> iterator = distanceList.iterator();
      while (iterator.hasNext()) {
        List<DistanceNode> dn = iterator.next();
        if (dn.get(0).getDistance() < minDistance) {
          toRemove = i;
          minDistance = dn.get(0).getDistance();
          // i y toRemove have the same distance to the first solution
        } else if (dn.get(0).getDistance() == minDistance) {
          int k = 0;
          while ((dn.get(k).getDistance() == distanceList.get(toRemove).get(k).getDistance())
              && k < (distanceList.get(i).size() - 1)) {
            k++;
          }

          if (dn.get(k).getDistance() < distanceList.get(toRemove).get(k).getDistance()) {
            toRemove = i;
          } // if
        } // if
        i++;
      } // while

      int tmp = aux.get(toRemove).getLocation();
      aux.remove(toRemove);
      distanceList.remove(toRemove);

      Iterator<List<DistanceNode>> externIterator = distanceList.iterator();
      while (externIterator.hasNext()) {
        Iterator<DistanceNode> interIterator = externIterator.next().iterator();
        while (interIterator.hasNext()) {
          if (interIterator.next().getReference() == tmp) {
            interIterator.remove();
            continue;
          } // if
        } // while
      } // while
    } // while
    return aux;
  } // environmentalSelection
Пример #18
0
  /**
   * Runs of the PESA2 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 {
    int archiveSize, bisections, maxEvaluations, evaluations, populationSize;
    AdaptiveGridArchive archive;
    SolutionSet solutionSet;
    Operator crossover, mutation, selection;

    // Read parameters
    populationSize = ((Integer) (inputParameters_.get("populationSize"))).intValue();
    archiveSize = ((Integer) (inputParameters_.get("archiveSize"))).intValue();
    bisections = ((Integer) (inputParameters_.get("bisections"))).intValue();
    maxEvaluations = ((Integer) (inputParameters_.get("maxEvaluations"))).intValue();

    // Get the operators
    crossover = operators_.get("crossover");
    mutation = operators_.get("mutation");

    // Initialize the variables
    evaluations = 0;
    archive = new AdaptiveGridArchive(archiveSize, bisections, problem_.getNumberOfObjectives());
    solutionSet = new SolutionSet(populationSize);
    HashMap parameters = null;
    selection = new PESA2Selection(parameters);

    // -> Create the initial individual and evaluate it and his constraints
    for (int i = 0; i < populationSize; i++) {
      Solution solution = new Solution(problem_);
      problem_.evaluate(solution);
      problem_.evaluateConstraints(solution);
      solutionSet.add(solution);
    }

    // Incorporate non-dominated solution to the archive
    for (int i = 0; i < solutionSet.size(); i++) {
      archive.add(solutionSet.get(i)); // Only non dominated are accepted by
      // the archive
    }

    // Clear the init solutionSet
    solutionSet.clear();

    // Iterations....
    Solution[] parents = new Solution[2];
    do {
      // -> Create the offSpring solutionSet
      while (solutionSet.size() < populationSize) {
        parents[0] = (Solution) selection.execute(archive);
        parents[1] = (Solution) selection.execute(archive);

        Solution[] offSpring = (Solution[]) crossover.execute(parents);
        mutation.execute(offSpring[0]);
        problem_.evaluate(offSpring[0]);
        problem_.evaluateConstraints(offSpring[0]);
        evaluations++;
        solutionSet.add(offSpring[0]);
      }

      for (int i = 0; i < solutionSet.size(); i++) archive.add(solutionSet.get(i));

      // Clear the solutionSet
      solutionSet.clear();

    } while (evaluations < maxEvaluations);
    // Return the  solutionSet of non-dominated individual
    return archive;
  } // execute
Пример #19
0
 protected boolean subfrontFillsIntoThePopulation(Ranking ranking, int rank) {
   return ranking.getSubfront(rank).size() < (populationSize - population.size());
 }
Пример #20
0
  /**
   * @author Juanjo This method selects N solutions from a set M, where N <= M using the same method
   *     proposed by Qingfu Zhang, W. Liu, and Hui Li in the paper describing MOEA/D-DRA (CEC 09
   *     COMPTETITION) An example is giving in that paper for two objectives. If N = 100, then the
   *     best solutions attenting to the weights (0,1), (1/99,98/99), ...,(98/99,1/99), (1,0) are
   *     selected.
   *     <p>Using this method result in 101 solutions instead of 100. We will just compute 100 even
   *     distributed weights and used them. The result is the same
   *     <p>In case of more than two objectives the procedure is: 1- Select a solution at random 2-
   *     Select the solution from the population which have maximum distance to it (whithout
   *     considering the already included)
   * @param n: The number of solutions to return
   * @return A solution set containing those elements
   */
  SolutionSet finalSelection(int n) throws JMException {
    SolutionSet res = new SolutionSet(n);
    if (problem_.getNumberOfObjectives() == 2) { // subcase 1
      double[][] intern_lambda = new double[n][2];
      for (int i = 0; i < n; i++) {
        double a = 1.0 * i / (n - 1);
        intern_lambda[i][0] = a;
        intern_lambda[i][1] = 1 - a;
      } // for

      // we have now the weights, now select the best solution for each of them
      for (int i = 0; i < n; i++) {
        Solution current_best = population.get(0);
        int index = 0;
        double value = fitnessFunction(current_best, intern_lambda[i]);
        for (int j = 1; j < n; j++) {
          double aux =
              fitnessFunction(
                  population.get(j), intern_lambda[i]); // we are looking the best for the weight i
          if (aux < value) { // solution in position j is better!
            value = aux;
            current_best = population.get(j);
          }
        }
        res.add(new Solution(current_best));
      }

    } else { // general case (more than two objectives)

      Distance distance_utility = new Distance();
      int random_index = PseudoRandom.randInt(0, population.size() - 1);

      // create a list containing all the solutions but the selected one (only references to them)
      List<Solution> candidate = new LinkedList<Solution>();
      candidate.add(population.get(random_index));

      for (int i = 0; i < population.size(); i++) {
        if (i != random_index) {
          candidate.add(population.get(i));
        }
      } // for

      while (res.size() < n) {
        int index = 0;
        Solution selected = candidate.get(0); // it should be a next! (n <= population size!)
        double distance_value =
            distance_utility.distanceToSolutionSetInObjectiveSpace(selected, res);
        int i = 1;
        while (i < candidate.size()) {
          Solution next_candidate = candidate.get(i);
          double aux =
              distance_value =
                  distance_utility.distanceToSolutionSetInObjectiveSpace(next_candidate, res);
          if (aux > distance_value) {
            distance_value = aux;
            index = i;
          }
          i++;
        }

        // add the selected to res and remove from candidate list
        res.add(new Solution(candidate.remove(index)));
      } //
    }
    return res;
  }