Skip to content

Commit

Permalink
#645: Mark BoundedGene.getMin() method to BoundeGene.min().
Browse files Browse the repository at this point in the history
The same for the `max` method. The getter has been deprecated.
  • Loading branch information
jenetics committed Jan 23, 2020
1 parent 780be48 commit 8b08a84
Show file tree
Hide file tree
Showing 18 changed files with 111 additions and 79 deletions.
Expand Up @@ -68,8 +68,8 @@ public class BigIntegerChromosome
*/
protected BigIntegerChromosome(final ISeq<BigIntegerGene> genes) {
super(genes);
_min = genes.get(0).getMin();
_max = genes.get(0).getMax();
_min = genes.get(0).min();
_max = genes.get(0).max();
}

/**
Expand Down
Expand Up @@ -81,11 +81,13 @@ public BigInteger getAllele() {
return _value;
}

@Deprecated
@Override
public BigInteger getMin() {
return _min;
}

@Deprecated
@Override
public BigInteger getMax() {
return _max;
Expand Down
Expand Up @@ -130,8 +130,8 @@ private void crossover(final MSeq<G> that, final MSeq<G> other, final int i) {
? ((v1 - v2)*0.5) - beta*0.5*abs(v1 - v2)
: ((v1 - v2)*0.5) + beta*0.5*abs(v1 - v2);

final double min = that.get(i).getMin().doubleValue();
final double max = that.get(i).getMax().doubleValue();
final double min = that.get(i).min().doubleValue();
final double max = that.get(i).max().doubleValue();
that.set(i, that.get(i).newInstance(clamp(v, min, max)));
}

Expand Down
Expand Up @@ -71,8 +71,8 @@ protected AbstractBoundedChromosome(
final IntRange lengthRange
) {
super(genes, lengthRange);
_min = genes.get(0).getMin();
_max = genes.get(0).getMax();
_min = genes.get(0).min();
_max = genes.get(0).max();
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions jenetics/src/main/java/io/jenetics/BoundedChromosome.java
Expand Up @@ -46,7 +46,7 @@ public interface BoundedChromosome<
* @return the minimum value of this {@code BoundedChromosome}.
*/
public default A getMin() {
return gene().getMin();
return gene().min();
}

/**
Expand All @@ -55,7 +55,7 @@ public default A getMin() {
* @return the maximum value of this {@code BoundedChromosome}.
*/
public default A getMax() {
return gene().getMax();
return gene().max();
}

}
30 changes: 27 additions & 3 deletions jenetics/src/main/java/io/jenetics/BoundedGene.java
Expand Up @@ -33,7 +33,7 @@
*
* @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
* @since 1.6
* @version 3.0
* @version !__version__!
*/
public interface BoundedGene<
A extends Comparable<? super A>,
Expand All @@ -47,20 +47,44 @@ public interface BoundedGene<
*
* @return The allowed min value.
*/
public default A min() {
return getMin();
}

/**
* Return the allowed min value.
*
* @return The allowed min value.
* @deprecated Use {@link #min()} ()} instead. Implementer must still
* implement this method.
*/
@Deprecated
public A getMin();

/**
* Return the allowed max value.
*
* @return The allowed max value.
*/
public default A max() {
return getMax();
}

/**
* Return the allowed max value.
*
* @return The allowed max value.
* @deprecated Use {@link #min()} ()} instead. Implementer must still
* implement this method.
*/
@Deprecated
public A getMax();

