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;
|
||||
|
||||
public class TerminatorExample {
|
||||
public static void main(String[] args) {
|
||||
F1Problem f1 = new F1Problem();
|
||||
double[] sol;
|
||||
// A combined terminator for fitness and phenotype convergence
|
||||
CombinedTerminator convT = new CombinedTerminator(
|
||||
// fitness-based stagnation period, absolute threshold, consider stagnation
|
||||
// in both direction (per dim.) or w.r.t. minimization only
|
||||
new FitnessConvergenceTerminator(0.0001, 1000, StagnationTypeEnum.fitnessCallBased, ChangeTypeEnum.absoluteChange, DirectionTypeEnum.decrease),
|
||||
new PhenotypeConvergenceTerminator(0.0001, 1000, StagnationTypeEnum.fitnessCallBased, ChangeTypeEnum.absoluteChange, DirectionTypeEnum.bidirectional),
|
||||
CombinedTerminator.AND);
|
||||
// Adding an evaluation terminator with OR to the convergence criterion
|
||||
OptimizerFactory.setTerminator(new CombinedTerminator(
|
||||
new EvaluationTerminator(20000),
|
||||
convT,
|
||||
CombinedTerminator.OR));
|
||||
sol = OptimizerFactory.optimizeToDouble(OptimizerFactory.PSO, f1, null);
|
||||
System.out.println(OptimizerFactory.lastEvalsPerformed()
|
||||
+ " evals performed. "
|
||||
+ OptimizerFactory.terminatedBecause()
|
||||
+ " Found solution: ");
|
||||
for (int i=0; i<f1.getProblemDimension(); i++) {
|
||||
|
||||
public static void main(String[] args) {
|
||||
F1Problem f1 = new F1Problem();
|
||||
double[] sol;
|
||||
// A combined terminator for fitness and phenotype convergence
|
||||
CombinedTerminator convT = new CombinedTerminator(
|
||||
// fitness-based stagnation period, absolute threshold, consider stagnation
|
||||
// in both direction (per dim.) or w.r.t. minimization only
|
||||
new FitnessConvergenceTerminator(0.0001, 1000, StagnationTypeEnum.fitnessCallBased, ChangeTypeEnum.absoluteChange, DirectionTypeEnum.decrease),
|
||||
new PhenotypeConvergenceTerminator(0.0001, 1000, StagnationTypeEnum.fitnessCallBased, ChangeTypeEnum.absoluteChange, DirectionTypeEnum.bidirectional),
|
||||
CombinedTerminator.AND);
|
||||
// Adding an evaluation terminator with OR to the convergence criterion
|
||||
OptimizerFactory.setTerminator(new CombinedTerminator(
|
||||
new EvaluationTerminator(20000),
|
||||
convT,
|
||||
CombinedTerminator.OR));
|
||||
sol = OptimizerFactory.optimizeToDouble(OptimizerFactory.PSO, f1, null);
|
||||
System.out.println(OptimizerFactory.lastEvalsPerformed()
|
||||
+ " evals performed. "
|
||||
+ OptimizerFactory.terminatedBecause()
|
||||
+ " Found solution: ");
|
||||
for (int i = 0; i < f1.getProblemDimension(); i++) {
|
||||
System.out.print(sol[i] + " ");
|
||||
}
|
||||
System.out.println();
|
||||
};
|
||||
System.out.println();
|
||||
}
|
||||
;
|
||||
}
|
@ -1,17 +1,19 @@
|
||||
package eva2.examples;
|
||||
|
||||
import eva2.OptimizerFactory;
|
||||
import eva2.optimization.problems.F1Problem;
|
||||
|
||||
public class TestingF1PSO {
|
||||
public static void main(String[] args) {
|
||||
F1Problem f1 = new F1Problem();
|
||||
// start a PSO with a runtime of 50000 evaluations
|
||||
OptimizerFactory.setEvaluationTerminator(50000);
|
||||
double[] sol = OptimizerFactory.optimizeToDouble(OptimizerFactory.PSO, f1, null);
|
||||
System.out.println(OptimizerFactory.terminatedBecause() + "\nFound solution: ");
|
||||
for (int i=0; i<f1.getProblemDimension(); i++) {
|
||||
|
||||
public static void main(String[] args) {
|
||||
F1Problem f1 = new F1Problem();
|
||||
// start a PSO with a runtime of 50000 evaluations
|
||||
OptimizerFactory.setEvaluationTerminator(50000);
|
||||
double[] sol = OptimizerFactory.optimizeToDouble(OptimizerFactory.PSO, f1, null);
|
||||
System.out.println(OptimizerFactory.terminatedBecause() + "\nFound solution: ");
|
||||
for (int i = 0; i < f1.getProblemDimension(); i++) {
|
||||
System.out.print(sol[i] + " ");
|
||||
}
|
||||
System.out.println();
|
||||
};
|
||||
System.out.println();
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
package eva2.examples;
|
||||
|
||||
import eva2.OptimizerFactory;
|
||||
import eva2.optimization.individuals.AbstractEAIndividual;
|
||||
import eva2.optimization.operators.crossover.CrossoverESDefault;
|
||||
@ -9,32 +10,34 @@ import eva2.optimization.strategies.EvolutionStrategies;
|
||||
import eva2.optimization.modules.GOParameters;
|
||||
|
||||
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
|
||||
AbstractEAIndividual.setOperators(
|
||||
fm0.getIndividualTemplate(),
|
||||
new MutateESCovarianceMatrixAdaption(true), 0.9,
|
||||
new CrossoverESDefault(), 0.1);
|
||||
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);
|
||||
|
||||
// access the ES
|
||||
EvolutionStrategies es = (EvolutionStrategies)esParams.getOptimizer();
|
||||
// set a (1+5) selection strategy
|
||||
es.setMu(1);
|
||||
es.setLambda(5);
|
||||
es.setPlusStrategy(true);
|
||||
// set evolutionary operators and probabilities
|
||||
AbstractEAIndividual.setOperators(
|
||||
fm0.getIndividualTemplate(),
|
||||
new MutateESCovarianceMatrixAdaption(true), 0.9,
|
||||
new CrossoverESDefault(), 0.1);
|
||||
|
||||
// run optimization and retrieve winner individual
|
||||
bestIndy = (AbstractEAIndividual)OptimizerFactory.optimizeToInd(esParams, null);
|
||||
System.out.println(esParams.getTerminator().lastTerminationMessage() + "\nFound solution: "
|
||||
+ AbstractEAIndividual.getDefaultDataString(bestIndy));
|
||||
};
|
||||
// access the ES
|
||||
EvolutionStrategies es = (EvolutionStrategies) esParams.getOptimizer();
|
||||
// set a (1+5) selection strategy
|
||||
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;
|
||||
|
||||
|
||||
import eva2.tools.chart2d.*;
|
||||
import java.awt.*;
|
||||
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 {
|
||||
|
||||
@ -19,27 +14,26 @@ public class TestingDArea {
|
||||
}
|
||||
|
||||
private void init() {
|
||||
JFrame frame = new JFrame("Testing DArea");
|
||||
JPanel panel = new JPanel();
|
||||
JFrame frame = new JFrame("Testing DArea");
|
||||
JPanel panel = new JPanel();
|
||||
frame.getContentPane().add(panel);
|
||||
|
||||
DArea area = new DArea();
|
||||
area = new DArea();
|
||||
area.setBackground(Color.white);
|
||||
area.setPreferredSize( new Dimension(600,500) );
|
||||
area.setVisibleRectangle( 1, 1, 100000, 1000 );
|
||||
area.setVisibleRectangle( 0,-3, 10, 10 );//m_PlotArea.setAutoFocus(true);
|
||||
area.setMinRectangle(0,0,1,1);
|
||||
ScaledBorder myBorder = new ScaledBorder();
|
||||
myBorder.x_label = "x";//"App. " + Name + " func. calls";
|
||||
myBorder.y_label = "y";//"fitness";
|
||||
area.setBorder( myBorder );
|
||||
area.setAutoGrid(true);
|
||||
area.setGridVisible(true);
|
||||
area.setBackground(Color.white);
|
||||
area.setPreferredSize(new Dimension(600, 500));
|
||||
area.setVisibleRectangle(1, 1, 100000, 1000);
|
||||
area.setVisibleRectangle(0, -3, 10, 10);//m_PlotArea.setAutoFocus(true);
|
||||
area.setMinRectangle(0, 0, 1, 1);
|
||||
ScaledBorder myBorder = new ScaledBorder();
|
||||
myBorder.x_label = "x";//"App. " + Name + " func. calls";
|
||||
myBorder.y_label = "y";//"fitness";
|
||||
area.setBorder(myBorder);
|
||||
area.setAutoGrid(true);
|
||||
area.setGridVisible(true);
|
||||
DRectangle rect = new DRectangle(1, 1, 2, 2);
|
||||
rect.setColor(Color.black);
|
||||
rect.setFillColor(Color.red);
|
||||
DPointSet points = new DPointSet();
|
||||
DPointSet points = new DPointSet();
|
||||
points.addDPoint(2, 3);
|
||||
points.addDPoint(4, 5);
|
||||
area.addDElement(rect);
|
||||
|
Loading…
x
Reference in New Issue
Block a user