Proper Population equality predicate.

This commit is contained in:
Marcel Kronfeld 2010-03-02 09:46:00 +00:00
parent 40ba96aab9
commit 476916b270
2 changed files with 57 additions and 33 deletions

View File

@ -4,6 +4,7 @@ package eva2;
* Main product and version information strings. * Main product and version information strings.
* *
* --- Changelog * --- Changelog
* 2.043: Added proper Population equality predicate.
* 2.042: Some bugfixes. Removing dependecy on sun.beans.editors, replaced non-free jpeg-codec. There should * 2.042: Some bugfixes. Removing dependecy on sun.beans.editors, replaced non-free jpeg-codec. There should
* be no more problems on OpenJDK. Added a simple initialization range, especially for use from Matlab. * be no more problems on OpenJDK. Added a simple initialization range, especially for use from Matlab.
* Some restructurings (RNG and Mathematics is now in eva2.tools.math). Some cleanup. * Some restructurings (RNG and Mathematics is now in eva2.tools.math). Some cleanup.
@ -70,7 +71,7 @@ package eva2;
public class EvAInfo { public class EvAInfo {
public static final String productName = "EvA2"; public static final String productName = "EvA2";
public static final String productLongName = "Evolutionary Algorithms Workbench 2"; public static final String productLongName = "Evolutionary Algorithms Workbench 2";
public static final String versionNum = new String ("2.042"); public static final String versionNum = new String ("2.043");
public static final String url = "http://www.ra.cs.uni-tuebingen.de/software/EvA2"; public static final String url = "http://www.ra.cs.uni-tuebingen.de/software/EvA2";
public static final String propertyFile = "resources/EvA2.props"; public static final String propertyFile = "resources/EvA2.props";

View File

@ -45,22 +45,20 @@ import eva2.tools.math.Jama.Matrix;
*/ */
public class Population extends ArrayList implements PopulationInterface, Cloneable, java.io.Serializable { public class Population extends ArrayList implements PopulationInterface, Cloneable, java.io.Serializable {
private transient static boolean TRACE = false;
protected int m_Generation = 0; protected int m_Generation = 0;
protected int m_FunctionCalls = 0; protected int m_FunctionCalls = 0;
protected int m_TargetSize = 50; protected int m_TargetSize = 50;
protected Population m_Archive = null; protected Population m_Archive = null;
PopulationInitMethod initMethod = PopulationInitMethod.individualDefault; PopulationInitMethod initMethod = PopulationInitMethod.individualDefault;
private double[] seedPos = new double[10];
private double aroundDist=0.1;
transient private ArrayList<InterfacePopulationChangedEventListener> listeners = null; transient private ArrayList<InterfacePopulationChangedEventListener> listeners = null;
// transient protected InterfacePopulationChangedEventListener m_Listener = null;
// the evaluation interval at which listeners are notified // the evaluation interval at which listeners are notified
protected int notifyEvalInterval = 0; protected int notifyEvalInterval = 0;
// additional data connected to the population
protected HashMap<String, Object> additionalPopData = null; protected HashMap<String, Object> additionalPopData = null;
// historical best indidivuals may be traced
public static final String funCallIntervalReached = "FunCallIntervalReached";
public static final String populationInitialized = "PopulationReinitOccured";
public static final String nextGenerationPerformed = "NextGenerationPerformed";
boolean useHistory = false; boolean useHistory = false;
private transient ArrayList<AbstractEAIndividual> m_History = new ArrayList<AbstractEAIndividual>(); private transient ArrayList<AbstractEAIndividual> m_History = new ArrayList<AbstractEAIndividual>();
@ -69,15 +67,11 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
// a sorted queue (for efficiency) // a sorted queue (for efficiency)
transient private ArrayList<AbstractEAIndividual> sortedArr = null; transient private ArrayList<AbstractEAIndividual> sortedArr = null;
private int lastFitCrit = -1; private int lastFitCrit = -1;
private AbstractEAIndividualComparator historyComparator = null; // private AbstractEAIndividualComparator historyComparator = null;
private double[] seedPos = new double[10];
private double aroundDist=0.1;
private transient static boolean TRACE = false;
// remember when the last evaluation was performed public static final String funCallIntervalReached = "FunCallIntervalReached";
// private Pair<Integer,Integer> evaluationTimeHashes = null; public static final String populationInitialized = "PopulationReinitOccured";
// remember when the last evaluation was performed public static final String nextGenerationPerformed = "NextGenerationPerformed";
// private int evaluationTimeModCount = -1;
public Population() { public Population() {
if (TRACE) System.err.println("TRACING POP"); if (TRACE) System.err.println("TRACING POP");
@ -159,7 +153,8 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
} }
/** /**
* Takes over all scalar parameters of the given population. * Takes over all scalar parameters of the given population and copies the additional data
* as well as listeners and the seed position. Those are considered functional.
* @param population * @param population
*/ */
public void setSameParams(Population population) { public void setSameParams(Population population) {
@ -169,6 +164,7 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
this.useHistory = population.useHistory; this.useHistory = population.useHistory;
this.notifyEvalInterval = population.notifyEvalInterval; this.notifyEvalInterval = population.notifyEvalInterval;
this.initMethod = population.initMethod; this.initMethod = population.initMethod;
this.aroundDist = population.aroundDist;
if (population.seedPos!=null) this.seedPos = population.seedPos.clone(); if (population.seedPos!=null) this.seedPos = population.seedPos.clone();
// this.m_Listener = population.m_Listener; // this.m_Listener = population.m_Listener;
if (population.listeners != null) this.listeners = (ArrayList<InterfacePopulationChangedEventListener>)population.listeners.clone(); if (population.listeners != null) this.listeners = (ArrayList<InterfacePopulationChangedEventListener>)population.listeners.clone();
@ -182,6 +178,33 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
} }
} }
/**
* Be aware that this does not check all fields. Fields which are not considered
* functional are omitted, such as archive, history and the listeners.
*/
public boolean equals(Object o) {
if (!super.equals(o)) return false;
if (o==null) return false;
if (!(o instanceof Population)) return false;
Population opop = (Population)o;
if (this.m_Generation != opop.m_Generation) return false;
if (this.m_FunctionCalls != opop.m_FunctionCalls) return false;
if (this.m_TargetSize != opop.m_TargetSize) return false;
if (this.useHistory != opop.useHistory) return false;
if (this.notifyEvalInterval != opop.notifyEvalInterval) return false;
if (this.initMethod != opop.initMethod) return false;
if (this.aroundDist != opop.aroundDist) return false;
if ((this.seedPos!=null) ^ (opop.seedPos!=null)) return false;
if ((this.seedPos!=null) && (!this.seedPos.equals(opop.seedPos))) return false;
//listeners may be omitted
if ((this.additionalPopData!=null) ^ (opop.additionalPopData!=null)) return false;
if (this.additionalPopData!=null) for (String s : this.additionalPopData.keySet()) {
if (this.additionalPopData.get(s)==null && (opop.additionalPopData.get(s)!=null)) return false;
if (this.additionalPopData.get(s)!=null && (!this.additionalPopData.get(s).equals(this.additionalPopData))) return false;
}
return true;
}
public void putData(String key, Object value) { public void putData(String key, Object value) {
if (additionalPopData == null) additionalPopData = new HashMap<String, Object>(); if (additionalPopData == null) additionalPopData = new HashMap<String, Object>();
additionalPopData.put(key, value); additionalPopData.put(key, value);
@ -343,26 +366,26 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
/** /**
* Activate or deactivate the history tracking, which stores the best individual in every * Activate or deactivate the history tracking, which stores the best individual in every
* generation in the incrGeneration() method. This uses a default individual comparator * generation in the incrGeneration() method.
* which is based on fitness.
* *
* @param useHist * @param useHist
*/ */
public void setUseHistory(boolean useHist) { public void setUseHistory(boolean useHist) {
this.setUseHistory(useHist, (useHist ? (new AbstractEAIndividualComparator()) : null)); useHistory = useHist;
// this.setUseHistory(useHist, (useHist ? (new AbstractEAIndividualComparator()) : null));
} }
/** // /**
* Activate or deactivate the history tracking, which stores the best individual in every // * Activate or deactivate the history tracking, which stores the best individual in every
* generation in the incrGeneration() method. // * generation in the incrGeneration() method.
* // *
* @param useHist // * @param useHist
* @param histComparator comparator to use for determining the best current individual // * @param histComparator comparator to use for determining the best current individual
*/ // */
public void setUseHistory(boolean useHist, AbstractEAIndividualComparator histComparator) { // public void setUseHistory(boolean useHist, AbstractEAIndividualComparator histComparator) {
useHistory = useHist; // useHistory = useHist;
this.historyComparator = histComparator; // this.historyComparator = histComparator;
} // }
public int getHistoryLength() { public int getHistoryLength() {
if (useHistory) return m_History.size(); if (useHistory) return m_History.size();