@Test(expected = IllegalArgumentException.class) public void testWrongBoundSettingArray() { Random rand = new Random(); double[] lowerBounds = { -1.0, -0.5, 0.0 }; double[] upperBounds = { -0.5, 0.0, 0.5 }; DoubleBounds bounds = new DoubleBounds(lowerBounds, upperBounds); DoubleGenotype listGeno = new DoubleGenotype(bounds); assertTrue(listGeno.isEmpty()); listGeno.init(rand, 4); }
public void init(Random random, int n) { try { getLowerBound(n - 1); getUpperBound(n - 1); } catch (IndexOutOfBoundsException outOfBoundException) { throw new IllegalArgumentException( "Cannot initialize a genotype with " + n + " entries with the specified bounds", outOfBoundException); } for (int i = 0; i < n; i++) { double lo = getLowerBound(i); double hi = getUpperBound(i); double value = lo + random.nextDouble() * (hi - lo); if (i >= size()) { add(value); } else { set(i, value); } } }
DoubleGenotype extends ArrayList<Double> implements ListGenotype<Double> { public void init(Random random, int n) { try { getLowerBound(n - 1); getUpperBound(n - 1); } catch (IndexOutOfBoundsException outOfBoundException) { throw new IllegalArgumentException( "Cannot initialize a genotype with " + n + " entries with the specified bounds", outOfBoundException); } for (int i = 0; i < n; i++) { double lo = getLowerBound(i); double hi = getUpperBound(i); double value = lo + random.nextDouble() * (hi - lo); if (i >= size()) { add(value); } else { set(i, value); } } } }
DoubleGenotype extends ArrayList<Double> implements ListGenotype<Double> { public void init(Random random, int n) { try { getLowerBound(n - 1); getUpperBound(n - 1); } catch (IndexOutOfBoundsException outOfBoundException) { throw new IllegalArgumentException( "Cannot initialize a genotype with " + n + " entries with the specified bounds", outOfBoundException); } for (int i = 0; i < n; i++) { double lo = getLowerBound(i); double hi = getUpperBound(i); double value = lo + random.nextDouble() * (hi - lo); if (i >= size()) { add(value); } else { set(i, value); } } } DoubleGenotype();  DoubleGenotype(double lowerBound, double upperBound);  DoubleGenotype(Bounds<Double> bounds); }
DoubleGenotype extends ArrayList<Double> implements ListGenotype<Double> { public void init(Random random, int n) { try { getLowerBound(n - 1); getUpperBound(n - 1); } catch (IndexOutOfBoundsException outOfBoundException) { throw new IllegalArgumentException( "Cannot initialize a genotype with " + n + " entries with the specified bounds", outOfBoundException); } for (int i = 0; i < n; i++) { double lo = getLowerBound(i); double hi = getUpperBound(i); double value = lo + random.nextDouble() * (hi - lo); if (i >= size()) { add(value); } else { set(i, value); } } } DoubleGenotype();  DoubleGenotype(double lowerBound, double upperBound);  DoubleGenotype(Bounds<Double> bounds); double getLowerBound(int index); double getUpperBound(int index); @Override @SuppressWarnings("unchecked") G newInstance(); void init(Random random, int n); }
DoubleGenotype extends ArrayList<Double> implements ListGenotype<Double> { public void init(Random random, int n) { try { getLowerBound(n - 1); getUpperBound(n - 1); } catch (IndexOutOfBoundsException outOfBoundException) { throw new IllegalArgumentException( "Cannot initialize a genotype with " + n + " entries with the specified bounds", outOfBoundException); } for (int i = 0; i < n; i++) { double lo = getLowerBound(i); double hi = getUpperBound(i); double value = lo + random.nextDouble() * (hi - lo); if (i >= size()) { add(value); } else { set(i, value); } } } DoubleGenotype();  DoubleGenotype(double lowerBound, double upperBound);  DoubleGenotype(Bounds<Double> bounds); double getLowerBound(int index); double getUpperBound(int index); @Override @SuppressWarnings("unchecked") G newInstance(); void init(Random random, int n);  }