From 0b1a7e30e80a26542b1ffc182328ff94a37dc19e Mon Sep 17 00:00:00 2001 From: Marcel Kronfeld Date: Wed, 2 Jun 2010 13:58:37 +0000 Subject: [PATCH] Population in synch with MK branch --- .../server/go/populations/Population.java | 84 ++++++++++++++++--- 1 file changed, 72 insertions(+), 12 deletions(-) diff --git a/src/eva2/server/go/populations/Population.java b/src/eva2/server/go/populations/Population.java index 4d176b51..672ba722 100644 --- a/src/eva2/server/go/populations/Population.java +++ b/src/eva2/server/go/populations/Population.java @@ -1456,7 +1456,10 @@ public class Population extends ArrayList implements PopulationInterface, Clonea } public boolean add(IndividualInterface o) { - return addIndividual((IndividualInterface)o); + if (o==null) { + EVAERROR.errorMsgOnce("Warning: tried to add null as individual, skipping add... (Population.add(IndividualInterface)), possibly multiple cases."); + return false; + } else return addIndividual((IndividualInterface)o); } public Population addToPop(IndividualInterface o) { @@ -1481,17 +1484,20 @@ public class Population extends ArrayList implements PopulationInterface, Clonea public Object set(int index, Object element, int fitIndex) { Object prev = super.set(index, element); modCount++; - if (lastFitCrit==fitIndex && (lastQModCount==(modCount-1))) { - // if nothing happend between this event and the last sorting by the same criterion... - if (!sortedArr.remove(prev)) System.err.println("Error in Population.set!"); - int i=0; - AbstractEAIndividualComparator comp = new AbstractEAIndividualComparator(fitIndex); - while (i0) { - i++; - } - sortedArr.add(i, (AbstractEAIndividual)element); - lastQModCount=modCount; - } + // Nelder Mead somehow managed to produce inconsistent sorted population - some hidden add/replace? +// if (lastFitCrit==fitIndex && (lastQModCount==(modCount-1))) { +// // if nothing happened between this event and the last sorting by the same criterion... +// if (!sortedArr.remove(prev)) { +// System.err.println("Error in Population.set!"); +// } +// int i=0; +// AbstractEAIndividualComparator comp = new AbstractEAIndividualComparator(fitIndex); +// while (i0) { +// i++; +// } +// sortedArr.add(i, (AbstractEAIndividual)element); +// lastQModCount=modCount; +// } return prev; } @@ -1628,6 +1634,15 @@ public class Population extends ArrayList implements PopulationInterface, Clonea return res; } + /** + * Returns the average, minimal and maximal individual distance as diversity measure for the population. + * If the given metric argument is null, the euclidian distance of individual positions is used, which + * presumes that {@link AbstractEAIndividual.getDoublePosition(indy)} returns a valid double position for the + * individuals of the population. + * This is of course rather expensive computationally. + * + * @return the average, minimal and maximal mean distance of individuals in an array of three + */ public static double[] getPopulationMeasures(List pop, InterfaceDistanceMetric metric) { double d; double[] res = new double[3]; @@ -2192,6 +2207,51 @@ public class Population extends ArrayList implements PopulationInterface, Clonea m_History.clear(); } + /** + * Checks if any individual entry is null. If so, false is returned, otherwise true. + * + * @return + */ + public boolean checkNoNullIndy() { + for (int i=0; i