@Override
public default boolean isValid() {
return
allele().compareTo(getMin()) >= 0 &&
allele().compareTo(getMax()) <= 0;
allele().compareTo(min()) >= 0 &&
allele().compareTo(max()) <= 0;
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions jenetics/src/main/java/io/jenetics/DoubleGene.java
Expand Up @@ -92,11 +92,13 @@ public Double getAllele() {
return _value;
}

@Deprecated
@Override
public Double getMin() {
return _min;
}

@Deprecated
@Override
public Double getMax() {
return _max;
Expand Down
4 changes: 2 additions & 2 deletions jenetics/src/main/java/io/jenetics/GaussianMutator.java
Expand Up @@ -59,8 +59,8 @@ public GaussianMutator() {

@Override
protected G mutate(final G gene, final Random random) {
final double min = gene.getMin().doubleValue();
final double max = gene.getMax().doubleValue();
final double min = gene.min().doubleValue();
final double max = gene.max().doubleValue();
final double std = (max - min)*0.25;

final double value = gene.doubleValue();
Expand Down
2 changes: 2 additions & 0 deletions jenetics/src/main/java/io/jenetics/IntegerGene.java
Expand Up @@ -93,11 +93,13 @@ public Integer getAllele() {
return _value;
}

@Deprecated
@Override
public Integer getMin() {
return _min;
}

@Deprecated
@Override
public Integer getMax() {
return _max;
Expand Down
4 changes: 2 additions & 2 deletions jenetics/src/main/java/io/jenetics/IntermediateCrossover.java
Expand Up @@ -111,8 +111,8 @@ public IntermediateCrossover() {
protected int crossover(final MSeq<G> v, final MSeq<G> w) {
final Random random = RandomRegistry.getRandom();

final double min = v.get(0).getMin().doubleValue();
final double max = v.get(0).getMax().doubleValue();
final double min = v.get(0).min().doubleValue();
final double max = v.get(0).max().doubleValue();

for (int i = 0, n = min(v.length(), w.length()); i < n; ++i) {
final double vi = v.get(i).doubleValue();
Expand Down
4 changes: 2 additions & 2 deletions jenetics/src/main/java/io/jenetics/LineCrossover.java
Expand Up @@ -105,8 +105,8 @@ public LineCrossover() {
protected int crossover(final MSeq<G> v, final MSeq<G> w) {
final Random random = RandomRegistry.getRandom();

final double min = v.get(0).getMin().doubleValue();
final double max = v.get(0).getMax().doubleValue();
final double min = v.get(0).min().doubleValue();
final double max = v.get(0).max().doubleValue();

final double a = nextDouble(-_p, 1 + _p, random);
final double b = nextDouble(-_p, 1 + _p, random);
Expand Down
2 changes: 2 additions & 0 deletions jenetics/src/main/java/io/jenetics/LongGene.java
Expand Up @@ -94,11 +94,13 @@ public Long getAllele() {
return _value;
}

@Deprecated
@Override
public Long getMin() {
return _min;
}

@Deprecated
@Override
public Long getMax() {
return _max;
Expand Down
36 changes: 18 additions & 18 deletions jenetics/src/test/java/io/jenetics/DoubleGeneTest.java
Expand Up @@ -77,12 +77,12 @@ public void mean() {
final DoubleGene b = template.newInstance((i - 100)*3.0);
final DoubleGene c = a.mean(b);

assertEquals(a.getMin().doubleValue(), min);
assertEquals(a.getMax().doubleValue(), max);
assertEquals(b.getMin().doubleValue(), min);
assertEquals(b.getMax().doubleValue(), max);
assertEquals(c.getMin().doubleValue(), min);
assertEquals(c.getMax().doubleValue(), max);
assertEquals(a.min().doubleValue(), min);
assertEquals(a.max().doubleValue(), max);
assertEquals(b.min().doubleValue(), min);
assertEquals(b.max().doubleValue(), max);
assertEquals(c.min().doubleValue(), min);
assertEquals(c.max().doubleValue(), max);
assertEquals(c.allele().doubleValue(), ((i - 50) + ((i - 100)*3))/2.0);
}
}
Expand All @@ -91,8 +91,8 @@ public void mean() {
public void doubleGeneIntegerIntegerInteger() {
DoubleGene gene = DoubleGene.of(1.234, 0.345, 2.123);
assertEquals(gene.allele().doubleValue(), 1.234);
assertEquals(gene.getMin().doubleValue(), 0.345);
assertEquals(gene.getMax().doubleValue(), 2.123);
assertEquals(gene.min().doubleValue(), 0.345);
assertEquals(gene.max().doubleValue(), 2.123);

try {
gene = DoubleGene.of(0.1, 2.1, 4.1);
Expand All @@ -105,8 +105,8 @@ public void doubleGeneIntegerIntegerInteger() {
@Test
public void doubleGeneIntegerInteger() {
DoubleGene gene = DoubleGene.of(-10.567, 10.567);
assertEquals(gene.getMin().doubleValue(), -10.567);
assertEquals(gene.getMax().doubleValue(), 10.567);
assertEquals(gene.min().doubleValue(), -10.567);
assertEquals(gene.max().doubleValue(), 10.567);
}

@Test
Expand All @@ -115,8 +115,8 @@ public void createNumber() {
DoubleGene g2 = gene.newInstance(5.0);

assertEquals(g2.allele().intValue(), 5);
assertEquals(g2.getMin().doubleValue(), -1234.1234);
assertEquals(g2.getMax().doubleValue(), 1234.1234);
assertEquals(g2.min().doubleValue(), -1234.1234);
assertEquals(g2.max().doubleValue(), 1234.1234);
}

@Test
Expand All @@ -131,9 +131,9 @@ public void getMinValue() {
DoubleGene g2 = DoubleGene.of(4.1, 1.1, 7.1);
DoubleGene g3 = DoubleGene.of(3.1, 0.1, 5.1);

assertEquals(g1.getMin().doubleValue(), 0.1);
assertEquals(g2.getMin().doubleValue(), 1.1);
assertEquals(g3.getMin().doubleValue(), 0.1);
assertEquals(g1.min().doubleValue(), 0.1);
assertEquals(g2.min().doubleValue(), 1.1);
assertEquals(g3.min().doubleValue(), 0.1);
}

@Test
Expand All @@ -142,9 +142,9 @@ public void getMaxValue() {
DoubleGene g2 = DoubleGene.of(4.2, 1.2, 7.2);
DoubleGene g3 = DoubleGene.of(3.2, 0.2, 5.2);

assertEquals(g1.getMax().doubleValue(), 5.2);
assertEquals(g2.getMax().doubleValue(), 7.2);
assertEquals(g3.getMax().doubleValue(), 5.2);
assertEquals(g1.max().doubleValue(), 5.2);
assertEquals(g2.max().doubleValue(), 7.2);
assertEquals(g3.max().doubleValue(), 5.2);
}

}
24 changes: 12 additions & 12 deletions jenetics/src/test/java/io/jenetics/IntegerGeneTest.java
Expand Up @@ -67,8 +67,8 @@ public void newInstanceDistribution() {
@Test
public void parameters() {
final IntegerGene gene = IntegerGene.of(10, 10);
Assert.assertEquals(gene.getMin().intValue(), 10);
Assert.assertEquals(gene.getMax().intValue(), 10);
Assert.assertEquals(gene.min().intValue(), 10);
Assert.assertEquals(gene.max().intValue(), 10);
Assert.assertEquals(gene.allele().intValue(), 10);
}

Expand All @@ -83,12 +83,12 @@ public void mean() {
final IntegerGene b = template.newInstance((i - 100L) *3);
final IntegerGene c = a.mean(b);

assertEquals(a.getMin().longValue(), min);
assertEquals(a.getMax().longValue(), max);
assertEquals(b.getMin().longValue(), min);
assertEquals(b.getMax().longValue(), max);
assertEquals(c.getMin().longValue(), min);
assertEquals(c.getMax().longValue(), max);
assertEquals(a.min().longValue(), min);
assertEquals(a.max().longValue(), max);
assertEquals(b.min().longValue(), min);
assertEquals(b.max().longValue(), max);
assertEquals(c.min().longValue(), min);
assertEquals(c.max().longValue(), max);
assertEquals(c.allele().longValue(), ((i - 50) + ((i - 100)*3))/2);
}
}
Expand All @@ -99,8 +99,8 @@ public void createNumber() {
IntegerGene g2 = gene.newInstance(5L);

assertEquals(g2.allele().longValue(), 5);
assertEquals(g2.getMin().longValue(), 0);
assertEquals(g2.getMax().longValue(), 12);
assertEquals(g2.min().longValue(), 0);
assertEquals(g2.max().longValue(), 12);
}

@Test
Expand All @@ -113,8 +113,8 @@ public void createInvalidNumber() {
public void set() {
IntegerGene gene = IntegerGene.of(5, 0, 10);
Assert.assertEquals(gene.allele().intValue(), 5);
Assert.assertEquals(gene.getMin().intValue(), 0);
Assert.assertEquals(gene.getMax().intValue(), 10);
Assert.assertEquals(gene.min().intValue(), 0);
Assert.assertEquals(gene.max().intValue(), 10);
}

}
20 changes: 10 additions & 10 deletions jenetics/src/test/java/io/jenetics/LongGeneTest.java
Expand Up @@ -75,12 +75,12 @@ public void mean() {
final LongGene b = template.newInstance((i - 100L) *3);
final LongGene c = a.mean(b);

assertEquals(a.getMin().longValue(), min);
assertEquals(a.getMax().longValue(), max);
assertEquals(b.getMin().longValue(), min);
assertEquals(b.getMax().longValue(), max);
assertEquals(c.getMin().longValue(), min);
assertEquals(c.getMax().longValue(), max);
assertEquals(a.min().longValue(), min);
assertEquals(a.max().longValue(), max);
assertEquals(b.min().longValue(), min);
assertEquals(b.max().longValue(), max);
assertEquals(c.min().longValue(), min);
assertEquals(c.max().longValue(), max);
assertEquals(c.allele().longValue(), ((i - 50) + ((i - 100)*3))/2);
}
}
Expand All @@ -91,8 +91,8 @@ public void createNumber() {
LongGene g2 = gene.newInstance(5L);

assertEquals(g2.allele().longValue(), 5);
assertEquals(g2.getMin().longValue(), 0);
assertEquals(g2.getMax().longValue(), 12);
assertEquals(g2.min().longValue(), 0);
assertEquals(g2.max().longValue(), 12);
}

@Test
Expand All @@ -105,8 +105,8 @@ public void createInvalidNumber() {
public void set() {
LongGene gene = LongGene.of(5L, 0L, 10L);
Assert.assertEquals(gene.allele().longValue(), 5L);
Assert.assertEquals(gene.getMin().longValue(), 0L);
Assert.assertEquals(gene.getMax().longValue(), 10L);
Assert.assertEquals(gene.min().longValue(), 0L);
Assert.assertEquals(gene.max().longValue(), 10L);
}

}
Expand Up @@ -56,8 +56,8 @@ public void geneMinMax() {
c = (NumericChromosome<N, G>) factory().newInstance();

for (G gene : c) {
Assert.assertEquals(gene.getMin(), c.getMin());
Assert.assertEquals(gene.getMax(), c.getMax());
Assert.assertEquals(gene.min(), c.getMin());
Assert.assertEquals(gene.max(), c.getMax());
}
}

Expand Down
4 changes: 2 additions & 2 deletions jenetics/src/test/java/io/jenetics/NumericGeneTester.java
Expand Up @@ -47,8 +47,8 @@ public void minMax() {
for (int i = 0; i < 100; ++i) {
final G gene = factory().newInstance();

Assert.assertTrue(gene.allele().compareTo(gene.getMin()) >= 0);
Assert.assertTrue(gene.allele().compareTo(gene.getMax()) <= 0);
Assert.assertTrue(gene.allele().compareTo(gene.min()) >= 0);
Assert.assertTrue(gene.allele().compareTo(gene.max()) <= 0);
}
}

Expand Down

0 comments on commit 8b08a84

Please sign in to comment.