diff --git a/src/eva2/cli/Main.java b/src/eva2/cli/Main.java index eef1d50e..c515fb55 100644 --- a/src/eva2/cli/Main.java +++ b/src/eva2/cli/Main.java @@ -96,7 +96,12 @@ final class YamlStatistics implements InterfaceStatistics { public void stopOptimizationPerformed(boolean normal, String stopMessage) { this.currentRun.put("stopMessage", stopMessage); 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); } diff --git a/src/eva2/cli/OptimizationBuilder.java b/src/eva2/cli/OptimizationBuilder.java index 6564e73d..1e4fe05e 100644 --- a/src/eva2/cli/OptimizationBuilder.java +++ b/src/eva2/cli/OptimizationBuilder.java @@ -168,9 +168,10 @@ public final class OptimizationBuilder { if (type.isPrimitive() && ((ArgumentTree)tree.get(name)).getValue() != null) { obj = BeanInspector.stringToPrimitive((String) ((ArgumentTree) tree.get(name)).getValue(), type); } else if (type.isArray() && ((ArgumentTree)tree.get(name)).getValue() != null) { - + // ToDo: Implement array parsing } else if (type.isEnum() && ((ArgumentTree)tree.get(name)).getValue() != null) { int enumIndex = Integer.parseInt((String)((ArgumentTree)tree.get(name)).getValue()); + // ToDo: Properly check obj = type.getEnumConstants()[enumIndex]; } else { @@ -180,7 +181,11 @@ public final class OptimizationBuilder { Class subType; if (className != null) { // 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 { subType = type; } @@ -207,8 +212,8 @@ public final class OptimizationBuilder { return instance; } - private static Class getClassFromName(String name, Class type) { - Class[] classes = ReflectPackage.getAssignableClassesInPackage("eva2", type, true, true); + private static Class getClassFromName(String packageName, String name, Class type) { + Class[] classes = ReflectPackage.getAssignableClassesInPackage(packageName, type, true, true); for (Class clazz : classes) { // We allow both the fully qualified name (eva2.optimization.strategies.GeneticAlgorithm // and the simple name (GeneticAlgorithm) diff --git a/src/eva2/optimization/operator/terminators/CombinedTerminator.java b/src/eva2/optimization/operator/terminators/CombinedTerminator.java index c2a8f315..1d6a8f83 100644 --- a/src/eva2/optimization/operator/terminators/CombinedTerminator.java +++ b/src/eva2/optimization/operator/terminators/CombinedTerminator.java @@ -129,7 +129,7 @@ public class CombinedTerminator implements InterfaceTerminator, Serializable { /** * @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) { this.logicalOperator = logicalOperator; } diff --git a/src/eva2/optimization/operator/terminators/FitnessValueTerminator.java b/src/eva2/optimization/operator/terminators/FitnessValueTerminator.java index 22315ec4..7e04bbdb 100644 --- a/src/eva2/optimization/operator/terminators/FitnessValueTerminator.java +++ b/src/eva2/optimization/operator/terminators/FitnessValueTerminator.java @@ -5,6 +5,7 @@ import eva2.optimization.population.InterfaceSolutionSet; import eva2.optimization.population.PopulationInterface; import eva2.problems.InterfaceOptimizationProblem; import eva2.util.annotation.Description; +import eva2.util.annotation.Parameter; import java.io.Serializable; import java.util.Arrays; @@ -22,7 +23,7 @@ public class FitnessValueTerminator implements InterfaceTerminator, * */ public FitnessValueTerminator() { - fitnessValue = new double[]{0.1}; + fitnessValue = new double[]{10E-4}; } @Override @@ -70,6 +71,7 @@ public class FitnessValueTerminator implements InterfaceTerminator, /** * */ + @Parameter(name = "fitness", description = "Set the fitness objective value.") public void setFitnessValue(double[] x) { fitnessValue = x; } @@ -80,8 +82,4 @@ public class FitnessValueTerminator implements InterfaceTerminator, public double[] getFitnessValue() { return fitnessValue; } - - public String fitnessValueTipText() { - return "Set the fitness objective value."; - } } \ No newline at end of file diff --git a/src/eva2/optimization/strategies/DifferentialEvolution.java b/src/eva2/optimization/strategies/DifferentialEvolution.java index 9f56a600..dbb578c7 100644 --- a/src/eva2/optimization/strategies/DifferentialEvolution.java +++ b/src/eva2/optimization/strategies/DifferentialEvolution.java @@ -693,7 +693,7 @@ public class DifferentialEvolution extends AbstractOptimizer implements java.io. * * @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) { this.differentialWeight = f; } @@ -702,17 +702,13 @@ public class DifferentialEvolution extends AbstractOptimizer implements java.io. 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 * crossover is performed here) * * @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) { if (k < 0) { k = 0; @@ -727,10 +723,6 @@ public class DifferentialEvolution extends AbstractOptimizer implements java.io. 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 * the best individual for DE2 @@ -751,6 +743,7 @@ public class DifferentialEvolution extends AbstractOptimizer implements java.io. * * @param l */ + @Parameter(description = "In case of trigonometric mutation DE, the TMO is applied with probability Mt.") public void setMt(double l) { this.mt = l; if (this.mt < 0) { @@ -765,16 +758,12 @@ public class DifferentialEvolution extends AbstractOptimizer implements java.io. 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. * * @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) { this.DEType = s; // show mt for trig. DE only @@ -786,10 +775,6 @@ public class DifferentialEvolution extends AbstractOptimizer implements java.io. return this.DEType; } - public String dETypeTipText() { - return "Choose the type of Differential Evolution."; - } - /** * @return the maximumAge */ @@ -800,14 +785,11 @@ public class DifferentialEvolution extends AbstractOptimizer implements java.io. /** * @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) { 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. * @@ -820,62 +802,47 @@ public class DifferentialEvolution extends AbstractOptimizer implements java.io. /** * @param forceRange the forceRange to set */ + @Parameter(description = "Set whether to enforce the problem range.") public void setCheckRange(boolean forceRange) { this.forceRange = forceRange; } - public String checkRangeTipText() { - return "Set whether to enforce the problem range."; - } - public boolean isRandomizeFKLambda() { 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) { 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() { return compareToParent; } + @Parameter(description = "Compare a challenge individual to its original parent instead of a random one.") public void setCompareToParent(boolean compareToParent) { this.compareToParent = compareToParent; } - public String compareToParentTipText() { - return "Compare a challenge individual to its original parent instead of a random one."; - } - public boolean isGenerational() { return generational; } + @Parameter(description = "Switch to generational DE as opposed to standard steady-state DE") public void setGenerational(boolean generational) { this.generational = generational; } - public String generationalTipText() { - return "Switch to generational DE as opposed to standard steady-state DE"; - } - public boolean isCyclePop() { return cyclePop; } + @Parameter(description = "if true, individuals are used as parents in a cyclic sequence - otherwise randomly ") public void setCyclePop(boolean cycle) { this.cyclePop = cycle; } - public String cyclePopTipText() { - return "if true, individuals are used as parents in a cyclic sequence - otherwise randomly "; - } - /** * @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) { this.reEvaluate = reEvaluate; } - - public String reEvaluateTipText() { - return "Re-evaluates individuals which are older than maximum age instead of discarding them"; - } } \ No newline at end of file