diff --git a/src/eva2/EvAInfo.java b/src/eva2/EvAInfo.java index 3edb3433..85107996 100644 --- a/src/eva2/EvAInfo.java +++ b/src/eva2/EvAInfo.java @@ -3,6 +3,7 @@ package eva2; /** * Main product and version information strings. * + * 2.025: FunctionArea may now plot circles easily. The FLensProblemViewer seems to be cured. * 2.024: Cleaned up AbstractGOParams, deactivated parent logging (saving memory) * 2.023: Cleaned up the PF strategy * 2.022: Some changes to the SimpleProblemWrapper, not of great interest. However, @@ -14,7 +15,7 @@ package eva2; public class EvAInfo { public static final String productName = "EvA 2"; public static final String productLongName = "Evolutionary Algorithms Workbench 2"; - public static final String versionNum = new String ("2.024"); + public static final String versionNum = new String ("2.025"); public static final String url = "http://www.ra.cs.uni-tuebingen.de/software/EvA2"; public static final String propertyFile = "resources/EvA2.props"; diff --git a/src/eva2/gui/Chart2DDPointIconText.java b/src/eva2/gui/Chart2DDPointIconText.java index b9a4123b..b3a38e69 100644 --- a/src/eva2/gui/Chart2DDPointIconText.java +++ b/src/eva2/gui/Chart2DDPointIconText.java @@ -16,6 +16,7 @@ public class Chart2DDPointIconText implements DPointIcon { private DPointIcon m_Icon = new Chart2DDPointIconCross(); private String m_Text = " "; + private Color m_Color; public Chart2DDPointIconText(String s) { m_Text = s; @@ -34,6 +35,7 @@ public class Chart2DDPointIconText implements DPointIcon { */ public void paint( Graphics g ){ this.m_Icon.paint(g); + g.setColor(m_Color); g.drawString(this.m_Text, 4, 4); } @@ -46,4 +48,13 @@ public class Chart2DDPointIconText implements DPointIcon { public DBorder getDBorder() { return new DBorder(4, 4, 4, 4); } + + /** + * Set the color for the text. + * + * @param col + */ + public void setColor(Color col) { + m_Color = col; + } } \ No newline at end of file diff --git a/src/eva2/gui/FunctionArea.java b/src/eva2/gui/FunctionArea.java index db9fc9d8..2e2b63be 100644 --- a/src/eva2/gui/FunctionArea.java +++ b/src/eva2/gui/FunctionArea.java @@ -88,7 +88,51 @@ public class FunctionArea extends DArea implements Serializable { repaint(); notifyNegLog = true; } - + + /** + * Plot a circle icon to the function area which is annotated with a char and + * a double value. + * + * @param c + * @param val + * @param position + */ + public void drawCircle(double val, double[] position, int graphID) { + drawCircle(""+val, position, graphID); + } + + /** + * Plot a circle icon to the function area which is annotated with a char and + * a double value. + * + * @param c + * @param val + * @param position + * @param graphID + */ + public void drawCircle(char c, double val, double[] position, int graphID) { + drawCircle(c+""+val, position, graphID); + } + + /** + * Plot a circle icon to the function area which is annotated with a char and + * a double value. The color corresponds to the color of the graph with given ID + * + * @param label + * @param position + * @param graphID + */ + public void drawCircle(String label, double[] position, int graphID) { + DPointSet popRep; + popRep = new DPointSet(); + popRep.addDPoint(new DPoint(position[0], position[1])); + DPointIcon icon = new Chart2DDPointIconText(label); + ((Chart2DDPointIconText)icon).setIcon(new Chart2DDPointIconCircle()); + ((Chart2DDPointIconText)icon).setColor(getGraphPointSet(graphID).getColor()); + popRep.setIcon(icon); + addDElement(popRep); + } + /** * */ diff --git a/src/eva2/gui/GraphPointSet.java b/src/eva2/gui/GraphPointSet.java index f2888ead..56ec9ead 100644 --- a/src/eva2/gui/GraphPointSet.java +++ b/src/eva2/gui/GraphPointSet.java @@ -40,7 +40,7 @@ public class GraphPointSet { private Color m_Color; private DPointIcon m_Icon; private int m_CacheIndex = 0; - private int m_CacheSize = 1; + private int m_CacheSize = 0; private double [] m_cachex; private double [] m_cachey; /** diff --git a/src/eva2/gui/Plot.java b/src/eva2/gui/Plot.java index 54330e58..fc352628 100644 --- a/src/eva2/gui/Plot.java +++ b/src/eva2/gui/Plot.java @@ -13,6 +13,7 @@ package eva2.gui; * IMPORTS *==========================================================================*/ import java.awt.AWTException; +import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Rectangle; import java.awt.Robot; @@ -276,6 +277,13 @@ public class Plot implements PlotInterface, Serializable { m_Frame.setVisible(true); } + public void setPreferredSize(Dimension prefSize) { + if (m_Frame != null) { + m_Frame.setPreferredSize(prefSize); + m_Frame.pack(); + } + } + /** * Return true if the Plot object is valid. * diff --git a/src/eva2/server/go/individuals/AbstractEAIndividual.java b/src/eva2/server/go/individuals/AbstractEAIndividual.java index 22751ea1..1af96383 100644 --- a/src/eva2/server/go/individuals/AbstractEAIndividual.java +++ b/src/eva2/server/go/individuals/AbstractEAIndividual.java @@ -21,9 +21,9 @@ import eva2.tools.EVAERROR; /** This is the abstract EA individual implementing the most important methods giving * access to mutation and crossover rates and operators, fitness values and selection * probabilities. All EA individuals should typically extend this abstract EA individual. - * In that case the EA individuals only implement the genotpye and phenotype interfaces. + * In that case the EA individuals only implement the genotype and phenotype interfaces. * The names of the implementation should be build like this: - * (Genotpye)Individual(Phenotype) + * (Genotype)Individual(Phenotype) * Thus a binary individual coding double values is named GAIndividualDoubleData and a * real-valued individual coding binary values is named ESIndividualBinaryData. * Created by IntelliJ IDEA. @@ -911,6 +911,10 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java. else return this.getFitness(); } + public boolean isDominantNotEqual(double[] otherFitness) { + return isDominatingFitnessNotEqual(m_Fitness, otherFitness); + } + public boolean isDominant(double[] otherFitness) { return isDominatingFitness(m_Fitness, otherFitness); } diff --git a/src/eva2/server/go/individuals/ESIndividualDoubleData.java b/src/eva2/server/go/individuals/ESIndividualDoubleData.java index 8deffb5b..ff28454e 100644 --- a/src/eva2/server/go/individuals/ESIndividualDoubleData.java +++ b/src/eva2/server/go/individuals/ESIndividualDoubleData.java @@ -1,14 +1,11 @@ package eva2.server.go.individuals; -import java.util.Arrays; - -import eva2.server.go.IndividualInterface; +import wsi.ra.math.RNG; import eva2.server.go.operators.crossover.CrossoverESDefault; import eva2.server.go.operators.mutation.InterfaceMutation; import eva2.server.go.operators.mutation.MutateESGlobal; import eva2.server.go.problems.InterfaceOptimizationProblem; -import wsi.ra.math.RNG; /** This individual uses a real-valued genotype to code for double values. * Created by IntelliJ IDEA. diff --git a/src/eva2/server/go/individuals/ESIndividualPermutationData.java b/src/eva2/server/go/individuals/ESIndividualPermutationData.java index 00ec3729..b3b72068 100644 --- a/src/eva2/server/go/individuals/ESIndividualPermutationData.java +++ b/src/eva2/server/go/individuals/ESIndividualPermutationData.java @@ -17,363 +17,363 @@ import wsi.ra.math.RNG; */ public class ESIndividualPermutationData extends AbstractEAIndividual implements InterfaceESIndividual, InterfaceDataTypePermutation, java.io.Serializable { - private double[][] m_Genotype; - private int[][] m_Phenotype; - private double[][][] m_Range; - private int[] firstindex; + private double[][] m_Genotype; + private int[][] m_Phenotype; + private double[][][] m_Range; + private int[] firstindex; - public ESIndividualPermutationData() { - this.m_MutationProbability = 1.0; - this.m_MutationOperator = new MutateESGlobal(); - this.m_CrossoverProbability = 0.5; - this.m_CrossoverOperator = new CrossoverESDefault(); - this.m_Genotype = new double[1][1]; - this.m_Range = new double[1][1][2]; - this.m_Range[0][0][0] = 0; - this.m_Range[0][0][1] = 1; - this.firstindex = new int[]{0}; - } + public ESIndividualPermutationData() { + this.m_MutationProbability = 1.0; + this.m_MutationOperator = new MutateESGlobal(); + this.m_CrossoverProbability = 0.5; + this.m_CrossoverOperator = new CrossoverESDefault(); + this.m_Genotype = new double[1][1]; + this.m_Range = new double[1][1][2]; + this.m_Range[0][0][0] = 0; + this.m_Range[0][0][1] = 1; + this.firstindex = new int[]{0}; + } - public ESIndividualPermutationData(ESIndividualPermutationData individual) { - if (individual.m_Phenotype != null) { - this.m_Phenotype = new int[individual.m_Phenotype.length][]; - for (int i = 0; i < m_Phenotype.length; i++) { - this.m_Phenotype[i] =new int[ individual.m_Phenotype[i].length]; - System.arraycopy(individual.m_Phenotype[i], 0, this.m_Phenotype[i], 0, this.m_Phenotype[i].length); - } - } + public ESIndividualPermutationData(ESIndividualPermutationData individual) { + if (individual.m_Phenotype != null) { + this.m_Phenotype = new int[individual.m_Phenotype.length][]; + for (int i = 0; i < m_Phenotype.length; i++) { + this.m_Phenotype[i] =new int[ individual.m_Phenotype[i].length]; + System.arraycopy(individual.m_Phenotype[i], 0, this.m_Phenotype[i], 0, this.m_Phenotype[i].length); + } + } - this.firstindex = individual.firstindex; - this.m_Genotype = new double[individual.m_Genotype.length][]; - this.m_Range = new double[individual.m_Genotype.length][][]; - for (int i = 0; i < this.m_Genotype.length; i++) { - // if (individual.m_Phenotype != null) { + this.firstindex = individual.firstindex; + this.m_Genotype = new double[individual.m_Genotype.length][]; + this.m_Range = new double[individual.m_Genotype.length][][]; + for (int i = 0; i < this.m_Genotype.length; i++) { + // if (individual.m_Phenotype != null) { - this.m_Genotype[i] = new double[individual.m_Genotype[i].length]; - this.m_Range[i] = new double[individual.m_Genotype[i].length][2]; - for (int j = 0; j < this.m_Genotype[i].length; j++) { - this.m_Genotype[i][j] = individual.m_Genotype[i][j]; - this.m_Range[i][j][0] = individual.m_Range[i][j][0]; - this.m_Range[i][j][1] = individual.m_Range[i][j][1]; - // } - } - } + this.m_Genotype[i] = new double[individual.m_Genotype[i].length]; + this.m_Range[i] = new double[individual.m_Genotype[i].length][2]; + for (int j = 0; j < this.m_Genotype[i].length; j++) { + this.m_Genotype[i][j] = individual.m_Genotype[i][j]; + this.m_Range[i][j][0] = individual.m_Range[i][j][0]; + this.m_Range[i][j][1] = individual.m_Range[i][j][1]; + // } + } + } - // cloning the members of AbstractEAIndividual - this.m_Age = individual.m_Age; - this.m_CrossoverOperator = individual.m_CrossoverOperator; - this.m_CrossoverProbability = individual.m_CrossoverProbability; - this.m_MutationOperator = (InterfaceMutation)individual.m_MutationOperator.clone(); - this.m_MutationProbability = individual.m_MutationProbability; - this.m_SelectionProbability = new double[individual.m_SelectionProbability.length]; - for (int i = 0; i < this.m_SelectionProbability.length; i++) { - this.m_SelectionProbability[i] = individual.m_SelectionProbability[i]; - } - this.m_Fitness = new double[individual.m_Fitness.length]; - for (int i = 0; i < this.m_Fitness.length; i++) { - this.m_Fitness[i] = individual.m_Fitness[i]; - } - cloneAEAObjects((AbstractEAIndividual) individual); + // cloning the members of AbstractEAIndividual + this.m_Age = individual.m_Age; + this.m_CrossoverOperator = individual.m_CrossoverOperator; + this.m_CrossoverProbability = individual.m_CrossoverProbability; + this.m_MutationOperator = (InterfaceMutation)individual.m_MutationOperator.clone(); + this.m_MutationProbability = individual.m_MutationProbability; + this.m_SelectionProbability = new double[individual.m_SelectionProbability.length]; + for (int i = 0; i < this.m_SelectionProbability.length; i++) { + this.m_SelectionProbability[i] = individual.m_SelectionProbability[i]; + } + this.m_Fitness = new double[individual.m_Fitness.length]; + for (int i = 0; i < this.m_Fitness.length; i++) { + this.m_Fitness[i] = individual.m_Fitness[i]; + } + cloneAEAObjects((AbstractEAIndividual) individual); - } + } - public Object clone() { - return (Object) new ESIndividualPermutationData(this); - } + public Object clone() { + return (Object) new ESIndividualPermutationData(this); + } - /** This method checks on equality regarding genotypic equality - * @param individual The individual to compare to. - * @return boolean if equal true else false. - */ - public boolean equalGenotypes(AbstractEAIndividual individual) { - if (individual instanceof ESIndividualPermutationData) { - ESIndividualPermutationData indy = (ESIndividualPermutationData) individual; - if ((this.m_Genotype == null) || (indy.m_Genotype == null)) return false; - if ((this.m_Range == null) || (indy.m_Range == null)) return false; - if (this.m_Range.length != indy.m_Range.length) return false; - for (int i = 0; i < this.m_Range.length; i++) { - if (this.m_Genotype[i] != indy.m_Genotype[i]) return false; - if (this.m_Range[i][0] != indy.m_Range[i][0]) return false; - if (this.m_Range[i][1] != indy.m_Range[i][1]) return false; - } - return true; - } else { - return false; - } - } + /** This method checks on equality regarding genotypic equality + * @param individual The individual to compare to. + * @return boolean if equal true else false. + */ + public boolean equalGenotypes(AbstractEAIndividual individual) { + if (individual instanceof ESIndividualPermutationData) { + ESIndividualPermutationData indy = (ESIndividualPermutationData) individual; + if ((this.m_Genotype == null) || (indy.m_Genotype == null)) return false; + if ((this.m_Range == null) || (indy.m_Range == null)) return false; + if (this.m_Range.length != indy.m_Range.length) return false; + for (int i = 0; i < this.m_Range.length; i++) { + if (this.m_Genotype[i] != indy.m_Genotype[i]) return false; + if (this.m_Range[i][0] != indy.m_Range[i][0]) return false; + if (this.m_Range[i][1] != indy.m_Range[i][1]) return false; + } + return true; + } else { + return false; + } + } - /************************************************************************************ - * InterfaceDataTypePermutation methods - */ + /************************************************************************************ + * InterfaceDataTypePermutation methods + */ - public void setPermutationDataLength(int[] length){ + public void setPermutationDataLength(int[] length){ - this.m_Genotype = new double[length.length][]; - this.m_Range = new double[length.length][][]; - for (int i = 0; i < this.m_Range.length; i++) { - this.m_Genotype[i] = new double[length[i]]; - } + this.m_Genotype = new double[length.length][]; + this.m_Range = new double[length.length][][]; + for (int i = 0; i < this.m_Range.length; i++) { + this.m_Genotype[i] = new double[length[i]]; + } - for (int i = 0; i < this.m_Range.length; i++) { + for (int i = 0; i < this.m_Range.length; i++) { - this.m_Range[i] = new double[length[i]][2]; - for (int j = 0; j < this.m_Range[i].length; j++) { - this.m_Range[i][j][0] = 0; - this.m_Range[i][j][1] = 1; - } - } - } + this.m_Range[i] = new double[length[i]][2]; + for (int j = 0; j < this.m_Range[i].length; j++) { + this.m_Range[i][j][0] = 0; + this.m_Range[i][j][1] = 1; + } + } + } - public int[] sizePermutation() { - int[] res = new int[m_Genotype.length]; - for (int i = 0; i < m_Genotype.length; i++) { - res[i] = m_Genotype[i].length; - } - return res; - } + public int[] sizePermutation() { + int[] res = new int[m_Genotype.length]; + for (int i = 0; i < m_Genotype.length; i++) { + res[i] = m_Genotype[i].length; + } + return res; + } - public void SetPermutationData(int[][] perm){ - this.m_Phenotype = perm; - this.m_Range = new double[perm.length][][]; - for (int i = 0; i < perm.length; i++) { - this.m_Range[i] = new double[perm[i].length][2]; - for (int j = 0; j < this.m_Range[i].length; j++) { - this.m_Range[i][j][0] = 0; - this.m_Range[i][j][1] = 1; - } - } + public void SetPermutationData(int[][] perm){ + this.m_Phenotype = perm; + this.m_Range = new double[perm.length][][]; + for (int i = 0; i < perm.length; i++) { + this.m_Range[i] = new double[perm[i].length][2]; + for (int j = 0; j < this.m_Range[i].length; j++) { + this.m_Range[i][j][0] = 0; + this.m_Range[i][j][1] = 1; + } + } - } + } - public void SetPermutationDataLamarckian(int[][] perm){ - this.SetPermutationData(perm); + public void SetPermutationDataLamarckian(int[][] perm){ + this.SetPermutationData(perm); - this.m_Genotype = new double[perm.length][]; - this.m_Range = new double[perm.length][][]; - for (int p = 0; p < perm.length; p++) { - int biggest = Integer.MIN_VALUE; - int smallest = Integer.MAX_VALUE; - this.m_Range[p] = new double[perm[p].length][2]; - for (int i = 0; i < perm[p].length; i++) { - if (perm[p][i] > biggest) biggest = perm[p][i]; - if (perm[p][i] < smallest) smallest = perm[p][i]; - this.m_Range[p][i][0] = 0; - this.m_Range[p][i][1] = 1; - } - for (int i = 0; i < this.m_Genotype[p].length; i++) { - this.m_Genotype[p][i] = (perm[p][i] - smallest)/(double)biggest; - } - } + this.m_Genotype = new double[perm.length][]; + this.m_Range = new double[perm.length][][]; + for (int p = 0; p < perm.length; p++) { + int biggest = Integer.MIN_VALUE; + int smallest = Integer.MAX_VALUE; + this.m_Range[p] = new double[perm[p].length][2]; + for (int i = 0; i < perm[p].length; i++) { + if (perm[p][i] > biggest) biggest = perm[p][i]; + if (perm[p][i] < smallest) smallest = perm[p][i]; + this.m_Range[p][i][0] = 0; + this.m_Range[p][i][1] = 1; + } + for (int i = 0; i < this.m_Genotype[p].length; i++) { + this.m_Genotype[p][i] = (perm[p][i] - smallest)/(double)biggest; + } + } - } + } - public int[][] getPermutationData() { - this.m_Phenotype = new int[this.m_Genotype.length][]; - for (int p = 0; p < m_Genotype.length; p++) { - this.m_Phenotype[p] = new int[m_Genotype[p].length]; - boolean notValid = true; - while (notValid) { - notValid = false; - for (int i = 0; i < this.m_Genotype[p].length; i++) { - for (int j = 0; j < this.m_Genotype[p].length; j++) { - if ((i != j) && (this.m_Genotype[p][i] == this.m_Genotype[p][j])) { - notValid = true; - this.m_Genotype[p][j] = RNG.randomDouble(0, 1); - } - } - } + public int[][] getPermutationData() { + this.m_Phenotype = new int[this.m_Genotype.length][]; + for (int p = 0; p < m_Genotype.length; p++) { + this.m_Phenotype[p] = new int[m_Genotype[p].length]; + boolean notValid = true; + while (notValid) { + notValid = false; + for (int i = 0; i < this.m_Genotype[p].length; i++) { + for (int j = 0; j < this.m_Genotype[p].length; j++) { + if ((i != j) && (this.m_Genotype[p][i] == this.m_Genotype[p][j])) { + notValid = true; + this.m_Genotype[p][j] = RNG.randomDouble(0, 1); + } + } + } - } - for (int i = 0; i < this.m_Genotype[p].length; i++) { - for (int j = 0; j < this.m_Genotype[p].length; j++) { - if (this.m_Genotype[p][i] > this.m_Genotype[p][j]) this.m_Phenotype[p][i]++; - } - } - } - return this.m_Phenotype; - } + } + for (int i = 0; i < this.m_Genotype[p].length; i++) { + for (int j = 0; j < this.m_Genotype[p].length; j++) { + if (this.m_Genotype[p][i] > this.m_Genotype[p][j]) this.m_Phenotype[p][i]++; + } + } + } + return this.m_Phenotype; + } - /** This method allows you to read the permutation data without - * an update from the genotype - * @return int[] representing the permutation. - */ - public int[][] getPermutationDataWithoutUpdate() { - return this.m_Phenotype; - } + /** This method allows you to read the permutation data without + * an update from the genotype + * @return int[] representing the permutation. + */ + public int[][] getPermutationDataWithoutUpdate() { + return this.m_Phenotype; + } - public int[] getFirstindex() { - return firstindex; - } - public void setFirstindex(int[] firstindex) { - this.firstindex = firstindex; - } + public int[] getFirstindex() { + return firstindex; + } + public void setFirstindex(int[] firstindex) { + this.firstindex = firstindex; + } -/************************************************************************************ - * AbstractEAIndividual methods - */ - /** This method will allow a default initialisation of the individual - * @param opt The optimization problem that is to be solved. - */ - public void init(InterfaceOptimizationProblem opt) { - this.defaultInit(); - this.m_MutationOperator.init(this, opt); - this.m_CrossoverOperator.init(this, opt); - } + /************************************************************************************ + * AbstractEAIndividual methods + */ + /** This method will allow a default initialisation of the individual + * @param opt The optimization problem that is to be solved. + */ + public void init(InterfaceOptimizationProblem opt) { + this.defaultInit(); + this.m_MutationOperator.init(this, opt); + this.m_CrossoverOperator.init(this, opt); + } - /** This method will init the individual with a given value for the - * phenotype. - * @param obj The initial value for the phenotype - * @param opt The optimization problem that is to be solved. - */ - public void initByValue(Object obj, InterfaceOptimizationProblem opt) { - if (obj instanceof int[][]) { - int[][] bs = (int[][]) obj; - if (bs.length != this.m_Genotype.length) System.out.println("Init value and requested length doesn't match!"); - this.SetPermutationDataLamarckian(bs); - } else { - this.defaultInit(); - System.out.println("Initial value for ESIndividualPermutationData is not int[]!"); - } - this.m_MutationOperator.init(this, opt); - this.m_CrossoverOperator.init(this, opt); - } + /** This method will init the individual with a given value for the + * phenotype. + * @param obj The initial value for the phenotype + * @param opt The optimization problem that is to be solved. + */ + public void initByValue(Object obj, InterfaceOptimizationProblem opt) { + if (obj instanceof int[][]) { + int[][] bs = (int[][]) obj; + if (bs.length != this.m_Genotype.length) System.out.println("Init value and requested length doesn't match!"); + this.SetPermutationDataLamarckian(bs); + } else { + this.defaultInit(); + System.out.println("Initial value for ESIndividualPermutationData is not int[]!"); + } + this.m_MutationOperator.init(this, opt); + this.m_CrossoverOperator.init(this, opt); + } - /** This method will return a string description of the GAIndividal - * noteably the Genotype. - * @return A descriptive string - */ - public String getStringRepresentation() { - String result = ""; - result += "ESIndividual coding permutation: ("; - result += "Fitness {"; - for (int i = 0; i < this.m_Fitness.length; i++) result += this.m_Fitness[i] + ";"; - result += "}/SelProb{"; - for (int i = 0; i < this.m_SelectionProbability.length; i++) result += this.m_SelectionProbability[i] + ";"; - result += "})\n Value: "; - result += "["; - for (int i = 0; i < this.m_Genotype.length; i++) { - result += this.m_Genotype[i] + "; "; - } - result += "]"; - return result; - } + /** This method will return a string description of the GAIndividal + * noteably the Genotype. + * @return A descriptive string + */ + public String getStringRepresentation() { + String result = ""; + result += "ESIndividual coding permutation: ("; + result += "Fitness {"; + for (int i = 0; i < this.m_Fitness.length; i++) result += this.m_Fitness[i] + ";"; + result += "}/SelProb{"; + for (int i = 0; i < this.m_SelectionProbability.length; i++) result += this.m_SelectionProbability[i] + ";"; + result += "})\n Value: "; + result += "["; + for (int i = 0; i < this.m_Genotype.length; i++) { + result += this.m_Genotype[i] + "; "; + } + result += "]"; + return result; + } -/************************************************************************************ - * InterfaceESIndividual methods - */ - /** This method will allow the user to read the ES 'genotype' - * @return BitSet - */ - public double[] getDGenotype() { - return mapMatrixToVector(m_Genotype); - } + /************************************************************************************ + * InterfaceESIndividual methods + */ + /** This method will allow the user to read the ES 'genotype' + * @return BitSet + */ + public double[] getDGenotype() { + return mapMatrixToVector(m_Genotype); + } - public double[] mapMatrixToVector(double[][] matrix) { - int sumentries = 0; - for (int i = 0; i < matrix.length; i++) { - sumentries += matrix[i].length; - } - double[] res = new double[sumentries]; - int counter = 0; - for (int i = 0; i < matrix.length; i++) { - for (int j = 0; j < matrix[i].length; j++) { - res[counter] = matrix[i][j]; - counter++; - } - } - return res; - } + public double[] mapMatrixToVector(double[][] matrix) { + int sumentries = 0; + for (int i = 0; i < matrix.length; i++) { + sumentries += matrix[i].length; + } + double[] res = new double[sumentries]; + int counter = 0; + for (int i = 0; i < matrix.length; i++) { + for (int j = 0; j < matrix[i].length; j++) { + res[counter] = matrix[i][j]; + counter++; + } + } + return res; + } - public double[][] mapVectorToMatrix(double[] vector, int[] sizes) { - double[][] matrix = new double[sizes.length][]; - int counter = 0; - for (int i = 0; i < sizes.length; i++) { - matrix[i] = new double[sizes[i]]; - for (int j = 0; j < matrix[i].length; j++) { - matrix[i][j] = vector[counter]; - counter++; - } - } + public double[][] mapVectorToMatrix(double[] vector, int[] sizes) { + double[][] matrix = new double[sizes.length][]; + int counter = 0; + for (int i = 0; i < sizes.length; i++) { + matrix[i] = new double[sizes[i]]; + for (int j = 0; j < matrix[i].length; j++) { + matrix[i][j] = vector[counter]; + counter++; + } + } - return matrix; - } + return matrix; + } - /** This method will allow the user to set the current ES 'genotype'. - * @param b The new genotype of the Individual - */ - public void SetDGenotype(double[] b) { - this.m_Genotype = mapVectorToMatrix(b, this.sizePermutation()); - for (int i = 0; i < this.m_Genotype.length; i++) { - for (int j = 0; j < this.m_Genotype[i].length; j++) { - if (this.m_Genotype[i][j] < this.m_Range[i][j][0]) this.m_Genotype[i][j] = this.m_Range[i][j][0]; - if (this.m_Genotype[i][j] > this.m_Range[i][j][1]) this.m_Genotype[i][j] = this.m_Range[i][j][1]; - } - } + /** This method will allow the user to set the current ES 'genotype'. + * @param b The new genotype of the Individual + */ + public void SetDGenotype(double[] b) { + this.m_Genotype = mapVectorToMatrix(b, this.sizePermutation()); + for (int i = 0; i < this.m_Genotype.length; i++) { + for (int j = 0; j < this.m_Genotype[i].length; j++) { + if (this.m_Genotype[i][j] < this.m_Range[i][j][0]) this.m_Genotype[i][j] = this.m_Range[i][j][0]; + if (this.m_Genotype[i][j] > this.m_Range[i][j][1]) this.m_Genotype[i][j] = this.m_Range[i][j][1]; + } + } - } + } - /** This method performs a simple one element mutation on the double vector - */ - public void defaultMutate() { - for (int i = 0; i < m_Genotype.length; i++) { - int mutationIndex = RNG.randomInt(0, this.m_Genotype[i].length-1); - this.m_Genotype[i][mutationIndex] += ((this.m_Range[i][mutationIndex][1] - this.m_Range[i][mutationIndex][0])/2)*RNG.gaussianDouble(0.05f); - if (this.m_Genotype[i][mutationIndex] < this.m_Range[i][mutationIndex][0]) this.m_Genotype[i][mutationIndex] = this.m_Range[i][mutationIndex][0]; - if (this.m_Genotype[i][mutationIndex] > this.m_Range[i][mutationIndex][1]) this.m_Genotype[i][mutationIndex] = this.m_Range[i][mutationIndex][1]; - } + /** This method performs a simple one element mutation on the double vector + */ + public void defaultMutate() { + for (int i = 0; i < m_Genotype.length; i++) { + int mutationIndex = RNG.randomInt(0, this.m_Genotype[i].length-1); + this.m_Genotype[i][mutationIndex] += ((this.m_Range[i][mutationIndex][1] - this.m_Range[i][mutationIndex][0])/2)*RNG.gaussianDouble(0.05f); + if (this.m_Genotype[i][mutationIndex] < this.m_Range[i][mutationIndex][0]) this.m_Genotype[i][mutationIndex] = this.m_Range[i][mutationIndex][0]; + if (this.m_Genotype[i][mutationIndex] > this.m_Range[i][mutationIndex][1]) this.m_Genotype[i][mutationIndex] = this.m_Range[i][mutationIndex][1]; + } - } + } - /** This method initializes the double vector - */ - public void defaultInit() { - for (int i = 0; i < this.m_Genotype.length; i++) { - for (int j = 0; j < this.m_Genotype[i].length; j++) { - this.m_Genotype[i][j] = RNG.randomDouble(this.m_Range[i][j][0], this.m_Range[i][j][1]); - } - } - } + /** This method initializes the double vector + */ + public void defaultInit() { + for (int i = 0; i < this.m_Genotype.length; i++) { + for (int j = 0; j < this.m_Genotype[i].length; j++) { + this.m_Genotype[i][j] = RNG.randomDouble(this.m_Range[i][j][0], this.m_Range[i][j][1]); + } + } + } - /** This method will return the range for all double attributes. - * @return The range array. - */ - public double[][] getDoubleRange() { - int sumentries = 0; - for (int i = 0; i < this.m_Range.length; i++) { - sumentries += this.m_Range[i].length; - } - double[][] res = new double[sumentries][2]; - int counter = 0; - for (int i = 0; i < this.m_Range.length; i++) { - for (int j = 0; j < this.m_Range[i].length; j++) { - res[counter][0] = this.m_Range[i][j][0]; - res[counter][1] = this.m_Range[i][j][1]; - counter++; - } - } - return res; - } - -/********************************************************************************************************************** - * These are for GUI - */ - /** This method allows the CommonJavaObjectEditorPanel to read the - * name to the current object. - * @return The name. - */ - public String getName() { - return "ES individual"; - } + /** This method will return the range for all double attributes. + * @return The range array. + */ + public double[][] getDoubleRange() { + int sumentries = 0; + for (int i = 0; i < this.m_Range.length; i++) { + sumentries += this.m_Range[i].length; + } + double[][] res = new double[sumentries][2]; + int counter = 0; + for (int i = 0; i < this.m_Range.length; i++) { + for (int j = 0; j < this.m_Range[i].length; j++) { + res[counter][0] = this.m_Range[i][j][0]; + res[counter][1] = this.m_Range[i][j][1]; + counter++; + } + } + return res; + } - /** This method returns a global info string - * @return description - */ - public String globalInfo() { - return "This is an ES individual suited to optimize permutations."; - } + /********************************************************************************************************************** + * These are for GUI + */ + /** This method allows the CommonJavaObjectEditorPanel to read the + * name to the current object. + * @return The name. + */ + public String getName() { + return "ES individual"; + } + + /** This method returns a global info string + * @return description + */ + public String globalInfo() { + return "This is an ES individual suited to optimize permutations."; + } } diff --git a/src/eva2/server/go/problems/FLensProblem.java b/src/eva2/server/go/problems/FLensProblem.java index 31e00362..31477128 100644 --- a/src/eva2/server/go/problems/FLensProblem.java +++ b/src/eva2/server/go/problems/FLensProblem.java @@ -1,31 +1,46 @@ package eva2.server.go.problems; -import javax.swing.*; +import java.awt.BasicStroke; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.Shape; +import java.awt.Stroke; +import java.awt.image.BufferedImage; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; + +import wsi.ra.math.RNG; import eva2.server.go.GOStandaloneVersion; import eva2.server.go.individuals.AbstractEAIndividual; import eva2.server.go.individuals.ESIndividualDoubleData; -import eva2.server.go.individuals.GAIndividualDoubleData; import eva2.server.go.individuals.InterfaceDataTypeDouble; import eva2.server.go.populations.Population; import eva2.server.go.strategies.InterfaceOptimizer; -import wsi.ra.math.RNG; import eva2.server.modules.GOParameters; -import java.awt.*; -import java.awt.image.BufferedImage; - class MyLensViewer extends JPanel { - private double[] m_BestVariables; + /** + * + */ + private static final long serialVersionUID = 7945150208043416139L; + private double[] m_BestVariables; private double m_BestFitness; - private int m_Height, m_Width, m_CenterX, m_CenterY; + private int m_Height, m_Width; FLensProblem m_LensProblem; public MyLensViewer (FLensProblem f) { this.m_LensProblem = f; - Dimension d = new Dimension (450, 350); + Dimension d = new Dimension (280, 220); this.setPreferredSize(d); this.setMinimumSize(d); resetBest(); @@ -40,12 +55,12 @@ class MyLensViewer extends JPanel { Shape tmpShape; BufferedImage bufferedImage; BasicStroke ds = new BasicStroke(); - Stroke dashStroke, lineStroke, pointStroke; - int currentPos, width, mag = 10; + Stroke dashStroke; + int mag = 10; int centerLens, centerScreen, segment; - lineStroke = ds; - pointStroke = new BasicStroke(ds.getLineWidth(), ds.getEndCap(), ds.getLineJoin(), ds.getMiterLimit() , new float[] {1, 4}, 0); +// lineStroke = ds; +// pointStroke = new BasicStroke(ds.getLineWidth(), ds.getEndCap(), ds.getLineJoin(), ds.getMiterLimit() , new float[] {1, 4}, 0); dashStroke = new BasicStroke(ds.getLineWidth(), ds.getEndCap(), ds.getLineJoin(), ds.getMiterLimit() , new float[] {8, 8}, 0); super.paint(g); @@ -54,16 +69,24 @@ class MyLensViewer extends JPanel { return; } // Create a buffered image in which to draw - try { - this.m_Height = (int)g.getClipBounds().getHeight(); - this.m_Width = (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..."); - } - if (this.m_Height == 0) this.m_Height = 250; - if (this.m_Width == 0) this.m_Width = 350; +// try { +// this.m_Height = (int)g.getClipBounds().getHeight(); +// this.m_Width = (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(); + m_Height = winDim.height; + m_Width = winDim.width; +// m_CenterX = m_Width/2; +// m_CenterY = m_Height/2; + +// if (this.m_Height == 0) this.m_Height = 250; +// if (this.m_Width == 0) this.m_Width = 350; +// System.out.println(" h w cx cy " + m_Height + " " + m_Width + " " + m_CenterX + " " + m_CenterY ); bufferedImage = new BufferedImage(this.m_Width, this.m_Height, BufferedImage.TYPE_INT_RGB); // Create a graphics contents on the buffered image Graphics2D g2D = bufferedImage.createGraphics(); @@ -139,6 +162,10 @@ class MyLensViewer extends JPanel { */ public class FLensProblem extends AbstractOptimizationProblem implements InterfaceOptimizationProblem, java.io.Serializable { + /** + * + */ + private static final long serialVersionUID = 4694920294291719310L; protected AbstractEAIndividual m_OverallBest = null; protected int m_ProblemDimension = 10; protected double m_Noise = 0.0; @@ -244,25 +271,6 @@ public class FLensProblem extends AbstractOptimizationProblem implements Interfa population.init(); } -// /** This method evaluates a given population and set the fitness values -// * accordingly -// * @param population The population that is to be evaluated. -// */ -// public void evaluate(Population population) { -// evaluatePopulationStart(population); -// AbstractEAIndividual tmpIndy; -// -// for (int i = 0; i < population.size(); i++) { -// tmpIndy = (AbstractEAIndividual) population.get(i); -// tmpIndy.resetConstraintViolation(); -// this.evaluate(tmpIndy); -// population.incrFunctionCalls(); -// } -// evaluatePopulationEnd(population); -// //if (sleepTime > 0 ) try { Thread.sleep(sleepTime); } catch(Exception e) {} -//// if (this.m_Show) this.updateProblemFrame(population); -// } - public void evaluatePopulationEnd(Population pop) { if (this.m_Show) this.updateProblemFrame(pop); } diff --git a/src/eva2/tools/Mathematics.java b/src/eva2/tools/Mathematics.java index be9ec322..8efe389f 100644 --- a/src/eva2/tools/Mathematics.java +++ b/src/eva2/tools/Mathematics.java @@ -588,8 +588,8 @@ public class Mathematics { } /** - * Normalizes the doubles in the array by their sum. - * + * Normalizes the doubles in the array by their sum, + * so that they add up to one. * @param doubles the array of double * @exception IllegalArgumentException if sum is Zero or NaN */ diff --git a/src/wsi/ra/chart2d/DLine.java b/src/wsi/ra/chart2d/DLine.java index 0623c6f0..073c333c 100644 --- a/src/wsi/ra/chart2d/DLine.java +++ b/src/wsi/ra/chart2d/DLine.java @@ -57,7 +57,11 @@ public class DLine extends DComponent if( color != null ) g.setColor( color ); Point p1 = m.getPoint( start ), p2 = m.getPoint( end ) ; - g.drawLine( p1.x, p1.y, p2.x, p2.y ); + if ((p1!=null) && (p2!=null)) { + g.drawLine( p1.x, p1.y, p2.x, p2.y ); + } else { + System.err.println("Couldnt paint rect!"); + } } public String toString(){ diff --git a/src/wsi/ra/chart2d/DMeasures.java b/src/wsi/ra/chart2d/DMeasures.java index b340592b..3ad6d08c 100644 --- a/src/wsi/ra/chart2d/DMeasures.java +++ b/src/wsi/ra/chart2d/DMeasures.java @@ -87,6 +87,9 @@ private boolean under_construction = false; */ public Point getPoint( double x, double y ){ DRectangle rect = getSourceOf( getDRectangle() ); + if (rect == null) { + return null; + } try{ if( x_scale != null ) x = x_scale.getSourceOf( x ); if( y_scale != null ) y = y_scale.getSourceOf( y ); @@ -214,8 +217,11 @@ private boolean under_construction = false; */ DRectangle getSourceOf( DRectangle rect ){ if( under_construction ) System.out.println("DMeasures.getSourceOf: "+rect); - if( !getDRectangle().contains( rect ) ) throw - new IllegalArgumentException("The rectangle lies not in the currently painted rectangle"); + if( !getDRectangle().contains( rect ) ) { + return null; + //throw new IllegalArgumentException("The rectangle lies not in the currently painted rectangle"); + } + if( x_scale == null && y_scale == null ) return rect; if( rect.isEmpty() ) return (DRectangle)rect.clone(); DPoint p1 = new DPoint( rect.x, rect.y ), diff --git a/src/wsi/ra/math/RNG.java b/src/wsi/ra/math/RNG.java index f1f707ba..f7d2c959 100644 --- a/src/wsi/ra/math/RNG.java +++ b/src/wsi/ra/math/RNG.java @@ -191,7 +191,10 @@ public class RNG extends Random { return (float)random.nextGaussian()*dev; } /** - * + * Return a Gaussian double with mean 0 and deviation dev. + * + * @param dev the deviation of the distribution. + * @return a Gaussian double with mean 0 and given deviation. */ public static double gaussianDouble(double dev) { //counter++; diff --git a/src/wsi/ra/tool/BasicResourceLoader.java b/src/wsi/ra/tool/BasicResourceLoader.java index 56ed02aa..a838136f 100644 --- a/src/wsi/ra/tool/BasicResourceLoader.java +++ b/src/wsi/ra/tool/BasicResourceLoader.java @@ -188,6 +188,7 @@ public class BasicResourceLoader implements ResourceLoader * @param rawData Strings containing an array with double data columns * @param colSplit String regexp for the splitting of a line * @param selectedCols indices of the columns to retrieve, null for all. + * @see java.util.regex.Pattern * @return */ public static double[][] parseDoubleArray(ArrayList rawData, String colSplit, int[] selectedCols) { @@ -199,7 +200,7 @@ public class BasicResourceLoader implements ResourceLoader entries = rawData.get(i).split(colSplit); if (i == 0) { // at the first pass dat = new double[rawData.size()][(selectedCols == null) ? entries.length : selectedCols.length]; - } + } fillLine(dat, i, entries, selectedCols); } } catch (Exception e) { @@ -270,11 +271,19 @@ public class BasicResourceLoader implements ResourceLoader } if (cols == null) { for (int i=0; i