1 10 package examples.multiobjective; 11 12 import java.util.*; 13 import org.jgap.*; 14 import org.jgap.impl.*; 15 16 22 public class MultiObjectiveFitnessFunction 23 extends BulkFitnessFunction { 24 25 private final static String CVS_REVISION = "$Revision: 1.2 $"; 26 27 public static final int MAX_BOUND = 4000; 28 29 public static final double MIN_X = -10; 30 31 public static final double MAX_X = 10; 32 33 43 public void evaluate(Population a_subject) { 44 Iterator it = a_subject.getChromosomes().iterator(); 45 while (it.hasNext()) { 46 IChromosome a_chrom1 = (IChromosome) it.next(); 47 DoubleGene g1 = (DoubleGene) a_chrom1.getGene(0); 49 double d = g1.doubleValue(); 50 double y1 = formula(1, d); 51 List l = new Vector(); 52 l.add(new Double (y1)); 53 double y2 = formula(2, d); 54 l.add(new Double (y2)); 55 ( (Chromosome) a_chrom1).setMultiObjectives(l); 56 } 57 } 58 59 public static Vector getVector(IChromosome a_chrom) { 60 Vector result = new Vector(); 61 List mo = ( (Chromosome) a_chrom).getMultiObjectives(); 66 Double d = (Double ) mo.get(0); 67 result.add(d); 68 d = (Double ) mo.get(1); 69 result.add(d); 70 return result; 71 } 72 73 private double formula(int a_index, double a_x) { 74 if (a_index == 1) { 75 return a_x * a_x; 76 } 77 else { 78 return (a_x - 2) * (a_x - 2); 79 } 80 } 81 82 88 public Object clone() { 89 return new MultiObjectiveFitnessFunction(); 90 } 91 } 92 | Popular Tags |