Refactor DE and add Rand/2 strategy
This commit is contained in:
parent
563c407f0b
commit
0479716f43
@ -102,7 +102,7 @@ public class OptimizerFactory {
|
||||
DifferentialEvolution de = new DifferentialEvolution();
|
||||
de.setProblem(problem);
|
||||
de.getPopulation().setTargetSize(popsize);
|
||||
de.setDEType(DEType.CurrentToBest);
|
||||
de.setDEType(DEType.RandToBest);
|
||||
de.setDifferentialWeight(f);
|
||||
de.setCrossoverRate(CR);
|
||||
de.setLambda(lambda);
|
||||
@ -1443,7 +1443,7 @@ public class OptimizerFactory {
|
||||
public static OptimizationParameters standardDE(
|
||||
AbstractOptimizationProblem problem) {
|
||||
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.setCrossoverRate(0.6);
|
||||
de.setLambda(0.6);
|
||||
|
@ -1,15 +1,17 @@
|
||||
package eva2.optimization.enums;
|
||||
|
||||
public enum DEType {
|
||||
RandOne, CurrentToBest, BestOne, BestTwo, Trigonometric, CurrentToRand;
|
||||
RandOne, RandTwo, RandToBest, BestOne, BestTwo, Trigonometric, CurrentToRand;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
switch(this) {
|
||||
case RandOne:
|
||||
return "DE/rand/1";
|
||||
case CurrentToBest:
|
||||
return "DE/current-to-best/1";
|
||||
case RandTwo:
|
||||
return "DE/rand/2";
|
||||
case RandToBest:
|
||||
return "DE/rand-to-best/1";
|
||||
case BestOne:
|
||||
return "DE/best/1";
|
||||
case BestTwo:
|
||||
|
@ -474,33 +474,21 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
|
||||
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
|
||||
* is for GUI only and has been especially introduced for the MOCCO GUI.
|
||||
*
|
||||
* @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() {
|
||||
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.
|
||||
*
|
||||
|
@ -406,12 +406,12 @@ public class MOCCOViewer extends JPanel implements InterfaceRefSolutionListener,
|
||||
@Override
|
||||
public void individualSelected(AbstractEAIndividual indy) {
|
||||
if (indy.isMarked()) {
|
||||
indy.unmark();
|
||||
indy.setMarked(false);
|
||||
} else {
|
||||
if (this.selectUniqueSolution) {
|
||||
this.moccoStandalone.state.paretoFront.unmarkAllIndividuals();
|
||||
}
|
||||
indy.mark();
|
||||
indy.setMarked(true);
|
||||
}
|
||||
this.paretoFrontView.updateView();
|
||||
if (this.refSolutionListener != null) {
|
||||
|
@ -1527,7 +1527,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
|
||||
*/
|
||||
public void unmarkAllIndividuals() {
|
||||
for (int i = 0; i < this.size(); i++) {
|
||||
this.get(i).unmark();
|
||||
this.get(i).setMarked(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ public class DifferentialEvolution extends AbstractOptimizer implements java.io.
|
||||
*/
|
||||
public DifferentialEvolution() {
|
||||
// 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) {
|
||||
@ -333,8 +333,20 @@ public class DifferentialEvolution extends AbstractOptimizer implements java.io.
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CurrentToBest: {
|
||||
// this is DE2 or DE/current-to-best/1
|
||||
case RandTwo: {
|
||||
// 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[] bestDelta = this.fetchDeltaBest(population, esIndy);
|
||||
if (parents != null) {
|
||||
@ -767,7 +779,7 @@ public class DifferentialEvolution extends AbstractOptimizer implements java.io.
|
||||
public void setDEType(eva2.optimization.enums.DEType s) {
|
||||
this.DEType = s;
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
@ -375,11 +375,7 @@ public abstract class AbstractOptimizationProblem implements InterfaceOptimizati
|
||||
@Override
|
||||
public boolean isMultiObjective() {
|
||||
if (this instanceof AbstractMultiObjectiveOptimizationProblem) {
|
||||
if (((AbstractMultiObjectiveOptimizationProblem) this).getMOSOConverter() instanceof MOSONoConvert) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return ((AbstractMultiObjectiveOptimizationProblem) this).getMOSOConverter() instanceof MOSONoConvert;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user