Exemplo n.º 1
0
 public static Individual mutateIndividual(Individual individualtoMutate) {
   // small change delta
   double delta = 0.001;
   Double[] individualtoMutateArray = individualtoMutate.getValues();
   // initialize the neighbor solution
   Double[] mutatedIndividual = new Double[Constants.DIMENSIONS];
   Arrays.fill(mutatedIndividual, 0.0);
   Individual mutatedIndv = new Individual();
   // loop and change values of neighbor
   // solution based on problem set
   for (int i = 0; i < individualtoMutateArray.length; i++) {
     if (individualtoMutateArray[i] < 1.00 && checkLimitCondition(individualtoMutateArray[i])) {
       mutatedIndividual[i] =
           DoubleFormatter.getFormattedDouble(individualtoMutateArray[i] + delta, FUNCTION_NAME);
     } else if (individualtoMutateArray[i] > 1.00
         && checkLimitCondition(individualtoMutateArray[i])) {
       mutatedIndividual[i] =
           DoubleFormatter.getFormattedDouble(individualtoMutateArray[i] - delta, FUNCTION_NAME);
     } else {
       mutatedIndividual[i] =
           DoubleFormatter.getFormattedDouble(individualtoMutateArray[i], FUNCTION_NAME);
     }
   }
   mutatedIndv.setValues(mutatedIndividual);
   mutatedIndv.setFitnessValue(getfitnessValueNP(mutatedIndividual));
   // return changed neighbor array
   return mutatedIndv;
 }
Exemplo n.º 2
0
 public static Double getfitnessValueNP(Double[] individual) {
   Double tempVar = 0.0;
   for (int i = 0; i < (individual.length - 1); i++) {
     tempVar +=
         (Math.pow((1 - individual[i]), 2)
             + 100 * Math.pow((individual[i + 1] - Math.pow(individual[i], 2)), 2));
   }
   return DoubleFormatter.getFormattedDouble(tempVar, FUNCTION_NAME);
 }
Exemplo n.º 3
0
 public static double getfitnessValue(double[] varArray) {
   double tempVar = 0.0;
   for (int i = 0; i < (varArray.length - 1); i++) {
     tempVar +=
         (Math.pow((1 - varArray[i]), 2)
             + 100 * Math.pow((varArray[i + 1] - Math.pow(varArray[i], 2)), 2));
   }
   return DoubleFormatter.getFormattedDouble(tempVar, FUNCTION_NAME);
 }