From 5ac95428936e76076b604c8ae5baa6b5c00740f3 Mon Sep 17 00:00:00 2001 From: Fabian Becker Date: Wed, 5 Feb 2014 19:35:33 +0100 Subject: [PATCH] Removed all m_ variable names (some remaining in comments -> I don't care!) Now gonna get drunk and celebrate: 7.5k lines refactored! FYEAH --- .../go/StandaloneOptimization.java | 186 ++++++------------ .../codings/ga/GAStandardCodingDouble.java | 51 ++--- .../codings/ga/GAStandardCodingInteger.java | 71 ++++--- .../modules/AbstractModuleAdapter.java | 11 +- .../optimization/modules/SAParameters.java | 32 ++- .../problems/ExternalRuntimeProblem.java | 3 - .../optimization/problems/FLensProblem.java | 23 --- .../optimization/stat/GenericStatistics.java | 20 +- src/eva2/optimization/stat/MovingAverage.java | 50 ++--- .../stat/StatisticsParameter.java | 17 +- .../stat/StatisticsStandalone.java | 29 ++- .../CHCAdaptiveSearchAlgorithm.java | 15 -- .../strategies/ClusterBasedNichingEA.java | 71 +------ .../optimization/strategies/EsDpiNiching.java | 12 +- .../strategies/IslandModelEA.java | 29 +-- 15 files changed, 180 insertions(+), 440 deletions(-) diff --git a/src/eva2/optimization/go/StandaloneOptimization.java b/src/eva2/optimization/go/StandaloneOptimization.java index 6d2e27cc..e792bb7e 100644 --- a/src/eva2/optimization/go/StandaloneOptimization.java +++ b/src/eva2/optimization/go/StandaloneOptimization.java @@ -40,8 +40,8 @@ public class StandaloneOptimization implements InterfaceStandaloneOptimization, 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 optionsPanel, m_O1, m_O2; + transient private JButton runButton, stopButton, continueButton, showSolutionButton; + transient private JComponent optionsPanel, parameterPanel1, parameterPanel2; transient private JComponent statusPanel; transient private JLabel statusField; transient private JProgressBar progressBar; @@ -65,12 +65,12 @@ public class StandaloneOptimization implements InterfaceStandaloneOptimization, transient private Population backupPopulation; transient private boolean continueFlag; // Plot Panel stuff - transient private Plot m_Plot; + transient private Plot plot; transient private ArrayList performedRuns = new ArrayList(); transient private ArrayList tmpData; transient private BufferedWriter outputFile; // Test - transient private List m_List; + transient private List list; /** * Create a new EALectureGUI. @@ -111,26 +111,26 @@ public class StandaloneOptimization implements InterfaceStandaloneOptimization, this.mainPanel.setLayout(new BorderLayout()); // build the button panel this.buttonPanel = new JPanel(); - this.m_RunButton = new JButton("Run"); - this.m_RunButton.addActionListener(this.runListener); - this.m_RunButton.setEnabled(true); - this.m_RunButton.setToolTipText("Run the optimization process with the current parameter settings."); - this.m_StopButton = new JButton("Stop"); - this.m_StopButton.addActionListener(this.stopListener); - this.m_StopButton.setEnabled(false); - this.m_StopButton.setToolTipText("Stop the runnig the optimization process."); - this.m_Continue = new JButton("Continue"); - this.m_Continue.addActionListener(this.continueListener); - this.m_Continue.setEnabled(false); - this.m_Continue.setToolTipText("Resume the previous optimization (check termination criteria and multiruns = 1!)."); - this.m_ShowSolution = new JButton("Show Solution"); - this.m_ShowSolution.addActionListener(this.showSolListener); - this.m_ShowSolution.setEnabled(true); - this.m_ShowSolution.setToolTipText("Show the current best solution."); - 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.runButton = new JButton("Run"); + this.runButton.addActionListener(this.runListener); + this.runButton.setEnabled(true); + this.runButton.setToolTipText("Run the optimization process with the current parameter settings."); + this.stopButton = new JButton("Stop"); + this.stopButton.addActionListener(this.stopListener); + this.stopButton.setEnabled(false); + this.stopButton.setToolTipText("Stop the runnig the optimization process."); + this.continueButton = new JButton("Continue"); + this.continueButton.addActionListener(this.continueListener); + this.continueButton.setEnabled(false); + this.continueButton.setToolTipText("Resume the previous optimization (check termination criteria and multiruns = 1!)."); + this.showSolutionButton = new JButton("Show Solution"); + this.showSolutionButton.addActionListener(this.showSolListener); + this.showSolutionButton.setEnabled(true); + this.showSolutionButton.setToolTipText("Show the current best solution."); + this.buttonPanel.add(this.runButton); + this.buttonPanel.add(this.continueButton); + this.buttonPanel.add(this.stopButton); + this.buttonPanel.add(this.showSolutionButton); this.mainPanel.add(this.buttonPanel, BorderLayout.NORTH); // build the Options Panel @@ -151,12 +151,12 @@ public class StandaloneOptimization implements InterfaceStandaloneOptimization, if ((object != null) && (editor != null)) { paraPanel.registerEditor(object, editor); } - this.m_O1 = (paraPanel.makePanel()); + this.parameterPanel1 = (paraPanel.makePanel()); this.optionsPanel = new JTabbedPane(); JParaPanel paraPanel2 = new JParaPanel(this.optimizationParameters, "MyGUI"); - this.m_O2 = (paraPanel2.makePanel()); - ((JTabbedPane) this.optionsPanel).addTab("Optimization Parameters", this.m_O2); - ((JTabbedPane) this.optionsPanel).addTab("Statistics", this.m_O1); + this.parameterPanel2 = (paraPanel2.makePanel()); + ((JTabbedPane) this.optionsPanel).addTab("Optimization Parameters", this.parameterPanel2); + ((JTabbedPane) this.optionsPanel).addTab("Statistics", this.parameterPanel1); this.mainPanel.add(this.optionsPanel, BorderLayout.CENTER); // build the Status Panel @@ -171,7 +171,7 @@ public class StandaloneOptimization implements InterfaceStandaloneOptimization, double[] tmpD = new double[2]; tmpD[0] = 1; tmpD[1] = 1; - this.m_Plot = new Plot("EA Lecture Plot", "Function calls", "Fitness", true); + this.plot = new Plot("EA Lecture Plot", "Function calls", "Fitness", true); // validate and show this.mainFrame.validate(); this.mainFrame.setVisible(true); @@ -192,16 +192,16 @@ public class StandaloneOptimization implements InterfaceStandaloneOptimization, @Override public void finished() { - m_RunButton.setEnabled(true); - m_Continue.setEnabled(true); - m_StopButton.setEnabled(false); + runButton.setEnabled(true); + continueButton.setEnabled(true); + stopButton.setEnabled(false); backupPopulation = (Population) optimizationParameters.getOptimizer().getPopulation().clone(); } }; worker.start(); - m_RunButton.setEnabled(false); - m_Continue.setEnabled(false); - m_StopButton.setEnabled(true); + runButton.setEnabled(false); + continueButton.setEnabled(false); + stopButton.setEnabled(true); } }; /** @@ -212,12 +212,12 @@ public class StandaloneOptimization implements InterfaceStandaloneOptimization, ActionListener stopListener = new ActionListener() { @Override public void actionPerformed(ActionEvent event) { - m_RunButton.setEnabled(true); - m_Continue.setEnabled(true); - m_StopButton.setEnabled(false); + runButton.setEnabled(true); + continueButton.setEnabled(true); + stopButton.setEnabled(false); worker.interrupt(); for (int i = 0; i < multiRuns; i++) { - m_Plot.clearGraph(1000 + i); + plot.clearGraph(1000 + i); } } }; @@ -238,9 +238,9 @@ public class StandaloneOptimization implements InterfaceStandaloneOptimization, @Override public void finished() { - m_RunButton.setEnabled(true); - m_Continue.setEnabled(true); - m_StopButton.setEnabled(false); + runButton.setEnabled(true); + continueButton.setEnabled(true); + stopButton.setEnabled(false); backupPopulation = (Population) optimizationParameters.getOptimizer().getPopulation().clone(); continueFlag = false; } @@ -250,9 +250,9 @@ public class StandaloneOptimization implements InterfaceStandaloneOptimization, continueFlag = true; multiRuns = 1; // multiruns machen bei continue einfach keinen Sinn... worker.start(); - m_RunButton.setEnabled(false); - m_Continue.setEnabled(false); - m_StopButton.setEnabled(true); + runButton.setEnabled(false); + continueButton.setEnabled(false); + stopButton.setEnabled(true); } }; /** @@ -334,14 +334,6 @@ public class StandaloneOptimization implements InterfaceStandaloneOptimization, break; } } - String m_MyHostName = "_"; - try { - m_MyHostName = InetAddress.getLocalHost().getHostName(); - } catch (Exception e) { - System.out.println("ERROR getting HostName (GOStandalone.startExperiment) " + e.getMessage()); - } -// EVAMail.SendMail("GOTask on "+m_MyHostName+ " finished", "Have a look at the results at the result file", "streiche@informatik.uni-tuebingen.de"); - } /** @@ -362,8 +354,8 @@ public class StandaloneOptimization implements InterfaceStandaloneOptimization, 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.outputPath + this.outputFileName + "_" + this.experimentName + "_" + m_StartDate + ".dat"; + String startDate = formatter.format(new Date()); + name = this.outputPath + this.outputFileName + "_" + this.experimentName + "_" + startDate + ".dat"; try { this.outputFile = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(name))); } catch (FileNotFoundException e) { @@ -389,7 +381,7 @@ public class StandaloneOptimization implements InterfaceStandaloneOptimization, 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(); + this.tmpData = new ArrayList<>(); this.currentRun = j; if (this.show) { this.statusField.setText("Optimizing Run " + (j + 1) + " of " + this.multiRuns + " Multi Runs..."); @@ -427,7 +419,7 @@ public class StandaloneOptimization implements InterfaceStandaloneOptimization, tmpMultiRun.add(this.tmpData); } if (this.show) { - this.m_Plot.setInfoString(this.currentExperiment, this.experimentName, 0.5f); + this.plot.setInfoString(this.currentExperiment, this.experimentName, 0.5f); } if (this.show) { this.draw(); @@ -449,7 +441,7 @@ public class StandaloneOptimization implements InterfaceStandaloneOptimization, } if (this.show) { for (int i = 0; i < this.multiRuns; i++) { - this.m_Plot.clearGraph(1000 + i); + this.plot.clearGraph(1000 + i); } } updateStatus(0); @@ -497,21 +489,13 @@ public class StandaloneOptimization implements InterfaceStandaloneOptimization, } } // Now enter this stuff into the graph - this.m_Plot.clearGraph(this.currentExperiment); -// tmpColor = Color.darkGray; -// 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; + this.plot.clearGraph(this.currentExperiment); for (int j = 0; j < data.length; j++) { if (this.continueFlag) { - this.m_Plot.setConnectedPoint(data[j][0] + this.recentFunctionCalls, data[j][1], this.currentExperiment); + this.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); + this.plot.setConnectedPoint(data[j][0], data[j][1], this.currentExperiment); } } this.currentExperiment++; @@ -594,11 +578,11 @@ public class StandaloneOptimization implements InterfaceStandaloneOptimization, 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.optimizationParameters.getProblem().getDoublePlotValue(population); - if (this.m_Plot != null) { + if (this.plot != null) { if (this.continueFlag) { - this.m_Plot.setConnectedPoint(tmpData[0].doubleValue() + this.recentFunctionCalls, tmpData[1].doubleValue(), 1000 + this.currentRun); + this.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.plot.setConnectedPoint(tmpData[0].doubleValue(), tmpData[1].doubleValue(), 1000 + this.currentRun); } } this.tmpData.add(tmpData); @@ -714,66 +698,14 @@ public class StandaloneOptimization implements InterfaceStandaloneOptimization, * @param name */ public void setList(List name) { - this.m_List = name; + this.list = name; } - public List getListe() { - return this.m_List; + public List getList() { + return this.list; } public String listTipText() { return "Set the name for the output file, if 'none' no output file will be created."; } -// /** This method allows you to set the number of functions calls that are to -// * be evaluated. Note generational optimizers may exceed this number since -// * they allways evaluate the complete population -// * @param functionCalls The maximal number of Function calls -// */ -// public void setFunctionCalls(int functionCalls) { -// this.functionCalls = functionCalls; -// } -// public int getFunctionCalls() { -// return this.functionCalls; -// } -// public String functionCallsTipText() { -// return "The maxiaml number of function(fitness) evaluations that are performed. Mote: Generational algorihtms may be delayed!"; -// } -// -// /** This method allows you to set the current optimizing algorithm -// * @param optimizer The new optimizing algorithm -// */ -// public void setOptimizer(InterfaceOptimizer optimizer) { -// this.optimizer = optimizer; -// this.optimizer.addPopulationChangedEventListener(this); -// this.experimentName = this.optimizer.getName()+"-"+this.performedRuns.size(); -// this.optimizer.SetProblem(this.problem); -// } -// public InterfaceOptimizer getOptimizer() { -// return this.optimizer; -// } -// public String optimizerTipText() { -// return "Choose a optimizing strategies."; -// } -// /** This method will set the problem that is to be optimized -// * @param problem -// */ -// public void SetProblem (InterfaceOptimizationProblem problem) { -// this.problem = problem; -// this.optimizer.SetProblem(this.problem); -// } -// public InterfaceOptimizationProblem getProblem () { -// return this.problem; -// } -// public String problemTipText() { -// return "Choose the problem that is to optimize and the EA individual parameters."; -// } -// public void setTest(InterfaceTest v) { -// this.test = v; -// } -// public InterfaceTest getTest() { -// return this.test; -// } -// public String testTipText() { -// return "Test"; -// } } diff --git a/src/eva2/optimization/individuals/codings/ga/GAStandardCodingDouble.java b/src/eva2/optimization/individuals/codings/ga/GAStandardCodingDouble.java index 697d8e1e..aa18a114 100644 --- a/src/eva2/optimization/individuals/codings/ga/GAStandardCodingDouble.java +++ b/src/eva2/optimization/individuals/codings/ga/GAStandardCodingDouble.java @@ -29,39 +29,28 @@ public class GAStandardCodingDouble implements InterfaceGADoubleCoding, java.io. */ public double decodeValueOld(BitSet refBitSet, double[] range, int[] locus, boolean correction) { double u_max, u_min; - int m_start, m_length; + int mStart, mLength; long tmpV; double output; //BitSet tmpBitSet; u_min = range[0]; u_max = range[1]; - m_start = locus[0]; - m_length = locus[1]; + mStart = locus[0]; + mLength = locus[1]; - if (m_length != lastLen) { - lastMaxVal = Math.pow(2, m_length) - 1; - lastLen = m_length; + if (mLength != lastLen) { + lastMaxVal = Math.pow(2, mLength) - 1; + lastLen = mLength; } - //tmpBitSet = new BitSet(m_length); tmpV = 0; - for (int i = 0; i < m_length; i++) { - if (refBitSet.get(m_start + m_length - 1 - i)) { + for (int i = 0; i < mLength; i++) { + if (refBitSet.get(mStart + mLength - 1 - i)) { tmpV += Math.pow(2, i); - // tmpBitSet.set(m_length - 1 - i); } } - //System.out.println("intval is "+tmpV); - //output = ((double)tmpV/m_max)*(u_max - u_min) + u_min; output = (((double) tmpV * (u_max - u_min)) / lastMaxVal) + u_min; -// System.out.println("m_min/m_max " + m_min +"/"+m_max); -// System.out.println("u_min/u_max " + u_min +"/"+u_max); -// System.out.println("Decoding Long Value: " + tmpV); -// System.out.println("Decoding Real Value: " + output); - // correction is not necessary - //System.out.print("FLOAT Value decoded : " + output + " " + this.printBitSet(tmpBitSet, m_length)); - //System.out.println(tmpV + "/" + m_max + "*(" + u_max + "-" + u_min + ")+" + u_min +"\n"); return output; } @@ -77,11 +66,11 @@ public class GAStandardCodingDouble implements InterfaceGADoubleCoding, java.io. @Override public double decodeValue(BitSet refBitSet, double[] range, int[] locus, boolean correction) { long val = (refBitSet.get(locus[0]) ? 1 : 0); - int m_length = locus[1]; + int mLength = locus[1]; - if (m_length != lastLen) { - lastMaxVal = Math.pow(2, m_length) - 1; - lastLen = m_length; + if (mLength != lastLen) { + lastMaxVal = Math.pow(2, mLength) - 1; + lastLen = mLength; } for (int i = 1 + locus[0]; i < locus[0] + locus[1]; i++) { @@ -106,23 +95,19 @@ public class GAStandardCodingDouble implements InterfaceGADoubleCoding, java.io. */ @Override public void codeValue(double value, double[] range, BitSet refBitSet, int[] locus) { - double u_max, u_min, m_max, m_min; + double uMax, uMin, mMax, mMin; int m_start, m_length, counter = 0; long tmpV; BitSet tmpBitSet; - u_min = range[0]; - u_max = range[1]; + uMin = range[0]; + uMax = range[1]; m_start = locus[0]; m_length = locus[1]; - m_max = Math.pow(2, m_length) - 1; - m_min = 0; + mMax = Math.pow(2, m_length) - 1; + mMin = 0; // here the value will be quantified - tmpV = Math.round((((value - u_min) * m_max / (u_max - u_min)))); -// System.out.println("m_min/m_max " + m_min +"/"+m_max); -// System.out.println("u_min/u_max " + u_min +"/"+u_max); -// System.out.println("Coding Long Value: " + tmpV); -// System.out.println("Coding Real Value: " + value); + tmpV = Math.round((((value - uMin) * mMax / (uMax - uMin)))); tmpBitSet = new BitSet(m_length); while (tmpV >= 1) { //System.out.println(tmpV); diff --git a/src/eva2/optimization/individuals/codings/ga/GAStandardCodingInteger.java b/src/eva2/optimization/individuals/codings/ga/GAStandardCodingInteger.java index 16070d27..5e94dc36 100644 --- a/src/eva2/optimization/individuals/codings/ga/GAStandardCodingInteger.java +++ b/src/eva2/optimization/individuals/codings/ga/GAStandardCodingInteger.java @@ -24,24 +24,22 @@ public class GAStandardCodingInteger implements InterfaceGAIntegerCoding, java.i */ @Override public int decodeValue(BitSet refBitSet, int[] range, int[] locus, boolean correction) { - int u_max, u_min, m_max, m_min; - int m_start, m_length, counter = 0; + int u_max, u_min; + int start, mLength; long tmpV; BitSet tmpBitSet; String output = ""; u_min = range[0]; u_max = range[1]; - m_start = locus[0]; - m_length = locus[1]; - m_max = (int) Math.pow(2, m_length) - 1; - m_min = 0; - tmpBitSet = new BitSet(m_length); + start = locus[0]; + mLength = locus[1]; + tmpBitSet = new BitSet(mLength); tmpV = 0; - for (int i = 0; i < m_length; i++) { - if (refBitSet.get(m_start + m_length - 1 - i)) { + for (int i = 0; i < mLength; i++) { + if (refBitSet.get(start + mLength - 1 - i)) { tmpV += Math.pow(2, i); - tmpBitSet.set(m_length - 1 - i); + tmpBitSet.set(mLength - 1 - i); output += "1"; } else { output += "0"; @@ -49,10 +47,10 @@ public class GAStandardCodingInteger implements InterfaceGAIntegerCoding, java.i } //System.out.println(tmpV); tmpV += u_min; - //System.out.println("Korregiere: " + tmpV + " " + u_min + " " + u_max + " " + output); + //System.out.println("Korrigiere: " + tmpV + " " + u_min + " " + u_max + " " + output); if (tmpV > u_max) { // this value is invalid - //System.out.print("Korregiere: " + tmpV + " > " + u_max); + //System.out.print("Korrigiere: " + tmpV + " > " + u_max); if (correction) { // a new value within the bounds is generated tmpV = RNG.randomInt(u_min, u_max); @@ -63,7 +61,6 @@ public class GAStandardCodingInteger implements InterfaceGAIntegerCoding, java.i //System.out.println("zu max: " + tmpV); } } - //System.out.println("INT Value decoded : " + (int)tmpV + " " + this.printBitSet(tmpBitSet, m_length)); return (int) tmpV; } @@ -79,26 +76,26 @@ public class GAStandardCodingInteger implements InterfaceGAIntegerCoding, java.i */ @Override public void codeValue(int value, int[] range, BitSet refBitSet, int[] locus) { - int u_max, u_min, m_max, m_min; - int m_start, m_length, counter = 0; + int uMax, uMin, mMax, mMin; + int start, length, counter = 0; long tmpV; BitSet tmpBitSet; - u_min = range[0]; - u_max = range[1]; - m_start = locus[0]; - m_length = locus[1]; - m_max = (int) Math.pow(2, m_length) - 1; - m_min = 0; - tmpV = value - u_min; - long tmpOut = tmpV;// damit ist tmpV im range m_Min m_Max - if (tmpV > m_max) { - tmpV = m_max; + uMin = range[0]; + uMax = range[1]; + start = locus[0]; + length = locus[1]; + mMax = (int) Math.pow(2, length) - 1; + mMin = 0; + tmpV = value - uMin; + long tmpOut = tmpV;// damit ist tmpV im range mMin mMax + if (tmpV > mMax) { + tmpV = mMax; } - if (tmpV < m_min) { - tmpV = m_min; + if (tmpV < mMin) { + tmpV = mMin; } - tmpBitSet = new BitSet(m_length); + tmpBitSet = new BitSet(length); while (tmpV >= 1) { //System.out.println(tmpV); if ((tmpV % 2) == 1) { @@ -113,23 +110,21 @@ public class GAStandardCodingInteger implements InterfaceGAIntegerCoding, java.i tmpV /= 2; // with this method the least significant bit will be at the lowest position } - //System.out.println("tmpV " + tmpOut + " Range("+m_min+";"+m_max+") "+m_length+" "+this.printBitSet(tmpBitSet,m_length)); - // Das sieht bis hierher richtig toll aus, nur jetzt wirds scheisse m_Length war im Arsch - for (int i = 0; i < m_length; i++) { + // Das sieht bis hierher richtig toll aus, nur jetzt wirds scheisse length war im Arsch + for (int i = 0; i < length; i++) { if (tmpBitSet.get(i)) { - refBitSet.set(m_start + m_length - 1 - i); + refBitSet.set(start + length - 1 - i); } else { - refBitSet.clear(m_start + m_length - 1 - i); + refBitSet.clear(start + length - 1 - i); } } - for (int i = 0; i < m_length; i++) { - if (refBitSet.get(m_start + m_length - 1 - i)) { - tmpBitSet.set(m_length - 1 - i); + for (int i = 0; i < length; i++) { + if (refBitSet.get(start + length - 1 - i)) { + tmpBitSet.set(length - 1 - i); } else { - tmpBitSet.clear(m_start + m_length - 1 - i); + tmpBitSet.clear(start + length - 1 - i); } } - //System.out.println("INT Value coded : " + value + " " + this.printBitSet(tmpBitSet, m_length)); } /** diff --git a/src/eva2/optimization/modules/AbstractModuleAdapter.java b/src/eva2/optimization/modules/AbstractModuleAdapter.java index 961e638c..1c99e688 100644 --- a/src/eva2/optimization/modules/AbstractModuleAdapter.java +++ b/src/eva2/optimization/modules/AbstractModuleAdapter.java @@ -1,14 +1,5 @@ package eva2.optimization.modules; -/* - * Title: EvA2 - * Description: - * Copyright: Copyright (c) 2003 - * Company: University of Tuebingen, Computer Architecture - * @author Holger Ulmer, Felix Streichert, Hannes Planatscher - * @version: $Revision: 306 $ - * $Date: 2007-12-04 14:22:52 +0100 (Tue, 04 Dec 2007) $ - * $Author: mkron $ - */ + import eva2.optimization.OptimizationStateListener; import eva2.optimization.go.InterfaceOptimizationParameters; diff --git a/src/eva2/optimization/modules/SAParameters.java b/src/eva2/optimization/modules/SAParameters.java index 8443816d..2912794f 100644 --- a/src/eva2/optimization/modules/SAParameters.java +++ b/src/eva2/optimization/modules/SAParameters.java @@ -17,22 +17,14 @@ import java.io.Serializable; import java.util.logging.Level; /** - * The class gives access to all SA parameters for the EvA - * top level GUI. - * Created by IntelliJ IDEA. - * User: streiche - * Date: 08.06.2004 - * Time: 21:25:12 - * To change this template use File | Settings | File Templates. + * */ -public class SAParameters extends AbstractOptimizationParameters implements InterfaceOptimizationParameters, Serializable { +public class SAParameters extends AbstractOptimizationParameters implements Serializable { // Opt. Algorithms and Parameters - private InterfaceOptimizer m_Optimizer = new SimulatedAnnealing(); - private InterfaceOptimizationProblem m_Problem = new B1Problem(); - //private int functionCalls = 1000; - private InterfaceTerminator m_Terminator = new EvaluationTerminator(); - // private String m_OutputFileName = "none"; - transient private InterfacePopulationChangedEventListener m_Listener; + private InterfaceOptimizer optimizer = new SimulatedAnnealing(); + private InterfaceOptimizationProblem problem = new B1Problem(); + private InterfaceTerminator terminator = new EvaluationTerminator(); + transient private InterfacePopulationChangedEventListener changedEventListener; /** * Load or create a new instance of the class. @@ -92,11 +84,11 @@ public class SAParameters extends AbstractOptimizationParameters implements Inte * @return The population of current solutions to a given problem. */ public Population getPopulation() { - return ((SimulatedAnnealing) this.m_Optimizer).getPopulation(); + return ((SimulatedAnnealing) this.optimizer).getPopulation(); } public void setPopulation(Population pop) { - ((SimulatedAnnealing) this.m_Optimizer).setPopulation(pop); + ((SimulatedAnnealing) this.optimizer).setPopulation(pop); } public String populationTipText() { @@ -110,11 +102,11 @@ public class SAParameters extends AbstractOptimizationParameters implements Inte * @return The initial temperature. */ public double getInitialTemperature() { - return ((SimulatedAnnealing) this.m_Optimizer).getInitialTemperature(); + return ((SimulatedAnnealing) this.optimizer).getInitialTemperature(); } public void setInitialTemperature(double pop) { - ((SimulatedAnnealing) this.m_Optimizer).setInitialTemperature(pop); + ((SimulatedAnnealing) this.optimizer).setInitialTemperature(pop); } public String initialTemperatureTipText() { @@ -128,14 +120,14 @@ public class SAParameters extends AbstractOptimizationParameters implements Inte * @return The initial temperature. */ public double getAlpha() { - return ((SimulatedAnnealing) this.m_Optimizer).getAlpha(); + return ((SimulatedAnnealing) this.optimizer).getAlpha(); } public void setAlpha(double a) { if (a > 1) { a = 1.0; } - ((SimulatedAnnealing) this.m_Optimizer).setAlpha(a); + ((SimulatedAnnealing) this.optimizer).setAlpha(a); } public String alphaTipText() { diff --git a/src/eva2/optimization/problems/ExternalRuntimeProblem.java b/src/eva2/optimization/problems/ExternalRuntimeProblem.java index 5c3d19df..218742a0 100644 --- a/src/eva2/optimization/problems/ExternalRuntimeProblem.java +++ b/src/eva2/optimization/problems/ExternalRuntimeProblem.java @@ -214,9 +214,6 @@ public class ExternalRuntimeProblem extends AbstractOptimizationProblem double[] fit = evaluate(x); individual.setFitness(fit); -// if (this.m_UseTestConstraint) { -// if (x[0] < 1) individual.addConstraintViolation(1-x[0]); -// } if ((this.bestIndividuum == null) || (this.bestIndividuum.getFitness(0) > individual.getFitness(0))) { this.bestIndividuum = (AbstractEAIndividual) individual.clone(); } diff --git a/src/eva2/optimization/problems/FLensProblem.java b/src/eva2/optimization/problems/FLensProblem.java index 6bf235e1..f4dad671 100644 --- a/src/eva2/optimization/problems/FLensProblem.java +++ b/src/eva2/optimization/problems/FLensProblem.java @@ -21,8 +21,6 @@ class MyLensViewer extends JPanel implements InterfaceSolutionViewer { */ private static final long serialVersionUID = 7945150208043416139L; Population indiesToPaint = new Population(); - // private double[] m_BestVariables; -// private double m_BestFitness; private int theHeight, theWidth; FLensProblem lensProblem; @@ -64,25 +62,11 @@ class MyLensViewer extends JPanel implements InterfaceSolutionViewer { System.out.println(" G == null!?"); return; } - // Create a buffered image in which to draw -// try { -// this.theHeight = (int)g.getClipBounds().getHeight(); -// this.theWidth = (int)g.getClipBounds().getWidth(); -// this.m_CenterX = (int)g.getClipBounds().getCenterX(); -// this.m_CenterY = (int)g.getClipBounds().getCenterY(); -// } catch (java.lang.NullPointerException npe) { -// //System.out.println("Try fail..."); -// } // This might cure the eternal display problems: just ignore clipping and leave it up to swing Dimension winDim = getSize(); theHeight = winDim.height; theWidth = winDim.width; -// m_CenterX = theWidth/2; -// m_CenterY = theHeight/2; -// if (this.theHeight == 0) this.theHeight = 250; -// if (this.theWidth == 0) this.theWidth = 350; -// System.out.println(" h w cx cy " + theHeight + " " + theWidth + " " + m_CenterX + " " + m_CenterY ); bufferedImage = new BufferedImage(this.theWidth, this.theHeight, BufferedImage.TYPE_INT_RGB); // Create a graphics contents on the buffered image Graphics2D g2D = bufferedImage.createGraphics(); @@ -176,7 +160,6 @@ class MyLensViewer extends JPanel implements InterfaceSolutionViewer { // this.paint(this.getGraphics()); } else { InterfaceDataTypeDouble best = (InterfaceDataTypeDouble) pop.getBestIndividual(); - //this.m_BestFitness = ((AbstractEAIndividual)best).getFitness(0); if (indiesToPaint.size() == 0 || ((AbstractEAIndividual) best).isDominant(indiesToPaint.getBestIndividual())) { if (indiesToPaint.size() == 1) { indiesToPaint.set(0, best); @@ -377,12 +360,6 @@ public class FLensProblem extends AbstractOptimizationProblem fitness += Math.pow(tmpFit[i], 2); } -// // 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++) -// 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.useMaterialConst) { diff --git a/src/eva2/optimization/stat/GenericStatistics.java b/src/eva2/optimization/stat/GenericStatistics.java index 3c4bafcd..f05a42cd 100644 --- a/src/eva2/optimization/stat/GenericStatistics.java +++ b/src/eva2/optimization/stat/GenericStatistics.java @@ -1,14 +1,5 @@ package eva2.optimization.stat; -/* - * Title: EvA2 - * Description: - * Copyright: Copyright (c) 2003 - * Company: University of Tuebingen, Computer Architecture - * @author Holger Ulmer, Felix Streichert, Hannes Planatscher - * @version: $Revision: 320 $ - * $Date: 2007-12-06 16:05:11 +0100 (Thu, 06 Dec 2007) $ - * $Author: mkron $ - */ + import eva2.gui.plot.DataViewer; import eva2.gui.plot.DataViewerInterface; @@ -24,7 +15,6 @@ import java.util.logging.Logger; public class GenericStatistics implements Serializable { private static final Logger LOGGER = Logger.getLogger(GenericStatistics.class.getName()); - //private Object m_target; private int test; private String[] propertyNames; private boolean[] states; @@ -43,7 +33,6 @@ public class GenericStatistics implements Serializable { * */ private GenericStatistics(GenericStatistics Source) { - //m_target = Source.m_target; test = Source.test; propertyNames = Source.propertyNames; states = Source.states; @@ -57,17 +46,13 @@ public class GenericStatistics implements Serializable { * */ public GenericStatistics(Object target) { - //m_target = target; - //System.out.println("GenericStatistics-->"); try { fields = getDeclaredFields(target); - //if (TRACE) System.out.println("fields-->"+m_fields.length); propertyNames = new String[fields.length]; states = new boolean[fields.length]; for (int i = 0; i < fields.length; i++) { String desc = fields[i].toString(); //System.out.println("desc "+desc); int istransient = desc.indexOf("transient"); - //if (TRACE) System.out.println("Field :"+m_fields[i].getName() ); Object FieldValue = null; if (istransient == -1 || fields[i].getName().equals("elementData")) { // the elementdatahack fields[i].setAccessible(true); @@ -176,13 +161,12 @@ public class GenericStatistics implements Serializable { if (fields[i].getName().equals(propertyNames[n])) { String desc = fields[i].toString(); //System.out.println("desc "+desc); int istransient = desc.indexOf("transient"); - //if (TRACE) System.out.println("Field :"+m_fields[i].getName() ); + Object FieldValue = null; if (istransient == -1 || fields[i].getName().equals("elementData")) { // the elementdatahack fields[i].setAccessible(true); try { FieldValue = fields[i].get(target); - //System.out.println("m_PropertyNames "+m_PropertyNames[n] +" value "+FieldValue.toString()); if (FieldValue instanceof Double) { data[index] = ((Double) FieldValue).doubleValue(); } diff --git a/src/eva2/optimization/stat/MovingAverage.java b/src/eva2/optimization/stat/MovingAverage.java index 273bb6a6..59afc23d 100644 --- a/src/eva2/optimization/stat/MovingAverage.java +++ b/src/eva2/optimization/stat/MovingAverage.java @@ -5,29 +5,29 @@ package eva2.optimization.stat; * */ public class MovingAverage { - private int m_size = 0; - private int m_index = 0; - private double m_Average; - private double[] m_array; - private boolean m_overflow = false; + private int size = 0; + private int index = 0; + private double average; + private double[] array; + private boolean overflow = false; /** * */ public MovingAverage(int size) { - m_size = size; - m_array = new double[size]; + this.size = size; + array = new double[size]; } /** * */ private MovingAverage(MovingAverage Source) { - m_size = Source.m_size; - m_index = Source.m_index; - m_Average = Source.m_Average; - m_array = (double[]) Source.m_array.clone(); - m_overflow = Source.m_overflow; + size = Source.size; + index = Source.index; + average = Source.average; + array = (double[]) Source.array.clone(); + overflow = Source.overflow; } /** @@ -41,29 +41,29 @@ public class MovingAverage { * */ public void add(double value) { - m_array[m_index] = value; - m_index++; - if (m_index == m_size) { - m_index = 0; - m_overflow = true; + array[index] = value; + index++; + if (index == size) { + index = 0; + overflow = true; } // - m_Average = 0; - int tail = m_index; - //if (m_overflow=true) - if (m_overflow) { - tail = m_size; + average = 0; + int tail = index; + //if (overflow=true) + if (overflow) { + tail = size; } for (int i = 0; i < tail; i++) { - m_Average += m_array[i]; + average += array[i]; } - m_Average /= tail; + average /= tail; } /** * */ public double getAverage() { - return m_Average; + return average; } } \ No newline at end of file diff --git a/src/eva2/optimization/stat/StatisticsParameter.java b/src/eva2/optimization/stat/StatisticsParameter.java index ad2a8180..3bee47e6 100644 --- a/src/eva2/optimization/stat/StatisticsParameter.java +++ b/src/eva2/optimization/stat/StatisticsParameter.java @@ -43,10 +43,10 @@ public class StatisticsParameter implements InterfaceStatisticsParameter, Interf public final static int OUTPUT_FILE_WINDOW = 2; SelectedTag outputTo = new SelectedTag("File (current dir.)", "Text-window", "Both file and text-window"); private int verboK = 10; - private int m_Textoutput = 0; + private int textoutput = 0; private int multiRuns = 1; private String resultFilePrefix = "EvA2"; - protected String m_Name = "not defined"; + protected String name = "not defined"; private boolean useStatPlot = true; private boolean showAdditionalProblemInfo = false; private double convergenceRateThreshold = 0.001; @@ -87,7 +87,7 @@ public class StatisticsParameter implements InterfaceStatisticsParameter, Interf * */ public StatisticsParameter() { - m_Name = "Statistics"; + name = "Statistics"; outputVerbosity.setSelectedTag(VERBOSITY_KTH_IT); outputTo.setSelectedTag(1); } @@ -98,9 +98,8 @@ public class StatisticsParameter implements InterfaceStatisticsParameter, Interf @Override public String toString() { String ret = "\r\nStatisticsParameter (" + super.toString() + "):\r\nmultiRuns=" + multiRuns - + ", m_Textoutput=" + m_Textoutput - + // ", m_Plotoutput=" + m_Plotoutput + - ", verbosity= " + outputVerbosity.getSelectedString() + + ", textoutput=" + textoutput + + ", verbosity= " + outputVerbosity.getSelectedString() + "\nTo " + outputTo.getSelectedString() + ", " + BeanInspector.toString(graphSel.getStrings()); return ret; @@ -125,9 +124,7 @@ public class StatisticsParameter implements InterfaceStatisticsParameter, Interf private StatisticsParameter(StatisticsParameter Source) { convergenceRateThreshold = Source.convergenceRateThreshold; useStatPlot = Source.useStatPlot; - m_Textoutput = Source.m_Textoutput; -// m_Plotoutput = Source.m_Plotoutput; -// m_PlotFitness = Source.m_PlotFitness; + textoutput = Source.textoutput; multiRuns = Source.multiRuns; resultFilePrefix = Source.resultFilePrefix; verboK = Source.verboK; @@ -145,7 +142,7 @@ public class StatisticsParameter implements InterfaceStatisticsParameter, Interf */ @Override public String getName() { - return m_Name; + return name; } /** diff --git a/src/eva2/optimization/stat/StatisticsStandalone.java b/src/eva2/optimization/stat/StatisticsStandalone.java index 076fa0f7..d7a31196 100644 --- a/src/eva2/optimization/stat/StatisticsStandalone.java +++ b/src/eva2/optimization/stat/StatisticsStandalone.java @@ -19,9 +19,8 @@ import java.util.List; public class StatisticsStandalone extends AbstractStatistics implements InterfaceStatistics, Serializable { private static final long serialVersionUID = -8451652609212653368L; - // private String m_InfoString; - private ArrayList> m_ResultData = null; - private ArrayList m_ResultHeaderStrings = null; + private ArrayList> resultData = null; + private ArrayList resultHeaderStrings = null; private boolean collectData = false; @@ -54,25 +53,25 @@ public class StatisticsStandalone extends AbstractStatistics implements Interfac @Override protected void initPlots(PopulationInterface pop, List informerList) { if (collectData) { - m_ResultData = new ArrayList>(statisticsParameter.getMultiRuns()); + resultData = new ArrayList>(statisticsParameter.getMultiRuns()); List description = getOutputHeaderFieldNames(informerList); - m_ResultHeaderStrings = new ArrayList(); + resultHeaderStrings = new ArrayList(); for (String str : description) { - m_ResultHeaderStrings.add(str); + resultHeaderStrings.add(str); } for (int i = 0; i < statisticsParameter.getMultiRuns(); i++) { - m_ResultData.add(new ArrayList()); + resultData.add(new ArrayList()); } } else { - m_ResultData = null; - m_ResultHeaderStrings = null; + resultData = null; + resultHeaderStrings = null; } } @Override protected void plotCurrentResults() { - if (collectData && (m_ResultData != null)) { - m_ResultData.get(optRunsPerformed).add(currentStatObjectData); + if (collectData && (resultData != null)) { + resultData.get(optRunsPerformed).add(currentStatObjectData); } } @@ -82,7 +81,7 @@ public class StatisticsStandalone extends AbstractStatistics implements Interfac if (specificData != null) { for (int i = 0; i < specificData.length; i++) { // ((ArrayList[]) resultFrame.get(i))[optRunsPerformed].add(new Double[] {new Double(functionCalls), specificData[i]}); - m_ResultData.get(optRunsPerformed).add(new Object[]{new Double(functionCalls), specificData}); + resultData.get(optRunsPerformed).add(new Object[]{new Double(functionCalls), specificData}); } } } @@ -108,14 +107,14 @@ public class StatisticsStandalone extends AbstractStatistics implements Interfac } public ArrayList> getCollectedData() { - return m_ResultData; + return resultData; } public ArrayList getCollectedRunData(int runIndex) { - return m_ResultData.get(runIndex); + return resultData.get(runIndex); } public ArrayList getCollectedDataHeaders() { - return m_ResultHeaderStrings; + return resultHeaderStrings; } } \ No newline at end of file diff --git a/src/eva2/optimization/strategies/CHCAdaptiveSearchAlgorithm.java b/src/eva2/optimization/strategies/CHCAdaptiveSearchAlgorithm.java index 403275fd..1eaa23b1 100644 --- a/src/eva2/optimization/strategies/CHCAdaptiveSearchAlgorithm.java +++ b/src/eva2/optimization/strategies/CHCAdaptiveSearchAlgorithm.java @@ -119,8 +119,6 @@ public class CHCAdaptiveSearchAlgorithm implements InterfaceOptimizer, java.io.S AbstractEAIndividual tmpIndy; result.clear(); -// this.m_NormationOperator.computeSelectionProbability(this.population, "Fitness"); - //System.out.println("Population:"+this.population.getSolutionRepresentationFor()); this.populationSelectionOperator.prepareSelection(this.population); this.recombSelectionOperator.prepareSelection(this.population); parents = this.populationSelectionOperator.selectFrom(this.population, this.population.getTargetSize()); @@ -224,7 +222,6 @@ public class CHCAdaptiveSearchAlgorithm implements InterfaceOptimizer, java.io.S } } nextGeneration.addPopulation(this.population); -// this.m_NormationOperator.computeSelectionProbability(nextGeneration, "Fitness"); this.populationSelectionOperator.prepareSelection(this.population); tmp = this.populationSelectionOperator.selectFrom(nextGeneration, this.population.getTargetSize()); nextGeneration.clear(); @@ -341,18 +338,6 @@ public class CHCAdaptiveSearchAlgorithm implements InterfaceOptimizer, java.io.S return new SolutionSet(getPopulation()); } -// /** This method will set the normation method that is to be used. -// * @param normation -// */ -// public void setNormationMethod (InterfaceNormation normation) { -// this.m_NormationOperator = normation; -// } -// public InterfaceNormation getNormationMethod () { -// return this.m_NormationOperator; -// } -// public String normationMethodTipText() { -// return "Select the normation method."; -// } /** * Enable/disable elitism. diff --git a/src/eva2/optimization/strategies/ClusterBasedNichingEA.java b/src/eva2/optimization/strategies/ClusterBasedNichingEA.java index 4661fa86..947aa307 100644 --- a/src/eva2/optimization/strategies/ClusterBasedNichingEA.java +++ b/src/eva2/optimization/strategies/ClusterBasedNichingEA.java @@ -596,36 +596,18 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis if (best == null) { best = (AbstractEAIndividual) curSpecies.getBestEAIndividual().getClone(); } -// if (useDistraction) { // Add distractor! -// if (distraction == null) distraction = new Distraction(distrDefaultStrength, Distraction.METH_BEST); -// distraction.addDistractorFrom(curSpecies); -// System.out.println("** Adding distractor! " + BeanInspector.toString(distraction.getDistractionCenter(curSpecies, distraction.getDistractionMethod().getSelectedTagID()))); -// } int toReinit = 0; - if (true) { //if (m_UseArchive) { + if (true) { populationArchive.add(best); // System.out.println((""+ population.getFunctionCalls() + " " + (BeanInspector.toString(best.getDoublePosition())).replaceAll(";|\\[|\\]", ""))); species.remove(i); // remove the converged Species toReinit = curSpecies.size(); } -// else { -// // reset the converged species to inactivity size = 1 -// toReinit=curSpecies.size()-1; -// deactivateSpecies(curSpecies, best, null); -// } // those will not be optimized anymore, so we dont need to doom them, but can directly add them to undiff! undifferentiatedPopulation.addPopulation(initializeIndividuals(toReinit)); undifferentiatedPopulation.incrFunctionCallsBy(toReinit); -// if (this.debug) { -// System.out.println("Undiff.Size: " + this.undifferentiatedPopulation.size() +"/"+this.undifferentiatedPopulation.getPopulationSize()); -// System.out.println("Diff.Size : " + ((Population)this.species.get(i)).size() +"/"+((Population)this.species.get(i)).getPopulationSize()); -// } -// if (this.debug) System.out.println("--------------------------End converged"); -////////////////////////////////////////////////////////////////////////////////////////////////////////////// } else { - // actually optimize D_i -// this.capMutationRate(curSpecies, 0.05); curSpecies.putData(InterfaceSpeciesAware.populationTagKey, InterfaceSpeciesAware.localPopTag); Population optimizedSpec = optimizeSpecies(curSpecies, true); this.species.set(i, optimizedSpec); @@ -998,35 +980,6 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis } } -// /** -// * Return true if the given population is considered active. -// * -// * @param pop a population -// * @return true, if pop is considered an active population, else false -// */ -// protected boolean isActive(Population pop) { -// return (pop.size() >= m_actSpecSize); -// } -// /** -// * Deactivate a given species by removing all individuals and inserting -// * only the given survivor, sets the population size to one. -// * -// * @param spec -// */ -// protected void deactivateSpecies(Population spec, AbstractEAIndividual survivor, Population collectDoomed) { -// if (!spec.remove(survivor)) System.err.println("WARNING: removing survivor failed in CBN.deactivateSpecies!");; -// if (collectDoomed!=null) collectDoomed.addPopulation(spec); -// spec.clear(); -// spec.add(survivor); -// spec.setPopulationSize(1); -// } -// public int countActiveSpec() { -// int k = 0; -// for (int i=0; i=1, only used in local mode).";