Skip to content

Commit

Permalink
#645: Deprecate getter for EvolutionStart.
Browse files Browse the repository at this point in the history
  • Loading branch information
jenetics committed Jan 23, 2020
1 parent a9db688 commit 1a0e139
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
Expand Up @@ -94,7 +94,7 @@ public void concat1b() {
EvolutionInit<IntegerGene> init = EvolutionInit.of(
EvolutionStreams.result(5)
.toEvolutionStart()
.getPopulation().stream()
.population().stream()
.map(Phenotype::genotype)
.collect(ISeq.toISeq()),
1
Expand Down
Expand Up @@ -49,10 +49,10 @@ static EvolutionStreamable<IntegerGene, Integer> streamable(final int size) {
@Override
public Integer get() {
if (value == null) {
value = start.get().getPopulation().isEmpty()
value = start.get().population().isEmpty()
? 0
: start.get()
.getPopulation()
.population()
.get(0)
.genotype()
.gene()
Expand Down
16 changes: 8 additions & 8 deletions jenetics/src/main/java/io/jenetics/engine/Engine.java
Expand Up @@ -218,7 +218,7 @@ public EvolutionResult<G, C> apply(final EvolutionStart<G, C> start) {
@Override
public EvolutionResult<G, C> evolve(final EvolutionStart<G, C> start) {
// Create initial population if `start` is empty.
final EvolutionStart<G, C> es = start.getPopulation().isEmpty()
final EvolutionStart<G, C> es = start.population().isEmpty()
? evolutionStart(start)
: start;

Expand All @@ -227,7 +227,7 @@ public EvolutionResult<G, C> evolve(final EvolutionStart<G, C> start) {

// Initial evaluation of the population.
final ISeq<Phenotype<G, C>> evaluated = timing.evaluation.timing(() ->
evaluate(es.getPopulation())
evaluate(es.population())
);

// Select the offspring population.
Expand All @@ -252,7 +252,7 @@ public EvolutionResult<G, C> evolve(final EvolutionStart<G, C> start) {
final CompletableFuture<AltererResult<G, C>> alteredOffspring =
offspring.thenApplyAsync(off ->
timing.offspringAlter.timing(() ->
_alterer.alter(off, es.getGeneration())
_alterer.alter(off, es.generation())
),
_executor
);
Expand All @@ -261,7 +261,7 @@ public EvolutionResult<G, C> evolve(final EvolutionStart<G, C> start) {
final CompletableFuture<FilterResult<G, C>> filteredSurvivors =
survivors.thenApplyAsync(sur ->
timing.survivorFilter.timing(() ->
filter(sur, es.getGeneration())
filter(sur, es.generation())
),
_executor
);
Expand All @@ -270,7 +270,7 @@ public EvolutionResult<G, C> evolve(final EvolutionStart<G, C> start) {
final CompletableFuture<FilterResult<G, C>> filteredOffspring =
alteredOffspring.thenApplyAsync(off ->
timing.offspringFilter.timing(() ->
filter(off.population(), es.getGeneration())
filter(off.population(), es.generation())
),
_executor
);
Expand Down Expand Up @@ -302,7 +302,7 @@ public EvolutionResult<G, C> evolve(final EvolutionStart<G, C> start) {
EvolutionResult<G, C> er = EvolutionResult.of(
_optimize,
result,
es.getGeneration(),
es.generation(),
timing.toDurations(),
killCount,
invalidCount,
Expand Down Expand Up @@ -422,8 +422,8 @@ public EvolutionStream<G, C> stream(final EvolutionInit<G> init) {

private EvolutionStart<G, C>
evolutionStart(final EvolutionStart<G, C> start) {
final ISeq<Phenotype<G, C>> population = start.getPopulation();
final long gen = start.getGeneration();
final ISeq<Phenotype<G, C>> population = start.population();
final long gen = start.generation();

final Stream<Phenotype<G, C>> stream = Stream.concat(
population.stream(),
Expand Down
24 changes: 23 additions & 1 deletion jenetics/src/main/java/io/jenetics/engine/EvolutionStart.java
Expand Up @@ -45,7 +45,7 @@
*
* @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
* @since 3.1
* @version 5.1
* @version !__version__!
*/
public final class EvolutionStart<
G extends Gene<?, G>,
Expand All @@ -68,6 +68,17 @@ private EvolutionStart(
*
* @return the start population
*/
public ISeq<Phenotype<G, C>> population() {
return _population;
}

/**
* Return the population before the evolution step.
*
* @return the start population
* @deprecated Use {@link #population()} instead
*/
@Deprecated
public ISeq<Phenotype<G, C>> getPopulation() {
return _population;
}
Expand All @@ -77,6 +88,17 @@ public ISeq<Phenotype<G, C>> getPopulation() {
*
* @return the start generation
*/
public long generation() {
return _generation;
}

/**
* Return the generation of the start population.
*
* @return the start generation
* @deprecated Use {@link #generation()} instead
*/
@Deprecated
public long getGeneration() {
return _generation;
}
Expand Down
Expand Up @@ -84,7 +84,7 @@ public void ofAdjustableEvolution() {

private static double var(final EvolutionStart<DoubleGene, Double> result) {
return result != null
? result.getPopulation().stream()
? result.population().stream()
.map(Phenotype::fitness)
.collect(DoubleMoments.toDoubleMoments())
.variance()
Expand Down

0 comments on commit 1a0e139

Please sign in to comment.