Skip to content
Snippets Groups Projects
Commit ce27b084 authored by Bernhard Johannes Berger's avatar Bernhard Johannes Berger
Browse files

Made size of elite and tournament selector relative to population size. fix #11

parent 7536f21e
No related branches found
No related tags found
No related merge requests found
Pipeline #244264 passed
......@@ -8,10 +8,14 @@ import io.jenetics.*;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.inject.Named;
@ApplicationScoped
public class SelectorFactory {
@Inject
@ConfigurationValue(entry = CoreBlackboardEntries.OPTIMISATION_CONFIGURATION, access = "algorithm.size-of-population")
private int sizeOfPopulation;
@Produces
@Named("survivor")
......@@ -60,9 +64,9 @@ public class SelectorFactory {
return new TruncationSelector<>(worstRank);
}
private static <G extends Gene<?,G>, C extends Comparable<? super C>> Selector<G, C> createTournamentSelector(final Instance config) {
int sampleSize = LanguageHelper.lookup(config, "size");
return new TournamentSelector<>(sampleSize);
private <G extends Gene<?,G>, C extends Comparable<? super C>> Selector<G, C> createTournamentSelector(final Instance config) {
int count = (int)(LanguageHelper.<Double>lookup(config, "size-factor") * sizeOfPopulation);
return new TournamentSelector<>(count);
}
private static <G extends Gene<?,G>, C extends Comparable<? super C>> Selector<G, C> createStochasticUniversalSelector(final Instance config) {
......@@ -82,9 +86,8 @@ public class SelectorFactory {
}
private <G extends Gene<?,G>, C extends Comparable<? super C>> EliteSelector<G,C> createEliteSelector(final Instance config) {
int count = LanguageHelper.lookup(config, "count");
final Instance nonEliteSelectorConfig = LanguageHelper.lookup(config, "nonEliteSelector");
int count = (int)(LanguageHelper.<Double>lookup(config, "size-factor") * sizeOfPopulation);
final Instance nonEliteSelectorConfig = LanguageHelper.lookup(config, "non-elite-selector");
if(nonEliteSelectorConfig == null) {
return new EliteSelector<>(count);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment