Stuff.
This commit is contained in:
parent
866f0dbd88
commit
cc9b29147f
3
src/META-INF/MANIFEST.MF
Normal file
3
src/META-INF/MANIFEST.MF
Normal file
@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: eva2.gui.Main
|
||||
|
@ -788,6 +788,7 @@ public class OptimizerFactory {
|
||||
if (runnable == null) {
|
||||
return null;
|
||||
}
|
||||
runnable.run();
|
||||
new Thread(runnable).start();
|
||||
lastRunnable = runnable;
|
||||
return runnable;
|
||||
|
@ -223,7 +223,7 @@ public class OptimizerRunnable implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
public double[] getDoubleSolution() {
|
||||
public double[] getDoubleSolution() {
|
||||
IndividualInterface indy = getResult();
|
||||
if (indy instanceof InterfaceDataTypeDouble) {
|
||||
return ((InterfaceDataTypeDouble) indy).getDoubleData();
|
||||
|
@ -1,6 +1,14 @@
|
||||
package eva2.cli;
|
||||
|
||||
import eva2.OptimizerFactory;
|
||||
import eva2.optimization.OptimizationStateListener;
|
||||
import eva2.optimization.go.InterfacePopulationChangedEventListener;
|
||||
import eva2.optimization.modules.OptimizationParameters;
|
||||
import eva2.optimization.operator.terminators.CombinedTerminator;
|
||||
import eva2.optimization.operator.terminators.EvaluationTerminator;
|
||||
import eva2.optimization.operator.terminators.FitnessValueTerminator;
|
||||
import eva2.optimization.problems.AbstractOptimizationProblem;
|
||||
import eva2.optimization.problems.F1Problem;
|
||||
import eva2.optimization.problems.InterfaceOptimizationProblem;
|
||||
import eva2.optimization.strategies.InterfaceOptimizer;
|
||||
import org.apache.commons.cli.*;
|
||||
@ -11,7 +19,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Main implements OptimizationStateListener {
|
||||
public class Main implements OptimizationStateListener, InterfacePopulationChangedEventListener {
|
||||
|
||||
|
||||
private static Options createDefaultCommandLineOptions() {
|
||||
@ -139,7 +147,34 @@ public class Main implements OptimizationStateListener {
|
||||
}
|
||||
}
|
||||
|
||||
Main optimizationMain = new Main();
|
||||
optimizationMain.runOptimization();
|
||||
}
|
||||
|
||||
private void runOptimization() {
|
||||
|
||||
// Terminate after 10000 function evaluations OR after reaching a fitness < 0.1
|
||||
OptimizerFactory.setEvaluationTerminator(50000);
|
||||
OptimizerFactory.addTerminator(new FitnessValueTerminator(new double[]{0.01}), CombinedTerminator.OR);
|
||||
|
||||
|
||||
int popsize = 30;
|
||||
double f = 0.8, lambda = 0.6, cr = 0.6;
|
||||
|
||||
AbstractOptimizationProblem problem = new F1Problem(popsize);
|
||||
|
||||
InterfaceOptimizer optimizer = OptimizerFactory.createDifferentialEvolution(problem, popsize, f, lambda, cr, this);
|
||||
|
||||
OptimizationParameters params = OptimizerFactory.makeParams(optimizer, popsize, problem);
|
||||
double[] result = OptimizerFactory.optimizeToDouble(params);
|
||||
|
||||
// This is stupid - why isn't there a way to wait for the optimization to finish?
|
||||
while(OptimizerFactory.terminatedBecause().equals("Not yet terminated")) {
|
||||
// wait
|
||||
}
|
||||
|
||||
System.out.println(OptimizerFactory.terminatedBecause());
|
||||
System.out.println(optimizer.getPopulation().getFunctionCalls());
|
||||
}
|
||||
|
||||
private static void showOptimizerHelp() {
|
||||
@ -159,4 +194,9 @@ public class Main implements OptimizationStateListener {
|
||||
System.out.printf("\t%s\n", name);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPopulationStateChanged(Object source, String name) {
|
||||
//System.out.println(name);
|
||||
}
|
||||
}
|
||||
|
@ -331,14 +331,6 @@ public class Main extends JFrame implements OptimizationStateListener {
|
||||
if (withGUI) {
|
||||
GridBagConstraints gbConstraints = new GridBagConstraints();
|
||||
|
||||
/* Set Look and Feel */
|
||||
try {
|
||||
//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
|
||||
} catch (Exception ex) {
|
||||
LOGGER.log(Level.INFO, "Could not set Look&Feel", ex);
|
||||
}
|
||||
|
||||
/* Create main frame with GridBagLayout */
|
||||
setTitle(EvAInfo.productName);
|
||||
setLayout(new GridBagLayout());
|
||||
@ -551,6 +543,25 @@ public class Main extends JFrame implements OptimizationStateListener {
|
||||
|
||||
System.setProperty("com.apple.mrj.application.growbox.intrudes", "false");
|
||||
System.setProperty("com.apple.mrj.application.live-resize", "true");
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||
} catch (InstantiationException e) {
|
||||
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||
} catch (UnsupportedLookAndFeelException e) {
|
||||
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||
}
|
||||
} else {
|
||||
/* Set Look and Feel */
|
||||
try {
|
||||
//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
|
||||
} catch (Exception ex) {
|
||||
LOGGER.log(Level.INFO, "Could not set Look&Feel", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/* Available command-line parameters */
|
||||
|
@ -1,9 +1,9 @@
|
||||
package eva2.optimization.population;
|
||||
|
||||
/**
|
||||
* This is just a wrapper type to distinct between a Population (current solution set
|
||||
* This is just a wrapper type to distinguish between a Population (current solution set
|
||||
* of an optimizer) and a final solution set, in which archived and deactivated
|
||||
* individuals may be contained as well. Both may be equal if the optimizer doesnt
|
||||
* individuals may be contained as well. Both may be equal if the optimizer doesn't
|
||||
* make this distinction.
|
||||
*
|
||||
* @author mkron
|
||||
|
Loading…
x
Reference in New Issue
Block a user