コード例 #1
0
ファイル: NSGAIISched.java プロジェクト: fmaziere/hcsp-chc
  /**
   * This method is used to evaluate the first population,that it is called after the calling to
   * <code>setup</code> method
   *
   * @throws JMException
   */
  public void evaluatePopulation() throws JMException {
    // NOTEIT First evaluation of the SolutionSet

    int loadingPosition = population_.getLoadingPosition();

    // Commented by Bernabe Dorronsoro
    //		if ( ( specialSolution_ != null ) ){
    //
    //			DecisionVariables[] best = new DecisionVariables[problem_.getNumberOfIslands()-1];
    //
    //			population_.clear();
    //			for( int f=0 ; f<populationSize_ ; ++f) {
    //				DecisionVariables specialDV   = problem_.generateSpecial( specialSolution_ );
    //				if ( f < numberOfSolutions_ ){
    //					for( int i=0 ; i<problem_.getNumberOfIslands() ; ++i ){
    //						if (i<loadingPosition)
    //							best[i] = new DecisionVariables( specialDV.extractSlice(i) );
    //						if (i>loadingPosition)
    //							best[i-1] = new DecisionVariables( specialDV.extractSlice(i) );
    //					} // for
    //
    //					population_.setBestRow( best , f );
    //				} // if
    //
    //				DecisionVariables decisionVar = new DecisionVariables( specialDV.extractSlice(
    // loadingPosition ) );
    //				Solution S = new Solution( problem_ , decisionVar );
    //				population_.add( S );
    //				S.unLink();
    //			} // for
    //
    //		} // if

    Iterator<Solution> it = population_.iterator();
    while (it.hasNext()) {
      Solution tmp = it.next();
      tmp.unLink();
      population_.linkExternalDecisionVariables(tmp);
      problem_.evaluate(tmp, loadingPosition);
      problem_.evaluateConstraints(tmp);
      ++evaluations_;
    } // while

    // population_.printObjectivesToFile( "FUN.S."+loadingPosition );
  } // evaluatePopulation
コード例 #2
0
ファイル: NSGAIISched.java プロジェクト: fmaziere/hcsp-chc
  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