Пример #1
0
  public void postGeneration() {
    // Create the solutionSet union of solutionSet and offSpring
    union_ = ((SolutionSet) population_).union(offspringPopulation_);

    // Ranking the union
    Ranking ranking = new Ranking(union_);

    if (ranking.getNumberOfSubfronts() == 0) System.out.println("No hay subfrentes!!");

    int remain = populationSize_;
    int index = 0;
    SolutionSet front = null;
    population_.clear();

    // Obtain the next front
    front = ranking.getSubfront(index);

    while ((remain > 0) && (remain >= front.size())) {
      // Assign crowding distance to individuals
      distance_.crowdingDistanceAssignment(front, problem_.getNumberOfObjectives());
      // Add the individuals of this front
      for (int k = 0; k < front.size(); k++) {
        population_.add(front.get(k));
      } // for

      // Decrement remain
      remain = remain - front.size();

      // Obtain the next front
      index++;
      if (remain > 0) {
        front = ranking.getSubfront(index);
      } // if
    } // while

    // Remain is less than front(index).size, insert only the best one
    if (remain > 0) { // front contains individuals to insert
      distance_.crowdingDistanceAssignment(front, problem_.getNumberOfObjectives());
      front.sort(new jmetal.coevolutionary.base.operator.comparator.CrowdingComparator());
      for (int k = 0; k < remain; k++) {
        population_.add(front.get(k));
      } // for

      remain = 0;
    } // if

    // This piece of code shows how to use the indicator object into the code
    // of NSGA-II. In particular, it finds the number of evaluations required
    // by the algorithm to obtain a Pareto front with a hypervolume higher
    // than the hypervolume of the true Pareto front.
    if ((indicators_ != null) && (requiredEvaluations_ == 0)) {
      double HV = indicators_.getHypervolume(population_);
      if (HV >= (0.98 * indicators_.getTrueParetoFrontHypervolume())) {
        requiredEvaluations_ = evaluations_;
      } // if
    } // if

    prepareBestSolutions();
  } // postGeneration
Пример #2
0
  public void setup(int islandId) throws JMException {
    islandID_ = islandId;

    distance_ = new Distance();

    // Read the parameters
    indicators_ = (QualityIndicator) this.getInputParameter("indicators");

    islands_ = ((Integer) getInputParameter("numberOfIslands")).intValue();
    populationSize_ = ((Integer) getInputParameter("populationSize")).intValue();
    maxEvaluations_ = ((Integer) getInputParameter("maxEvaluations")).intValue();
    numberOfSolutions_ = ((Integer) getInputParameter("numberOfSolutions")).intValue();
    bestSolutionsFirstLevel_ = ((Integer) getInputParameter("bestSolutionsFirstLevel")).intValue();
    specialSolution_ = ((String) getInputParameter("specialSolution"));
    mergeSolution_ = ((Integer) this.getInputParameter("mergeSolution")).intValue();

    // Initialize the variables
    population_ =
        new SolutionSet(islandId, islands_, numberOfSolutions_, populationSize_, mergeSolution_);
    evaluations_ = 0;
    // bestSolutions = new Solution[islands-1];

    requiredEvaluations_ = 0;

    // Read the operators
    mutationOperator_ = operators_.get("mutation");
    crossoverOperator_ = operators_.get("crossover");
    selectionOperator_ = operators_.get("selection");
    localSearchOperator_ = operators_.get("localsearch");

    // NOTEIT Creation of the SolutionSet of the Islands
    // Create the initial solutionSet
    Solution newSolution = null;

    //		for( int i=0 ; i<populationSize_ ; ++i) {
    //			newSolution = new Solution( problem_ );
    //			population_.add( newSolution );
    //		} // for

    int minminInit =
        PseudoRandom.randInt(0, populationSize_ - 1); // To initialize one individual with min-min

    for (int i = 0; i < populationSize_; i++) {
      if (specialSolution_ == null) {
        newSolution = new Solution(problem_);
      } // if
      else if (specialSolution_.contains("OneMinmin")) {
        if (minminInit == i) {
          // int [] vars = ScheduleStrategy.minMin(ETC_, numberOfTasks, numberOfMachines)
          DecisionVariables specialDV = problem_.generateSpecial(specialSolution_, islandId);
          newSolution = new Solution(problem_, specialDV);
        } else newSolution = new Solution(problem_);
      } else if (specialSolution_.equalsIgnoreCase("Min-Min")) {
        DecisionVariables specialDV = problem_.generateSpecial(specialSolution_, islandId);
        newSolution = new Solution(problem_, specialDV);
      } // else
      //			problem_.evaluate( newSolution );
      //			problem_.evaluateConstraints( newSolution );
      population_.add(newSolution);
      newSolution.setLocation(i);
      //			evaluations++;
    } // for

    prepareSetupBestSolutions();
  } // setup
Пример #3
0
  public void generation() throws JMException {

    //		if ( ( (evaluations_%4000) == 0 ) && (population_.getLoadingPosition()==0) ){
    //			String file = "FUN." + ((int) evaluations_/4000 );
    //			population_.printObjectivesToFile( file );
    //		} // if

    // Create the offSpring solutionSet
    int loadingPosition = population_.getLoadingPosition();

    //		System.out.println("Isla: " + loadingPosition + "Numero de islas: " + islands_ + "Numero de
    // variables: " + problem_.getNumberOfVariables());

    offspringPopulation_ =
        new SolutionSet(
            loadingPosition, islands_, numberOfSolutions_, populationSize_, mergeSolution_);
    // Link the external dv's
    offspringPopulation_.setBestExternResults(population_);
    Solution[] parents = new Solution[2];
    for (int i = 0; i < (populationSize_ / 2); i++) {
      // obtain parents
      Object obj = selectionOperator_.execute(population_, loadingPosition);

      if (obj.getClass()
          .getCanonicalName()
          .toString()
          .equalsIgnoreCase(Solution.class.getCanonicalName().toString())) {
        parents[0] = (Solution) obj;
        parents[1] = (Solution) selectionOperator_.execute(population_, loadingPosition);
      } // if
      else {
        parents = (Solution[]) obj;
      } // else

      if (evaluations_ < maxEvaluations_) {
        Solution[] offSpring = (Solution[]) crossoverOperator_.execute(parents, loadingPosition);

        offSpring[0].unLink();
        offSpring[1].unLink();

        mutationOperator_.execute(offSpring[0], loadingPosition);
        mutationOperator_.execute(offSpring[1], loadingPosition);

        if (localSearchOperator_ != null) {
          localSearchOperator_.execute(offSpring[0], loadingPosition);
          //					evaluations_ += localSearchOperator_.getEvaluations();
          localSearchOperator_.execute(offSpring[1], loadingPosition);
          //					evaluations_ += localSearchOperator_.getEvaluations();
        } // if

        population_.linkExternalDecisionVariables(offSpring[0]);
        population_.linkExternalDecisionVariables(offSpring[1]);

        problem_.evaluate(offSpring[0], loadingPosition);
        problem_.evaluateConstraints(offSpring[0]);
        problem_.evaluate(offSpring[1], loadingPosition);
        problem_.evaluateConstraints(offSpring[1]);

        offspringPopulation_.add(offSpring[0]);
        offspringPopulation_.add(offSpring[1]);
        evaluations_ += 2;
      } // if
      else {
        offspringPopulation_.add(new Solution(parents[0]));
        offspringPopulation_.add(new Solution(parents[1]));
      } // else
    } // for
  } // generation