parent
1b8b77c52f
commit
b7749711ca
@ -26,10 +26,8 @@ public class EnumEditor extends PropertyEditorSupport {
|
||||
public void setValue(Object value) {
|
||||
if (value instanceof Enum) {
|
||||
enumConstants = ((Enum) value).getClass().getEnumConstants();
|
||||
// enumType = ((Enum)value);
|
||||
super.setValue(value);
|
||||
} else if (value.getClass().isArray() && value.getClass().getComponentType().isEnum()) {
|
||||
// values = value.getClass().getComponentType().getEnumConstants();
|
||||
Enum<?>[] e = (Enum[]) (value);
|
||||
enumConstants = (Enum[]) e.getClass().getComponentType().getEnumConstants();
|
||||
super.setValue(value);
|
||||
@ -92,6 +90,6 @@ enum TestEnum {
|
||||
asdf, sdf, asdfa;
|
||||
|
||||
public String toString() {
|
||||
return "Foo";
|
||||
return "Foo" + name();
|
||||
}
|
||||
}
|
@ -5,7 +5,6 @@ import eva2.gui.editor.GenericObjectEditor;
|
||||
import eva2.optimization.go.InterfaceNotifyOnInformers;
|
||||
import eva2.problems.InterfaceAdditionalPopulationInformer;
|
||||
import eva2.tools.EVAERROR;
|
||||
import eva2.tools.SelectedTag;
|
||||
import eva2.tools.Serializer;
|
||||
import eva2.tools.StringSelection;
|
||||
import eva2.util.annotation.Description;
|
||||
|
@ -7,11 +7,11 @@ import eva2.optimization.individuals.InterfaceDataTypeDouble;
|
||||
import eva2.optimization.population.Population;
|
||||
import eva2.problems.AbstractOptimizationProblem;
|
||||
import eva2.problems.InterfaceOptimizationProblem;
|
||||
import eva2.tools.SelectedTag;
|
||||
import eva2.tools.math.Mathematics;
|
||||
import eva2.tools.math.RNG;
|
||||
import eva2.util.annotation.Description;
|
||||
import eva2.util.annotation.Hidden;
|
||||
import eva2.util.annotation.Parameter;
|
||||
|
||||
/**
|
||||
* 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")
|
||||
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;
|
||||
/**
|
||||
* switch for the speed adaptation mechanism
|
||||
@ -36,7 +49,7 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
|
||||
/**
|
||||
* the change detection strategy
|
||||
*/
|
||||
protected SelectedTag changeDetectStrategy;
|
||||
protected ChangeDetectionStrategy changeDetectStrategy;
|
||||
|
||||
private double maxSpeedLimit = 0.1;
|
||||
private double minSpeedLimit = .003;
|
||||
@ -54,7 +67,7 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
|
||||
*/
|
||||
public DynamicParticleSwarmOptimization() {
|
||||
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;
|
||||
maxSpeedLimit = a.maxSpeedLimit;
|
||||
minSpeedLimit = a.minSpeedLimit;
|
||||
changeDetectStrategy.setSelectedAs(a.changeDetectStrategy);
|
||||
changeDetectStrategy = a.changeDetectStrategy;
|
||||
}
|
||||
|
||||
@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!");
|
||||
}
|
||||
}
|
||||
//if (AbstractEAIndividual.getDoublePosition(indy)[0]<500000) {
|
||||
// System.err.println(indy.getStringRepresentation());
|
||||
//}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -399,16 +409,9 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
|
||||
|
||||
envHasChanged = detectChange(this.population);
|
||||
|
||||
// if (envHasChanged) {
|
||||
// System.out.println("environmental change detected!");
|
||||
// }
|
||||
|
||||
if (doSpeedAdaptation) {
|
||||
adaptTrackingSpeed(((InterfaceDataTypeDouble) population.get(0)).getDoubleRange());
|
||||
}
|
||||
// if (problem instanceof DynLocalizationProblem) {
|
||||
// ((DynLocalizationProblem)problem).adaptPSOByPopulation(population, this);
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -427,8 +430,6 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////// end optimize loop
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@ -438,17 +439,17 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
|
||||
* @return true if the population has changed as to the detect strategy, else false
|
||||
*/
|
||||
protected boolean detectChange(Population population) {
|
||||
switch (changeDetectStrategy.getSelectedTag().getID()) {
|
||||
case 0:
|
||||
switch (changeDetectStrategy) {
|
||||
case RandomAnchor:
|
||||
if (detectAnchor >= 0) {
|
||||
return !(java.util.Arrays.equals(detectFit, this.population.getIndividual(detectAnchor).getFitness()));
|
||||
} else {
|
||||
System.err.println("warning, inconsistency in detectChange");
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
case AssumeChange:
|
||||
return true;
|
||||
case 2:
|
||||
case AssumeNoChange:
|
||||
return false;
|
||||
}
|
||||
System.err.println("warning, inconsistency in detectChange");
|
||||
@ -626,26 +627,22 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
|
||||
/**
|
||||
* @return the changeDetectStrategy
|
||||
*/
|
||||
public SelectedTag getChangeDetectStrategy() {
|
||||
public ChangeDetectionStrategy getChangeDetectStrategy() {
|
||||
return changeDetectStrategy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param changeDetectStrategy the changeDetectStrategy to set
|
||||
*/
|
||||
public void setChangeDetectStrategy(SelectedTag changeDetectStrategy) {
|
||||
public void setChangeDetectStrategy(ChangeDetectionStrategy 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
|
||||
} else {
|
||||
detectAnchor = -1;
|
||||
}
|
||||
}
|
||||
|
||||
public String phi0TipText() {
|
||||
return "the random perturbation factor in relation to the problem range";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the phi0 value
|
||||
*/
|
||||
@ -656,6 +653,7 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
|
||||
/**
|
||||
* @param phi0 the phi0 to set
|
||||
*/
|
||||
@Parameter(description = "The random perturbation factor in relation to the problem range")
|
||||
public void setPhi0(double phi0) {
|
||||
this.phi0 = phi0;
|
||||
}
|
||||
@ -670,14 +668,11 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
|
||||
/**
|
||||
* @param phi3 the phi3 to set
|
||||
*/
|
||||
@Parameter(description = "Acceleration of the problem specific attractor")
|
||||
public void setPhi3(double phi3) {
|
||||
this.phi3 = phi3;
|
||||
}
|
||||
|
||||
public String phi3TipText() {
|
||||
return "Acceleration of the problem specific attractor";
|
||||
}
|
||||
|
||||
public Plot getPlot() {
|
||||
return plot;
|
||||
}
|
||||
|
@ -3,9 +3,8 @@ package eva2.problems;
|
||||
import eva2.optimization.individuals.AbstractEAIndividual;
|
||||
import eva2.optimization.individuals.ESIndividualDoubleData;
|
||||
import eva2.optimization.population.Population;
|
||||
import eva2.tools.SelectedTag;
|
||||
import eva2.tools.Tag;
|
||||
import eva2.util.annotation.Description;
|
||||
import eva2.util.annotation.Parameter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@ -15,16 +14,16 @@ import java.io.Serializable;
|
||||
@Description("Sphere Model, changing Environment.")
|
||||
public class F7Problem extends AbstractProblemDoubleOffset implements Serializable {
|
||||
|
||||
public enum TimeIntervalType {
|
||||
FunctionCalls, Generation
|
||||
}
|
||||
private double t = 250;
|
||||
private double change = 4;
|
||||
protected SelectedTag timeIntervalType;
|
||||
protected TimeIntervalType timeIntervalType;
|
||||
private int currentTimeStamp;
|
||||
|
||||
public F7Problem() {
|
||||
Tag[] tag = new Tag[2];
|
||||
tag[0] = new Tag(0, "Function Calls");
|
||||
tag[1] = new Tag(1, "Generation");
|
||||
this.timeIntervalType = new SelectedTag(0, tag);
|
||||
this.timeIntervalType = TimeIntervalType.FunctionCalls;
|
||||
this.template = new ESIndividualDoubleData();
|
||||
}
|
||||
|
||||
@ -32,7 +31,7 @@ public class F7Problem extends AbstractProblemDoubleOffset implements Serializab
|
||||
super(b);
|
||||
this.change = b.change;
|
||||
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++) {
|
||||
tmpIndy = (AbstractEAIndividual) population.get(i);
|
||||
tmpIndy.resetConstraintViolation();
|
||||
if (this.timeIntervalType.getSelectedTag().getID() == 0) {
|
||||
if (this.timeIntervalType == TimeIntervalType.FunctionCalls) {
|
||||
this.currentTimeStamp = population.getFunctionCalls();
|
||||
} else {
|
||||
this.currentTimeStamp = population.getGeneration();
|
||||
@ -126,6 +125,7 @@ public class F7Problem extends AbstractProblemDoubleOffset implements Serializab
|
||||
*
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
@Parameter(description = "Set the time interval for environmental change.")
|
||||
public void sett(double d) {
|
||||
if (d < 1) {
|
||||
d = 1;
|
||||
@ -137,15 +137,12 @@ public class F7Problem extends AbstractProblemDoubleOffset implements Serializab
|
||||
return this.t;
|
||||
}
|
||||
|
||||
public String tTipText() {
|
||||
return "Set the time interval for environmental change.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value for tau1 with this method.
|
||||
*
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
@Parameter(description = "Set the amount of environmental change (x[i]-b).")
|
||||
public void setChange(double d) {
|
||||
this.change = d;
|
||||
}
|
||||
@ -154,24 +151,17 @@ public class F7Problem extends AbstractProblemDoubleOffset implements Serializab
|
||||
return this.change;
|
||||
}
|
||||
|
||||
public String changeTipText() {
|
||||
return "Set the amount of environmental change (x[i]-b).";
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value for tau1 with this method.
|
||||
*
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setTimeIntervalType(SelectedTag d) {
|
||||
@Parameter(description = "Choose the timeinterval type.")
|
||||
public void setTimeIntervalType(TimeIntervalType d) {
|
||||
this.timeIntervalType = d;
|
||||
}
|
||||
|
||||
public SelectedTag getTimeIntervalType() {
|
||||
public TimeIntervalType getTimeIntervalType() {
|
||||
return this.timeIntervalType;
|
||||
}
|
||||
|
||||
public String timeIntervalTypeTipText() {
|
||||
return "Choose the timeinterval type.";
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user