@Override public void doublePointsCrossover(AbstractChromosome another) { IntegerChromosome bca = (IntegerChromosome) another; int x = Randoms.intInRange(0, genes.length - 1); int y = Randoms.intInRange(0, genes.length - 1); if (x > y) { x ^= y; y ^= x; x ^= y; } for (int i = x; i <= y; i++) { Functions.swap(this.genes, bca.genes, i); } }
@Override public void initialize() { for (int i = 0; i < genes.length; i++) { Constraint c = this.getConstraintSet().getConstraint(i + 1); genes[i] = Randoms.intInRange((int) c.getMinimum(), (int) c.getMaximum()); } }
@Override public void mutate(double pm) { for (int i = 0; i < genes.length; i++) { if (Math.random() < pm) { Constraint c = this.getConstraintSet().getConstraint(i + 1); genes[i] = Randoms.intInRange((int) c.getMinimum(), (int) c.getMaximum()); } } }
@Override public void singlePointCrossover(AbstractChromosome another) { IntegerChromosome bca = (IntegerChromosome) another; /** x >= 1 && x <= len - 2 */ int x = Randoms.intInRange(1, genes.length - 2); // System.out.println(x); for (int i = 0; i <= x; i++) { Functions.swap(this.genes, bca.genes, i); } }