Refactor DE and add Rand/2 strategy

This commit is contained in:
Fabian Becker 2014-11-18 11:34:59 +01:00
parent 563c407f0b
commit 0479716f43
7 changed files with 32 additions and 34 deletions

View File

@ -102,7 +102,7 @@ public class OptimizerFactory {
DifferentialEvolution de = new DifferentialEvolution(); DifferentialEvolution de = new DifferentialEvolution();
de.setProblem(problem); de.setProblem(problem);
de.getPopulation().setTargetSize(popsize); de.getPopulation().setTargetSize(popsize);
de.setDEType(DEType.CurrentToBest); de.setDEType(DEType.RandToBest);
de.setDifferentialWeight(f); de.setDifferentialWeight(f);
de.setCrossoverRate(CR); de.setCrossoverRate(CR);
de.setLambda(lambda); de.setLambda(lambda);
@ -1443,7 +1443,7 @@ public class OptimizerFactory {
public static OptimizationParameters standardDE( public static OptimizationParameters standardDE(
AbstractOptimizationProblem problem) { AbstractOptimizationProblem problem) {
DifferentialEvolution de = new DifferentialEvolution(); DifferentialEvolution de = new DifferentialEvolution();
de.setDEType(DEType.CurrentToBest); // this sets current-to-best de.setDEType(DEType.RandToBest); // this sets current-to-best
de.setDifferentialWeight(0.8); de.setDifferentialWeight(0.8);
de.setCrossoverRate(0.6); de.setCrossoverRate(0.6);
de.setLambda(0.6); de.setLambda(0.6);

View File

@ -1,15 +1,17 @@
package eva2.optimization.enums; package eva2.optimization.enums;
public enum DEType { public enum DEType {
RandOne, CurrentToBest, BestOne, BestTwo, Trigonometric, CurrentToRand; RandOne, RandTwo, RandToBest, BestOne, BestTwo, Trigonometric, CurrentToRand;
@Override @Override
public String toString() { public String toString() {
switch(this) { switch(this) {
case RandOne: case RandOne:
return "DE/rand/1"; return "DE/rand/1";
case CurrentToBest: case RandTwo:
return "DE/current-to-best/1"; return "DE/rand/2";
case RandToBest:
return "DE/rand-to-best/1";
case BestOne: case BestOne:
return "DE/best/1"; return "DE/best/1";
case BestTwo: case BestTwo:

View File

@ -474,33 +474,21 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
return this.constraintViolation > 0; return this.constraintViolation > 0;
} }
@Hidden
public void setMarked(boolean t) {
this.isMarked = t;
}
/** /**
* This method returns whether or not the individual is marked. This feature * This method returns whether or not the individual is marked. This feature
* is for GUI only and has been especially introduced for the MOCCO GUI. * is for GUI only and has been especially introduced for the MOCCO GUI.
* *
* @return true if marked false if not * @return true if marked false if not
*/ */
public boolean getMarked() {
return this.isMarked;
}
@Hidden
public void setMarked(boolean t) {
this.isMarked = t;
}
public boolean isMarked() { public boolean isMarked() {
return this.isMarked; return this.isMarked;
} }
public void unmark() {
this.isMarked = false;
}
public void mark() {
this.isMarked = true;
}
/** /**
* Allows marking an individual as infeasible if fitness penalty is used. * Allows marking an individual as infeasible if fitness penalty is used.
* *

View File

@ -406,12 +406,12 @@ public class MOCCOViewer extends JPanel implements InterfaceRefSolutionListener,
@Override @Override
public void individualSelected(AbstractEAIndividual indy) { public void individualSelected(AbstractEAIndividual indy) {
if (indy.isMarked()) { if (indy.isMarked()) {
indy.unmark(); indy.setMarked(false);
} else { } else {
if (this.selectUniqueSolution) { if (this.selectUniqueSolution) {
this.moccoStandalone.state.paretoFront.unmarkAllIndividuals(); this.moccoStandalone.state.paretoFront.unmarkAllIndividuals();
} }
indy.mark(); indy.setMarked(true);
} }
this.paretoFrontView.updateView(); this.paretoFrontView.updateView();
if (this.refSolutionListener != null) { if (this.refSolutionListener != null) {

View File

@ -1527,7 +1527,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
*/ */
public void unmarkAllIndividuals() { public void unmarkAllIndividuals() {
for (int i = 0; i < this.size(); i++) { for (int i = 0; i < this.size(); i++) {
this.get(i).unmark(); this.get(i).setMarked(false);
} }
} }

View File

@ -57,7 +57,7 @@ public class DifferentialEvolution extends AbstractOptimizer implements java.io.
*/ */
public DifferentialEvolution() { public DifferentialEvolution() {
// sets DE2 as default // sets DE2 as default
DEType = eva2.optimization.enums.DEType.CurrentToBest; DEType = eva2.optimization.enums.DEType.RandToBest;
} }
public DifferentialEvolution(int popSize, eva2.optimization.enums.DEType type, double f, double cr, double lambda, double mt) { public DifferentialEvolution(int popSize, eva2.optimization.enums.DEType type, double f, double cr, double lambda, double mt) {
@ -333,8 +333,20 @@ public class DifferentialEvolution extends AbstractOptimizer implements java.io.
} }
break; break;
} }
case CurrentToBest: { case RandTwo: {
// this is DE2 or DE/current-to-best/1 // this is DE/current-to-rand/1
double[] rndDelta = this.fetchDeltaRandom(population);
double[] rndDelta2 = this.fetchDeltaRandom(population);
if (parents != null) {
parents.add(population.getEAIndividual(parentIndex));
} // Add wherever oX is used directly
for (int i = 0; i < oX.length; i++) {
vX[i] = oX[i] + this.getCurrentF() * rndDelta[i] + this.getCurrentF() * rndDelta2[i];
}
break;
}
case RandToBest: {
// this is DE2 or DE/rand-to-best/1
double[] rndDelta = this.fetchDeltaRandom(population); double[] rndDelta = this.fetchDeltaRandom(population);
double[] bestDelta = this.fetchDeltaBest(population, esIndy); double[] bestDelta = this.fetchDeltaBest(population, esIndy);
if (parents != null) { if (parents != null) {
@ -767,7 +779,7 @@ public class DifferentialEvolution extends AbstractOptimizer implements java.io.
public void setDEType(eva2.optimization.enums.DEType s) { public void setDEType(eva2.optimization.enums.DEType s) {
this.DEType = s; this.DEType = s;
// show mt for trig. DE only // show mt for trig. DE only
GenericObjectEditor.setShowProperty(this.getClass(), "lambda", s == eva2.optimization.enums.DEType.CurrentToBest); GenericObjectEditor.setShowProperty(this.getClass(), "lambda", s == eva2.optimization.enums.DEType.RandToBest);
GenericObjectEditor.setShowProperty(this.getClass(), "mt", s == eva2.optimization.enums.DEType.Trigonometric); GenericObjectEditor.setShowProperty(this.getClass(), "mt", s == eva2.optimization.enums.DEType.Trigonometric);
} }

View File

@ -375,11 +375,7 @@ public abstract class AbstractOptimizationProblem implements InterfaceOptimizati
@Override @Override
public boolean isMultiObjective() { public boolean isMultiObjective() {
if (this instanceof AbstractMultiObjectiveOptimizationProblem) { if (this instanceof AbstractMultiObjectiveOptimizationProblem) {
if (((AbstractMultiObjectiveOptimizationProblem) this).getMOSOConverter() instanceof MOSONoConvert) { return ((AbstractMultiObjectiveOptimizationProblem) this).getMOSOConverter() instanceof MOSONoConvert;
return true;
} else {
return false;
}
} else { } else {
return false; return false;
} }