// constriction coefficient (M. Clerc) private double constrictionCoefficient(double c1, double c2) { double rho = c1 + c2; // rho = 1.0 ; if (rho <= 4) { return 1.0; } else { return 2 / (2 - rho - Math.sqrt(Math.pow(rho, 2.0) - 4.0 * rho)); } } // constrictionCoefficient
/** * Returns the distance between two solutions in objective space. * * @param solutionI The first <code>Solution</code>. * @param solutionJ The second <code>Solution</code>. * @return the distance between solutions in objective space. */ public double distanceBetweenObjectives(Solution solutionI, Solution solutionJ) { double diff; // Auxiliar var double distance = 0.0; // -> Calculate the euclidean distance for (int nObj = 0; nObj < solutionI.numberOfObjectives(); nObj++) { diff = solutionI.getObjective(nObj) - solutionJ.getObjective(nObj); distance += Math.pow(diff, 2.0); } // for // Return the euclidean distance return Math.sqrt(distance); } // distanceBetweenObjectives.
/** * Returns the distance between two solutions in the search space. * * @param solutionI The first <code>Solution</code>. * @param solutionJ The second <code>Solution</code>. * @return the distance between solutions. * @throws JMException */ public double distanceBetweenSolutions(Solution solutionI, Solution solutionJ) throws JMException { // ->Obtain his decision variables Variable[] decisionVariableI = solutionI.getDecisionVariables(); Variable[] decisionVariableJ = solutionJ.getDecisionVariables(); double diff; // Auxiliar var double distance = 0.0; // -> Calculate the Euclidean distance for (int i = 0; i < decisionVariableI.length; i++) { diff = decisionVariableI[i].getValue() - decisionVariableJ[i].getValue(); distance += Math.pow(diff, 2.0); } // for // -> Return the euclidean distance return Math.sqrt(distance); } // distanceBetweenSolutions