diff --git a/src/eva2/gui/BeanInspector.java b/src/eva2/gui/BeanInspector.java index 449a52e9..312217b6 100644 --- a/src/eva2/gui/BeanInspector.java +++ b/src/eva2/gui/BeanInspector.java @@ -614,6 +614,24 @@ public class BeanInspector { return false; } + /** + * Get the primitive class of a Java primitive encapsulation, or null if not applicable. + * E.g., returns int for Integer, long for Long, Boolean for Boolean etc. + * + * @param cls + * @return + */ + public static Class getJavaPrimitive(Class cls) { + if (cls.isPrimitive()) return cls; + if (cls == Double.class) return double.class; + else if (cls == Integer.class) return int.class; + else if (cls == Boolean.class) return Boolean.class; + else if (cls == Byte.class) return byte.class; + else if (cls == Short.class) return short.class; + else if (cls == Long.class) return long.class; + else if (cls == Float.class) return float.class; + return null; + } /** * Try to convert an object to a destination type, especially for primitive types (int, double etc. * but also Integer, Double etc.). diff --git a/src/eva2/gui/PropertyEditorProvider.java b/src/eva2/gui/PropertyEditorProvider.java index a12c7618..83c1d2c4 100644 --- a/src/eva2/gui/PropertyEditorProvider.java +++ b/src/eva2/gui/PropertyEditorProvider.java @@ -1,6 +1,5 @@ package eva2.gui; -import java.awt.Color; import java.beans.PropertyDescriptor; import java.beans.PropertyEditor; import java.beans.PropertyEditorManager; @@ -108,6 +107,11 @@ public class PropertyEditorProvider { if (editor == null) editor = PropertyEditorManager.findEditor(type); if (TRACE) System.out.println((editor == null ) ? "No editor from PEM by type" : ("Found " + editor.getClass())); + + if (editor == null && (BeanInspector.isJavaPrimitive(value.getClass()))) { + Class prim = BeanInspector.getJavaPrimitive(value.getClass()); + if (prim!=null) editor = PropertyEditorManager.findEditor(prim); + } if ((editor == null) && useDefaultGOE ) { if (type.isArray()) editor = new GenericArrayEditor(); else if (type.isEnum()) editor = new EnumEditor(); diff --git a/src/eva2/gui/PropertySheetPanel.java b/src/eva2/gui/PropertySheetPanel.java index fe24022b..18351af0 100644 --- a/src/eva2/gui/PropertySheetPanel.java +++ b/src/eva2/gui/PropertySheetPanel.java @@ -203,7 +203,7 @@ public class PropertySheetPanel extends JPanel implements PropertyChangeListener int methsFound = 0; // dont loop too long, so count until all found // unhide all properties // TODO this may be superfluous? - boolean[] hideStateBackup = GenericObjectEditor.setHideAllProperties(m_Target.getClass(), false); +// boolean[] hideStateBackup = GenericObjectEditor.setHideAllProperties(m_Target.getClass(), false); // System.out.println("hide stats were: " + BeanInspector.toString(hideStateBackup)); for (int i = 0; i < m_Methods.length; i++) { String name = m_Methods[i].getDisplayName(); @@ -229,7 +229,7 @@ public class PropertySheetPanel extends JPanel implements PropertyChangeListener if (methsFound == 3) break; // small speed-up } // end for (int i = 0; i < m_Methods.length; i++) { // restore hide states of all properties - GenericObjectEditor.setHideProperties(m_Target.getClass(), hideStateBackup); +// GenericObjectEditor.setHideProperties(m_Target.getClass(), hideStateBackup); // Now lets search for the individual properties, their // values, views and editors... diff --git a/src/eva2/server/go/populations/Population.java b/src/eva2/server/go/populations/Population.java index 0c0221a1..329c7c57 100644 --- a/src/eva2/server/go/populations/Population.java +++ b/src/eva2/server/go/populations/Population.java @@ -17,6 +17,7 @@ import eva2.server.go.PopulationInterface; import eva2.server.go.individuals.AbstractEAIndividual; import eva2.server.go.individuals.AbstractEAIndividualComparator; import eva2.server.go.individuals.InterfaceDataTypeDouble; +import eva2.server.go.individuals.InterfaceGAIndividual; import eva2.server.go.operators.distancemetric.EuclideanMetric; import eva2.server.go.operators.distancemetric.InterfaceDistanceMetric; import eva2.server.go.operators.distancemetric.PhenotypeMetric; @@ -55,6 +56,8 @@ public class Population extends ArrayList implements PopulationInterface, Clonea protected Population m_Archive = null; PopulationInitMethod initMethod = PopulationInitMethod.individualDefault; private double[] seedPos = new double[10]; + private Pair seedCardinality=new Pair(5,1); + private double aroundDist=0.1; transient private ArrayList listeners = null; // the evaluation interval at which listeners are notified @@ -173,6 +176,7 @@ public class Population extends ArrayList implements PopulationInterface, Clonea this.notifyEvalInterval = population.notifyEvalInterval; this.initMethod = population.initMethod; this.aroundDist = population.aroundDist; + this.seedCardinality = population.seedCardinality.clone(); if (population.seedPos!=null) this.seedPos = population.seedPos.clone(); // this.m_Listener = population.m_Listener; if (population.listeners != null) this.listeners = (ArrayList)population.listeners.clone(); @@ -287,6 +291,9 @@ public class Population extends ArrayList implements PopulationInterface, Clonea PostProcess.createPopInSubRange(this, aroundDist, this.getTargetSize(), template); } else System.err.println("Warning, skipping seed initialization: too small individual seed!"); break; + case binCardinality: + createBinCardinality(this, true, seedCardinality.head(), seedCardinality.tail()); + break; } firePropertyChangedEvent(Population.populationInitialized); } @@ -356,9 +363,7 @@ public class Population extends ArrayList implements PopulationInterface, Clonea return; } AbstractEAIndividual template = pop.getEAIndividual(0); - if (fillPop && (pop.size()0) curCard += (int)Math.round(RNG.gaussianDouble((double)stdDev)); + curCard=Math.max(0, Math.min(curCard, gaIndy.getGenotypeLength())); +// System.out.println("Current cardinality: " + curCard); + gaIndy.SetBGenotype(RNG.randomBitSet(curCard, gaIndy.getGenotypeLength())); +// System.out.println(pop.getEAIndividual(i)); + } + } else { + System.err.println("Error: InterfaceGAIndividual required for binary cardinality initialization!"); + } + } + + /** + * Fill the population up to the target size with clones of a template individual. + * + * @param template a template individual used to fill the population + */ + public void fill(AbstractEAIndividual template) { + if (this.size() getSeedCardinality() { + return seedCardinality; + } + public void setSeedCardinality(Pair seedCardinality) { + this.seedCardinality = seedCardinality; + } + public String seedCardinalityTipText() { + return "The initial cardinality for binary genotype individuals, given as pair of mean and std.dev."; + } + // /** // * Mark the population at the current state as evaluated. Changes to the modCount or hashes of individuals // * will invalidate the mark. diff --git a/src/eva2/server/go/populations/PopulationInitMethod.java b/src/eva2/server/go/populations/PopulationInitMethod.java index 8852e849..4cda571c 100644 --- a/src/eva2/server/go/populations/PopulationInitMethod.java +++ b/src/eva2/server/go/populations/PopulationInitMethod.java @@ -1,5 +1,5 @@ package eva2.server.go.populations; public enum PopulationInitMethod { - individualDefault, randomLatinHypercube, aroundSeed; + individualDefault, randomLatinHypercube, aroundSeed, binCardinality; } diff --git a/src/eva2/tools/Pair.java b/src/eva2/tools/Pair.java index eb4d4e64..0260537d 100644 --- a/src/eva2/tools/Pair.java +++ b/src/eva2/tools/Pair.java @@ -26,6 +26,8 @@ public class Pair implements Serializable { this.tail = tail; } + public Pair() { + } /** * * @return @@ -68,7 +70,19 @@ public class Pair implements Serializable { public S head() { return head; } - + + /** + * + * @return + */ + public S getHead() { + return head; + } + + public String headTipText() { + return "First pair entry"; + } + /** * * @return @@ -77,6 +91,14 @@ public class Pair implements Serializable { return tail; } + public T getTail() { + return tail; + } + + public String tailTipText() { + return "Last pair entry"; + } + /* * (non-Javadoc) * @@ -87,6 +109,10 @@ public class Pair implements Serializable { return "(" + head.toString() + "," + tail.toString() + ")"; } + public String getName() { + return this.toString(); + } + /** * * @param head diff --git a/src/eva2/tools/math/RNG.java b/src/eva2/tools/math/RNG.java index 24d59f87..7f121ce3 100644 --- a/src/eva2/tools/math/RNG.java +++ b/src/eva2/tools/math/RNG.java @@ -1,6 +1,7 @@ package eva2.tools.math; import java.util.ArrayList; +import java.util.BitSet; import java.util.Random; @@ -98,32 +99,6 @@ public class RNG { return result; } - /** - * This method returns a random permutation of n int values - * - * @param length - * The number of int values - * @return The permutation [0-length-1] - */ - public static int[] randomPermutation(int length) { - boolean[] validList = new boolean[length]; - int[] result = new int[length]; - int index; - for (int i = 0; i < validList.length; i++) - validList[i] = true; - for (int i = 0; i < result.length; i++) { - index = randomInt(0, length - 1); - while (!validList[index]) { - index++; - if (index == length) - index = 0; - } - validList[index] = false; - result[i] = index; - } - return result; - } - /** * This method returns a random permutation of n int values * @@ -310,6 +285,29 @@ public class RNG { return randomInt(); } + /** + * Create a random bitset with given cardinality and lengths, + */ + public static BitSet randomBitSet(int cardinality, int length) { + BitSet bs = new BitSet(length); + int[] perm = randomPerm(length); + for (int i=0; i