Commit ff1a1bef authored by RomanKosovnenko's avatar RomanKosovnenko
Browse files

add setters to GeneticSolver

parent 2dce6269
......@@ -7,6 +7,8 @@ import de.tudresden.inf.st.mquat.jastadd.model.Root;
import de.tudresden.inf.st.mquat.solving.BenchmarkableSolver;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.net.ssl.SslConfiguration;
import de.tudresden.inf.st.mquat.jastadd.model.Solution;
import de.tudresden.inf.st.mquat.solving.SolvingException;
......@@ -58,32 +60,72 @@ public class GeneticMain {
long timeoutValue = 20; //from scenarios.json
String timeoutUnit = "SECONDS"; //from scenarios.json, possible values - "SECONDS", "MINUTES"
//
double treeCrossoverOperatorMin = 0.0d;
double treeCrossoverOperatorMax = 1.0d;
double treeCrossoverOperatorProbability = 0.5;
double treeMutateOperatorMin = 0.0d;
double treeMutateOperatorMax = 1.0d;
double treeMutateOperatorP = 0.9;
double treeMutateOperatorP1 = 3.0;
double treeMutateOperatorP2 = 0.7;
double treeMutateOperatorP3 = 0.4;
double opt4jEvaluatorK1 = 0.5;
double opt4jEvaluatorK2 = 0.5;
//
///
int lambda = 25;
double crossoverRate= 0.95;
int mu = 25;
int tournament = 0;
///
int generations = 200000;
int populationSize = 1000;
if (args.length == 2) {
logger.debug("============ Args: " + args[0] + " and " + args[1]);
generations = Integer.parseInt(args[0]);
populationSize = Integer.parseInt(args[1]);
logger.debug("============ generations = " + generations + ", populationSize = " + populationSize);
} else if (args.length == 15){
} else if (args.length == 30){
logger.debug("============ Args: " + String.join("and",args));
generations = Integer.parseInt(args[0]);
populationSize = Integer.parseInt(args[1]);
numTopLevelComponents = Integer.parseInt(args[2]);
avgNumImplSubComponents = Integer.parseInt(args[3]);
implSubComponentStdDerivation = Integer.parseInt(args[4]);
avgNumCompSubComponents = Integer.parseInt(args[5]);
compSubComponentStdDerivation = Integer.parseInt(args[6]);
componentDepth = Integer.parseInt(args[7]);
numImplementations = Integer.parseInt(args[8]);
excessComputeResourceRatio = Double.parseDouble(args[9]);
numRequests = Integer.parseInt(args[10]);
numCpus = Integer.parseInt(args[11]);
seed = Integer.parseInt(args[12]);
timeoutValue = Integer.parseInt(args[13]);
timeoutUnit = args[14];
numTopLevelComponents = Integer.parseInt(args[0]);
avgNumImplSubComponents = Integer.parseInt(args[1]);
implSubComponentStdDerivation = Integer.parseInt(args[2]);
avgNumCompSubComponents = Integer.parseInt(args[3]);
compSubComponentStdDerivation = Integer.parseInt(args[4]);
componentDepth = Integer.parseInt(args[5]);
numImplementations = Integer.parseInt(args[6]);
excessComputeResourceRatio = Double.parseDouble(args[7]);
numRequests = Integer.parseInt(args[8]);
numCpus = Integer.parseInt(args[9]);
seed = Integer.parseInt(args[10]);
timeoutValue = Integer.parseInt(args[11]);
timeoutUnit = args[12];
generations = Integer.parseInt(args[13]);
populationSize = Integer.parseInt(args[14]);
//
treeCrossoverOperatorMin = Double.parseDouble(args[15]);
treeCrossoverOperatorMax = Double.parseDouble(args[16]);
treeCrossoverOperatorProbability = Double.parseDouble(args[17]);
treeMutateOperatorMin = Double.parseDouble(args[18]);
treeMutateOperatorMax = Double.parseDouble(args[19]);
treeMutateOperatorP = Double.parseDouble(args[20]);
treeMutateOperatorP1 = Double.parseDouble(args[21]);
treeMutateOperatorP2 = Double.parseDouble(args[22]);
treeMutateOperatorP3 = Double.parseDouble(args[23]);
opt4jEvaluatorK1 = Double.parseDouble(args[24]);
opt4jEvaluatorK2 = Double.parseDouble(args[25]);
//
///
lambda = Integer.parseInt(args[26]);
crossoverRate = Double.parseDouble(args[27]);
mu = Integer.parseInt(args[28]);
tournament = Integer.parseInt(args[29]);
///
logger.debug( String.format("============ generations = %d populationSize = %d numTopLevelComponents = %d" +
" avgNumImplSubComponents = %d implSubComponentStdDerivation = %d avgNumCompSubComponents = %d compSubComponentStdDerivation = %d componentDepth = %d" +
" numImplementations = %d excessComputeResourceRatio = %f numRequests = %d numCpus = %d seed = %d timeoutValue = %d timeoutUnit = %s",
......@@ -104,6 +146,25 @@ public class GeneticMain {
BenchmarkableSolver solver = new GeneticSolver(GeneticSolver.SelectorType.NSGA2, generations, populationSize);
solver.setTimeout(timeoutValue, TimeUnit.valueOf(timeoutUnit));
//
((GeneticSolver) solver).setTreeCrossoverOperatorMin(treeCrossoverOperatorMin);
((GeneticSolver) solver).setTreeCrossoverOperatorMax(treeCrossoverOperatorMax);
((GeneticSolver) solver).setTreeCrossoverOperatorProbability(treeCrossoverOperatorProbability);
((GeneticSolver) solver).setTreeMutateOperatorMin(treeMutateOperatorMin);
((GeneticSolver) solver).setTreeMutateOperatorMax(treeMutateOperatorMax);
((GeneticSolver) solver).setTreeMutateOperatorP(treeMutateOperatorP);
((GeneticSolver) solver).setTreeMutateOperatorP1(treeMutateOperatorP1);
((GeneticSolver) solver).setTreeMutateOperatorP2(treeMutateOperatorP2);
((GeneticSolver) solver).setTreeMutateOperatorP3(treeMutateOperatorP3);
((GeneticSolver) solver).setOpt4jEvaluatorK1(opt4jEvaluatorK1);
((GeneticSolver) solver).setOpt4jEvaluatorK2(opt4jEvaluatorK2);
//
///
((GeneticSolver) solver).setLambda(lambda);
((GeneticSolver) solver).setCrossoverRate(crossoverRate);
((GeneticSolver) solver).setMu(mu);
((GeneticSolver) solver).setTournament(tournament);
///
Path path_for_results = Paths.get("results/scenarios");
createDirIfNecessary(path_for_results);
Path results_file = Paths.get(path_for_results.toString() + "/" + scenario_name + ".csv");
......
......@@ -46,18 +46,22 @@ public class GeneticSolver implements BenchmarkableSolver {
private double treeCrossoverOperatorMin;
private double treeCrossoverOperatorMax;
private double treeCrossoverOperatorProbability;
private double treeMutateOperatorMin;
private double treeMutateOperatorMax;
private double treeMutateOperatorP;
private double treeMutateOperatorP1;
private double treeMutateOperatorP2;
private double treeMutateOperatorP3;
private double opt4jEvaluatorK1;
private double opt4jEvaluatorK2;
//
///
private int lambda;
private double crossoverRate;
private int mu;
private int tournament;
///
public GeneticSolver() {
this(SelectorType.NSGA2, 100, 100);
}
......@@ -87,12 +91,12 @@ public class GeneticSolver implements BenchmarkableSolver {
EvolutionaryAlgorithmModule ea = new EvolutionaryAlgorithmModule();
ea.setGenerations(this.generations); //The number of generations.
ea.setAlpha(this.populationSize); //The size of the population.4
//
ea.setLambda(lambda); //The number of offspring per generation. //Dep inj no
ea.setCrossoverRate(crossoverRate); //Performs a crossover operation with this given rate. //Dep inj no
ea.setCrossoverRateType(CrossoverRateType.CONSTANT); // no more variants //Dep inj no
ea.setMu(mu); //The number of parents per generation. //Dep inj no
//
Opt4jModule mquatModule = new Opt4jModule();
......@@ -198,4 +202,54 @@ public class GeneticSolver implements BenchmarkableSolver {
NSGA2,
SPEA2
}
//
public void setTreeCrossoverOperatorMin(double treeCrossoverOperatorMin) {
this.treeCrossoverOperatorMin = treeCrossoverOperatorMin;
}
public void setTreeCrossoverOperatorMax(double treeCrossoverOperatorMax) {
this.treeCrossoverOperatorMax = treeCrossoverOperatorMax;
}
public void setTreeCrossoverOperatorProbability(double treeCrossoverOperatorProbability) {
this.treeCrossoverOperatorProbability = treeCrossoverOperatorProbability;
}
public void setTreeMutateOperatorMin(double treeMutateOperatorMin) {
this.treeMutateOperatorMin = treeMutateOperatorMin;
}
public void setTreeMutateOperatorMax(double treeMutateOperatorMax) {
this.treeMutateOperatorMax = treeMutateOperatorMax;
}
public void setTreeMutateOperatorP(double treeMutateOperatorP) {
this.treeMutateOperatorP = treeMutateOperatorP;
}
public void setTreeMutateOperatorP1(double treeMutateOperatorP1) {
this.treeMutateOperatorP1 = treeMutateOperatorP1;
}
public void setTreeMutateOperatorP2(double treeMutateOperatorP2) {
this.treeMutateOperatorP2 = treeMutateOperatorP2;
}
public void setTreeMutateOperatorP3(double treeMutateOperatorP3) {
this.treeMutateOperatorP3 = treeMutateOperatorP3;
}
public void setOpt4jEvaluatorK1(double opt4jEvaluatorK1) {
this.opt4jEvaluatorK1 = opt4jEvaluatorK1;
}
public void setOpt4jEvaluatorK2(double opt4jEvaluatorK2) {
this.opt4jEvaluatorK2 = opt4jEvaluatorK2;
}
//
///
public void setLambda(int lambda) {
this.lambda = lambda;
}
public void setCrossoverRate(double crossoverRate) {
this.crossoverRate = crossoverRate;
}
public void setMu(int mu) {
this.mu = mu;
}
public void setTournament(int tournament) {
this.tournament = tournament;
}
///
}
......@@ -8,6 +8,8 @@ import org.opt4j.core.Objective.Sign;
import org.opt4j.core.Objectives;
import org.opt4j.core.problem.Evaluator;
import com.google.inject.Inject;
public class Opt4jEvaluator implements Evaluator<Solution> {
//
......
......@@ -22,9 +22,9 @@ import java.util.Random;
public class TreeCrossoverOperator implements Crossover<TreeGenotype<Request, Instance, Resource, Implementation>> {
private final Random random;
private final double Min = 0.0d; //Dep inj TreeCrossoverOperatorMin
private final double Max = 1.0d; //Dep inj TreeCrossoverOperatorMax
private final double probability = 0.5; //Dep inj TreeCrossoverOperatorProbability
private double Min = 0.0d; //Dep inj TreeCrossoverOperatorMin
private double Max = 1.0d; //Dep inj TreeCrossoverOperatorMax
private double probability = 0.5; //Dep inj TreeCrossoverOperatorProbability
@Inject
public TreeCrossoverOperator(Rand random, @TreeCrossoverOperatorMin double treeCrossoverOperatorMin, @TreeCrossoverOperatorMax double treeCrossoverOperatorMax, @TreeCrossoverOperatorProbability double treeCrossoverOperatorProbability) {
......
......@@ -23,8 +23,8 @@ import java.util.Random;
public class TreeMutateOperator implements Mutate<TreeGenotype<Request, Instance, Resource, Implementation>> {
private final Random random;
private final double Min = 0.0d; //Dep inj TreeMutateOperatorMin
private final double Max = 1.0d; //Dep inj TreeMutateOperatorMax
private double Min = 0.0d; //Dep inj TreeMutateOperatorMin
private double Max = 1.0d; //Dep inj TreeMutateOperatorMax
//
private double treeMutateOperatorP;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment