/** * Reproduce method that generates a new <code>Chrome</code> object from the two given ones. * * @param x First <code>Chrome</code> object * @param y Second <code>Chrome</code> object * @return The <code>Chrome</code> object which was created from <code>x</code> and <code>y</code> */ public Chrome reproduce(Chrome x, Chrome y) { Random r = new Random(); CustomMap childGenes = new CustomMap(); // Randomly choose the intersection point int intersectionPoint = r.nextInt(x.getSize()); for (int i = 0; i < intersectionPoint; i++) { childGenes.addKey(x.getMapKey(i)); childGenes.addValue(x.getMapValue(i)); } for (int i = intersectionPoint; i < x.getSize(); i++) { childGenes.addKey(y.getMapKey(i)); childGenes.addValue(y.getMapValue(i)); } return new Chrome(childGenes, mRooms, mInstructors, mSlots); }