/** As we want the maximum of the function, lower y's are less fit */ public boolean lessFitThan(Dna defiant) { MinusXSquared d = (MinusXSquared) defiant; if (this.getY() < d.getY()) { return true; } return false; }
/** Detects if the solutions are the same */ public boolean asFitAs(Dna defiant) { MinusXSquared d = (MinusXSquared) defiant; if (this.getY() == d.getY()) { return true; } return false; }
/** * The crossover operation consists of calculating the simple mean between the x's of each dna * involved. */ public Dna crossover(Dna dna) { MinusXSquared mxs = (MinusXSquared) dna; MinusXSquared newMxs = new MinusXSquared(); double newX = (this.x + mxs.getX()) / 2; newMxs.setX(newX); return newMxs; }