New MaximumTimeTerminator
closes #28 - Implements new MaximumTimeTerminator - Bit of cleanup + making some classes final where useful
This commit is contained in:
parent
079715bb24
commit
6465afb3e9
@ -26,7 +26,7 @@ import java.util.logging.Logger;
|
||||
/**
|
||||
* There are some trick methods interpreted here. Check EvA2Notes.txt.
|
||||
*/
|
||||
public class PropertySheetPanel extends JPanel implements PropertyChangeListener {
|
||||
public final class PropertySheetPanel extends JPanel implements PropertyChangeListener {
|
||||
|
||||
public final static Logger LOGGER = Logger.getLogger(PropertySheetPanel.class.getName());
|
||||
/**
|
||||
|
@ -7,6 +7,7 @@ import eva2.problems.InterfaceOptimizationProblem;
|
||||
import eva2.util.annotation.Description;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -63,8 +64,7 @@ public class FitnessValueTerminator implements InterfaceTerminator,
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
String ret = "FitnessValueTerminator,fitnessValue=" + fitnessValue;
|
||||
return ret;
|
||||
return "FitnessValueTerminator,fitnessValue=" + Arrays.toString(fitnessValue);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,55 @@
|
||||
package eva2.optimization.operator.terminators;
|
||||
|
||||
import eva2.optimization.population.InterfaceSolutionSet;
|
||||
import eva2.optimization.population.PopulationInterface;
|
||||
import eva2.problems.InterfaceOptimizationProblem;
|
||||
import eva2.util.annotation.Description;
|
||||
import eva2.util.annotation.Parameter;
|
||||
|
||||
/**
|
||||
* This terminator stops the optimization after maximumTime seconds have passed.
|
||||
*
|
||||
* Note: Actual execution time depends on when the termination criteria is checked
|
||||
* (usually after a generation has been performed) and on the precision of the system
|
||||
* clock. Runs will terminate after a minimum of maximumTime seconds.
|
||||
*/
|
||||
@Description("Terminate if a maximum time (seconds) was reached.")
|
||||
public class MaximumTimeTerminator implements InterfaceTerminator {
|
||||
@Parameter(name = "maxTime", description = "Maximum time in seconds")
|
||||
private int maximumTime = 5;
|
||||
|
||||
private long startTime;
|
||||
|
||||
@Override
|
||||
public boolean isTerminated(PopulationInterface pop) {
|
||||
return (startTime/1000.0) + maximumTime < (System.currentTimeMillis()/1000.0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTerminated(InterfaceSolutionSet pop) {
|
||||
return (startTime/1000.0) + maximumTime < (System.currentTimeMillis()/1000.0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String lastTerminationMessage() {
|
||||
return "Maximum Time of " + maximumTime + " seconds reached";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(InterfaceOptimizationProblem prob) {
|
||||
startTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MaximumTimeTerminator,maximumTime=" + maximumTime;
|
||||
}
|
||||
|
||||
public int getMaximumTime() {
|
||||
return maximumTime;
|
||||
}
|
||||
|
||||
public void setMaximumTime(int maximumTime) {
|
||||
this.maximumTime = maximumTime;
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ import eva2.optimization.individuals.AbstractEAIndividual;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
class WaitForEvARunnable implements Runnable {
|
||||
final class WaitForEvARunnable implements Runnable {
|
||||
OptimizerRunnable runnable;
|
||||
MatlabProblem mp;
|
||||
|
||||
|
@ -4,7 +4,6 @@ package eva2.problems.simple;
|
||||
* A simple interface to easily include new optimization problems in Java into the
|
||||
* EvA framework.
|
||||
*/
|
||||
|
||||
public interface InterfaceSimpleProblem<T> {
|
||||
/**
|
||||
* Evaluate a double vector representing a possible problem solution as
|
||||
|
@ -1,10 +1,9 @@
|
||||
package eva2.problems.simple;
|
||||
|
||||
import eva2.util.annotation.Description;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.BitSet;
|
||||
|
||||
public abstract class SimpleProblemBinary implements InterfaceSimpleProblem<BitSet>, Serializable {
|
||||
public static String globalInfo() {
|
||||
return "A simple binary problem. Override globalInfo() to insert more information.";
|
||||
}
|
||||
}
|
||||
@Description("A simple binary problem. Override globalInfo() to insert more information.")
|
||||
public abstract class SimpleProblemBinary implements InterfaceSimpleProblem<BitSet>, Serializable { }
|
@ -1,9 +1,8 @@
|
||||
package eva2.problems.simple;
|
||||
|
||||
import eva2.util.annotation.Description;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public abstract class SimpleProblemDouble implements InterfaceSimpleProblem<double[]>, Serializable {
|
||||
public static String globalInfo() {
|
||||
return "A simple double valued problem. Override globalInfo() to insert more information.";
|
||||
}
|
||||
}
|
||||
@Description("A simple double valued problem. Override globalInfo() to insert more information.")
|
||||
public abstract class SimpleProblemDouble implements InterfaceSimpleProblem<double[]>, Serializable {}
|
||||
|
@ -10,7 +10,7 @@ import eva2.tools.Pair;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class BayNet {
|
||||
public final class BayNet {
|
||||
|
||||
private boolean[][] network = null;
|
||||
private int dimension = 3;
|
||||
|
@ -3,7 +3,7 @@ package eva2.tools.math;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class BayNode {
|
||||
public final class BayNode {
|
||||
|
||||
private int id;
|
||||
private int numberOfParents = 0;
|
||||
|
@ -10,7 +10,7 @@ import java.util.Random;
|
||||
* Random number generator used across all optimizations
|
||||
* for reproducability of runs.
|
||||
*/
|
||||
public class RNG {
|
||||
public final class RNG {
|
||||
|
||||
private static Random random;
|
||||
private static long randomSeed;
|
||||
|
@ -1,6 +1,5 @@
|
||||
package eva2.tools.math;
|
||||
|
||||
import eva2.problems.AbstractProblemDouble;
|
||||
import eva2.tools.math.Jama.Matrix;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -9,7 +8,7 @@ import java.util.Collections;
|
||||
/**
|
||||
* Statistic utils.
|
||||
*/
|
||||
public class StatisticUtils {
|
||||
public final class StatisticUtils {
|
||||
/**
|
||||
* The natural logarithm of 2.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user