Fix performance issue with CLI execution (SnakeYAML doesn't perform well
when serializing large objects) Implement easier access for terminators.
This commit is contained in:
parent
5a80cb781e
commit
ca108a5d97
@ -96,7 +96,12 @@ final class YamlStatistics implements InterfaceStatistics {
|
|||||||
public void stopOptimizationPerformed(boolean normal, String stopMessage) {
|
public void stopOptimizationPerformed(boolean normal, String stopMessage) {
|
||||||
this.currentRun.put("stopMessage", stopMessage);
|
this.currentRun.put("stopMessage", stopMessage);
|
||||||
this.currentRun.put("totalFunctionCalls", this.currentParameters.getOptimizer().getPopulation().getFunctionCalls());
|
this.currentRun.put("totalFunctionCalls", this.currentParameters.getOptimizer().getPopulation().getFunctionCalls());
|
||||||
this.currentRun.put("generations", currentGenerations);
|
// ToDo: Figure out a sane way to do this. Having multirun > 1 increases SnakeYAML memory consumption to beyond infinity
|
||||||
|
//this.currentRun.put("generations", currentGenerations);
|
||||||
|
Population pop = this.currentParameters.getOptimizer().getAllSolutions().getSolutions();
|
||||||
|
this.currentRun.put("solution", pop.getBestEAIndividual().getDoublePosition().clone());
|
||||||
|
this.currentRun.put("bestFitness", pop.getBestFitness().clone());
|
||||||
|
this.currentRun.put("meanFitness", pop.getMeanFitness().clone());
|
||||||
this.runs.add(currentRun);
|
this.runs.add(currentRun);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,9 +168,10 @@ public final class OptimizationBuilder {
|
|||||||
if (type.isPrimitive() && ((ArgumentTree)tree.get(name)).getValue() != null) {
|
if (type.isPrimitive() && ((ArgumentTree)tree.get(name)).getValue() != null) {
|
||||||
obj = BeanInspector.stringToPrimitive((String) ((ArgumentTree) tree.get(name)).getValue(), type);
|
obj = BeanInspector.stringToPrimitive((String) ((ArgumentTree) tree.get(name)).getValue(), type);
|
||||||
} else if (type.isArray() && ((ArgumentTree)tree.get(name)).getValue() != null) {
|
} else if (type.isArray() && ((ArgumentTree)tree.get(name)).getValue() != null) {
|
||||||
|
// ToDo: Implement array parsing
|
||||||
} else if (type.isEnum() && ((ArgumentTree)tree.get(name)).getValue() != null) {
|
} else if (type.isEnum() && ((ArgumentTree)tree.get(name)).getValue() != null) {
|
||||||
int enumIndex = Integer.parseInt((String)((ArgumentTree)tree.get(name)).getValue());
|
int enumIndex = Integer.parseInt((String)((ArgumentTree)tree.get(name)).getValue());
|
||||||
|
|
||||||
// ToDo: Properly check
|
// ToDo: Properly check
|
||||||
obj = type.getEnumConstants()[enumIndex];
|
obj = type.getEnumConstants()[enumIndex];
|
||||||
} else {
|
} else {
|
||||||
@ -180,7 +181,11 @@ public final class OptimizationBuilder {
|
|||||||
Class subType;
|
Class subType;
|
||||||
if (className != null) {
|
if (className != null) {
|
||||||
// Try to get the actual class from its name
|
// Try to get the actual class from its name
|
||||||
subType = getClassFromName(className, type);
|
if (className.endsWith("Problem")) {
|
||||||
|
subType = getClassFromName("eva2.problems", className, type);
|
||||||
|
} else {
|
||||||
|
subType = getClassFromName("eva2.optimization", className, type);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
subType = type;
|
subType = type;
|
||||||
}
|
}
|
||||||
@ -207,8 +212,8 @@ public final class OptimizationBuilder {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Class<?> getClassFromName(String name, Class type) {
|
private static Class<?> getClassFromName(String packageName, String name, Class type) {
|
||||||
Class<?>[] classes = ReflectPackage.getAssignableClassesInPackage("eva2", type, true, true);
|
Class<?>[] classes = ReflectPackage.getAssignableClassesInPackage(packageName, type, true, true);
|
||||||
for (Class clazz : classes) {
|
for (Class clazz : classes) {
|
||||||
// We allow both the fully qualified name (eva2.optimization.strategies.GeneticAlgorithm
|
// We allow both the fully qualified name (eva2.optimization.strategies.GeneticAlgorithm
|
||||||
// and the simple name (GeneticAlgorithm)
|
// and the simple name (GeneticAlgorithm)
|
||||||
|
@ -129,7 +129,7 @@ public class CombinedTerminator implements InterfaceTerminator, Serializable {
|
|||||||
/**
|
/**
|
||||||
* @param logicalOperator the logicalOperator to set
|
* @param logicalOperator the logicalOperator to set
|
||||||
*/
|
*/
|
||||||
@Parameter(description = "Set the boolean operator to be used to combine the two terminators.")
|
@Parameter(name = "operator", description = "Set the boolean operator to be used to combine the two terminators.")
|
||||||
public void setLogicalOperator(LogicalOperator logicalOperator) {
|
public void setLogicalOperator(LogicalOperator logicalOperator) {
|
||||||
this.logicalOperator = logicalOperator;
|
this.logicalOperator = logicalOperator;
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import eva2.optimization.population.InterfaceSolutionSet;
|
|||||||
import eva2.optimization.population.PopulationInterface;
|
import eva2.optimization.population.PopulationInterface;
|
||||||
import eva2.problems.InterfaceOptimizationProblem;
|
import eva2.problems.InterfaceOptimizationProblem;
|
||||||
import eva2.util.annotation.Description;
|
import eva2.util.annotation.Description;
|
||||||
|
import eva2.util.annotation.Parameter;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -22,7 +23,7 @@ public class FitnessValueTerminator implements InterfaceTerminator,
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public FitnessValueTerminator() {
|
public FitnessValueTerminator() {
|
||||||
fitnessValue = new double[]{0.1};
|
fitnessValue = new double[]{10E-4};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -70,6 +71,7 @@ public class FitnessValueTerminator implements InterfaceTerminator,
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Parameter(name = "fitness", description = "Set the fitness objective value.")
|
||||||
public void setFitnessValue(double[] x) {
|
public void setFitnessValue(double[] x) {
|
||||||
fitnessValue = x;
|
fitnessValue = x;
|
||||||
}
|
}
|
||||||
@ -80,8 +82,4 @@ public class FitnessValueTerminator implements InterfaceTerminator,
|
|||||||
public double[] getFitnessValue() {
|
public double[] getFitnessValue() {
|
||||||
return fitnessValue;
|
return fitnessValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String fitnessValueTipText() {
|
|
||||||
return "Set the fitness objective value.";
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -693,7 +693,7 @@ public class DifferentialEvolution extends AbstractOptimizer implements java.io.
|
|||||||
*
|
*
|
||||||
* @param f
|
* @param f
|
||||||
*/
|
*/
|
||||||
@Parameter(name = "F", description = "Differential Weight")
|
@Parameter(name = "F", description = "F is a real and constant factor which controls the amplification of the differential variation.")
|
||||||
public void setDifferentialWeight(double f) {
|
public void setDifferentialWeight(double f) {
|
||||||
this.differentialWeight = f;
|
this.differentialWeight = f;
|
||||||
}
|
}
|
||||||
@ -702,17 +702,13 @@ public class DifferentialEvolution extends AbstractOptimizer implements java.io.
|
|||||||
return this.differentialWeight;
|
return this.differentialWeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String differentialWeightTipText() {
|
|
||||||
return "F is a real and constant factor which controls the amplification of the differential variation.";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Probability of alteration through DE (something like a discrete uniform
|
* Probability of alteration through DE (something like a discrete uniform
|
||||||
* crossover is performed here)
|
* crossover is performed here)
|
||||||
*
|
*
|
||||||
* @param k
|
* @param k
|
||||||
*/
|
*/
|
||||||
@Parameter(name = "CR", description = "Crossover Rate")
|
@Parameter(name = "CR", description = "Probability of alteration through DE (a.k.a. CR, similar to discrete uniform crossover).")
|
||||||
public void setCrossoverRate(double k) {
|
public void setCrossoverRate(double k) {
|
||||||
if (k < 0) {
|
if (k < 0) {
|
||||||
k = 0;
|
k = 0;
|
||||||
@ -727,10 +723,6 @@ public class DifferentialEvolution extends AbstractOptimizer implements java.io.
|
|||||||
return this.crossoverRate;
|
return this.crossoverRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String crossoverrateTipText() {
|
|
||||||
return "Probability of alteration through DE (a.k.a. CR, similar to discrete uniform crossover).";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enhance greediness through amplification of the differential vector to
|
* Enhance greediness through amplification of the differential vector to
|
||||||
* the best individual for DE2
|
* the best individual for DE2
|
||||||
@ -751,6 +743,7 @@ public class DifferentialEvolution extends AbstractOptimizer implements java.io.
|
|||||||
*
|
*
|
||||||
* @param l
|
* @param l
|
||||||
*/
|
*/
|
||||||
|
@Parameter(description = "In case of trigonometric mutation DE, the TMO is applied with probability Mt.")
|
||||||
public void setMt(double l) {
|
public void setMt(double l) {
|
||||||
this.mt = l;
|
this.mt = l;
|
||||||
if (this.mt < 0) {
|
if (this.mt < 0) {
|
||||||
@ -765,16 +758,12 @@ public class DifferentialEvolution extends AbstractOptimizer implements java.io.
|
|||||||
return this.mt;
|
return this.mt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String mtTipText() {
|
|
||||||
return "In case of trigonometric mutation DE, the TMO is applied with probability Mt.";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method allows you to choose the type of Differential Evolution.
|
* This method allows you to choose the type of Differential Evolution.
|
||||||
*
|
*
|
||||||
* @param s The type.
|
* @param s The type.
|
||||||
*/
|
*/
|
||||||
@Parameter(name = "type", description = "Mutation type for DE")
|
@Parameter(name = "type", description = "Choose the type of Differential Evolution.")
|
||||||
public void setDEType(eva2.optimization.enums.DEType s) {
|
public void setDEType(eva2.optimization.enums.DEType s) {
|
||||||
this.DEType = s;
|
this.DEType = s;
|
||||||
// show mt for trig. DE only
|
// show mt for trig. DE only
|
||||||
@ -786,10 +775,6 @@ public class DifferentialEvolution extends AbstractOptimizer implements java.io.
|
|||||||
return this.DEType;
|
return this.DEType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String dETypeTipText() {
|
|
||||||
return "Choose the type of Differential Evolution.";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the maximumAge
|
* @return the maximumAge
|
||||||
*/
|
*/
|
||||||
@ -800,14 +785,11 @@ public class DifferentialEvolution extends AbstractOptimizer implements java.io.
|
|||||||
/**
|
/**
|
||||||
* @param maximumAge the maximumAge to set
|
* @param maximumAge the maximumAge to set
|
||||||
*/
|
*/
|
||||||
|
@Parameter(description = "The maximum age of individuals, older ones are discarded. Set to -1 (or 0) to deactivate")
|
||||||
public void setMaximumAge(int maximumAge) {
|
public void setMaximumAge(int maximumAge) {
|
||||||
this.maximumAge = maximumAge;
|
this.maximumAge = maximumAge;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String maximumAgeTipText() {
|
|
||||||
return "The maximum age of individuals, older ones are discarded. Set to -1 (or 0) to deactivate";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the problem range will be enforced.
|
* Check whether the problem range will be enforced.
|
||||||
*
|
*
|
||||||
@ -820,62 +802,47 @@ public class DifferentialEvolution extends AbstractOptimizer implements java.io.
|
|||||||
/**
|
/**
|
||||||
* @param forceRange the forceRange to set
|
* @param forceRange the forceRange to set
|
||||||
*/
|
*/
|
||||||
|
@Parameter(description = "Set whether to enforce the problem range.")
|
||||||
public void setCheckRange(boolean forceRange) {
|
public void setCheckRange(boolean forceRange) {
|
||||||
this.forceRange = forceRange;
|
this.forceRange = forceRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String checkRangeTipText() {
|
|
||||||
return "Set whether to enforce the problem range.";
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRandomizeFKLambda() {
|
public boolean isRandomizeFKLambda() {
|
||||||
return randomizeFKLambda;
|
return randomizeFKLambda;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Parameter(description = "If true, values for k, f, lambda are randomly sampled around +/- 20% of the given values.")
|
||||||
public void setRandomizeFKLambda(boolean randomizeFK) {
|
public void setRandomizeFKLambda(boolean randomizeFK) {
|
||||||
this.randomizeFKLambda = randomizeFK;
|
this.randomizeFKLambda = randomizeFK;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String randomizeFKLambdaTipText() {
|
|
||||||
return "If true, values for k, f, lambda are randomly sampled around +/- 20% of the given values.";
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCompareToParent() {
|
public boolean isCompareToParent() {
|
||||||
return compareToParent;
|
return compareToParent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Parameter(description = "Compare a challenge individual to its original parent instead of a random one.")
|
||||||
public void setCompareToParent(boolean compareToParent) {
|
public void setCompareToParent(boolean compareToParent) {
|
||||||
this.compareToParent = compareToParent;
|
this.compareToParent = compareToParent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String compareToParentTipText() {
|
|
||||||
return "Compare a challenge individual to its original parent instead of a random one.";
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isGenerational() {
|
public boolean isGenerational() {
|
||||||
return generational;
|
return generational;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Parameter(description = "Switch to generational DE as opposed to standard steady-state DE")
|
||||||
public void setGenerational(boolean generational) {
|
public void setGenerational(boolean generational) {
|
||||||
this.generational = generational;
|
this.generational = generational;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String generationalTipText() {
|
|
||||||
return "Switch to generational DE as opposed to standard steady-state DE";
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCyclePop() {
|
public boolean isCyclePop() {
|
||||||
return cyclePop;
|
return cyclePop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Parameter(description = "if true, individuals are used as parents in a cyclic sequence - otherwise randomly ")
|
||||||
public void setCyclePop(boolean cycle) {
|
public void setCyclePop(boolean cycle) {
|
||||||
this.cyclePop = cycle;
|
this.cyclePop = cycle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String cyclePopTipText() {
|
|
||||||
return "if true, individuals are used as parents in a cyclic sequence - otherwise randomly ";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the maximumAge
|
* @return the maximumAge
|
||||||
*/
|
*/
|
||||||
@ -885,11 +852,8 @@ public class DifferentialEvolution extends AbstractOptimizer implements java.io.
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
|
@Parameter(description = "Re-evaluates individuals which are older than maximum age instead of discarding them")
|
||||||
public void setReEvaluate(boolean reEvaluate) {
|
public void setReEvaluate(boolean reEvaluate) {
|
||||||
this.reEvaluate = reEvaluate;
|
this.reEvaluate = reEvaluate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String reEvaluateTipText() {
|
|
||||||
return "Re-evaluates individuals which are older than maximum age instead of discarding them";
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user