Skip to content

Commit

Permalink
Merge pull request #646 from jenetics/issues/JENETICS-645-deprecate_b…
Browse files Browse the repository at this point in the history
…ean_getter

#645: Deprecate bean getter
  • Loading branch information
jenetics committed Jan 23, 2020
2 parents 412a017 + b3abfd0 commit a87292b
Show file tree
Hide file tree
Showing 197 changed files with 1,494 additions and 777 deletions.
2 changes: 1 addition & 1 deletion jenetics.doc/src/main/java/DTLZ1.java
Expand Up @@ -65,7 +65,7 @@ public static void main(final String[] args) {
final ISeq<Vec<double[]>> front = ENGINE.stream()
.limit(2500)
.collect(MOEA.toParetoSet(IntRange.of(1000, 1100)))
.map(Phenotype::getFitness);
.map(Phenotype::fitness);
}

}
2 changes: 1 addition & 1 deletion jenetics.doc/src/main/java/DTLZ1Diagram.java
Expand Up @@ -48,7 +48,7 @@ public static void main(final String[] args) throws IOException {
final ISeq<Vec<double[]>> front = DTLZ1.ENGINE.stream()
.limit(3500)
.collect(MOEA.toParetoSet(IntRange.of(1000, 1100)))
.map(Phenotype::getFitness);
.map(Phenotype::fitness);

System.out.println(front.size());

Expand Down
6 changes: 3 additions & 3 deletions jenetics.doc/src/main/java/SymbolicRegression.java
Expand Up @@ -77,13 +77,13 @@ public static void main(final String[] args) {
.limit(Limits.byFitnessThreshold(0.01))
.collect(EvolutionResult.toBestEvolutionResult());

final ProgramGene<Double> program = er.getBestPhenotype()
.getGenotype()
final ProgramGene<Double> program = er.bestPhenotype()
.genotype()
.gene();

final TreeNode<Op<Double>> tree = program.toTreeNode();
MathExpr.rewrite(tree);
System.out.println("G: " + er.getTotalGenerations());
System.out.println("G: " + er.totalGenerations());
System.out.println("F: " + new MathExpr(tree));
System.out.println("E: " + REGRESSION.error(tree));
}
Expand Down
2 changes: 1 addition & 1 deletion jenetics.doc/src/main/java/TravelingSalesman.java
Expand Up @@ -112,7 +112,7 @@ public static void main(String[] args) {

out.println(statistics);
out.println("Known min path length: " + minPathLength);
out.println("Found min path length: " + best.getFitness());
out.println("Found min path length: " + best.fitness());
}

}
Expand Up @@ -87,7 +87,7 @@ public AltererResult<G, C> alter(
indexes(RandomRegistry.getRandom(), pop.size(), p).forEach(i -> {
final Phenotype<G, C> pt = pop.get(i);

final Genotype<G> gt = pt.getGenotype();
final Genotype<G> gt = pt.genotype();
final Genotype<G> mgt = mutate(gt, p, alterations);

final Phenotype<G, C> mpt = Phenotype.of(mgt, generation);
Expand Down Expand Up @@ -151,7 +151,7 @@ public static void main(final String[] args) {
.limit(20)
.collect(EvolutionResult.toBestEvolutionResult());

System.out.println(result.getBestFitness());
System.out.println(result.bestFitness());
}

}
Expand Up @@ -101,7 +101,7 @@ public static void main(final String[] args)
System.out.println("Writing evolution result.");
IO.object.write(future.get(), resultPath);

System.out.println("Best fitness: " + future.get().getBestFitness());
System.out.println("Best fitness: " + future.get().bestFitness());
}
}

