More refactoring
Making sure FLensProblem still runs and works with StandaloneOptimization UI
This commit is contained in:
parent
595d0084a9
commit
5a7b0fe429
@ -1,14 +0,0 @@
|
||||
package eva2.optimization.go;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 27.05.2003
|
||||
* Time: 16:24:32
|
||||
* To change this template use Options | File Templates.
|
||||
*/
|
||||
public interface InterfaceGOStandalone {
|
||||
void startExperiment();
|
||||
|
||||
void setShow(boolean t);
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package eva2.optimization.go;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public interface InterfaceStandaloneOptimization {
|
||||
void startExperiment();
|
||||
|
||||
void setShow(boolean t);
|
||||
}
|
@ -26,7 +26,7 @@ import java.io.*;
|
||||
* Time: 14:31:56
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class MOCCOStandalone implements InterfaceGOStandalone, InterfacePopulationChangedEventListener, Serializable {
|
||||
public class MOCCOStandalone implements InterfaceStandaloneOptimization, InterfacePopulationChangedEventListener, Serializable {
|
||||
|
||||
public volatile MOCCOState m_State;
|
||||
private SwingWorker worker;
|
||||
@ -455,7 +455,7 @@ public class MOCCOStandalone implements InterfaceGOStandalone, InterfacePopulati
|
||||
}
|
||||
|
||||
/***********************************************************************************************
|
||||
* InterfaceGOStandalone
|
||||
* InterfaceStandaloneOptimization
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -34,17 +34,17 @@ import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
@eva2.util.annotation.Description(text = "This is a simple example framework for Evolutionary Algorithms.")
|
||||
public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopulationChangedEventListener, java.io.Serializable {
|
||||
public class StandaloneOptimization implements InterfaceStandaloneOptimization, InterfacePopulationChangedEventListener, java.io.Serializable {
|
||||
|
||||
// Interface GUI Stuff
|
||||
transient private JFrame m_Frame;
|
||||
transient private JPanel m_MainPanel;
|
||||
transient private JPanel m_ButtonPanel;
|
||||
transient private JFrame mainFrame;
|
||||
transient private JPanel mainPanel;
|
||||
transient private JPanel buttonPanel;
|
||||
transient private JButton m_RunButton, m_StopButton, m_Continue, m_ShowSolution;
|
||||
transient private JComponent m_OptionsPanel, m_O1, m_O2;
|
||||
transient private JComponent m_StatusPanel;
|
||||
transient private JLabel m_StatusField;
|
||||
transient private JProgressBar m_ProgressBar;
|
||||
transient private JComponent optionsPanel, m_O1, m_O2;
|
||||
transient private JComponent statusPanel;
|
||||
transient private JLabel statusField;
|
||||
transient private JProgressBar progressBar;
|
||||
transient private SwingWorker worker;
|
||||
transient private boolean show = false;
|
||||
// transient private InterfaceTest test = new Test1();
|
||||
@ -52,71 +52,65 @@ public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopu
|
||||
//transient private InterfaceOptimizer optimizer = new EvolutionaryMultiObjectiveOptimization();
|
||||
//transient private InterfaceOptimizationProblem problem = new TF1Problem();
|
||||
//transient private int functionCalls = 1000;
|
||||
private OptimizationParameters m_GO;
|
||||
transient private int m_MultiRuns = 1;
|
||||
transient private int m_RecentFC;
|
||||
private OptimizationParameters optimizationParameters;
|
||||
transient private int multiRuns = 1;
|
||||
transient private int recentFunctionCalls;
|
||||
transient private int currentExperiment = 0;
|
||||
transient private int currentRun;
|
||||
transient private int currentProgress;
|
||||
transient private String m_ExperimentName;
|
||||
transient private String m_OutputPath = "";
|
||||
transient private String m_OutputFileName = "none";
|
||||
// transient private GOStandaloneVersion m_yself;
|
||||
transient private String experimentName;
|
||||
transient private String outputPath = "";
|
||||
transient private String outputFileName = "none";
|
||||
// these parameters are for the continue option
|
||||
transient private Population m_Backup;
|
||||
transient private boolean m_ContinueFlag;
|
||||
transient private Population backupPopulation;
|
||||
transient private boolean continueFlag;
|
||||
// Plot Panel stuff
|
||||
transient private Plot m_Plot;
|
||||
transient private ArrayList m_PerformedRuns = new ArrayList();
|
||||
transient private ArrayList m_TmpData;
|
||||
transient private BufferedWriter m_OutputFile;
|
||||
transient private ArrayList performedRuns = new ArrayList();
|
||||
transient private ArrayList<Double[]> tmpData;
|
||||
transient private BufferedWriter outputFile;
|
||||
// Test
|
||||
transient private List m_List;
|
||||
|
||||
/**
|
||||
* Create a new EALectureGUI.
|
||||
*/
|
||||
public GOStandaloneVersion() {
|
||||
// this.m_List = new List();
|
||||
// this.m_List.add("Test1");
|
||||
// this.m_List.add("Test2");
|
||||
// this.m_List.add("Test3");
|
||||
// this.m_yself = this;
|
||||
this.m_GO = OptimizationParameters.getInstance();
|
||||
this.m_ExperimentName = this.m_GO.getOptimizer().getName() + "-" + this.m_PerformedRuns.size();
|
||||
this.m_GO.addPopulationChangedEventListener(this);
|
||||
RNG.setRandomSeed(m_GO.getSeed());
|
||||
public StandaloneOptimization() {
|
||||
this.optimizationParameters = OptimizationParameters.getInstance();
|
||||
this.experimentName = this.optimizationParameters.getOptimizer().getName() + "-" + this.performedRuns.size();
|
||||
this.optimizationParameters.addPopulationChangedEventListener(this);
|
||||
RNG.setRandomSeed(optimizationParameters.getSeed());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method allows you to get the current GO parameters
|
||||
*/
|
||||
public OptimizationParameters getGOParameters() {
|
||||
return this.m_GO;
|
||||
return this.optimizationParameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will generate a Plot Frame and a main Editing Frame
|
||||
*/
|
||||
public void initFrame() {
|
||||
this.m_ProgressBar = new JProgressBar();
|
||||
this.progressBar = new JProgressBar();
|
||||
// init the main frame
|
||||
this.m_Frame = new JFrame();
|
||||
this.m_Frame.setTitle("Genetic Optimizing");
|
||||
this.m_Frame.setSize(500, 400);
|
||||
this.m_Frame.setLocation(530, 50);
|
||||
this.m_Frame.addWindowListener(new WindowAdapter() {
|
||||
this.mainFrame = new JFrame();
|
||||
this.mainFrame.setTitle("Genetic Optimizing");
|
||||
this.mainFrame.setSize(500, 400);
|
||||
this.mainFrame.setLocation(530, 50);
|
||||
this.mainFrame.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent ev) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
// build the main panel
|
||||
this.m_MainPanel = new JPanel();
|
||||
this.m_Frame.getContentPane().add(this.m_MainPanel);
|
||||
this.m_MainPanel.setLayout(new BorderLayout());
|
||||
this.mainPanel = new JPanel();
|
||||
this.mainFrame.getContentPane().add(this.mainPanel);
|
||||
this.mainPanel.setLayout(new BorderLayout());
|
||||
// build the button panel
|
||||
this.m_ButtonPanel = new JPanel();
|
||||
this.buttonPanel = new JPanel();
|
||||
this.m_RunButton = new JButton("Run");
|
||||
this.m_RunButton.addActionListener(this.runListener);
|
||||
this.m_RunButton.setEnabled(true);
|
||||
@ -133,22 +127,22 @@ public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopu
|
||||
this.m_ShowSolution.addActionListener(this.showSolListener);
|
||||
this.m_ShowSolution.setEnabled(true);
|
||||
this.m_ShowSolution.setToolTipText("Show the current best solution.");
|
||||
this.m_ButtonPanel.add(this.m_RunButton);
|
||||
this.m_ButtonPanel.add(this.m_Continue);
|
||||
this.m_ButtonPanel.add(this.m_StopButton);
|
||||
this.m_ButtonPanel.add(this.m_ShowSolution);
|
||||
this.m_MainPanel.add(this.m_ButtonPanel, BorderLayout.NORTH);
|
||||
this.buttonPanel.add(this.m_RunButton);
|
||||
this.buttonPanel.add(this.m_Continue);
|
||||
this.buttonPanel.add(this.m_StopButton);
|
||||
this.buttonPanel.add(this.m_ShowSolution);
|
||||
this.mainPanel.add(this.buttonPanel, BorderLayout.NORTH);
|
||||
|
||||
// build the Options Panel
|
||||
JParaPanel paraPanel = new JParaPanel(this, "MyGUI");
|
||||
Class object = null, editor = null;
|
||||
String tmp = "eva2.server.oa.go.Tools.InterfaceTest";
|
||||
String tmp = "eva2.optimization.go.Tools.InterfaceTest";
|
||||
try {
|
||||
object = Class.forName(tmp);
|
||||
} catch (java.lang.ClassNotFoundException e) {
|
||||
System.out.println("No Class found for " + tmp);
|
||||
}
|
||||
tmp = "eva2.gui.GenericObjectEditor";
|
||||
tmp = "eva2.gui.editor.GenericObjectEditor";
|
||||
try {
|
||||
editor = Class.forName(tmp);
|
||||
} catch (java.lang.ClassNotFoundException e) {
|
||||
@ -158,31 +152,29 @@ public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopu
|
||||
paraPanel.registerEditor(object, editor);
|
||||
}
|
||||
this.m_O1 = (paraPanel.makePanel());
|
||||
// TODO this is defunct anyways... (MK, 2010-03)
|
||||
// Main.setProperty("eva2.server.oa.go.Tools.InterfaceTest", "eva2.server.oa.go.Tools.Test1,eva2.server.oa.go.Tools.Test2");
|
||||
this.m_OptionsPanel = new JTabbedPane();
|
||||
JParaPanel paraPanel2 = new JParaPanel(this.m_GO, "MyGUI");
|
||||
this.optionsPanel = new JTabbedPane();
|
||||
JParaPanel paraPanel2 = new JParaPanel(this.optimizationParameters, "MyGUI");
|
||||
this.m_O2 = (paraPanel2.makePanel());
|
||||
((JTabbedPane) this.m_OptionsPanel).addTab("GO Parameters", this.m_O2);
|
||||
((JTabbedPane) this.m_OptionsPanel).addTab("GO Statistics", this.m_O1);
|
||||
this.m_MainPanel.add(this.m_OptionsPanel, BorderLayout.CENTER);
|
||||
((JTabbedPane) this.optionsPanel).addTab("Optimization Parameters", this.m_O2);
|
||||
((JTabbedPane) this.optionsPanel).addTab("Statistics", this.m_O1);
|
||||
this.mainPanel.add(this.optionsPanel, BorderLayout.CENTER);
|
||||
|
||||
// build the Status Panel
|
||||
this.m_StatusPanel = new JPanel();
|
||||
this.m_StatusPanel.setLayout(new BorderLayout());
|
||||
this.m_StatusField = new JLabel("Click Run to begin...");
|
||||
this.m_ProgressBar = new JProgressBar();
|
||||
this.m_StatusPanel.add(this.m_StatusField, BorderLayout.NORTH);
|
||||
this.m_StatusPanel.add(this.m_ProgressBar, BorderLayout.SOUTH);
|
||||
this.m_MainPanel.add(this.m_StatusPanel, BorderLayout.SOUTH);
|
||||
this.statusPanel = new JPanel();
|
||||
this.statusPanel.setLayout(new BorderLayout());
|
||||
this.statusField = new JLabel("Click Run to begin...");
|
||||
this.progressBar = new JProgressBar();
|
||||
this.statusPanel.add(this.statusField, BorderLayout.NORTH);
|
||||
this.statusPanel.add(this.progressBar, BorderLayout.SOUTH);
|
||||
this.mainPanel.add(this.statusPanel, BorderLayout.SOUTH);
|
||||
// The plot frame
|
||||
double[] tmpD = new double[2];
|
||||
tmpD[0] = 1;
|
||||
tmpD[1] = 1;
|
||||
this.m_Plot = new Plot("EA Lecture Plot", "Function calls", "Fitness", true);
|
||||
// validate and show
|
||||
this.m_Frame.validate();
|
||||
this.m_Frame.setVisible(true);
|
||||
this.mainFrame.validate();
|
||||
this.mainFrame.setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -203,7 +195,7 @@ public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopu
|
||||
m_RunButton.setEnabled(true);
|
||||
m_Continue.setEnabled(true);
|
||||
m_StopButton.setEnabled(false);
|
||||
m_Backup = (Population) m_GO.getOptimizer().getPopulation().clone();
|
||||
backupPopulation = (Population) optimizationParameters.getOptimizer().getPopulation().clone();
|
||||
}
|
||||
};
|
||||
worker.start();
|
||||
@ -224,7 +216,7 @@ public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopu
|
||||
m_Continue.setEnabled(true);
|
||||
m_StopButton.setEnabled(false);
|
||||
worker.interrupt();
|
||||
for (int i = 0; i < m_MultiRuns; i++) {
|
||||
for (int i = 0; i < multiRuns; i++) {
|
||||
m_Plot.clearGraph(1000 + i);
|
||||
}
|
||||
}
|
||||
@ -249,14 +241,14 @@ public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopu
|
||||
m_RunButton.setEnabled(true);
|
||||
m_Continue.setEnabled(true);
|
||||
m_StopButton.setEnabled(false);
|
||||
m_Backup = (Population) m_GO.getOptimizer().getPopulation().clone();
|
||||
m_ContinueFlag = false;
|
||||
backupPopulation = (Population) optimizationParameters.getOptimizer().getPopulation().clone();
|
||||
continueFlag = false;
|
||||
}
|
||||
};
|
||||
// also mal ganz anders ich gehe davon aus, dass der Benutzer das Ding parametrisiert hat
|
||||
// setze einfach die Backup population ein...
|
||||
m_ContinueFlag = true;
|
||||
m_MultiRuns = 1; // multiruns machen bei continue einfach keinen Sinn...
|
||||
continueFlag = true;
|
||||
multiRuns = 1; // multiruns machen bei continue einfach keinen Sinn...
|
||||
worker.start();
|
||||
m_RunButton.setEnabled(false);
|
||||
m_Continue.setEnabled(false);
|
||||
@ -271,11 +263,11 @@ public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopu
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
JFrame frame = new JFrame();
|
||||
frame.setTitle("The current best solution for " + m_GO.getProblem().getName());
|
||||
frame.setTitle("The current best solution for " + optimizationParameters.getProblem().getName());
|
||||
frame.setSize(400, 300);
|
||||
frame.setLocation(450, 250);
|
||||
Population pop = m_GO.getOptimizer().getPopulation();
|
||||
frame.getContentPane().add(m_GO.getProblem().drawIndividual(pop.getGeneration(), pop.getFunctionCalls(), pop.getBestEAIndividual()));
|
||||
Population pop = optimizationParameters.getOptimizer().getPopulation();
|
||||
frame.getContentPane().add(optimizationParameters.getProblem().drawIndividual(pop.getGeneration(), pop.getFunctionCalls(), pop.getBestEAIndividual()));
|
||||
frame.validate();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
@ -287,16 +279,16 @@ public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopu
|
||||
@Override
|
||||
public void startExperiment() {
|
||||
// This is for the CBN-TEST RUNS
|
||||
this.m_GO.setOptimizer(new EvolutionStrategies());
|
||||
this.m_GO.setProblem(new F1Problem());
|
||||
this.optimizationParameters.setOptimizer(new EvolutionStrategies());
|
||||
this.optimizationParameters.setProblem(new F1Problem());
|
||||
EvaluationTerminator terminator = new EvaluationTerminator();
|
||||
terminator.setFitnessCalls(50000);
|
||||
this.m_GO.setTerminator(terminator);
|
||||
this.m_MultiRuns = 10;
|
||||
this.optimizationParameters.setTerminator(terminator);
|
||||
this.multiRuns = 10;
|
||||
int experimentType = 0;
|
||||
this.m_ExperimentName = "InferringGRN";
|
||||
this.m_OutputFileName = "Result";
|
||||
this.m_OutputPath = "results/";
|
||||
this.experimentName = "InferringGRN";
|
||||
this.outputFileName = "Result";
|
||||
this.outputPath = "results/";
|
||||
// These are some tmp Variables
|
||||
InterfaceDataTypeDouble tmpIndy = new ESIndividualDoubleData();
|
||||
InterfaceMutation tmpMut = new MutateESFixedStepSize();
|
||||
@ -304,14 +296,14 @@ public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopu
|
||||
switch (experimentType) {
|
||||
case 0: {
|
||||
// use the Struture Skeletalizing with GA
|
||||
this.m_OutputFileName = "Prim4_StructSkelGATESTIT";
|
||||
this.outputFileName = "Prim4_StructSkelGATESTIT";
|
||||
GeneticAlgorithm ga = new GeneticAlgorithm();
|
||||
SelectTournament tour = new SelectTournament();
|
||||
tour.setTournamentSize(10);
|
||||
ga.setParentSelection(tour);
|
||||
ga.setPartnerSelection(tour);
|
||||
this.m_GO.setOptimizer(ga);
|
||||
this.m_GO.getOptimizer().getPopulation().setTargetSize(100);
|
||||
this.optimizationParameters.setOptimizer(ga);
|
||||
this.optimizationParameters.getOptimizer().getPopulation().setTargetSize(100);
|
||||
F1Problem problem = new F1Problem();
|
||||
tmpIndy = new GAIndividualDoubleData();
|
||||
((GAIndividualDoubleData) tmpIndy).setCrossoverOperator(new CrossoverGAGINPoint());
|
||||
@ -319,25 +311,25 @@ public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopu
|
||||
((GAIndividualDoubleData) tmpIndy).setMutationProbability(1.0);
|
||||
((F1Problem) problem).setEAIndividual(tmpIndy);
|
||||
//((FGRNInferringProblem)this.problem).setStructreSkelInterval(1);
|
||||
this.m_GO.getOptimizer().setProblem(problem);
|
||||
this.m_GO.getOptimizer().addPopulationChangedEventListener(this);
|
||||
this.optimizationParameters.getOptimizer().setProblem(problem);
|
||||
this.optimizationParameters.getOptimizer().addPopulationChangedEventListener(this);
|
||||
this.doWork();
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
// use the simple ES Local
|
||||
this.m_OutputFileName = "X360_StandardES";
|
||||
this.outputFileName = "X360_StandardES";
|
||||
EvolutionStrategies es = new EvolutionStrategies();
|
||||
this.m_GO.setOptimizer(es);
|
||||
this.m_GO.getOptimizer().getPopulation().setTargetSize(50);
|
||||
this.optimizationParameters.setOptimizer(es);
|
||||
this.optimizationParameters.getOptimizer().getPopulation().setTargetSize(50);
|
||||
F1Problem problem = new F1Problem();
|
||||
tmpIndy = new ESIndividualDoubleData();
|
||||
((AbstractEAIndividual) tmpIndy).setMutationOperator(new MutateESLocal());
|
||||
((F1Problem) problem).setEAIndividual(tmpIndy);
|
||||
//((FGRNInferringProblem)this.problem).setUseHEigenMatrix(true);
|
||||
//((FGRNInferringProblem)this.problem).setUseOnlyPositiveNumbers(true);
|
||||
this.m_GO.getOptimizer().setProblem(problem);
|
||||
this.m_GO.getOptimizer().addPopulationChangedEventListener(this);
|
||||
this.optimizationParameters.getOptimizer().setProblem(problem);
|
||||
this.optimizationParameters.getOptimizer().addPopulationChangedEventListener(this);
|
||||
this.doWork();
|
||||
break;
|
||||
}
|
||||
@ -360,109 +352,109 @@ public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopu
|
||||
*/
|
||||
public Object doWork() {
|
||||
try {
|
||||
this.m_GO.saveInstance();
|
||||
this.optimizationParameters.saveInstance();
|
||||
if (this.show) {
|
||||
this.m_StatusField.setText("Optimizing...");
|
||||
this.statusField.setText("Optimizing...");
|
||||
}
|
||||
|
||||
RNG.setRandomSeed(m_GO.getSeed());
|
||||
RNG.setRandomSeed(optimizationParameters.getSeed());
|
||||
// opening output file...
|
||||
if (!this.m_OutputFileName.equalsIgnoreCase("none")) {
|
||||
if (!this.outputFileName.equalsIgnoreCase("none")) {
|
||||
String name = "";
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("E'_'yyyy.MM.dd'_'HH.mm.ss");
|
||||
String m_StartDate = formatter.format(new Date());
|
||||
name = this.m_OutputPath + this.m_OutputFileName + "_" + this.m_ExperimentName + "_" + m_StartDate + ".dat";
|
||||
name = this.outputPath + this.outputFileName + "_" + this.experimentName + "_" + m_StartDate + ".dat";
|
||||
try {
|
||||
this.m_OutputFile = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(name)));
|
||||
this.outputFile = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(name)));
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out.println("Could not open output file! Filename: " + name);
|
||||
}
|
||||
} else {
|
||||
this.m_OutputFile = null;
|
||||
this.outputFile = null;
|
||||
}
|
||||
|
||||
// init problem
|
||||
this.m_GO.getProblem().initializeProblem();
|
||||
this.m_GO.getOptimizer().setProblem(this.m_GO.getProblem());
|
||||
this.optimizationParameters.getProblem().initializeProblem();
|
||||
this.optimizationParameters.getOptimizer().setProblem(this.optimizationParameters.getProblem());
|
||||
// int optimizer and population
|
||||
//this.m_GO.getOptimizer().init();
|
||||
//this.optimizationParameters.getOptimizer().init();
|
||||
|
||||
// init the log data
|
||||
ArrayList tmpMultiRun = new ArrayList();
|
||||
this.m_PerformedRuns.add(tmpMultiRun);
|
||||
this.performedRuns.add(tmpMultiRun);
|
||||
|
||||
// something to log file
|
||||
//if (m_OutputFile != null) this.writeToFile(this.m_GO.getOptimizer().getStringRepresentation());
|
||||
//if (outputFile != null) this.writeToFile(this.optimizationParameters.getOptimizer().getStringRepresentation());
|
||||
//this.writeToFile("Here i'll write something characterizing the algorithm.");
|
||||
|
||||
for (int j = 0; j < this.m_MultiRuns; j++) {
|
||||
this.m_GO.getProblem().initializeProblem(); // in the loop as well, dynamic probs may need that (MK)
|
||||
this.m_TmpData = new ArrayList();
|
||||
for (int j = 0; j < this.multiRuns; j++) {
|
||||
this.optimizationParameters.getProblem().initializeProblem(); // in the loop as well, dynamic probs may need that (MK)
|
||||
this.tmpData = new ArrayList<Double[]>();
|
||||
this.currentRun = j;
|
||||
if (this.show) {
|
||||
this.m_StatusField.setText("Optimizing Run " + (j + 1) + " of " + this.m_MultiRuns + " Multi Runs...");
|
||||
this.statusField.setText("Optimizing Run " + (j + 1) + " of " + this.multiRuns + " Multi Runs...");
|
||||
}
|
||||
if (Thread.interrupted()) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
// write header to file
|
||||
this.writeToFile(" FitnessCalls\t Best\t Mean\t Worst \t" + BeanInspector.toString(this.m_GO.getProblem().getAdditionalDataHeader(), '\t', false, ""));
|
||||
if ((this.m_ContinueFlag) && (this.m_Backup != null)) {
|
||||
this.m_RecentFC += this.m_Backup.getFunctionCalls();
|
||||
this.m_GO.getOptimizer().getProblem().initializeProblem();
|
||||
this.m_GO.getOptimizer().addPopulationChangedEventListener(null);
|
||||
this.m_GO.getOptimizer().setPopulation(this.m_Backup);
|
||||
this.m_GO.getOptimizer().getProblem().evaluate(this.m_GO.getOptimizer().getPopulation());
|
||||
this.m_GO.getOptimizer().getProblem().evaluate(this.m_GO.getOptimizer().getPopulation().getArchive());
|
||||
this.m_GO.getOptimizer().initByPopulation(this.m_Backup, false);
|
||||
this.m_GO.getOptimizer().getPopulation().SetFunctionCalls(0);
|
||||
this.m_GO.addPopulationChangedEventListener(this);
|
||||
this.writeToFile(" FitnessCalls\t Best\t Mean\t Worst \t" + BeanInspector.toString(this.optimizationParameters.getProblem().getAdditionalDataHeader(), '\t', false, ""));
|
||||
if ((this.continueFlag) && (this.backupPopulation != null)) {
|
||||
this.recentFunctionCalls += this.backupPopulation.getFunctionCalls();
|
||||
this.optimizationParameters.getOptimizer().getProblem().initializeProblem();
|
||||
this.optimizationParameters.getOptimizer().addPopulationChangedEventListener(null);
|
||||
this.optimizationParameters.getOptimizer().setPopulation(this.backupPopulation);
|
||||
this.optimizationParameters.getOptimizer().getProblem().evaluate(this.optimizationParameters.getOptimizer().getPopulation());
|
||||
this.optimizationParameters.getOptimizer().getProblem().evaluate(this.optimizationParameters.getOptimizer().getPopulation().getArchive());
|
||||
this.optimizationParameters.getOptimizer().initByPopulation(this.backupPopulation, false);
|
||||
this.optimizationParameters.getOptimizer().getPopulation().SetFunctionCalls(0);
|
||||
this.optimizationParameters.addPopulationChangedEventListener(this);
|
||||
} else {
|
||||
this.m_RecentFC = 0;
|
||||
this.m_GO.getOptimizer().init();
|
||||
this.recentFunctionCalls = 0;
|
||||
this.optimizationParameters.getOptimizer().init();
|
||||
}
|
||||
//while (this.m_GO.getOptimizer().getPopulation().getFunctionCalls() < this.functionCalls) {
|
||||
while (!this.m_GO.getTerminator().isTerminated(this.m_GO.getOptimizer().getPopulation())) {
|
||||
//while (this.optimizationParameters.getOptimizer().getPopulation().getFunctionCalls() < this.functionCalls) {
|
||||
while (!this.optimizationParameters.getTerminator().isTerminated(this.optimizationParameters.getOptimizer().getPopulation())) {
|
||||
//System.out.println("Simulated Function calls "+ this.optimizer.getPopulation().getFunctionCalls());
|
||||
if (Thread.interrupted()) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
m_GO.getOptimizer().optimize();
|
||||
optimizationParameters.getOptimizer().optimize();
|
||||
}
|
||||
System.gc();
|
||||
// @TODO if you want the final report include this
|
||||
//this.writeToFile(this.m_GO.getProblem().getStringRepresentationForProblem(this.m_GO.getOptimizer()));
|
||||
tmpMultiRun.add(this.m_TmpData);
|
||||
//this.writeToFile(this.optimizationParameters.getProblem().getStringRepresentationForProblem(this.optimizationParameters.getOptimizer()));
|
||||
tmpMultiRun.add(this.tmpData);
|
||||
}
|
||||
if (this.show) {
|
||||
this.m_Plot.setInfoString(this.currentExperiment, this.m_ExperimentName, 0.5f);
|
||||
this.m_Plot.setInfoString(this.currentExperiment, this.experimentName, 0.5f);
|
||||
}
|
||||
if (this.show) {
|
||||
this.draw();
|
||||
}
|
||||
this.m_ExperimentName = this.m_GO.getOptimizer().getName() + "-" + this.m_PerformedRuns.size();
|
||||
this.experimentName = this.optimizationParameters.getOptimizer().getName() + "-" + this.performedRuns.size();
|
||||
} catch (InterruptedException e) {
|
||||
updateStatus(0);
|
||||
if (this.show) {
|
||||
this.m_StatusField.setText("Interrupted...");
|
||||
this.statusField.setText("Interrupted...");
|
||||
}
|
||||
return "Interrupted";
|
||||
}
|
||||
if (this.m_OutputFile != null) {
|
||||
if (this.outputFile != null) {
|
||||
try {
|
||||
this.m_OutputFile.close();
|
||||
this.outputFile.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Failed to close output file!");
|
||||
}
|
||||
}
|
||||
if (this.show) {
|
||||
for (int i = 0; i < this.m_MultiRuns; i++) {
|
||||
for (int i = 0; i < this.multiRuns; i++) {
|
||||
this.m_Plot.clearGraph(1000 + i);
|
||||
}
|
||||
}
|
||||
updateStatus(0);
|
||||
if (this.show) {
|
||||
this.m_StatusField.setText("Finished...");
|
||||
this.statusField.setText("Finished...");
|
||||
}
|
||||
return "All Done";
|
||||
}
|
||||
@ -476,8 +468,8 @@ public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopu
|
||||
double[][] data;
|
||||
// Color tmpColor;
|
||||
|
||||
for (int i = this.m_PerformedRuns.size() - 1; i < this.m_PerformedRuns.size(); i++) {
|
||||
multiRuns = (ArrayList) this.m_PerformedRuns.get(i);
|
||||
for (int i = this.performedRuns.size() - 1; i < this.performedRuns.size(); i++) {
|
||||
multiRuns = (ArrayList) this.performedRuns.get(i);
|
||||
// determine minimum run length
|
||||
int minRunLen = Integer.MAX_VALUE;
|
||||
for (int j = 0; j < multiRuns.size(); j++) {
|
||||
@ -507,17 +499,17 @@ public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopu
|
||||
// Now enter this stuff into the graph
|
||||
this.m_Plot.clearGraph(this.currentExperiment);
|
||||
// tmpColor = Color.darkGray;
|
||||
// if (this.m_GO.getOptimizer().getName().equalsIgnoreCase("MCS")) tmpColor = Color.magenta;
|
||||
// if (this.m_GO.getOptimizer().getName().equalsIgnoreCase("MS-HC")) tmpColor = Color.green;
|
||||
// if (this.m_GO.getOptimizer().getName().equalsIgnoreCase("GA")) tmpColor = Color.blue;
|
||||
// if (this.m_GO.getOptimizer().getName().equalsIgnoreCase("PBIL")) tmpColor = Color.CYAN;
|
||||
// if (this.m_GO.getOptimizer().getName().equalsIgnoreCase("CHC")) tmpColor = Color.ORANGE;
|
||||
// if (this.m_GO.getOptimizer().getName().equalsIgnoreCase("ES")) tmpColor = Color.red;
|
||||
// if (this.m_GO.getOptimizer().getName().equalsIgnoreCase("CBN-EA")) tmpColor = Color.black;
|
||||
// if (this.optimizationParameters.getOptimizer().getName().equalsIgnoreCase("MCS")) tmpColor = Color.magenta;
|
||||
// if (this.optimizationParameters.getOptimizer().getName().equalsIgnoreCase("MS-HC")) tmpColor = Color.green;
|
||||
// if (this.optimizationParameters.getOptimizer().getName().equalsIgnoreCase("GA")) tmpColor = Color.blue;
|
||||
// if (this.optimizationParameters.getOptimizer().getName().equalsIgnoreCase("PBIL")) tmpColor = Color.CYAN;
|
||||
// if (this.optimizationParameters.getOptimizer().getName().equalsIgnoreCase("CHC")) tmpColor = Color.ORANGE;
|
||||
// if (this.optimizationParameters.getOptimizer().getName().equalsIgnoreCase("ES")) tmpColor = Color.red;
|
||||
// if (this.optimizationParameters.getOptimizer().getName().equalsIgnoreCase("CBN-EA")) tmpColor = Color.black;
|
||||
|
||||
for (int j = 0; j < data.length; j++) {
|
||||
if (this.m_ContinueFlag) {
|
||||
this.m_Plot.setConnectedPoint(data[j][0] + this.m_RecentFC, data[j][1], this.currentExperiment);
|
||||
if (this.continueFlag) {
|
||||
this.m_Plot.setConnectedPoint(data[j][0] + this.recentFunctionCalls, data[j][1], this.currentExperiment);
|
||||
} else {
|
||||
this.m_Plot.setConnectedPoint(data[j][0], data[j][1], this.currentExperiment);
|
||||
}
|
||||
@ -532,11 +524,11 @@ public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopu
|
||||
* this case we're just changing the progress bars value.
|
||||
*/
|
||||
void updateStatus(final int i) {
|
||||
if (this.m_ProgressBar != null) {
|
||||
if (this.progressBar != null) {
|
||||
Runnable doSetProgressBarValue = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
m_ProgressBar.setValue(i);
|
||||
progressBar.setValue(i);
|
||||
}
|
||||
};
|
||||
SwingUtilities.invokeLater(doSetProgressBarValue);
|
||||
@ -550,7 +542,7 @@ public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopu
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
GOStandaloneVersion program = new GOStandaloneVersion();
|
||||
StandaloneOptimization program = new StandaloneOptimization();
|
||||
RNG.setRandomSeed(1);
|
||||
program.initFrame();
|
||||
program.setShow(true);
|
||||
@ -571,9 +563,9 @@ public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopu
|
||||
public void registerPopulationStateChanged(Object source, String name) {
|
||||
if (name.equals(Population.NEXT_GENERATION_PERFORMED)) {
|
||||
Population population = ((InterfaceOptimizer) source).getPopulation();
|
||||
double x = 100 / this.m_MultiRuns;
|
||||
if (this.m_GO.getTerminator() instanceof EvaluationTerminator) {
|
||||
double y = x / (double) ((EvaluationTerminator) this.m_GO.getTerminator()).getFitnessCalls();
|
||||
double x = 100 / this.multiRuns;
|
||||
if (this.optimizationParameters.getTerminator() instanceof EvaluationTerminator) {
|
||||
double y = x / (double) ((EvaluationTerminator) this.optimizationParameters.getTerminator()).getFitnessCalls();
|
||||
currentProgress = (int) (this.currentRun * x + population.getFunctionCalls() * y);
|
||||
} else {
|
||||
currentProgress = (int) (this.currentRun * x);
|
||||
@ -595,21 +587,21 @@ public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopu
|
||||
tmpLine.append("\t");
|
||||
tmpLine.append(population.getWorstEAIndividual().getFitness(0));
|
||||
//tmpLine.append("\t");
|
||||
//tmpLine.append(this.m_GO.getProblem().getAdditionalDataValue(population));
|
||||
//tmpLine.append(this.optimizationParameters.getProblem().getAdditionalDataValue(population));
|
||||
this.writeToFile(tmpLine.toString());
|
||||
|
||||
Double[] tmpData = new Double[2];
|
||||
tmpData[0] = new Double(population.getFunctionCalls());
|
||||
// instead of adding simply the best fitness value i'll ask the problem what to show
|
||||
tmpData[1] = this.m_GO.getProblem().getDoublePlotValue(population);
|
||||
tmpData[1] = this.optimizationParameters.getProblem().getDoublePlotValue(population);
|
||||
if (this.m_Plot != null) {
|
||||
if (this.m_ContinueFlag) {
|
||||
this.m_Plot.setConnectedPoint(tmpData[0].doubleValue() + this.m_RecentFC, tmpData[1].doubleValue(), 1000 + this.currentRun);
|
||||
if (this.continueFlag) {
|
||||
this.m_Plot.setConnectedPoint(tmpData[0].doubleValue() + this.recentFunctionCalls, tmpData[1].doubleValue(), 1000 + this.currentRun);
|
||||
} else {
|
||||
this.m_Plot.setConnectedPoint(tmpData[0].doubleValue(), tmpData[1].doubleValue(), 1000 + this.currentRun);
|
||||
}
|
||||
}
|
||||
this.m_TmpData.add(tmpData);
|
||||
this.tmpData.add(tmpData);
|
||||
}
|
||||
}
|
||||
|
||||
@ -620,12 +612,12 @@ public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopu
|
||||
*/
|
||||
private void writeToFile(String line) {
|
||||
String write = line + "\n";
|
||||
if (this.m_OutputFile == null) {
|
||||
if (this.outputFile == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.m_OutputFile.write(write, 0, write.length());
|
||||
this.m_OutputFile.flush();
|
||||
this.outputFile.write(write, 0, write.length());
|
||||
this.outputFile.flush();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Problems writing to output file!");
|
||||
}
|
||||
@ -654,11 +646,11 @@ public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopu
|
||||
* @param multiruns The number of multiruns that are to be performed
|
||||
*/
|
||||
public void setMultiRuns(int multiruns) {
|
||||
this.m_MultiRuns = multiruns;
|
||||
this.multiRuns = multiruns;
|
||||
}
|
||||
|
||||
public int getMultiRuns() {
|
||||
return this.m_MultiRuns;
|
||||
return this.multiRuns;
|
||||
}
|
||||
|
||||
public String multiRunsTipText() {
|
||||
@ -670,7 +662,7 @@ public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopu
|
||||
*
|
||||
* @param seed The seed for the random number generator
|
||||
*/
|
||||
// MK: These methods have nothing to do with the seed parameter from the m_GO object which is actually used, so I comment them out
|
||||
// MK: These methods have nothing to do with the seed parameter from the optimizationParameters object which is actually used, so I comment them out
|
||||
// public void setSeed(long seed) {
|
||||
// RNG.setseed(seed);
|
||||
// }
|
||||
@ -688,11 +680,11 @@ public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopu
|
||||
* @param experimentName The experiment name
|
||||
*/
|
||||
public void setExpName(String experimentName) {
|
||||
this.m_ExperimentName = experimentName;
|
||||
this.experimentName = experimentName;
|
||||
}
|
||||
|
||||
public String getExpName() {
|
||||
return this.m_ExperimentName;
|
||||
return this.experimentName;
|
||||
}
|
||||
|
||||
public String expNameTipText() {
|
||||
@ -705,11 +697,11 @@ public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopu
|
||||
* @param name
|
||||
*/
|
||||
public void setOutputFileName(String name) {
|
||||
this.m_OutputFileName = name;
|
||||
this.outputFileName = name;
|
||||
}
|
||||
|
||||
public String getOutputFileName() {
|
||||
return this.m_OutputFileName;
|
||||
return this.outputFileName;
|
||||
}
|
||||
|
||||
public String outputFileNameTipText() {
|
||||
@ -753,7 +745,7 @@ public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopu
|
||||
// public void setOptimizer(InterfaceOptimizer optimizer) {
|
||||
// this.optimizer = optimizer;
|
||||
// this.optimizer.addPopulationChangedEventListener(this);
|
||||
// this.m_ExperimentName = this.optimizer.getName()+"-"+this.m_PerformedRuns.size();
|
||||
// this.experimentName = this.optimizer.getName()+"-"+this.performedRuns.size();
|
||||
// this.optimizer.SetProblem(this.problem);
|
||||
// }
|
||||
// public InterfaceOptimizer getOptimizer() {
|
@ -5,12 +5,8 @@ import eva2.optimization.population.Population;
|
||||
|
||||
/**
|
||||
* The non dominated sorting GA archiving method, based on dominace sorting.
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 27.02.2004
|
||||
* Time: 16:50:45
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
@eva2.util.annotation.Description(text="Non-dominating sorting GA revision 1.0.")
|
||||
public class ArchivingNSGA extends AbstractArchiving implements java.io.Serializable {
|
||||
|
||||
public InterfaceRemoveSurplusIndividuals m_Cleaner = new RemoveSurplusIndividualsDynamicHyperCube();
|
||||
@ -55,19 +51,6 @@ public class ArchivingNSGA extends AbstractArchiving implements java.io.Serializ
|
||||
this.m_Cleaner.removeSurplusIndividuals(archive);
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************************************************************
|
||||
* These are for GUI
|
||||
*/
|
||||
/**
|
||||
* This method returns a global info string
|
||||
*
|
||||
* @return description
|
||||
*/
|
||||
public static String globalInfo() {
|
||||
return "Non-dominating sorting GA revision 1.0.";
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will return a naming String
|
||||
*
|
||||
|
@ -3,12 +3,7 @@ package eva2.optimization.operator.archiving;
|
||||
import eva2.optimization.population.Population;
|
||||
|
||||
/**
|
||||
* This Interface give the general methods required for a archiving method.
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 05.06.2003
|
||||
* Time: 11:27:36
|
||||
* To change this template use Options | File Templates.
|
||||
* This Interface give the general methods required for an archiving method.
|
||||
*/
|
||||
public interface InterfaceArchiving {
|
||||
|
||||
@ -20,7 +15,7 @@ public interface InterfaceArchiving {
|
||||
public Object clone();
|
||||
|
||||
/**
|
||||
* This method allows you to merge to populations into an archive.
|
||||
* This method allows you to merge populations into an archive.
|
||||
* This method will add elements from pop to the archive but will also
|
||||
* remove elements from the archive if the archive target size is exceeded.
|
||||
*
|
||||
|
@ -28,16 +28,7 @@ import java.util.logging.Logger;
|
||||
* The Population also provides for appropriate counting of function calls performed.
|
||||
* For initialization, the default individual initialization method may be used, as well as a
|
||||
* random latin hypercube implementation for InterfaceDataTypeDouble individuals.
|
||||
* <p/>
|
||||
* Copyright: Copyright (c) 2003
|
||||
* Company: University of Tuebingen, Computer Architecture
|
||||
*
|
||||
* @author Felix Streichert, Marcel Kronfeld
|
||||
* @version: $Revision: 307 $
|
||||
* $Date: 2007-12-04 14:31:47 +0100 (Tue, 04 Dec 2007) $
|
||||
* $Author: mkron $
|
||||
*/
|
||||
|
||||
public class Population extends ArrayList implements PopulationInterface, Cloneable, java.io.Serializable {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(Population.class.getName());
|
||||
|
@ -147,7 +147,7 @@ public class F8Problem extends AbstractProblemDoubleOffset
|
||||
// double dim = (double)this.problemDimension;
|
||||
//
|
||||
// for (int i = 0; i < x.length; i++) {
|
||||
// double xi = x[i]-m_XOffSet;
|
||||
// double xi = x[i]-xOffset;
|
||||
// sum1 += (xi)*(xi);
|
||||
// sum2 += Math.cos(c * (xi));
|
||||
// }
|
||||
|
@ -1,7 +1,7 @@
|
||||
package eva2.optimization.problems;
|
||||
|
||||
|
||||
import eva2.optimization.go.GOStandaloneVersion;
|
||||
import eva2.optimization.go.StandaloneOptimization;
|
||||
import eva2.optimization.individuals.AbstractEAIndividual;
|
||||
import eva2.optimization.individuals.ESIndividualDoubleData;
|
||||
import eva2.optimization.individuals.InterfaceDataTypeDouble;
|
||||
@ -97,14 +97,14 @@ class MyLensViewer extends JPanel implements InterfaceSolutionViewer {
|
||||
g2D.setPaint(Color.black);
|
||||
g2D.drawLine(0, this.m_Height / 2, this.m_Width, this.m_Height / 2);
|
||||
centerLens = 5 + 50;
|
||||
centerScreen = centerLens + (int) this.m_LensProblem.m_FocalLength * 10;
|
||||
segment = 10 * (int) this.m_LensProblem.m_Radius * 2 / (this.m_LensProblem.m_ProblemDimension - 1);
|
||||
centerScreen = centerLens + (int) this.m_LensProblem.focalLength * 10;
|
||||
segment = 10 * (int) this.m_LensProblem.radius * 2 / (this.m_LensProblem.problemDimension - 1);
|
||||
g2D.setStroke(dashStroke);
|
||||
g2D.drawLine(centerLens, this.m_Height / 2 + (int) this.m_LensProblem.m_Radius * 10, centerLens, this.m_Height / 2 - (int) this.m_LensProblem.m_Radius * 10);
|
||||
g2D.drawLine(centerScreen, this.m_Height / 2 + (int) this.m_LensProblem.m_Radius * 10 + 10, centerScreen, this.m_Height / 2 - (int) this.m_LensProblem.m_Radius * 10 - 10);
|
||||
g2D.drawLine(centerLens, this.m_Height / 2 + (int) this.m_LensProblem.radius * 10, centerLens, this.m_Height / 2 - (int) this.m_LensProblem.radius * 10);
|
||||
g2D.drawLine(centerScreen, this.m_Height / 2 + (int) this.m_LensProblem.radius * 10 + 10, centerScreen, this.m_Height / 2 - (int) this.m_LensProblem.radius * 10 - 10);
|
||||
g2D.setStroke(ds);
|
||||
// System.out.println("indies to paint: " + indiesToPaint.size());
|
||||
paintLens(m_LensProblem.m_ProblemDimension, m_Height, m_LensProblem.m_Radius, mag, centerLens, centerScreen, segment, g2D);
|
||||
paintLens(m_LensProblem.problemDimension, m_Height, m_LensProblem.radius, mag, centerLens, centerScreen, segment, g2D);
|
||||
// Now put everything on the screen
|
||||
g.drawImage(bufferedImage, 0, 0, this);
|
||||
}
|
||||
@ -193,12 +193,9 @@ class MyLensViewer extends JPanel implements InterfaceSolutionViewer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 13.07.2004
|
||||
* Time: 09:49:37
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*
|
||||
*/
|
||||
@eva2.util.annotation.Description(text="Focussing of a lens is to be optimized.")
|
||||
public class FLensProblem extends AbstractOptimizationProblem
|
||||
implements InterfaceOptimizationProblem, InterfaceHasSolutionViewer, java.io.Serializable {
|
||||
|
||||
@ -206,20 +203,20 @@ public class FLensProblem extends AbstractOptimizationProblem
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 4694920294291719310L;
|
||||
protected AbstractEAIndividual m_OverallBest = null;
|
||||
protected int m_ProblemDimension = 10;
|
||||
protected double m_Noise = 0.0;
|
||||
protected double m_XOffSet = 0.0;
|
||||
protected double m_YOffSet = 0.0;
|
||||
protected AbstractEAIndividual overallBest = null;
|
||||
protected int problemDimension = 10;
|
||||
protected double noise = 0.0;
|
||||
protected double xOffset = 0.0;
|
||||
protected double yOffset = 0.0;
|
||||
transient protected boolean m_Show = false;
|
||||
//protected int sleepTime = 0;
|
||||
|
||||
transient private JFrame m_ProblemFrame;
|
||||
transient private MyLensViewer m_Panel;
|
||||
public double m_Radius = 5;
|
||||
public double m_FocalLength = 20;
|
||||
public double m_Epsilon = 1.5;
|
||||
private boolean m_UseMaterialConst = false;
|
||||
transient private JFrame problemFrame;
|
||||
transient private MyLensViewer lensViewerPanel;
|
||||
public double radius = 5;
|
||||
public double focalLength = 20;
|
||||
public double epsilon = 1.5;
|
||||
private boolean useMaterialConst = false;
|
||||
|
||||
public FLensProblem() {
|
||||
this.template = new ESIndividualDoubleData();
|
||||
@ -234,17 +231,17 @@ public class FLensProblem extends AbstractOptimizationProblem
|
||||
this.template = (AbstractEAIndividual) ((AbstractEAIndividual) b.template).clone();
|
||||
}
|
||||
//FLensProblem
|
||||
if (b.m_OverallBest != null) {
|
||||
this.m_OverallBest = (AbstractEAIndividual) ((AbstractEAIndividual) b.m_OverallBest).clone();
|
||||
if (b.overallBest != null) {
|
||||
this.overallBest = (AbstractEAIndividual) ((AbstractEAIndividual) b.overallBest).clone();
|
||||
}
|
||||
this.m_ProblemDimension = b.m_ProblemDimension;
|
||||
this.m_Noise = b.m_Noise;
|
||||
this.m_XOffSet = b.m_XOffSet;
|
||||
this.m_YOffSet = b.m_YOffSet;
|
||||
this.m_Radius = b.m_Radius;
|
||||
this.m_FocalLength = b.m_FocalLength;
|
||||
this.m_Epsilon = b.m_Epsilon;
|
||||
this.m_UseMaterialConst = b.m_UseMaterialConst;
|
||||
this.problemDimension = b.problemDimension;
|
||||
this.noise = b.noise;
|
||||
this.xOffset = b.xOffset;
|
||||
this.yOffset = b.yOffset;
|
||||
this.radius = b.radius;
|
||||
this.focalLength = b.focalLength;
|
||||
this.epsilon = b.epsilon;
|
||||
this.useMaterialConst = b.useMaterialConst;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -256,15 +253,15 @@ public class FLensProblem extends AbstractOptimizationProblem
|
||||
* This method inits a problem view frame
|
||||
*/
|
||||
public void initProblemFrame() {
|
||||
if (this.m_ProblemFrame == null) {
|
||||
this.m_ProblemFrame = new JFrame("Lens Problem Viewer");
|
||||
this.m_Panel = new MyLensViewer(this);
|
||||
this.m_ProblemFrame.getContentPane().add(this.m_Panel);
|
||||
this.m_ProblemFrame.pack();
|
||||
this.m_ProblemFrame.setVisible(true);
|
||||
//this.m_ProblemFrame.show();
|
||||
if (this.problemFrame == null) {
|
||||
this.problemFrame = new JFrame("Lens Problem Viewer");
|
||||
this.lensViewerPanel = new MyLensViewer(this);
|
||||
this.problemFrame.getContentPane().add(this.lensViewerPanel);
|
||||
this.problemFrame.pack();
|
||||
this.problemFrame.setVisible(true);
|
||||
//this.problemFrame.show();
|
||||
} else {
|
||||
this.m_Panel.resetView();
|
||||
this.lensViewerPanel.resetView();
|
||||
}
|
||||
}
|
||||
|
||||
@ -272,11 +269,11 @@ public class FLensProblem extends AbstractOptimizationProblem
|
||||
* This method gets rid of the problem view frame
|
||||
*/
|
||||
public void disposeProblemFrame() {
|
||||
if (this.m_ProblemFrame != null) {
|
||||
this.m_ProblemFrame.dispose();
|
||||
if (this.problemFrame != null) {
|
||||
this.problemFrame.dispose();
|
||||
}
|
||||
this.m_ProblemFrame = null;
|
||||
this.m_Panel = null;
|
||||
this.problemFrame = null;
|
||||
this.lensViewerPanel = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -286,8 +283,8 @@ public class FLensProblem extends AbstractOptimizationProblem
|
||||
* @param population The current population.
|
||||
*/
|
||||
public void updateProblemFrame(Population population) {
|
||||
if (this.m_Panel != null) {
|
||||
this.m_Panel.updateView(population, false);
|
||||
if (this.lensViewerPanel != null) {
|
||||
this.lensViewerPanel.updateView(population, false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -296,7 +293,7 @@ public class FLensProblem extends AbstractOptimizationProblem
|
||||
*/
|
||||
@Override
|
||||
public void initializeProblem() {
|
||||
this.m_OverallBest = null;
|
||||
this.overallBest = null;
|
||||
if (this.m_Show) {
|
||||
this.initProblemFrame();
|
||||
}
|
||||
@ -309,10 +306,10 @@ public class FLensProblem extends AbstractOptimizationProblem
|
||||
*/
|
||||
@Override
|
||||
public void initializePopulation(Population population) {
|
||||
this.m_OverallBest = null;
|
||||
((InterfaceDataTypeDouble) this.template).setDoubleDataLength(this.m_ProblemDimension);
|
||||
this.overallBest = null;
|
||||
((InterfaceDataTypeDouble) this.template).setDoubleDataLength(this.problemDimension);
|
||||
// set the range
|
||||
double[][] range = new double[this.m_ProblemDimension][2];
|
||||
double[][] range = new double[this.problemDimension][2];
|
||||
for (int i = 0; i < range.length; i++) {
|
||||
range[i][0] = 0.1;
|
||||
range[i][1] = 5.0;
|
||||
@ -345,18 +342,18 @@ public class FLensProblem extends AbstractOptimizationProblem
|
||||
x = new double[((InterfaceDataTypeDouble) individual).getDoubleData().length];
|
||||
System.arraycopy(((InterfaceDataTypeDouble) individual).getDoubleData(), 0, x, 0, x.length);
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
x[i] -= this.m_XOffSet;
|
||||
x[i] -= this.xOffset;
|
||||
}
|
||||
fitness = this.doEvaluation(x);
|
||||
for (int i = 0; i < fitness.length; i++) {
|
||||
// add noise to the fitness
|
||||
fitness[i] += RNG.gaussianDouble(this.m_Noise);
|
||||
fitness[i] += this.m_YOffSet;
|
||||
fitness[i] += RNG.gaussianDouble(this.noise);
|
||||
fitness[i] += this.yOffset;
|
||||
// set the fitness of the individual
|
||||
individual.SetFitness(i, fitness[i]);
|
||||
}
|
||||
if ((this.m_OverallBest == null) || (this.m_OverallBest.getFitness(0) > individual.getFitness(0))) {
|
||||
this.m_OverallBest = (AbstractEAIndividual) individual.clone();
|
||||
if ((this.overallBest == null) || (this.overallBest.getFitness(0) > individual.getFitness(0))) {
|
||||
this.overallBest = (AbstractEAIndividual) individual.clone();
|
||||
}
|
||||
}
|
||||
|
||||
@ -386,11 +383,11 @@ public class FLensProblem extends AbstractOptimizationProblem
|
||||
// // The fitness is the sum over all segments of the deviation from the center
|
||||
// // of focus of a beam running through a segment.
|
||||
// for (int i = 1; i < x.length; i++)
|
||||
// fitness = fitness + Math.pow(m_Radius - m_SegmentHight / 2 - m_SegmentHight * (i - 1) - m_FocalLength / m_SegmentHight * (epsilon - 1) * (x[i] - x[i-1]),2);
|
||||
// fitness = fitness + Math.pow(radius - m_SegmentHight / 2 - m_SegmentHight * (i - 1) - focalLength / m_SegmentHight * (epsilon - 1) * (x[i] - x[i-1]),2);
|
||||
|
||||
// Here the thickness of the middle segment of the lens is added to the fitness
|
||||
// to permit the optimization to reduce the overall thickness of the lens
|
||||
if (this.m_UseMaterialConst) {
|
||||
if (this.useMaterialConst) {
|
||||
fitness += x[(int) (x.length / 2)];
|
||||
}
|
||||
|
||||
@ -405,13 +402,13 @@ public class FLensProblem extends AbstractOptimizationProblem
|
||||
* @return double[]
|
||||
*/
|
||||
public double[] testLens(double[] x) {
|
||||
double m_SegmentHight = 2 * m_Radius / (x.length - 1);
|
||||
double m_SegmentHight = 2 * radius / (x.length - 1);
|
||||
double[] result = new double[x.length - 1];
|
||||
// Computation of fitness. Uses an approximation for very thin lenses.
|
||||
// The fitness is the sum over all segments of the deviation from the center
|
||||
// of focus of a beam running through a segment.
|
||||
for (int i = 1; i < x.length; i++) {
|
||||
result[i - 1] = m_Radius - m_SegmentHight / 2 - m_SegmentHight * (i - 1) - m_FocalLength / m_SegmentHight * (m_Epsilon - 1) * (x[i] - x[i - 1]);
|
||||
result[i - 1] = radius - m_SegmentHight / 2 - m_SegmentHight * (i - 1) - focalLength / m_SegmentHight * (epsilon - 1) * (x[i] - x[i - 1]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -441,7 +438,7 @@ public class FLensProblem extends AbstractOptimizationProblem
|
||||
*/
|
||||
public String getFinalReportOn(InterfaceOptimizer optimizer) {
|
||||
String result = optimizer.getStringRepresentation() + "\n";
|
||||
result += this.getSolutionRepresentationFor(this.m_OverallBest);
|
||||
result += this.getSolutionRepresentationFor(this.overallBest);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -458,8 +455,8 @@ public class FLensProblem extends AbstractOptimizationProblem
|
||||
result += "FX Problem:\n";
|
||||
result += "Here the individual codes a vector of real number x and FX(x)= x is to be minimized.\n";
|
||||
result += "Parameters:\n";
|
||||
result += "Dimension : " + this.m_ProblemDimension + "\n";
|
||||
result += "Noise level : " + this.m_Noise + "\n";
|
||||
result += "Dimension : " + this.problemDimension + "\n";
|
||||
result += "Noise level : " + this.noise + "\n";
|
||||
result += "Solution representation:\n";
|
||||
//result += this.template.getSolutionRepresentationFor();
|
||||
return result;
|
||||
@ -485,7 +482,7 @@ public class FLensProblem extends AbstractOptimizationProblem
|
||||
System.out.println("TEST");
|
||||
FLensProblem f = new FLensProblem();
|
||||
System.out.println("Working Dir " + System.getProperty("user.dir"));
|
||||
GOStandaloneVersion program = new GOStandaloneVersion();
|
||||
StandaloneOptimization program = new StandaloneOptimization();
|
||||
OptimizationParameters GO = program.getGOParameters();
|
||||
GO.setProblem(f);
|
||||
RNG.setRandomSeed(1);
|
||||
@ -493,9 +490,6 @@ public class FLensProblem extends AbstractOptimizationProblem
|
||||
program.setShow(true);
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************
|
||||
* These are for GUI
|
||||
*/
|
||||
/**
|
||||
* This method allows the CommonJavaObjectEditorPanel to read the
|
||||
* name to the current object.
|
||||
@ -507,15 +501,6 @@ public class FLensProblem extends AbstractOptimizationProblem
|
||||
return "Lens Problem";
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a global info string
|
||||
*
|
||||
* @return description
|
||||
*/
|
||||
public static String globalInfo() {
|
||||
return "Focussing of a lens is to be optimized.";
|
||||
}
|
||||
|
||||
/**
|
||||
* This method allows you to choose how much noise is to be added to the
|
||||
* fitness. This can be used to make the optimization problem more difficult.
|
||||
@ -526,11 +511,11 @@ public class FLensProblem extends AbstractOptimizationProblem
|
||||
if (noise < 0) {
|
||||
noise = 0;
|
||||
}
|
||||
this.m_Noise = noise;
|
||||
this.noise = noise;
|
||||
}
|
||||
|
||||
public double getNoise() {
|
||||
return this.m_Noise;
|
||||
return this.noise;
|
||||
}
|
||||
|
||||
public String noiseTipText() {
|
||||
@ -543,11 +528,11 @@ public class FLensProblem extends AbstractOptimizationProblem
|
||||
* @param XOffSet The offset for the decision variables.
|
||||
*/
|
||||
public void setXOffSet(double XOffSet) {
|
||||
this.m_XOffSet = XOffSet;
|
||||
this.xOffset = XOffSet;
|
||||
}
|
||||
|
||||
public double getXOffSet() {
|
||||
return this.m_XOffSet;
|
||||
return this.xOffset;
|
||||
}
|
||||
|
||||
public String xOffSetTipText() {
|
||||
@ -561,11 +546,11 @@ public class FLensProblem extends AbstractOptimizationProblem
|
||||
* @param YOffSet The offset for the objective value.
|
||||
*/
|
||||
public void setYOffSet(double YOffSet) {
|
||||
this.m_YOffSet = YOffSet;
|
||||
this.yOffset = YOffSet;
|
||||
}
|
||||
|
||||
public double getYOffSet() {
|
||||
return this.m_YOffSet;
|
||||
return this.yOffset;
|
||||
}
|
||||
|
||||
public String yOffSetTipText() {
|
||||
@ -579,11 +564,11 @@ public class FLensProblem extends AbstractOptimizationProblem
|
||||
* @param multiruns The number of multiruns that are to be performed
|
||||
*/
|
||||
public void setProblemDimension(int multiruns) {
|
||||
this.m_ProblemDimension = multiruns;
|
||||
this.problemDimension = multiruns;
|
||||
}
|
||||
|
||||
public int getProblemDimension() {
|
||||
return this.m_ProblemDimension;
|
||||
return this.problemDimension;
|
||||
}
|
||||
|
||||
public String problemDimensionTipText() {
|
||||
@ -591,7 +576,7 @@ public class FLensProblem extends AbstractOptimizationProblem
|
||||
}
|
||||
|
||||
/**
|
||||
* This method allows you to toggel the solution representation.
|
||||
* This method allows you to toggle the solution representation.
|
||||
*
|
||||
* @param show Whether to show the result or not
|
||||
*/
|
||||
@ -618,11 +603,11 @@ public class FLensProblem extends AbstractOptimizationProblem
|
||||
* @param show Whether to show the result or not
|
||||
*/
|
||||
public void setUseMaterialConst(boolean show) {
|
||||
this.m_UseMaterialConst = show;
|
||||
this.useMaterialConst = show;
|
||||
}
|
||||
|
||||
public boolean getUseMaterialConst() {
|
||||
return this.m_UseMaterialConst;
|
||||
return this.useMaterialConst;
|
||||
}
|
||||
|
||||
public String useMaterialConstTipText() {
|
||||
@ -660,6 +645,6 @@ public class FLensProblem extends AbstractOptimizationProblem
|
||||
*/
|
||||
@Override
|
||||
public InterfaceSolutionViewer getSolutionViewer() {
|
||||
return m_Panel;
|
||||
return lensViewerPanel;
|
||||
}
|
||||
}
|
@ -7,11 +7,7 @@ import eva2.optimization.strategies.InterfaceOptimizer;
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 18.03.2003
|
||||
* Time: 09:52:52
|
||||
* To change this template use Options | File Templates.
|
||||
*
|
||||
*/
|
||||
public interface InterfaceOptimizationProblem extends InterfaceAdditionalPopulationInformer {
|
||||
|
||||
@ -71,7 +67,7 @@ public interface InterfaceOptimizationProblem extends InterfaceAdditionalPopulat
|
||||
|
||||
/**
|
||||
* This method allows you to output a string that describes a found solution
|
||||
* in a way that is most suiteable for a given problem.
|
||||
* in a way that is most suitable for a given problem.
|
||||
*
|
||||
* @param individual The individual that is to be shown.
|
||||
* @return The description.
|
||||
|
@ -43,8 +43,8 @@ public interface InterfaceProblemDouble {
|
||||
*
|
||||
* @param dim
|
||||
* @return the upper bound of the double range in the given dimension
|
||||
* @see makeRange()
|
||||
* @see getRangeLowerBound(int dim)
|
||||
* @see #makeRange()
|
||||
* @see #getRangeLowerBound(int dim)
|
||||
*/
|
||||
public double getRangeUpperBound(int dim);
|
||||
|
||||
@ -54,8 +54,8 @@ public interface InterfaceProblemDouble {
|
||||
*
|
||||
* @param dim
|
||||
* @return the lower bound of the double range in the given dimension
|
||||
* @see makeRange()
|
||||
* @see getRangeUpperBound(int dim)
|
||||
* @see #makeRange()
|
||||
* @see #getRangeUpperBound(int dim)
|
||||
*/
|
||||
public double getRangeLowerBound(int dim);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user