diff --git a/src/eva2/optimization/strategies/ANPSO.java b/src/eva2/optimization/strategies/ANPSO.java index 9df2c4b7..fa322109 100644 --- a/src/eva2/optimization/strategies/ANPSO.java +++ b/src/eva2/optimization/strategies/ANPSO.java @@ -123,8 +123,8 @@ public class ANPSO extends NichePSO implements InterfaceAdditionalPopulationInfo getMainSwarm().setPhi1(2.05); getMainSwarm().setPhi2(2.05); getMainSwarm().setInertnessOrChi(0.7298437881283576); -// setMainSwarmInertness(new NoParameterAging(0.7298437881283576)); - setMainSwarmAlgoType(getMainSwarm().getAlgoType().setSelectedTag("Constriction")); // constriction + getMainSwarm().setAlgoType(ParticleSwarmOptimization.PSOType.Constriction); + setMainSwarmAlgoType(ParticleSwarmOptimization.PSOType.Constriction); // constriction setMaxInitialSubSwarmSize(0); // deactivate early reinits setMainSwarmTopology(PSOTopology.grid); setMainSwarmTopologyRange(1); @@ -905,7 +905,8 @@ public class ANPSO extends NichePSO implements InterfaceAdditionalPopulationInfo anpso.getMainSwarm().setPhi1(2.05); anpso.getMainSwarm().setPhi2(2.05); anpso.getMainSwarm().setInertnessOrChi(0.7298437881283576); - anpso.setMainSwarmAlgoType(anpso.getMainSwarm().getAlgoType().setSelectedTag("Constriction")); // constriction + anpso.getMainSwarm().setAlgoType(ParticleSwarmOptimization.PSOType.Constriction); + anpso.setMainSwarmAlgoType(ParticleSwarmOptimization.PSOType.Constriction); // constriction anpso.setMaxInitialSubSwarmSize(0); // deactivate early reinits anpso.setMainSwarmTopology(PSOTopology.grid); anpso.setMainSwarmTopologyRange(1); @@ -924,7 +925,8 @@ public class ANPSO extends NichePSO implements InterfaceAdditionalPopulationInfo anpso.getMainSwarm().setParameterControl(new ParamAdaption[]{new LinearParamAdaption("inertnessOrChi", 0.7, 0.2)}); // anpso.setMainSwarmInertness(new LinearParameterAging(0.7, 0.2, evalCnt/anpso.getMainSwarmSize())); - anpso.setMainSwarmAlgoType(anpso.getMainSwarm().getAlgoType().setSelectedTag("Inertness")); + anpso.getMainSwarm().setAlgoType(ParticleSwarmOptimization.PSOType.Inertness); + anpso.setMainSwarmAlgoType(ParticleSwarmOptimization.PSOType.Inertness); // inertness anpso.getMainSwarm().setPhi1(1.2); anpso.getMainSwarm().setPhi2(0.6); // ANPSO uses communication in the main swarm //Possible topologies are: "Linear", "Grid", "Star", "Multi-Swarm", "Tree", "HPSO", "Random" in that order starting by 0. @@ -944,7 +946,8 @@ public class ANPSO extends NichePSO implements InterfaceAdditionalPopulationInfo anpso.getMainSwarm().setParameterControl(new ParamAdaption[]{new LinearParamAdaption("inertnessOrChi", 0.7, 0.2)}); - anpso.setMainSwarmAlgoType(anpso.getMainSwarm().getAlgoType().setSelectedTag("Inertness")); + anpso.getMainSwarm().setAlgoType(ParticleSwarmOptimization.PSOType.Inertness); + anpso.setMainSwarmAlgoType(ParticleSwarmOptimization.PSOType.Inertness); anpso.getMainSwarm().setPhi1(1.2); anpso.getMainSwarm().setPhi2(1.2); // ANPSO uses communication in the main swarm //Possible topologies are: "Linear", "Grid", "Star", "Multi-Swarm", "Tree", "HPSO", "Random" in that order starting by 0. diff --git a/src/eva2/optimization/strategies/CBNPSO.java b/src/eva2/optimization/strategies/CBNPSO.java index 3f8ad323..10ef9307 100644 --- a/src/eva2/optimization/strategies/CBNPSO.java +++ b/src/eva2/optimization/strategies/CBNPSO.java @@ -33,17 +33,6 @@ public class CBNPSO extends ClusterBasedNichingEA implements Serializable { public CBNPSO(boolean threshAdaption) { this(10, 15, 0.001, 1e-10, 15, 100, threshAdaption); -// super(); -// setDifferentiationCA(new ClusteringDensityBased(getClusterDiffDist(), 10, new IndividualDataMetric(ParticleSwarmOptimization.partBestPosKey))); -// setMergingCA(new ClusteringDensityBased(0.001, 3, new IndividualDataMetric(ParticleSwarmOptimization.partBestPosKey))); -// setEpsilonBound(1e-10); -// setHaltingWindow(15); -// setMaxSpeciesSize(15); -// setOptimizer(new ParticleSwarmOptimization(100, 2.05, 2.05, PSOTopologyEnum.grid, 2)); -// ParamAdaption[] defAdpt = new ParamAdaption[]{getDefaultSinusoidalAdaption()}; -// setParameterControl(defAdpt); -// if (threshAdaption) addParameterControl(getDefaultThreshAdaption()); -// setPopulationSize(100); } public CBNPSO(int minSpecSize, int maxSpecSize, double sigmaMerge, double epsilonConv, int haltingWindow, int popSize, boolean threshAdaption) { diff --git a/src/eva2/optimization/strategies/DynamicParticleSwarmOptimization.java b/src/eva2/optimization/strategies/DynamicParticleSwarmOptimization.java index 4b238414..899d11bb 100644 --- a/src/eva2/optimization/strategies/DynamicParticleSwarmOptimization.java +++ b/src/eva2/optimization/strategies/DynamicParticleSwarmOptimization.java @@ -256,7 +256,7 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization for (int i = 0; i < lastVelocity.length; i++) { // the component from the old velocity curVelocity[i] = this.inertnessOrChi * lastVelocity[i]; - if (algType.getSelectedTag().getID() == 1) { + if (algType == PSOType.Constriction) { chi = inertnessOrChi; } else { chi = 1.; diff --git a/src/eva2/optimization/strategies/NichePSO.java b/src/eva2/optimization/strategies/NichePSO.java index e01772af..0c147dfb 100644 --- a/src/eva2/optimization/strategies/NichePSO.java +++ b/src/eva2/optimization/strategies/NichePSO.java @@ -94,7 +94,7 @@ public class NichePSO extends AbstractOptimizer implements InterfaceAdditionalPo // protected double mainSwarmPhi2 = 0; // by default no communication in the mainswarm protected PSOTopology mainSwarmTopology = PSOTopology.grid; // = 1; protected int mainSwarmTopologyRange = 0; - private int mainSwarmAlgoType = 0; // 0: inertness, 1: constriction + private ParticleSwarmOptimization.PSOType mainSwarmAlgoType = ParticleSwarmOptimization.PSOType.Inertness; // 0: inertness, 1: constriction // private InterfaceParameterAging mainSwarmParamAging = new LinearParameterAging(); protected ParameterControlManager paramControl = new ParameterControlManager(); boolean returnRepresentativeSolutionsOnly = true; // if true only the representatives of every subswarm are returned, else every particles pbest @@ -237,7 +237,8 @@ public class NichePSO extends AbstractOptimizer implements InterfaceAdditionalPo getMainSwarm().setGcpso(false); // getMainSwarm().setAlgoType(new SelectedTag("Inertness")); getMainSwarm().setParameterControl(new ParamAdaption[]{getDefaultInertnessAdaption()}); - setMainSwarmAlgoType(getMainSwarm().getAlgoType().setSelectedTag(mainSwarmAlgoType)); // set algo type, may influence aging + getMainSwarm().setAlgoType(mainSwarmAlgoType); + setMainSwarmAlgoType(mainSwarmAlgoType); // set algo type, may influence aging // getMainSwarm().setPhi1(mainSwarmPhi1); // cognitive component "tendency to return to the best position visited so far" // getMainSwarm().setPhi2(mainSwarmPhi2); // social component "tendency to be attracted towards the best position found in its neighbourhood." @@ -263,7 +264,7 @@ public class NichePSO extends AbstractOptimizer implements InterfaceAdditionalPo // choose PSO-type for the subswarmoptimizer getSubswarmOptimizerTemplate().setGcpso(true); getSubswarmOptimizerTemplate().setRho(0.1); // on 2D Problems empirically better than default value 1 - getSubswarmOptimizerTemplate().getAlgoType().setSelectedTag("Constriction");//setAlgoType(new SelectedTag("Inertness")); + getSubswarmOptimizerTemplate().setAlgoType(ParticleSwarmOptimization.PSOType.Constriction); //"Several studies propose different values for these parameters" (http://tracer.uc3m.es/tws/pso/parameters.html) //Bergh2002 p.87 @@ -974,16 +975,16 @@ public class NichePSO extends AbstractOptimizer implements InterfaceAdditionalPo this.mainSwarmTopologyRange = mainSwarmTopologyRange; } - public SelectedTag getMainSwarmAlgoType() { - if (mainSwarmAlgoType != getMainSwarm().getAlgoType().getSelectedTagID()) { + public ParticleSwarmOptimization.PSOType getMainSwarmAlgoType() { + if (mainSwarmAlgoType != getMainSwarm().getAlgoType()) { System.err.println("Error in NichePSO:getMainSwarmAlgoType() !!"); } return getMainSwarm().getAlgoType(); } - public void setMainSwarmAlgoType(SelectedTag st) { + public void setMainSwarmAlgoType(ParticleSwarmOptimization.PSOType st) { getMainSwarm().setAlgoType(st); - mainSwarmAlgoType = st.getSelectedTagID(); + mainSwarmAlgoType = st; // mainSwarmParamAging.setStartValue(getMainSwarm().getInertnessOrChi()); } @@ -2048,12 +2049,12 @@ public class NichePSO extends AbstractOptimizer implements InterfaceAdditionalPo npso.setMaxAllowedSwarmRadius(0.0001); // formally limits the swarm radius of the subswarms // Parameter for the mainswarm - npso.getMainSwarmAlgoType().setSelectedTag("Inertness"); + npso.setMainSwarmAlgoType(ParticleSwarmOptimization.PSOType.Inertness); npso.getMainSwarm().setPhi1(1.2); npso.getMainSwarm().setPhi2(0); // by default no communication in the mainswarm npso.setMainSwarmTopologyTag(0); // this doesnt have any effect due to no communication npso.setMainSwarmTopologyRange(0); - npso.mainSwarmAlgoType = 0; + npso.mainSwarmAlgoType = ParticleSwarmOptimization.PSOType.Inertness; npso.getMainSwarm().setParameterControl(new ParamAdaption[]{getDefaultInertnessAdaption()}); // npso.getMainSwarm().setSpeedLimit(avgRange/2.); // npso.getMainSwarm().setCheckSpeedLimit(true); @@ -2062,7 +2063,7 @@ public class NichePSO extends AbstractOptimizer implements InterfaceAdditionalPo npso.getSubswarmOptimizerTemplate().setGcpso(true); npso.getSubswarmOptimizerTemplate().setRho(0.1); // on 2D Problems empirically better than default value 1 // npso.getSubswarmOptimizerTemplate().setAlgoType(new SelectedTag("Constriction")); - npso.getSubswarmOptimizerTemplate().setAlgoType(npso.getSubswarmOptimizerTemplate().getAlgoType().setSelectedTag("Constriction")); // constriction + npso.getSubswarmOptimizerTemplate().setAlgoType(ParticleSwarmOptimization.PSOType.Constriction); // constriction npso.getSubswarmOptimizerTemplate().setConstriction(2.05, 2.05); // npso.getSubswarmOptimizerTemplate().setInertnessAging(new LinearParameterAging(0.7, 0.2, evalCnt/(10*popSize))); // expect shorter @@ -2103,12 +2104,13 @@ public class NichePSO extends AbstractOptimizer implements InterfaceAdditionalPo npso.setMaxAllowedSwarmRadius(0.0001); // formally limits the swarm radius of the subswarms // Parameter for the mainswarm - npso.setMainSwarmAlgoType(npso.getMainSwarm().getAlgoType().setSelectedTag("Inertness")); // constriction + npso.getMainSwarm().setAlgoType(ParticleSwarmOptimization.PSOType.Inertness); + npso.setMainSwarmAlgoType(ParticleSwarmOptimization.PSOType.Inertness); npso.getMainSwarm().setPhi1(1.2); // npso.SetMainSwarmPhi2(0); // by default no communication in the mainswarm npso.setMainSwarmTopologyTag(0); // this doesnt have any effect due to no communication npso.setMainSwarmTopologyRange(0); - npso.mainSwarmAlgoType = 0; + npso.mainSwarmAlgoType = ParticleSwarmOptimization.PSOType.Inertness; npso.getMainSwarm().setParameterControl(new ParamAdaption[]{getDefaultInertnessAdaption()}); // npso.setMainSwarmInertness(new LinearParameterAging(0.7, 0.2, evalCnt/popSize)); // npso.getMainSwarm().setSpeedLimit(avgRange/2.); @@ -2117,7 +2119,7 @@ public class NichePSO extends AbstractOptimizer implements InterfaceAdditionalPo // parameters for the subswarms npso.getSubswarmOptimizerTemplate().setGcpso(true); npso.getSubswarmOptimizerTemplate().setRho(0.01); - npso.getSubswarmOptimizerTemplate().setAlgoType(new SelectedTag("Constriction")); + npso.getSubswarmOptimizerTemplate().setAlgoType(ParticleSwarmOptimization.PSOType.Constriction); npso.getSubswarmOptimizerTemplate().setConstriction(2.05, 2.05); // npso.getSubswarmOptimizerTemplate().setInertnessAging(new NoParameterAging(npso.getSubswarmOptimizerTemplate().getInertnessOrChi())); diff --git a/src/eva2/optimization/strategies/ParticleSwarmOptimization.java b/src/eva2/optimization/strategies/ParticleSwarmOptimization.java index 0e327590..eb66fb82 100644 --- a/src/eva2/optimization/strategies/ParticleSwarmOptimization.java +++ b/src/eva2/optimization/strategies/ParticleSwarmOptimization.java @@ -24,6 +24,7 @@ import eva2.tools.math.Jama.Matrix; import eva2.tools.math.Mathematics; import eva2.tools.math.RNG; import eva2.util.annotation.Description; +import eva2.util.annotation.Parameter; import java.util.ArrayList; import java.util.Arrays; @@ -42,10 +43,7 @@ import java.util.Vector; @Description("Particle Swarm Optimization by Kennedy and Eberhart.") public class ParticleSwarmOptimization extends AbstractOptimizer implements java.io.Serializable, InterfaceAdditionalPopulationInformer { - /** - * Generated serial version uid. - */ - private static final long serialVersionUID = -149996122795669589L; + public enum PSOType { Inertness, Constriction } Object[] sortedPop = null; protected AbstractEAIndividual bestIndividual = null; protected boolean checkRange = true; @@ -56,7 +54,7 @@ public class ParticleSwarmOptimization extends AbstractOptimizer implements java * Defines which version of PSO is applied, classical inertness or * constriction (using chi) */ - protected SelectedTag algType; + protected PSOType algType; protected int topologyRange = 2; protected double initialVelocity = 0.2; protected double speedLimit = 0.1; @@ -92,7 +90,6 @@ public class ParticleSwarmOptimization extends AbstractOptimizer implements java transient final static String sortedIndexKey = "sortedParticleIndex"; transient final static String dmsGroupIndexKey = "dmsGroupIndex"; protected String indentifier = ""; - transient private Vector changeListener; transient private TopoPlot topoPlot = null; /// sleep time so that visual plot can be followed easier protected int sleepTime = 0; @@ -109,8 +106,7 @@ public class ParticleSwarmOptimization extends AbstractOptimizer implements java public ParticleSwarmOptimization() { topology = PSOTopology.grid; - algType = new SelectedTag("Inertness", "Constriction"); - algType.setSelectedTag(1); + algType = PSOType.Constriction; setConstriction(getPhi1(), getPhi2()); hideHideable(); @@ -118,9 +114,7 @@ public class ParticleSwarmOptimization extends AbstractOptimizer implements java public ParticleSwarmOptimization(ParticleSwarmOptimization a) { topology = a.topology; - if (a.algType != null) { - this.algType = (SelectedTag) a.algType.clone(); - } + this.algType = a.algType; this.population = (Population) a.population.clone(); this.optimizationProblem = a.optimizationProblem; this.indentifier = a.indentifier; @@ -145,7 +139,7 @@ public class ParticleSwarmOptimization extends AbstractOptimizer implements java */ public ParticleSwarmOptimization(int popSize, double p1, double p2, PSOTopology topo, int topoRange) { this(); - algType.setSelectedTag(1); // set to constriction + algType = PSOType.Constriction; // set to constriction population = new Population(popSize); setPhiValues(p1, p2); topologyRange = topoRange; @@ -292,7 +286,7 @@ public class ParticleSwarmOptimization extends AbstractOptimizer implements java * @param requiredType optional required type identifier of the individual. * @return double array containing the vectorial sum of particle velocities * or an array containing the average absolute speed - * @see AbstractEAIndividual.getData(String) + * @see AbstractEAIndividual#getData(String) */ public static double[] getPopulationVelSpeed(Population pop, int calcModeSwitch, final String velocityKey, final String typeString, final Object requiredType) { AbstractEAIndividual indy = (AbstractEAIndividual) pop.get(0); @@ -742,7 +736,7 @@ public class ParticleSwarmOptimization extends AbstractOptimizer implements java for (int i = 0; i < personalBestPos.length; i++) { // the component from the old velocity accel[i] = 0; - if (algType.getSelectedTag().getID() == 1) { + if (algType == PSOType.Constriction) { chi = inertnessOrChi; } else { chi = 1.; @@ -1582,7 +1576,7 @@ public class ParticleSwarmOptimization extends AbstractOptimizer implements java if (pSum <= 4) { System.err.println("error, invalid tauSum value in PSO::setConstriction"); } else { - if (!getAlgoType().isSelectedString("Constriction")) { + if (getAlgoType() != PSOType.Constriction) { System.err.println("Warning, PSO algorithm variant constriction expected!"); } phi1 = tau1; @@ -1613,9 +1607,10 @@ public class ParticleSwarmOptimization extends AbstractOptimizer implements java * * @param l */ + @Parameter(description = "Acceleration for the cognition model.") public void setPhi1(double l) { this.phi1 = l; - if (algType.getSelectedTag().getID() == 1) { + if (algType == PSOType.Constriction) { setConstriction(getPhi1(), getPhi2()); } } @@ -1624,18 +1619,15 @@ public class ParticleSwarmOptimization extends AbstractOptimizer implements java return this.phi1; } - public String phi1TipText() { - return "Acceleration for the cognition model."; - } - /** * This method will set greediness to move towards the best social * * @param l */ + @Parameter(description = "Acceleration for the social model.") public void setPhi2(double l) { this.phi2 = l; - if (algType.getSelectedTag().getID() == 1) { + if (algType == PSOType.Constriction) { setConstriction(getPhi1(), getPhi2()); } } @@ -1644,10 +1636,6 @@ public class ParticleSwarmOptimization extends AbstractOptimizer implements java return this.phi2; } - public String phi2TipText() { - return "Acceleration for the social model."; - } - /** * Set the phi1 / phi2 parameter values (and in the constriction variant, * adapt constriction factor). @@ -1658,7 +1646,7 @@ public class ParticleSwarmOptimization extends AbstractOptimizer implements java public void setPhiValues(double phi1, double phi2) { this.phi1 = phi1; this.phi2 = phi2; - if (algType.isSelectedString("Constriction")) { + if (algType == PSOType.Constriction) { setConstriction(phi1, phi2); } } @@ -1682,6 +1670,7 @@ public class ParticleSwarmOptimization extends AbstractOptimizer implements java * * @param t The type. */ + @Parameter(description = "Choose the topology type") public void setTopology(PSOTopology t) { this.topology = t; setGOEShowProperties(getClass()); @@ -1709,35 +1698,29 @@ public class ParticleSwarmOptimization extends AbstractOptimizer implements java return topology; } - public String topologyTipText() { - return "Choose the topology type"; - } - /** * This method allows you to choose the algorithm type. * * @param s The type. */ - public void setAlgoType(SelectedTag s) { + public void setAlgoType(PSOType s) { this.algType = s; - if (s.getSelectedTag().getID() == 1) { + if (algType == PSOType.Constriction) { setConstriction(getPhi1(), getPhi2()); } } - public SelectedTag getAlgoType() { + @Parameter(description = "Choose the inertness or constriction method. Chi is calculated automatically in constriction.") + public PSOType getAlgoType() { return this.algType; } - public String algoTypeTipText() { - return "Choose the inertness or constriction method. Chi is calculated automatically in constriction."; - } - /** * The range of the local neighbourhood. * * @param s The range. */ + @Parameter(description = "The range of the neighborhood topology.") public void setTopologyRange(int s) { this.topologyRange = s; } @@ -1746,15 +1729,12 @@ public class ParticleSwarmOptimization extends AbstractOptimizer implements java return this.topologyRange; } - public String topologyRangeTipText() { - return "The range of the neighborhood topology."; - } - /** * Toggle Check Constraints. * * @param s Check Constraints. */ + @Parameter(description = "Toggle whether particles are allowed to leave the range.") public void setCheckRange(boolean s) { this.checkRange = s; } @@ -1763,10 +1743,6 @@ public class ParticleSwarmOptimization extends AbstractOptimizer implements java return this.checkRange; } - public String checkRangeTipText() { - return "Toggle whether particles are allowed to leave the range."; - } - /** * @return true if swarm visualization is turned on */ diff --git a/src/eva2/optimization/strategies/StarANPSO.java b/src/eva2/optimization/strategies/StarANPSO.java index 70c1fe03..f8c2f06d 100644 --- a/src/eva2/optimization/strategies/StarANPSO.java +++ b/src/eva2/optimization/strategies/StarANPSO.java @@ -10,7 +10,8 @@ public class StarANPSO extends ANPSO { super(); NichePSO.starNPSO(this, defaultEvalCnt); - setMainSwarmAlgoType(getMainSwarm().getAlgoType().setSelectedTag("Inertness")); + getMainSwarm().setAlgoType(ParticleSwarmOptimization.PSOType.Inertness); + setMainSwarmAlgoType(ParticleSwarmOptimization.PSOType.Inertness); getMainSwarm().setParameterControl(new ParamAdaption[]{new LinearParamAdaption("inertnessOrChi", 0.7, 0.2)}); // setMainSwarmInertness(new LinearParameterAging(0.7, 0.2, defaultEvalCnt/getMainSwarmSize()));