Skip to content

Commit

Permalink
#566: Normalize evolution params.
Browse files Browse the repository at this point in the history
  • Loading branch information
jenetics committed Aug 22, 2019
1 parent e6425e8 commit ef7912c
Showing 1 changed file with 27 additions and 28 deletions.
55 changes: 27 additions & 28 deletions jenetics/src/main/java/io/jenetics/engine/EvolutionParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,25 @@ public final class EvolutionParams<
private final Selector<G, C> _offspringSelector;
private final Alterer<G, C> _alterer;
private final Optimize _optimize;
private final int _offspringCount;
private final int _survivorsCount;
private final int _populationSize;
private final double _offspringFraction;
private final long _maximalPhenotypeAge;

private EvolutionParams(
final Selector<G, C> survivorsSelector,
final Selector<G, C> offspringSelector,
final Alterer<G, C> alterer,
final Optimize optimize,
final int offspringCount,
final int survivorsCount,
final int populationSize,
final double offspringFraction,
final long maximalPhenotypeAge
) {
_survivorsSelector = survivorsSelector;
_offspringSelector = offspringSelector;
_alterer = alterer;
_optimize = optimize;
_offspringCount = offspringCount;
_survivorsCount = survivorsCount;
_populationSize = populationSize;
_offspringFraction = offspringFraction;
_maximalPhenotypeAge = maximalPhenotypeAge;
}

Expand Down Expand Up @@ -109,13 +109,32 @@ public Alterer<G, C> getAlterer() {
return _alterer;
}


/**
* Return the offspring fraction.
*
* @return the offspring fraction.
*/
public double getOffspringFraction() {
return _offspringFraction;
}

/**
* Return the number of individuals of a population.
*
* @return the number of individuals of a population
*/
public int getPopulationSize() {
return _populationSize;
}

/**
* Return the number of selected offsprings.
*
* @return the number of selected offsprings
*/
public int getOffspringCount() {
return _offspringCount;
return (int)Math.round(_populationSize*_offspringFraction);
}

/**
Expand All @@ -124,16 +143,7 @@ public int getOffspringCount() {
* @return the number of selected survivors
*/
public int getSurvivorsCount() {
return _survivorsCount;
}

/**
* Return the number of individuals of a population.
*
* @return the number of individuals of a population
*/
public int getPopulationSize() {
return _offspringCount + _survivorsCount;
return _populationSize - getOffspringCount();
}

/**
Expand Down Expand Up @@ -204,17 +214,6 @@ public static final class Builder<
private Builder() {
}

public Builder<G, C> evolutionParams(final EvolutionParams<G, C> params) {
survivorsSelector(params.getSurvivorsSelector());
offspringSelector(params.getOffspringSelector());
alterers(params.getAlterer());
optimize(params.getOptimize());
offspringFraction(params.getS());
populationSize(params.getPopulationSize());
maximalPhenotypeAge(params.getMaximalPhenotypeAge());
return this;
}

/**
* The selector used for selecting the offspring population. <i>Default
* values is set to {@code TournamentSelector<>(3)}.</i>
Expand Down

0 comments on commit ef7912c

Please sign in to comment.