Remove last uses of SelectedTag from core package

refs #32
This commit is contained in:
Fabian Becker 2014-11-06 10:24:51 +01:00
parent 1b8b77c52f
commit b7749711ca
4 changed files with 40 additions and 58 deletions

View File

@ -26,10 +26,8 @@ public class EnumEditor extends PropertyEditorSupport {
public void setValue(Object value) { public void setValue(Object value) {
if (value instanceof Enum) { if (value instanceof Enum) {
enumConstants = ((Enum) value).getClass().getEnumConstants(); enumConstants = ((Enum) value).getClass().getEnumConstants();
// enumType = ((Enum)value);
super.setValue(value); super.setValue(value);
} else if (value.getClass().isArray() && value.getClass().getComponentType().isEnum()) { } else if (value.getClass().isArray() && value.getClass().getComponentType().isEnum()) {
// values = value.getClass().getComponentType().getEnumConstants();
Enum<?>[] e = (Enum[]) (value); Enum<?>[] e = (Enum[]) (value);
enumConstants = (Enum[]) e.getClass().getComponentType().getEnumConstants(); enumConstants = (Enum[]) e.getClass().getComponentType().getEnumConstants();
super.setValue(value); super.setValue(value);
@ -92,6 +90,6 @@ enum TestEnum {
asdf, sdf, asdfa; asdf, sdf, asdfa;
public String toString() { public String toString() {
return "Foo"; return "Foo" + name();
} }
} }

View File

@ -5,7 +5,6 @@ import eva2.gui.editor.GenericObjectEditor;
import eva2.optimization.go.InterfaceNotifyOnInformers; import eva2.optimization.go.InterfaceNotifyOnInformers;
import eva2.problems.InterfaceAdditionalPopulationInformer; import eva2.problems.InterfaceAdditionalPopulationInformer;
import eva2.tools.EVAERROR; import eva2.tools.EVAERROR;
import eva2.tools.SelectedTag;
import eva2.tools.Serializer; import eva2.tools.Serializer;
import eva2.tools.StringSelection; import eva2.tools.StringSelection;
import eva2.util.annotation.Description; import eva2.util.annotation.Description;

View File

@ -7,11 +7,11 @@ import eva2.optimization.individuals.InterfaceDataTypeDouble;
import eva2.optimization.population.Population; import eva2.optimization.population.Population;
import eva2.problems.AbstractOptimizationProblem; import eva2.problems.AbstractOptimizationProblem;
import eva2.problems.InterfaceOptimizationProblem; import eva2.problems.InterfaceOptimizationProblem;
import eva2.tools.SelectedTag;
import eva2.tools.math.Mathematics; import eva2.tools.math.Mathematics;
import eva2.tools.math.RNG; import eva2.tools.math.RNG;
import eva2.util.annotation.Description; import eva2.util.annotation.Description;
import eva2.util.annotation.Hidden; import eva2.util.annotation.Hidden;
import eva2.util.annotation.Parameter;
/** /**
* This extends our particle swarm implementation to dynamic optimization problems. * This extends our particle swarm implementation to dynamic optimization problems.
@ -19,6 +19,19 @@ import eva2.util.annotation.Hidden;
@Description("Particle Swarm Optimization tuned for tracking a dynamic target") @Description("Particle Swarm Optimization tuned for tracking a dynamic target")
public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization { public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization {
public enum ChangeDetectionStrategy { RandomAnchor, AssumeChange, AssumeNoChange;
@Override
public String toString() {
switch (this) {
case RandomAnchor: return "Random Anchor";
case AssumeChange: return "Assume Change";
case AssumeNoChange: return "Assume no change";
default: return name();
}
}
}
private boolean envHasChanged = false; private boolean envHasChanged = false;
/** /**
* switch for the speed adaptation mechanism * switch for the speed adaptation mechanism
@ -36,7 +49,7 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
/** /**
* the change detection strategy * the change detection strategy
*/ */
protected SelectedTag changeDetectStrategy; protected ChangeDetectionStrategy changeDetectStrategy;
private double maxSpeedLimit = 0.1; private double maxSpeedLimit = 0.1;
private double minSpeedLimit = .003; private double minSpeedLimit = .003;
@ -54,7 +67,7 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
*/ */
public DynamicParticleSwarmOptimization() { public DynamicParticleSwarmOptimization() {
super(); super();
this.changeDetectStrategy = new SelectedTag("Random Anchor", "Assume change", "Assume no change"); this.changeDetectStrategy = ChangeDetectionStrategy.RandomAnchor;
} }
/** /**
@ -75,7 +88,7 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
detectFit = a.detectFit; detectFit = a.detectFit;
maxSpeedLimit = a.maxSpeedLimit; maxSpeedLimit = a.maxSpeedLimit;
minSpeedLimit = a.minSpeedLimit; minSpeedLimit = a.minSpeedLimit;
changeDetectStrategy.setSelectedAs(a.changeDetectStrategy); changeDetectStrategy = a.changeDetectStrategy;
} }
@Override @Override
@ -378,9 +391,6 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
throw new RuntimeException("Could not perform PSO update, because individual is not instance of InterfaceESIndividual!"); throw new RuntimeException("Could not perform PSO update, because individual is not instance of InterfaceESIndividual!");
} }
} }
//if (AbstractEAIndividual.getDoublePosition(indy)[0]<500000) {
// System.err.println(indy.getStringRepresentation());
//}
} }
/** /**
@ -399,16 +409,9 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
envHasChanged = detectChange(this.population); envHasChanged = detectChange(this.population);
// if (envHasChanged) {
// System.out.println("environmental change detected!");
// }
if (doSpeedAdaptation) { if (doSpeedAdaptation) {
adaptTrackingSpeed(((InterfaceDataTypeDouble) population.get(0)).getDoubleRange()); adaptTrackingSpeed(((InterfaceDataTypeDouble) population.get(0)).getDoubleRange());
} }
// if (problem instanceof DynLocalizationProblem) {
// ((DynLocalizationProblem)problem).adaptPSOByPopulation(population, this);
// }
} }
@Override @Override
@ -427,8 +430,6 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
} }
} }
/////////////////////////////// end optimize loop
/** /**
* Checks for env change depending on the detection strategy. * Checks for env change depending on the detection strategy.
* For anchor detection, if detectAnchor is a valid ID, it returns true if the anchor individuals fitness has changed. * For anchor detection, if detectAnchor is a valid ID, it returns true if the anchor individuals fitness has changed.
@ -438,17 +439,17 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
* @return true if the population has changed as to the detect strategy, else false * @return true if the population has changed as to the detect strategy, else false
*/ */
protected boolean detectChange(Population population) { protected boolean detectChange(Population population) {
switch (changeDetectStrategy.getSelectedTag().getID()) { switch (changeDetectStrategy) {
case 0: case RandomAnchor:
if (detectAnchor >= 0) { if (detectAnchor >= 0) {
return !(java.util.Arrays.equals(detectFit, this.population.getIndividual(detectAnchor).getFitness())); return !(java.util.Arrays.equals(detectFit, this.population.getIndividual(detectAnchor).getFitness()));
} else { } else {
System.err.println("warning, inconsistency in detectChange"); System.err.println("warning, inconsistency in detectChange");
} }
break; break;
case 1: case AssumeChange:
return true; return true;
case 2: case AssumeNoChange:
return false; return false;
} }
System.err.println("warning, inconsistency in detectChange"); System.err.println("warning, inconsistency in detectChange");
@ -626,26 +627,22 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
/** /**
* @return the changeDetectStrategy * @return the changeDetectStrategy
*/ */
public SelectedTag getChangeDetectStrategy() { public ChangeDetectionStrategy getChangeDetectStrategy() {
return changeDetectStrategy; return changeDetectStrategy;
} }
/** /**
* @param changeDetectStrategy the changeDetectStrategy to set * @param changeDetectStrategy the changeDetectStrategy to set
*/ */
public void setChangeDetectStrategy(SelectedTag changeDetectStrategy) { public void setChangeDetectStrategy(ChangeDetectionStrategy changeDetectStrategy) {
this.changeDetectStrategy = changeDetectStrategy; this.changeDetectStrategy = changeDetectStrategy;
if (changeDetectStrategy.getSelectedTag().getID() == 0) { // random anchor if (changeDetectStrategy == ChangeDetectionStrategy.RandomAnchor) { // random anchor
detectAnchor = 0; // this will be set to a random individual detectAnchor = 0; // this will be set to a random individual
} else { } else {
detectAnchor = -1; detectAnchor = -1;
} }
} }
public String phi0TipText() {
return "the random perturbation factor in relation to the problem range";
}
/** /**
* @return the phi0 value * @return the phi0 value
*/ */
@ -656,6 +653,7 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
/** /**
* @param phi0 the phi0 to set * @param phi0 the phi0 to set
*/ */
@Parameter(description = "The random perturbation factor in relation to the problem range")
public void setPhi0(double phi0) { public void setPhi0(double phi0) {
this.phi0 = phi0; this.phi0 = phi0;
} }
@ -670,14 +668,11 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
/** /**
* @param phi3 the phi3 to set * @param phi3 the phi3 to set
*/ */
@Parameter(description = "Acceleration of the problem specific attractor")
public void setPhi3(double phi3) { public void setPhi3(double phi3) {
this.phi3 = phi3; this.phi3 = phi3;
} }
public String phi3TipText() {
return "Acceleration of the problem specific attractor";
}
public Plot getPlot() { public Plot getPlot() {
return plot; return plot;
} }

View File

@ -3,9 +3,8 @@ package eva2.problems;
import eva2.optimization.individuals.AbstractEAIndividual; import eva2.optimization.individuals.AbstractEAIndividual;
import eva2.optimization.individuals.ESIndividualDoubleData; import eva2.optimization.individuals.ESIndividualDoubleData;
import eva2.optimization.population.Population; import eva2.optimization.population.Population;
import eva2.tools.SelectedTag;
import eva2.tools.Tag;
import eva2.util.annotation.Description; import eva2.util.annotation.Description;
import eva2.util.annotation.Parameter;
import java.io.Serializable; import java.io.Serializable;
@ -15,16 +14,16 @@ import java.io.Serializable;
@Description("Sphere Model, changing Environment.") @Description("Sphere Model, changing Environment.")
public class F7Problem extends AbstractProblemDoubleOffset implements Serializable { public class F7Problem extends AbstractProblemDoubleOffset implements Serializable {
public enum TimeIntervalType {
FunctionCalls, Generation
}
private double t = 250; private double t = 250;
private double change = 4; private double change = 4;
protected SelectedTag timeIntervalType; protected TimeIntervalType timeIntervalType;
private int currentTimeStamp; private int currentTimeStamp;
public F7Problem() { public F7Problem() {
Tag[] tag = new Tag[2]; this.timeIntervalType = TimeIntervalType.FunctionCalls;
tag[0] = new Tag(0, "Function Calls");
tag[1] = new Tag(1, "Generation");
this.timeIntervalType = new SelectedTag(0, tag);
this.template = new ESIndividualDoubleData(); this.template = new ESIndividualDoubleData();
} }
@ -32,7 +31,7 @@ public class F7Problem extends AbstractProblemDoubleOffset implements Serializab
super(b); super(b);
this.change = b.change; this.change = b.change;
this.t = b.t; this.t = b.t;
this.timeIntervalType = (SelectedTag) b.timeIntervalType.clone(); this.timeIntervalType = b.timeIntervalType;
} }
/** /**
@ -59,7 +58,7 @@ public class F7Problem extends AbstractProblemDoubleOffset implements Serializab
for (int i = 0; i < population.size(); i++) { for (int i = 0; i < population.size(); i++) {
tmpIndy = (AbstractEAIndividual) population.get(i); tmpIndy = (AbstractEAIndividual) population.get(i);
tmpIndy.resetConstraintViolation(); tmpIndy.resetConstraintViolation();
if (this.timeIntervalType.getSelectedTag().getID() == 0) { if (this.timeIntervalType == TimeIntervalType.FunctionCalls) {
this.currentTimeStamp = population.getFunctionCalls(); this.currentTimeStamp = population.getFunctionCalls();
} else { } else {
this.currentTimeStamp = population.getGeneration(); this.currentTimeStamp = population.getGeneration();
@ -126,6 +125,7 @@ public class F7Problem extends AbstractProblemDoubleOffset implements Serializab
* *
* @param d The mutation operator. * @param d The mutation operator.
*/ */
@Parameter(description = "Set the time interval for environmental change.")
public void sett(double d) { public void sett(double d) {
if (d < 1) { if (d < 1) {
d = 1; d = 1;
@ -137,15 +137,12 @@ public class F7Problem extends AbstractProblemDoubleOffset implements Serializab
return this.t; return this.t;
} }
public String tTipText() {
return "Set the time interval for environmental change.";
}
/** /**
* Set the value for tau1 with this method. * Set the value for tau1 with this method.
* *
* @param d The mutation operator. * @param d The mutation operator.
*/ */
@Parameter(description = "Set the amount of environmental change (x[i]-b).")
public void setChange(double d) { public void setChange(double d) {
this.change = d; this.change = d;
} }
@ -154,24 +151,17 @@ public class F7Problem extends AbstractProblemDoubleOffset implements Serializab
return this.change; return this.change;
} }
public String changeTipText() {
return "Set the amount of environmental change (x[i]-b).";
}
/** /**
* Set the value for tau1 with this method. * Set the value for tau1 with this method.
* *
* @param d The mutation operator. * @param d The mutation operator.
*/ */
public void setTimeIntervalType(SelectedTag d) { @Parameter(description = "Choose the timeinterval type.")
public void setTimeIntervalType(TimeIntervalType d) {
this.timeIntervalType = d; this.timeIntervalType = d;
} }
public SelectedTag getTimeIntervalType() { public TimeIntervalType getTimeIntervalType() {
return this.timeIntervalType; return this.timeIntervalType;
} }
public String timeIntervalTypeTipText() {
return "Choose the timeinterval type.";
}
} }