コード例 #1
2
ファイル: QAP.java プロジェクト: lokolte/ia-2008
  /**
   * Evaluates a solution
   *
   * @param solution The solution to evaluate
   */
  public void evaluate(Solution solution) {
    double fitness1, fitness2;
    int x, y;
    fitness1 = 0.0;
    fitness2 = 0.0;

    for (int i = 0; i < (numberOfCities_); i++) {
      for (int j = 0; j < (numberOfCities_); j++) {
        x = ((Permutation) solution.getDecisionVariables().variables_[0]).vector_[i];
        y = ((Permutation) solution.getDecisionVariables().variables_[0]).vector_[j];

        fitness1 += distanceMatrix_[i][j] * flujo1[x][y];
      }
    }

    for (int i = 0; i < (numberOfCities_); i++) {
      for (int j = 0; j < (numberOfCities_); j++) {
        x = ((Permutation) solution.getDecisionVariables().variables_[0]).vector_[i];
        y = ((Permutation) solution.getDecisionVariables().variables_[0]).vector_[j];

        fitness2 += distanceMatrix_[i][j] * flujo2[x][y];
      }
    }

    solution.setObjective(0, fitness1);
    solution.setObjective(1, fitness2);
  } // evaluate