@Test public void testNewInstance() { System.out.println("newInstance"); byte[] father = {1,1,1,0,1,0,0,1,0,0,0}; int length = father.length; BitString instance = new BitString(father, null, Crossover.SINGLE_POINT, 1.0, 0.0); BitString result = instance.newInstance(); assertEquals(length, result.length()); boolean same = true; for (int i = 0; i < length; i++) { if (father[i] != result.bits()[i]) { same = false; } } assertFalse(same); }
@Override public BitString newInstance() { return new BitString(length, measure, crossover, crossoverRate, mutationRate); }
BitString implements Chromosome { @Override public BitString newInstance() { return new BitString(length, measure, crossover, crossoverRate, mutationRate); } }
BitString implements Chromosome { @Override public BitString newInstance() { return new BitString(length, measure, crossover, crossoverRate, mutationRate); } 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 BitString newInstance() { return new BitString(length, measure, crossover, crossoverRate, mutationRate); } 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 BitString newInstance() { return new BitString(length, measure, crossover, crossoverRate, mutationRate); } 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; }