private CenterObject getMutant(CenterObject center, float f) { CenterObject mutant = new CenterObject(); int a = (int) (Math.random() * n); int b = (int) (Math.random() * n); int c = (int) (Math.random() * n); // System.out.println("a b c:" + a + " " + b + " " + c); DataObject objA = objects.get(a); DataObject objB = objects.get(b); DataObject objC = objects.get(c); DataObject obj; for (int i = 0; i < k; i++) { int year = (int) (objA.getYear() + f * (objB.getYear() - objC.getYear())); double ratio1 = objA.getRatio1() + f * (objB.getRatio1() - objC.getRatio1()); double ratio2 = objA.getRatio2() + f * (objB.getRatio2() - objC.getRatio2()); obj = new DataObject(); obj.setYear(year); obj.setRatio1(ratio1); obj.setRatio2(ratio2); mutant.getObjs().add(obj); System.out.println("Mutant " + i); printCenter(mutant); } return mutant; }
// initialize objects private void initDataObjects() { objects = new ArrayList<DataObject>(); for (int i = 0; i < n; i++) { DataObject obj = new DataObject(); int year = (int) (Math.random() * MAX_YEAR); double ratio1 = Math.random() % MAX_RATIO; double ratio2 = Math.random() % MAX_RATIO; obj.setYear(year); obj.setRatio1(ratio1); obj.setRatio2(ratio2); objects.add(obj); } System.out.println("Data Size:" + objects.size()); }