Reformatted several files, code cleanup
This commit is contained in:
parent
6edf5a50f6
commit
88d6c93931
@ -11,29 +11,31 @@ import eva2.optimization.operators.terminators.PopulationMeasureTerminator.Stagn
|
|||||||
import eva2.optimization.problems.F1Problem;
|
import eva2.optimization.problems.F1Problem;
|
||||||
|
|
||||||
public class TerminatorExample {
|
public class TerminatorExample {
|
||||||
public static void main(String[] args) {
|
|
||||||
F1Problem f1 = new F1Problem();
|
public static void main(String[] args) {
|
||||||
double[] sol;
|
F1Problem f1 = new F1Problem();
|
||||||
// A combined terminator for fitness and phenotype convergence
|
double[] sol;
|
||||||
CombinedTerminator convT = new CombinedTerminator(
|
// A combined terminator for fitness and phenotype convergence
|
||||||
// fitness-based stagnation period, absolute threshold, consider stagnation
|
CombinedTerminator convT = new CombinedTerminator(
|
||||||
// in both direction (per dim.) or w.r.t. minimization only
|
// fitness-based stagnation period, absolute threshold, consider stagnation
|
||||||
new FitnessConvergenceTerminator(0.0001, 1000, StagnationTypeEnum.fitnessCallBased, ChangeTypeEnum.absoluteChange, DirectionTypeEnum.decrease),
|
// in both direction (per dim.) or w.r.t. minimization only
|
||||||
new PhenotypeConvergenceTerminator(0.0001, 1000, StagnationTypeEnum.fitnessCallBased, ChangeTypeEnum.absoluteChange, DirectionTypeEnum.bidirectional),
|
new FitnessConvergenceTerminator(0.0001, 1000, StagnationTypeEnum.fitnessCallBased, ChangeTypeEnum.absoluteChange, DirectionTypeEnum.decrease),
|
||||||
CombinedTerminator.AND);
|
new PhenotypeConvergenceTerminator(0.0001, 1000, StagnationTypeEnum.fitnessCallBased, ChangeTypeEnum.absoluteChange, DirectionTypeEnum.bidirectional),
|
||||||
// Adding an evaluation terminator with OR to the convergence criterion
|
CombinedTerminator.AND);
|
||||||
OptimizerFactory.setTerminator(new CombinedTerminator(
|
// Adding an evaluation terminator with OR to the convergence criterion
|
||||||
new EvaluationTerminator(20000),
|
OptimizerFactory.setTerminator(new CombinedTerminator(
|
||||||
convT,
|
new EvaluationTerminator(20000),
|
||||||
CombinedTerminator.OR));
|
convT,
|
||||||
sol = OptimizerFactory.optimizeToDouble(OptimizerFactory.PSO, f1, null);
|
CombinedTerminator.OR));
|
||||||
System.out.println(OptimizerFactory.lastEvalsPerformed()
|
sol = OptimizerFactory.optimizeToDouble(OptimizerFactory.PSO, f1, null);
|
||||||
+ " evals performed. "
|
System.out.println(OptimizerFactory.lastEvalsPerformed()
|
||||||
+ OptimizerFactory.terminatedBecause()
|
+ " evals performed. "
|
||||||
+ " Found solution: ");
|
+ OptimizerFactory.terminatedBecause()
|
||||||
for (int i=0; i<f1.getProblemDimension(); i++) {
|
+ " Found solution: ");
|
||||||
|
for (int i = 0; i < f1.getProblemDimension(); i++) {
|
||||||
System.out.print(sol[i] + " ");
|
System.out.print(sol[i] + " ");
|
||||||
}
|
}
|
||||||
System.out.println();
|
System.out.println();
|
||||||
};
|
}
|
||||||
|
;
|
||||||
}
|
}
|
@ -1,17 +1,19 @@
|
|||||||
package eva2.examples;
|
package eva2.examples;
|
||||||
|
|
||||||
import eva2.OptimizerFactory;
|
import eva2.OptimizerFactory;
|
||||||
import eva2.optimization.problems.F1Problem;
|
import eva2.optimization.problems.F1Problem;
|
||||||
|
|
||||||
public class TestingF1PSO {
|
public class TestingF1PSO {
|
||||||
public static void main(String[] args) {
|
|
||||||
F1Problem f1 = new F1Problem();
|
public static void main(String[] args) {
|
||||||
// start a PSO with a runtime of 50000 evaluations
|
F1Problem f1 = new F1Problem();
|
||||||
OptimizerFactory.setEvaluationTerminator(50000);
|
// start a PSO with a runtime of 50000 evaluations
|
||||||
double[] sol = OptimizerFactory.optimizeToDouble(OptimizerFactory.PSO, f1, null);
|
OptimizerFactory.setEvaluationTerminator(50000);
|
||||||
System.out.println(OptimizerFactory.terminatedBecause() + "\nFound solution: ");
|
double[] sol = OptimizerFactory.optimizeToDouble(OptimizerFactory.PSO, f1, null);
|
||||||
for (int i=0; i<f1.getProblemDimension(); i++) {
|
System.out.println(OptimizerFactory.terminatedBecause() + "\nFound solution: ");
|
||||||
|
for (int i = 0; i < f1.getProblemDimension(); i++) {
|
||||||
System.out.print(sol[i] + " ");
|
System.out.print(sol[i] + " ");
|
||||||
}
|
}
|
||||||
System.out.println();
|
System.out.println();
|
||||||
};
|
}
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
package eva2.examples;
|
package eva2.examples;
|
||||||
|
|
||||||
import eva2.OptimizerFactory;
|
import eva2.OptimizerFactory;
|
||||||
import eva2.optimization.individuals.AbstractEAIndividual;
|
import eva2.optimization.individuals.AbstractEAIndividual;
|
||||||
import eva2.optimization.operators.crossover.CrossoverESDefault;
|
import eva2.optimization.operators.crossover.CrossoverESDefault;
|
||||||
@ -9,32 +10,34 @@ import eva2.optimization.strategies.EvolutionStrategies;
|
|||||||
import eva2.optimization.modules.GOParameters;
|
import eva2.optimization.modules.GOParameters;
|
||||||
|
|
||||||
public class TestingPlusCmaEs {
|
public class TestingPlusCmaEs {
|
||||||
public static void main(String[] args) {
|
|
||||||
// a simple bimodal target function, two optima near (1.7,0) and (-1.44/0)
|
|
||||||
FM0Problem fm0 = new FM0Problem();
|
|
||||||
AbstractEAIndividual bestIndy;
|
|
||||||
// create standard ES parameters
|
|
||||||
GOParameters esParams = OptimizerFactory.standardES(fm0);
|
|
||||||
esParams.setTerminator(new EvaluationTerminator(2000));
|
|
||||||
// set a random seed based on system time
|
|
||||||
esParams.setSeed(0);
|
|
||||||
|
|
||||||
// set evolutionary operators and probabilities
|
public static void main(String[] args) {
|
||||||
AbstractEAIndividual.setOperators(
|
// a simple bimodal target function, two optima near (1.7,0) and (-1.44/0)
|
||||||
fm0.getIndividualTemplate(),
|
FM0Problem fm0 = new FM0Problem();
|
||||||
new MutateESCovarianceMatrixAdaption(true), 0.9,
|
AbstractEAIndividual bestIndy;
|
||||||
new CrossoverESDefault(), 0.1);
|
// create standard ES parameters
|
||||||
|
GOParameters esParams = OptimizerFactory.standardES(fm0);
|
||||||
|
esParams.setTerminator(new EvaluationTerminator(2000));
|
||||||
|
// set a random seed based on system time
|
||||||
|
esParams.setSeed(0);
|
||||||
|
|
||||||
// access the ES
|
// set evolutionary operators and probabilities
|
||||||
EvolutionStrategies es = (EvolutionStrategies)esParams.getOptimizer();
|
AbstractEAIndividual.setOperators(
|
||||||
// set a (1+5) selection strategy
|
fm0.getIndividualTemplate(),
|
||||||
es.setMu(1);
|
new MutateESCovarianceMatrixAdaption(true), 0.9,
|
||||||
es.setLambda(5);
|
new CrossoverESDefault(), 0.1);
|
||||||
es.setPlusStrategy(true);
|
|
||||||
|
|
||||||
// run optimization and retrieve winner individual
|
// access the ES
|
||||||
bestIndy = (AbstractEAIndividual)OptimizerFactory.optimizeToInd(esParams, null);
|
EvolutionStrategies es = (EvolutionStrategies) esParams.getOptimizer();
|
||||||
System.out.println(esParams.getTerminator().lastTerminationMessage() + "\nFound solution: "
|
// set a (1+5) selection strategy
|
||||||
+ AbstractEAIndividual.getDefaultDataString(bestIndy));
|
es.setMu(1);
|
||||||
};
|
es.setLambda(5);
|
||||||
|
es.setPlusStrategy(true);
|
||||||
|
|
||||||
|
// run optimization and retrieve winner individual
|
||||||
|
bestIndy = (AbstractEAIndividual) OptimizerFactory.optimizeToInd(esParams, null);
|
||||||
|
System.out.println(esParams.getTerminator().lastTerminationMessage() + "\nFound solution: "
|
||||||
|
+ AbstractEAIndividual.getDefaultDataString(bestIndy));
|
||||||
|
}
|
||||||
|
;
|
||||||
}
|
}
|
@ -1,16 +1,11 @@
|
|||||||
package eva2.optimization.tools;
|
package eva2.optimization.tools;
|
||||||
|
|
||||||
|
|
||||||
import eva2.tools.chart2d.*;
|
import eva2.tools.chart2d.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by IntelliJ IDEA.
|
*
|
||||||
* User: streiche
|
|
||||||
* Date: 06.05.2004
|
|
||||||
* Time: 13:17:55
|
|
||||||
* To change this template use File | Settings | File Templates.
|
|
||||||
*/
|
*/
|
||||||
public class TestingDArea {
|
public class TestingDArea {
|
||||||
|
|
||||||
@ -19,27 +14,26 @@ public class TestingDArea {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
JFrame frame = new JFrame("Testing DArea");
|
JFrame frame = new JFrame("Testing DArea");
|
||||||
JPanel panel = new JPanel();
|
JPanel panel = new JPanel();
|
||||||
frame.getContentPane().add(panel);
|
frame.getContentPane().add(panel);
|
||||||
|
|
||||||
DArea area = new DArea();
|
DArea area = new DArea();
|
||||||
area = new DArea();
|
area.setBackground(Color.white);
|
||||||
area.setBackground(Color.white);
|
area.setPreferredSize(new Dimension(600, 500));
|
||||||
area.setPreferredSize( new Dimension(600,500) );
|
area.setVisibleRectangle(1, 1, 100000, 1000);
|
||||||
area.setVisibleRectangle( 1, 1, 100000, 1000 );
|
area.setVisibleRectangle(0, -3, 10, 10);//m_PlotArea.setAutoFocus(true);
|
||||||
area.setVisibleRectangle( 0,-3, 10, 10 );//m_PlotArea.setAutoFocus(true);
|
area.setMinRectangle(0, 0, 1, 1);
|
||||||
area.setMinRectangle(0,0,1,1);
|
ScaledBorder myBorder = new ScaledBorder();
|
||||||
ScaledBorder myBorder = new ScaledBorder();
|
myBorder.x_label = "x";//"App. " + Name + " func. calls";
|
||||||
myBorder.x_label = "x";//"App. " + Name + " func. calls";
|
myBorder.y_label = "y";//"fitness";
|
||||||
myBorder.y_label = "y";//"fitness";
|
area.setBorder(myBorder);
|
||||||
area.setBorder( myBorder );
|
area.setAutoGrid(true);
|
||||||
area.setAutoGrid(true);
|
area.setGridVisible(true);
|
||||||
area.setGridVisible(true);
|
|
||||||
DRectangle rect = new DRectangle(1, 1, 2, 2);
|
DRectangle rect = new DRectangle(1, 1, 2, 2);
|
||||||
rect.setColor(Color.black);
|
rect.setColor(Color.black);
|
||||||
rect.setFillColor(Color.red);
|
rect.setFillColor(Color.red);
|
||||||
DPointSet points = new DPointSet();
|
DPointSet points = new DPointSet();
|
||||||
points.addDPoint(2, 3);
|
points.addDPoint(2, 3);
|
||||||
points.addDPoint(4, 5);
|
points.addDPoint(4, 5);
|
||||||
area.addDElement(rect);
|
area.addDElement(rect);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user