@Test public void testMutate() { System.out.println("mutate"); MathEx.setSeed(19650218); byte[] father = {1,1,1,0,1,0,0,1,0,0,0}; BitString instance = new BitString(father.clone(), null, Crossover.SINGLE_POINT, 1.0, 0.1); instance.mutate(); byte[] mutant = {1,1,1,1,1,0,0,1,0,1,0}; for (int i = 0; i < father.length; i++) { assertEquals(mutant[i], instance.bits()[i]); } }
@Override public void mutate() { for (int i = 0; i < length; i++) { if (MathEx.random() < mutationRate) { bits[i] ^= 1; } } }
BitString implements Chromosome { @Override public void mutate() { for (int i = 0; i < length; i++) { if (MathEx.random() < mutationRate) { bits[i] ^= 1; } } } }
BitString implements Chromosome { @Override public void mutate() { for (int i = 0; i < length; i++) { if (MathEx.random() < mutationRate) { bits[i] ^= 1; } } } BitString(int length, FitnessMeasure<BitString> measure);  BitString(int length, FitnessMeasure<BitString> measure, Crossover crossover, double crossoverRate, double mutationRate);  BitString(byte[] bits, FitnessMeasure<BitString> measure);  BitString(byte[] bits, FitnessMeasure<BitString> measure, Crossover crossover, double crossoverRate, double mutationRate); }
BitString implements Chromosome { @Override public void mutate() { for (int i = 0; i < length; i++) { if (MathEx.random() < mutationRate) { bits[i] ^= 1; } } } BitString(int length, FitnessMeasure<BitString> measure);  BitString(int length, FitnessMeasure<BitString> measure, Crossover crossover, double crossoverRate, double mutationRate);  BitString(byte[] bits, FitnessMeasure<BitString> measure);  BitString(byte[] bits, FitnessMeasure<BitString> measure, Crossover crossover, double crossoverRate, double mutationRate); int length(); byte[] bits(); @Override int compareTo(Chromosome o); @Override double fitness(); @Override BitString newInstance(); BitString newInstance(byte[] bits); @Override BitString[] crossover(Chromosome another); @Override void mutate(); @Override String toString(); }
BitString implements Chromosome { @Override public void mutate() { for (int i = 0; i < length; i++) { if (MathEx.random() < mutationRate) { bits[i] ^= 1; } } } BitString(int length, FitnessMeasure<BitString> measure);  BitString(int length, FitnessMeasure<BitString> measure, Crossover crossover, double crossoverRate, double mutationRate);  BitString(byte[] bits, FitnessMeasure<BitString> measure);  BitString(byte[] bits, FitnessMeasure<BitString> measure, Crossover crossover, double crossoverRate, double mutationRate); int length(); byte[] bits(); @Override int compareTo(Chromosome o); @Override double fitness(); @Override BitString newInstance(); BitString newInstance(byte[] bits); @Override BitString[] crossover(Chromosome another); @Override void mutate(); @Override String toString(); final int length; }