Removes SelectedType where unnecessary.

refs #32
- Replaced SelectedType with an enum in CombinedTerminator
This commit is contained in:
Fabian Becker 2014-11-04 22:54:13 +01:00
parent cb89110e86
commit 43768d1f96
4 changed files with 21 additions and 33 deletions

View File

@ -21,12 +21,12 @@ public class TerminatorExample {
// in both direction (per dim.) or w.r.t. minimization only // in both direction (per dim.) or w.r.t. minimization only
new FitnessConvergenceTerminator(0.0001, 1000, StagnationTypeEnum.fitnessCallBased, ChangeTypeEnum.absoluteChange, DirectionTypeEnum.decrease), new FitnessConvergenceTerminator(0.0001, 1000, StagnationTypeEnum.fitnessCallBased, ChangeTypeEnum.absoluteChange, DirectionTypeEnum.decrease),
new PhenotypeConvergenceTerminator(0.0001, 1000, StagnationTypeEnum.fitnessCallBased, ChangeTypeEnum.absoluteChange, DirectionTypeEnum.bidirectional), new PhenotypeConvergenceTerminator(0.0001, 1000, StagnationTypeEnum.fitnessCallBased, ChangeTypeEnum.absoluteChange, DirectionTypeEnum.bidirectional),
CombinedTerminator.AND); true);
// Adding an evaluation terminator with OR to the convergence criterion // Adding an evaluation terminator with OR to the convergence criterion
OptimizerFactory.setTerminator(new CombinedTerminator( OptimizerFactory.setTerminator(new CombinedTerminator(
new EvaluationTerminator(20000), new EvaluationTerminator(20000),
convT, convT,
CombinedTerminator.OR)); false));
sol = OptimizerFactory.optimizeToDouble(OptimizerFactory.PSO, f1, null); sol = OptimizerFactory.optimizeToDouble(OptimizerFactory.PSO, f1, null);
System.out.println(OptimizerFactory.lastEvalsPerformed() System.out.println(OptimizerFactory.lastEvalsPerformed()
+ " evals performed. " + " evals performed. "

View File

@ -986,7 +986,7 @@ public final class PropertySheetPanel extends JPanel implements PropertyChangeLi
} }
} }
class PropertyCellRenderer implements TableCellRenderer { final class PropertyCellRenderer implements TableCellRenderer {
private Logger LOGGER = Logger.getLogger(PropertyCellRenderer.class.getName()); private Logger LOGGER = Logger.getLogger(PropertyCellRenderer.class.getName());
JLabel empty = new JLabel(); JLabel empty = new JLabel();
@ -1028,7 +1028,7 @@ class PropertyCellRenderer implements TableCellRenderer {
} }
} }
class PropertyCellEditor extends AbstractCellEditor implements TableCellEditor { final class PropertyCellEditor extends AbstractCellEditor implements TableCellEditor {
private Logger LOGGER = Logger.getLogger(PropertyCellEditor.class.getName()); private Logger LOGGER = Logger.getLogger(PropertyCellEditor.class.getName());
private JLabel empty = new JLabel(); private JLabel empty = new JLabel();
private Object value; private Object value;

View File

@ -3,30 +3,28 @@ package eva2.optimization.operator.terminators;
import eva2.optimization.population.InterfaceSolutionSet; 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.tools.SelectedTag;
import eva2.util.annotation.Description; import eva2.util.annotation.Description;
import eva2.util.annotation.Parameter;
import java.io.Serializable; import java.io.Serializable;
@Description("Boolean combination of two terminators.") @Description("Boolean combination of two terminators.")
public class CombinedTerminator implements InterfaceTerminator, Serializable { public class CombinedTerminator implements InterfaceTerminator, Serializable {
public enum LogicalOperator { AND, OR }
/** /**
* *
*/ */
private static final long serialVersionUID = -4748749151972645021L; private static final long serialVersionUID = -4748749151972645021L;
private InterfaceTerminator t1 = new FitnessConvergenceTerminator(); private InterfaceTerminator t1 = new FitnessConvergenceTerminator();
private InterfaceTerminator t2 = new EvaluationTerminator(); private InterfaceTerminator t2 = new EvaluationTerminator();
private SelectedTag andOrTag = new SelectedTag("OR", "AND"); private LogicalOperator logicalOperator = LogicalOperator.AND;
private String msg = null; private String msg = null;
public static final boolean AND = true;
public static final boolean OR = false;
/** /**
* *
*/ */
public CombinedTerminator() { public CombinedTerminator() { }
}
/** /**
* Convenience constructor combining the given terminators in the expected way. * Convenience constructor combining the given terminators in the expected way.
@ -34,7 +32,7 @@ public class CombinedTerminator implements InterfaceTerminator, Serializable {
public CombinedTerminator(InterfaceTerminator t1, InterfaceTerminator t2, boolean bAnd) { public CombinedTerminator(InterfaceTerminator t1, InterfaceTerminator t2, boolean bAnd) {
this.t1 = t1; this.t1 = t1;
this.t2 = t2; this.t2 = t2;
andOrTag.setSelectedTag(bAnd ? "AND" : "OR"); logicalOperator = bAnd ? LogicalOperator.AND : LogicalOperator.OR;
} }
@Override @Override
@ -90,7 +88,7 @@ public class CombinedTerminator implements InterfaceTerminator, Serializable {
return ret; return ret;
} }
if (andOrTag.isSelectedString("AND")) { if (logicalOperator == LogicalOperator.AND) {
// make sure that both terminators are triggered by every call, because some judge // make sure that both terminators are triggered by every call, because some judge
// time-dependently and store information on the population. // time-dependently and store information on the population.
ret = getTermState(t1, curPopOrSols); ret = getTermState(t1, curPopOrSols);
@ -122,21 +120,18 @@ public class CombinedTerminator implements InterfaceTerminator, Serializable {
} }
/** /**
* @return the andOrTag * @return the logicalOperator
*/ */
public SelectedTag getAndOrTag() { public LogicalOperator getLogicalOperator() {
return andOrTag; return logicalOperator;
} }
/** /**
* @param andOrTag the andOrTag to set * @param logicalOperator the logicalOperator to set
*/ */
public void setAndOrTag(SelectedTag andOrTag) { @Parameter(description = "Set the boolean operator to be used to combine the two terminators.")
this.andOrTag = andOrTag; public void setLogicalOperator(LogicalOperator logicalOperator) {
} this.logicalOperator = logicalOperator;
public String andOrTagTipText() {
return "Set the boolean operator to be used to combine the two terminators.";
} }
/** /**
@ -149,14 +144,11 @@ public class CombinedTerminator implements InterfaceTerminator, Serializable {
/** /**
* @param t1 the t1 to set * @param t1 the t1 to set
*/ */
@Parameter(description = "The first terminator to be combined.")
public void setTerminatorOne(InterfaceTerminator t1) { public void setTerminatorOne(InterfaceTerminator t1) {
this.t1 = t1; this.t1 = t1;
} }
public String terminatorOneTipText() {
return "The first terminator to be combined.";
}
/** /**
* @return the t2 * @return the t2
*/ */
@ -167,12 +159,8 @@ public class CombinedTerminator implements InterfaceTerminator, Serializable {
/** /**
* @param t2 the t2 to set * @param t2 the t2 to set
*/ */
@Parameter(description = "The second terminator to be combined.")
public void setTerminatorTwo(InterfaceTerminator t2) { public void setTerminatorTwo(InterfaceTerminator t2) {
this.t2 = t2; this.t2 = t2;
} }
public String terminatorTwoTipText() {
return "The second terminator to be combined.";
}
} }

View File

@ -179,7 +179,7 @@ public abstract class PopulationMeasureTerminator implements InterfaceTerminator
* Return true if the population measure did not exceed the * Return true if the population measure did not exceed the
* threshold for convergence since the last saved state. * threshold for convergence since the last saved state.
* *
* @param curFit * @param pop
* @return * @return
*/ */
protected boolean isStillConverged(PopulationInterface pop) { protected boolean isStillConverged(PopulationInterface pop) {