/** * 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
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- @Override public void evaluate(Solution solution) { double fitness0 = 0.0; double fitness1 = 0.0; double fitness2 = 0.0; double fitness3 = 0.0; boolean verificador; int x; int y; // percorre o vetor de solucoes for (int i = 0; i < numberOfElements_; i++) { // pega o id da classe x = ((Permutation) solution.getDecisionVariables()[0]).vector_[i]; // percorre as colunas da matrix de dependencia for (int k = 0; k < numberOfElements_; k++) { // verifica se existe dependencia de x para k if (dependency_matrix_[x][k] == 1) { verificador = false; // verifica se a classe já exite for (int j = 0; j <= i; j++) { y = ((Permutation) solution.getDecisionVariables()[0]).vector_[j]; if (y == k) { verificador = true; } } // adiciona os valores ao fitnesse se a classe não tiver sido testada ainda if (verificador == false) { fitness0 += attribute_coupling_matrix_[x][k]; fitness1 += method_coupling_matrix_[x][k]; fitness2 += method_return_type_matrix_[x][k]; fitness3 += method_param_type_matrix_[x][k]; } } } } // System.out.println(fitness0+" "+fitness1+" "+fitness2+" "+fitness3); solution.setObjective(0, fitness0); solution.setObjective(1, fitness1); solution.setObjective(2, fitness2); solution.setObjective(3, fitness3); }
/** * Evaluates a solution * * @param solution The solution to evaluate * @throws JMException */ public void evaluate(Solution solution) throws JMException { DecisionVariables gen = solution.getDecisionVariables(); double[] x = new double[numberOfVariables_]; double[] f = new double[numberOfObjectives_]; double[] theta = new double[numberOfObjectives_ - 1]; int k = numberOfVariables_ - numberOfObjectives_ + 1; for (int i = 0; i < numberOfVariables_; i++) x[i] = gen.variables_[i].getValue(); double g = 0.0; for (int i = numberOfVariables_ - k; i < numberOfVariables_; i++) g += java.lang.Math.pow(x[i], 0.1); double t = java.lang.Math.PI / (4.0 * (1.0 + g)); theta[0] = x[0] * java.lang.Math.PI / 2; for (int i = 1; i < (numberOfObjectives_ - 1); i++) theta[i] = t * (1.0 + 2.0 * g * x[i]); for (int i = 0; i < numberOfObjectives_; i++) f[i] = 1.0 + g; for (int i = 0; i < numberOfObjectives_; i++) { for (int j = 0; j < numberOfObjectives_ - (i + 1); j++) f[i] *= java.lang.Math.cos(theta[j]); if (i != 0) { int aux = numberOfObjectives_ - (i + 1); f[i] *= java.lang.Math.sin(theta[aux]); } // if } // for for (int i = 0; i < numberOfObjectives_; i++) solution.setObjective(i, f[i]); } // evaluate
/** * Evaluates a solution * * @param solution The solution to evaluate * @throws JMException */ public void evaluate(Solution solution) throws JMException { XReal x = new XReal(solution); double[] f = new double[numberOfObjectives_]; double sum1 = 0.0; for (int var = 0; var < numberOfVariables_; var++) { sum1 += StrictMath.pow( x.getValue(var) - (1.0 / StrictMath.sqrt((double) numberOfVariables_)), 2.0); } double exp1 = StrictMath.exp((-1.0) * sum1); f[0] = 1 - exp1; double sum2 = 0.0; for (int var = 0; var < numberOfVariables_; var++) { sum2 += StrictMath.pow( x.getValue(var) + (1.0 / StrictMath.sqrt((double) numberOfVariables_)), 2.0); } double exp2 = StrictMath.exp((-1.0) * sum2); f[1] = 1 - exp2; solution.setObjective(0, f[0]); solution.setObjective(1, f[1]); } // evaluate
/** * Evaluates a solution * * @param solution The solution to evaluate * @throws Exception */ public void evaluate(Solution solution) throws Exception { ProblemVariables decisionVariables = solution.getProblemVariables(); double[] f = new double[numberOfObjectives_]; f[0] = decisionVariables.variables[0].getValue(); double g = this.evalG(decisionVariables); double h = this.evalH(f[0], g); f[1] = h * g; solution.setObjective(0, f[0]); solution.setObjective(1, f[1]); } // evaluate
/** * Evaluates a solution * * @param solution The solution to evaluate * @throws JMException */ public void evaluate(Solution solution) throws JMException { Variable[] variable = solution.getDecisionVariables(); double[] f = new double[numberOfObjectives_]; double x1 = variable[0].getValue(); double x2 = variable[1].getValue(); f[0] = 2.0 + (x1 - 2.0) * (x1 - 2.0) + (x2 - 1.0) * (x2 - 1.0); f[1] = 9.0 * x1 - (x2 - 1.0) * (x2 - 1.0); solution.setObjective(0, f[0]); solution.setObjective(1, f[1]); } // evaluate
/** * Evaluates a solution. * * @param solution The solution to evaluate. * @throws JMException */ public void evaluate(Solution solution) throws JMException { Variable[] decisionVariables = solution.getDecisionVariables(); double[] x = new double[numberOfVariables_]; for (int i = 0; i < numberOfVariables_; i++) x[i] = decisionVariables[i].getValue(); int count1, count2, count3; double sum1, sum2, sum3, yj, hj; sum1 = sum2 = sum3 = 0.0; count1 = count2 = count3 = 0; for (int j = 3; j <= numberOfVariables_; j++) { yj = x[j - 1] - 2.0 * x[1] * Math.sin(2.0 * Math.PI * x[0] + j * Math.PI / numberOfVariables_); hj = 4.0 * yj * yj - Math.cos(8.0 * Math.PI * yj) + 1.0; if (j % 3 == 1) { sum1 += hj; count1++; } else if (j % 3 == 2) { sum2 += hj; count2++; } else { sum3 += hj; count3++; } } solution.setObjective( 0, Math.cos(0.5 * Math.PI * x[0]) * Math.cos(0.5 * Math.PI * x[1]) + 2.0 * sum1 / (double) count1); solution.setObjective( 1, Math.cos(0.5 * Math.PI * x[0]) * Math.sin(0.5 * Math.PI * x[1]) + 2.0 * sum2 / (double) count2); solution.setObjective(2, Math.sin(0.5 * Math.PI * x[0]) + 2.0 * sum3 / (double) count3); } // evaluate
/** * Evaluates a solution * * @param solution The solution to evaluate * @throws JMException */ public void evaluate(Solution solution) throws JMException { Variable[] gen = solution.getDecisionVariables(); Vector<Double> x = new Vector<Double>(numberOfVariables_); Vector<Double> y = new Vector<Double>(numberOfObjectives_); for (int i = 0; i < numberOfVariables_; i++) { x.addElement(gen[i].getValue()); y.addElement(0.0); } // for LZ09_.objective(x, y); for (int i = 0; i < numberOfObjectives_; i++) solution.setObjective(i, y.get(i)); } // evaluate
/** * Evaluates a solution * * @param solution The solution to evaluate * @throws JMException */ public void evaluate(Solution solution) throws JMException { DecisionVariables decisionVariables = solution.getDecisionVariables(); double[] x = new double[numberOfVariables_]; double[] fx = new double[numberOfVariables_]; double g; double h; double sum; for (int i = 0; i < numberOfVariables_; i++) x[i] = decisionVariables.variables_[i].getValue(); fx[0] = x[0]; sum = 0.0; for (int i = 1; i < numberOfVariables_; i++) sum += (x[i] * x[i] - x[0]) * (x[i] * x[i] - x[0]); g = 1.0 + 9.0 * sum / (numberOfVariables_ - 1.0); h = 1.0 - Math.sqrt(x[0] / g); fx[1] = g * h; solution.setObjective(0, fx[0]); solution.setObjective(1, fx[1]); } // evaluate