Expand Down
Expand Up @@ -74,8 +74,8 @@ public static void main(final String[] args) {
.limit(bySteadyFitness(50))
.collect(toBestEvolutionResult());

System.out.println(best.getTotalGenerations());
System.out.println(best.getBestPhenotype());
System.out.println(best.totalGenerations());
System.out.println(best.bestPhenotype());
}

}
4 changes: 2 additions & 2 deletions jenetics.example/src/main/java/io/jenetics/example/Game.java
Expand Up @@ -77,7 +77,7 @@ public static void main(final String[] args) {
final Player other;
if (pop != null) {
final int index = RandomRegistry.getRandom().nextInt(pop.size());
other = codec.decode(pop.get(index).getGenotype());
other = codec.decode(pop.get(index).genotype());
} else {
other = Player.of(0.5);
}
Expand All @@ -92,7 +92,7 @@ public static void main(final String[] args) {
final Player best = codec.decode(
engine.stream()
.limit(Limits.bySteadyFitness(50))
.peek(er -> population.set(er.getPopulation()))
.peek(er -> population.set(er.population()))
.collect(EvolutionResult.toBestGenotype())
);

Expand Down
Expand Up @@ -44,7 +44,7 @@ public class LastMonday {
// The used Codec.
private static final Codec<LocalDate, AnyGene<LocalDate>> CODEC = Codec.of(
Genotype.of(AnyChromosome.of(LastMonday::nextRandomMonday)),
gt -> gt.gene().getAllele()
gt -> gt.gene().allele()
);

// Supplier of random 'LocalDate' objects. The implementation is responsible
Expand Down
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
Expand Up @@ -55,7 +55,7 @@ public OnesCounting(final int length, final double onesProbability) {

@Override
public Function<ISeq<BitGene>, Integer> fitness() {
return genes -> (int)genes.stream().filter(BitGene::getBit).count();
return genes -> (int)genes.stream().filter(BitGene::bit).count();
}

@Override
Expand Down
Expand Up @@ -95,7 +95,7 @@ public Codec<ISeq<Rect>, AnyGene<Rect>> codec() {
MAX_RECT_COUNT
)),
gt -> gt.chromosome().stream()
.map(AnyGene::getAllele)
.map(AnyGene::allele)
.filter(r -> r != Rect.EMPTY)
.collect(ISeq.toISeq())
);
Expand Down
Expand Up @@ -40,7 +40,7 @@ public class RepairingConstraint implements Constraint<DoubleGene, Double> {
@Override
public boolean test(final Phenotype<DoubleGene, Double> pt) {
return isValid(
pt.getGenotype().chromosome()
pt.genotype().chromosome()
.as(DoubleChromosome.class)
.toArray()
);
Expand All @@ -55,7 +55,7 @@ public Phenotype<DoubleGene, Double> repair(
final Phenotype<DoubleGene, Double> pt,
final long generation
) {
final double[] x = pt.getGenotype().chromosome()
final double[] x = pt.genotype().chromosome()
.as(DoubleChromosome.class)
.toArray();

Expand Down
Expand Up @@ -66,7 +66,7 @@ public static void main(final String[] args) {
.collect(EvolutionResult.toBestEvolutionResult())
);

System.out.println(result.getBestPhenotype());
System.out.println(result.bestPhenotype());
}

}
Expand Up @@ -67,7 +67,7 @@ public ISeq<Phenotype<G, C>> eval(final Seq<Phenotype<G, C>> population) {
.map(Observable::just),
population.stream()
.filter(Phenotype::nonEvaluated)
.map(pt -> _fitness.apply(pt.getGenotype())
.map(pt -> _fitness.apply(pt.genotype())
.map(pt::withFitness))
);

Expand All @@ -88,7 +88,7 @@ public static void main(final String[] args) {
.limit(100)
.collect(EvolutionResult.toBestEvolutionResult());

System.out.println(result.getBestPhenotype());
System.out.println(result.bestPhenotype());
}

private static Observable<Double> fitness(final Genotype<DoubleGene> gt) {
Expand Down
Expand Up @@ -39,8 +39,8 @@
public class Sorting {

private static int dist(Chromosome<EnumGene<Integer>> path, int i, int j) {
return (path.get(i).getAllele() - path.get(j).getAllele())*
(path.get(i).getAllele() - path.get(j).getAllele());
return (path.get(i).allele() - path.get(j).allele())*
(path.get(i).allele() - path.get(j).allele());
}

private static int length(final Genotype<EnumGene<Integer>> genotype) {
Expand Down Expand Up @@ -76,7 +76,7 @@ public static void main(final String[] args) {
.collect(EvolutionResult.toBestEvolutionResult());

System.out.println(statistics);
System.out.println(result.getBestPhenotype());
System.out.println(result.bestPhenotype());
}

}
Expand Up @@ -105,13 +105,13 @@ public static void main(final String[] args) {
.limit(Limits.byFitnessThreshold(0.01))
.collect(EvolutionResult.toBestEvolutionResult());

final ProgramGene<Double> program = result.getBestPhenotype()
.getGenotype()
final ProgramGene<Double> program = result.bestPhenotype()
.genotype()
.gene();

final TreeNode<Op<Double>> tree = program.toTreeNode();
MathExpr.rewrite(tree);
System.out.println("Generations: " + result.getTotalGenerations());
System.out.println("Generations: " + result.totalGenerations());
System.out.println("Function: " + new MathExpr(tree));
System.out.println("Error: " + REGRESSION.error(tree));

Expand Down
Expand Up @@ -102,9 +102,9 @@ public static void main(String[] args) throws IOException {
.peek(statistics)
.collect(toBestPhenotype());

final ISeq<WayPoint> path = best.getGenotype()
final ISeq<WayPoint> path = best.genotype()
.chromosome().stream()
.map(Gene::getAllele)
.map(Gene::allele)
.collect(ISeq.toISeq());

final GPX gpx = GPX.builder()
Expand All @@ -113,7 +113,7 @@ public static void main(String[] args) throws IOException {
.addSegment(s -> s.points(path.asList())))
.build();

final double km = tsm.fitness(best.getGenotype())/1_000.0;
final double km = tsm.fitness(best.genotype())/1_000.0;
GPX.writer(" ")
.write(gpx, format("%s/out_%d.gpx", getProperty("user.home"), (int)km));

Expand Down
Expand Up @@ -47,16 +47,16 @@ public EvolutionResultPanel() {
}

void update(final EvolutionResult<?, Double> result) {
final String generation = Long.toString(result.getGeneration());
final String bestFitness = _format.format(result.getBestFitness());
final double age = result.getPopulation().stream()
.collect(averagingLong(p -> p.getAge(result.getGeneration())));
final String generation = Long.toString(result.generation());
final String bestFitness = _format.format(result.bestFitness());
final double age = result.population().stream()
.collect(averagingLong(p -> p.age(result.generation())));

_generationTextField.setText(generation);
_bestFitnessTextField.setText(bestFitness);
_populationAgeTextField.setText(_format.format(age));
_evaluationTimeTextField.setText(format(
result.getDurations().getEvaluationDuration()
result.durations().evaluationDuration()
));
}

Expand Down
Expand Up @@ -428,8 +428,8 @@ private void onNewResult(
) {
invokeLater(() -> {
final Genotype<PolygonGene> gt = best
.getBestPhenotype()
.getGenotype();
.bestPhenotype()
.genotype();

bestEvolutionResultPanel.update(best);
currentevolutionResultPanel.update(current);
Expand Down
Expand Up @@ -195,7 +195,7 @@ private static void evolve(
final AtomicLong time = new AtomicLong(0);

worker.start((current, best) -> {
final long generation = current.getGeneration();
final long generation = current.generation();

if (generation%generationGap == 0 || generation == 1) {
final double duration = System.currentTimeMillis() - time.get();
Expand All @@ -207,22 +207,22 @@ private static void evolve(
format(IMAGE_PATTERN, generation)
);

final Phenotype<PolygonGene, Double> pt = best.getBestPhenotype();
final Phenotype<PolygonGene, Double> pt = best.bestPhenotype();
if (latest.get() == null || latest.get().compareTo(pt) < 0) {
log(
"Writing '%s': fitness=%1.4f, speed=%1.2f.",
file, pt.getFitness(), speed
file, pt.fitness(), speed
);

latest.set(pt);
final PolygonChromosome ch =
(PolygonChromosome)pt.getGenotype().chromosome();
(PolygonChromosome)pt.genotype().chromosome();

writeImage(file, ch, image.getWidth(), image.getHeight());
} else {
log(
"No improvement - %07d: fitness=%1.4f, speed=%1.2f.",
generation, pt.getFitness(), speed
generation, pt.fitness(), speed
);
}
}
Expand Down
Expand Up @@ -48,7 +48,7 @@ public Chromosome<PolygonGene> newInstance(final ISeq<PolygonGene> genes) {

@Override
public Chromosome<PolygonGene> newInstance() {
return new PolygonChromosome(length(), gene().getAllele().length());
return new PolygonChromosome(length(), gene().allele().length());
}

public void draw(final Graphics2D g, final int width, final int height) {
Expand All @@ -59,7 +59,7 @@ public void draw(final Graphics2D g, final int width, final int height) {
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));

for (PolygonGene gene : this) {
gene.getAllele().draw(g, width, height);
gene.allele().draw(g, width, height);
}
}

Expand Down
Expand Up @@ -37,6 +37,7 @@ private PolygonGene(final Polygon polygon) {
_polygon = requireNonNull(polygon);
}

@Deprecated
@Override
public Polygon getAllele() {
return _polygon;
Expand All @@ -59,7 +60,7 @@ public PolygonGene newInstance(final Polygon polygon) {

@Override
public PolygonGene mean(final PolygonGene other) {
return of(getAllele().mean(other.getAllele()));
return of(allele().mean(other.allele()));
}

static ISeq<PolygonGene> seq(final int polygonCount, final int polygonLength) {
Expand Down
Expand Up @@ -54,7 +54,7 @@ protected MutatorResult<Chromosome<PolygonGene>> mutate(
}

private PolygonGene mutate(final PolygonGene gene) {
return gene.newInstance(gene.getAllele().mutate(_rate, _magnitude));
return gene.newInstance(gene.allele().mutate(_rate, _magnitude));
}

}
Expand Up @@ -91,13 +91,14 @@ public ISeq<G> flattenedNodes() {
}

@Override
@Deprecated
public G getRoot() {
return _genes.get(0);
}

@Override
public boolean isRoot() {
return getRoot() == this;
return root() == this;
}

@Override
Expand Down Expand Up @@ -128,6 +129,7 @@ public int childOffset() {
return _childOffset;
}

@Deprecated
@Override
public A getAllele() {
return _allele;
Expand All @@ -141,6 +143,7 @@ public A getAllele() {
* @throws IllegalStateException if this gene is not part of a chromosome
*/
@Override
@Deprecated
public Optional<G> getParent() {
checkTreeState();

Expand Down

0 comments on commit a87292b

Please sign in to comment.