Skip to content

Commit

Permalink
#645: Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
jenetics committed Jan 23, 2020
1 parent fe5ab01 commit b3abfd0
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 12 deletions.
Expand Up @@ -67,14 +67,14 @@ public class MultiRootGP {
// First 'program'
ProgramChromosome.of(
5,
ch -> ch.getRoot().size() <= 50,
ch -> ch.root().size() <= 50,
OPERATIONS,
TERMINALS
),
// Second 'program'
ProgramChromosome.of(
5,
ch -> ch.getRoot().size() <= 50,
ch -> ch.root().size() <= 50,
OPERATIONS,
TERMINALS
)
Expand Down
24 changes: 22 additions & 2 deletions jenetics.ext/src/main/java/io/jenetics/ext/TreeChromosome.java
Expand Up @@ -36,8 +36,8 @@ public interface TreeChromosome<A, G extends TreeGene<A, G>>
* Return the root gene of this chromosome. Since the gene type is also a
* {@link io.jenetics.ext.util.Tree}, you are able to assign it to one.
* <pre>{@code
* final Tree<A, ?> t1 = getRoot();
* final Tree<?, ?> t2 = getRoot();
* final Tree<A, ?> t1 = root();
* final Tree<?, ?> t2 = root();
* }</pre>
* This method is also an alias for {@link #gene()}, which returns the
* first gene of the chromosome.
Expand All @@ -46,6 +46,26 @@ public interface TreeChromosome<A, G extends TreeGene<A, G>>
*
* @return the root tree gene of this chromosome
*/
public default G root() {
return gene();
}

/**
* Return the root gene of this chromosome. Since the gene type is also a
* {@link io.jenetics.ext.util.Tree}, you are able to assign it to one.
* <pre>{@code
* final Tree<A, ?> t1 = root();
* final Tree<?, ?> t2 = root();
* }</pre>
* This method is also an alias for {@link #gene()}, which returns the
* first gene of the chromosome.
*
* @see #gene()
*
* @return the root tree gene of this chromosome
* @deprecated Use {@link #root()} instead
*/
@Deprecated
public default G getRoot() {
return gene();
}
Expand Down
Expand Up @@ -46,7 +46,7 @@ public IntTreeGene newTree(int levels, Random random) {
.map(n -> new IntTreeGene(n.value(), n.childOffset(), n.childCount()))
.collect(ISeq.toISeq());

return new IntTreeChromosome(genes).getRoot();
return new IntTreeChromosome(genes).root();
}

}
Expand Down
Expand Up @@ -158,7 +158,7 @@ private boolean isSuperValid() {
*/
@Override
public A apply(final A[] args) {
return getRoot().apply(args);
return root().apply(args);
}

/**
Expand All @@ -173,7 +173,7 @@ public A apply(final A[] args) {
*/
@SafeVarargs
public final A eval(final A... args) {
return getRoot().eval(args);
return root().eval(args);
}

@Override
Expand All @@ -183,7 +183,7 @@ public ProgramChromosome<A> newInstance(final ISeq<ProgramGene<A>> genes) {

@Override
public ProgramChromosome<A> newInstance() {
return create(getRoot().depth(), _validator, _operations, _terminals);
return create(root().depth(), _validator, _operations, _terminals);
}

/**
Expand Down
Expand Up @@ -297,7 +297,7 @@ public static <T> Regression<T> of(
operations,
terminals,
depth,
ch -> ch.getRoot().size() <= max
ch -> ch.root().size() <= max
);
}

Expand Down
Expand Up @@ -90,7 +90,7 @@ public void createFromTree() {
final ProgramChromosome<Double> chromosome = ProgramChromosome
.of(tree, OPERATIONS, TERMINALS);

Assert.assertTrue(Tree.equals(tree, chromosome.getRoot()));
Assert.assertTrue(Tree.equals(tree, chromosome.root()));
}

@Test(invocationCount = 10)
Expand Down Expand Up @@ -159,7 +159,7 @@ public void sameRootAndFirstGene() {
OPERATIONS,
TERMINALS
);
Assert.assertSame(ch.getRoot(), ch.gene());
Assert.assertSame(ch.root(), ch.gene());
}

@Test
Expand Down
Expand Up @@ -53,7 +53,7 @@ public class ProgramGeneTest {

private static final ProgramGene<Double> PROG = ProgramChromosome
.of(5, OPERATIONS, TERMINALS)
.getRoot();
.root();

private static final TreeNode<Op<Double>> TREE = TreeNode.ofTree(PROG);

Expand Down

0 comments on commit b3abfd0

Please sign in to comment.