Merging mk branch rev 130.

This commit is contained in:
Marcel Kronfeld 2008-08-04 14:59:40 +00:00
parent 99e5ca1450
commit 18b63d9d97
13 changed files with 485 additions and 394 deletions

View File

@ -16,9 +16,11 @@ import eva2.server.go.populations.Population;
import eva2.server.modules.GOParameters; import eva2.server.modules.GOParameters;
import eva2.server.modules.Processor; import eva2.server.modules.Processor;
import eva2.server.stat.AbstractStatistics; import eva2.server.stat.AbstractStatistics;
import eva2.server.stat.InterfaceStatistics;
import eva2.server.stat.StatisticsDummy; import eva2.server.stat.StatisticsDummy;
import eva2.server.stat.InterfaceTextListener; import eva2.server.stat.InterfaceTextListener;
import eva2.server.stat.StatisticsStandalone; import eva2.server.stat.StatisticsStandalone;
import eva2.server.stat.StatsParameter;
/** /**
@ -77,6 +79,10 @@ public class OptimizerRunnable implements Runnable {
return proc.getGOParams(); return proc.getGOParams();
} }
public InterfaceStatistics getStats() {
return proc.getStatistics();
}
public void setTextListener(InterfaceTextListener lsnr) { public void setTextListener(InterfaceTextListener lsnr) {
proc.getStatistics().removeTextListener(listener); proc.getStatistics().removeTextListener(listener);
this.listener = lsnr; this.listener = lsnr;
@ -175,7 +181,9 @@ public class OptimizerRunnable implements Runnable {
} }
/** /**
* Set the verbosity level in the statistics module to the given value. See StatsParameter. * Set the verbosity level in the statistics module to the given value.
*
* @see StatsParameter
* @param vLev * @param vLev
*/ */
public void setVerbosityLevel(int vLev) { public void setVerbosityLevel(int vLev) {
@ -183,4 +191,35 @@ public class OptimizerRunnable implements Runnable {
proc.getStatistics().getStatisticsParameter().getOutputVerbosity().setSelectedTag(vLev); proc.getStatistics().getStatisticsParameter().getOutputVerbosity().setSelectedTag(vLev);
} else System.err.println("Invalid verbosity leveln in OptimizerRunnable.setVerbosityLevel!"); } else System.err.println("Invalid verbosity leveln in OptimizerRunnable.setVerbosityLevel!");
} }
/**
* Set the output direction in the statistics module.
*
* @see StatsParameter
* @param outp
*/
public void setOutputTo(int outp) {
((StatsParameter)proc.getStatistics().getStatisticsParameter()).setOutputTo(outp);
}
/**
* Set the number of multiruns in the statistics module.
* @param multis
*/
public void setMultiRuns(int multis) {
((AbstractStatistics)proc.getStatistics()).getStatisticsParameter().setMultiRuns(multis);
}
/**
* Set the additional info output.
* @see StatsParameter
* @param addInfo
*/
public void setOutputAdditionalInfo(boolean addInfo) {
((AbstractStatistics)proc.getStatistics()).getStatisticsParameter().setOutputAdditionalInfo(addInfo);
}
// public void configureStats(int verbosityLevel, int outputDirection, int multiRuns, boolean additionalInfo) {
// asdf
// }
} }

View File

@ -3,6 +3,7 @@ package eva2.server.go.individuals;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.BitSet; import java.util.BitSet;
import java.util.HashMap;
import java.util.List; import java.util.List;
import wsi.ra.math.RNG; import wsi.ra.math.RNG;
@ -57,8 +58,9 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
public double m_MutationProbability = 0.2; public double m_MutationProbability = 0.2;
protected InterfaceMutation m_MutationOperator = new NoMutation(); protected InterfaceMutation m_MutationOperator = new NoMutation();
protected InterfaceCrossover m_CrossoverOperator = new NoCrossover(); protected InterfaceCrossover m_CrossoverOperator = new NoCrossover();
protected String[] m_Identifiers = new String[m_ObjectIncrement]; // protected String[] m_Identifiers = new String[m_ObjectIncrement];
protected Object[] m_Objects = new Object[m_ObjectIncrement]; // protected Object[] m_Objects = new Object[m_ObjectIncrement];
protected HashMap<String,Object> m_dataHash = new HashMap<String,Object>();
public AbstractEAIndividual() { public AbstractEAIndividual() {
m_IDcounter++; m_IDcounter++;
@ -111,8 +113,7 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
*/ */
public void cloneAEAObjects(AbstractEAIndividual individual) { public void cloneAEAObjects(AbstractEAIndividual individual) {
// m_Name = new String(individual.m_Name); // m_Name = new String(individual.m_Name);
m_Identifiers = new String[individual.m_Identifiers.length]; m_dataHash = (HashMap<String,Object>)(individual.m_dataHash.clone());
m_Objects = new Object[individual.m_Identifiers.length];
m_ConstraintViolation = individual.m_ConstraintViolation; m_ConstraintViolation = individual.m_ConstraintViolation;
m_AreaConst4ParallelViolated = individual.m_AreaConst4ParallelViolated; m_AreaConst4ParallelViolated = individual.m_AreaConst4ParallelViolated;
m_Marked = individual.m_Marked; m_Marked = individual.m_Marked;
@ -122,8 +123,6 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
parentTree = new AbstractEAIndividual[individual.parentTree.length]; parentTree = new AbstractEAIndividual[individual.parentTree.length];
for (int i=0; i<parentTree.length; i++) parentTree[i] = individual.parentTree[i]; for (int i=0; i<parentTree.length; i++) parentTree[i] = individual.parentTree[i];
} }
System.arraycopy(individual.m_Identifiers,0,m_Identifiers,0,individual.m_Identifiers.length);
System.arraycopy(individual.m_Objects,0,m_Objects,0,individual.m_Objects.length);
} }
/** This method allows you to compare two individuals /** This method allows you to compare two individuals
@ -199,11 +198,12 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
// } // }
} }
/** Returns a hash code value for the object. This method is supported for the /**
* Returns a hash code value for the object. This method is supported for the
* benefit of hashtables such as those provided by java.util.Hashtable * benefit of hashtables such as those provided by java.util.Hashtable
*/ */
public int hashCode() { public int hashCode() {
String t = this.getStringRepresentation(); String t = AbstractEAIndividual.getDefaultStringRepresentation(this);
return t.hashCode(); return t.hashCode();
} }
@ -412,8 +412,7 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
/** This method allows you to reset the user data /** This method allows you to reset the user data
*/ */
public void resetUserData() { public void resetUserData() {
this.m_Identifiers = new String[m_ObjectIncrement]; m_dataHash.clear();
this.m_Objects = new Object[m_ObjectIncrement];
} }
/** This method allows you to reset the level of constraint violation for an /** This method allows you to reset the level of constraint violation for an
@ -741,28 +740,7 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
* @param obj The object that is to be stored. * @param obj The object that is to be stored.
*/ */
public void SetData(String name, Object obj) { public void SetData(String name, Object obj) {
for (int i = 0; i < this.m_Identifiers.length; i++) { m_dataHash.put(name, obj);
if (this.m_Identifiers[i] == null) {
// Identifier has not been found, but there is empty space to store it
this.m_Identifiers[i] = name;
this.m_Objects[i] = obj;
return;
}
if (this.m_Identifiers[i].equalsIgnoreCase(name)) {
this.m_Objects[i] = obj;
return;
}
}
// The identifier could not be found and there is not enough space
String[] tmpId = new String[this.m_Identifiers.length + this.m_ObjectIncrement];
Object[] tmpOb = new Object[this.m_Identifiers.length + this.m_ObjectIncrement];
for (int i = 0; i < this.m_Identifiers.length; i++) {
tmpId[i] = this.m_Identifiers[i];
tmpOb[i] = this.m_Objects[i];
}
this.m_Identifiers = tmpId;
this.m_Objects = tmpOb;
this.SetData(name, obj);
} }
/** This method will return a stored object. /** This method will return a stored object.
@ -770,19 +748,13 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
* @return Object * @return Object
*/ */
public Object getData(String name) { public Object getData(String name) {
if (name.equalsIgnoreCase("SelectionProbability")) return this.getSelectionProbability(); // if (name.equalsIgnoreCase("SelectionProbability")) return this.getSelectionProbability();
if (name.equalsIgnoreCase("SelectionProbabilityArray")) return this.getSelectionProbability(); // if (name.equalsIgnoreCase("SelectionProbabilityArray")) return this.getSelectionProbability();
if (name.equalsIgnoreCase("Fitness")) return this.getFitness(); // if (name.equalsIgnoreCase("Fitness")) return this.getFitness();
if (name.equalsIgnoreCase("FitnessArray")) return this.getFitness(); // if (name.equalsIgnoreCase("FitnessArray")) return this.getFitness();
for (int i = 0; i < this.m_Identifiers.length; i++) { Object data = m_dataHash.get(name);
if (this.m_Identifiers[i] == null) { if (data==null) System.err.println("Warning: data key " + name + " unknown!");
return null; return data;
}
if (this.m_Identifiers[i].equalsIgnoreCase(name)) {
return this.m_Objects[i];
}
}
return null;
} }
/** This method will return a string description of the Individal /** This method will return a string description of the Individal
@ -799,6 +771,8 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
* @return The description. * @return The description.
*/ */
public static String getDefaultStringRepresentation(AbstractEAIndividual individual) { public static String getDefaultStringRepresentation(AbstractEAIndividual individual) {
// Note that changing this method might change the hashcode of an individual
// which might interfere with some functionality.
StringBuffer sb = new StringBuffer(getDefaultDataString(individual)); StringBuffer sb = new StringBuffer(getDefaultDataString(individual));
sb.append(", fitness: "); sb.append(", fitness: ");
@ -818,6 +792,8 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
* @return * @return
*/ */
public static String getDefaultDataString(IndividualInterface individual) { public static String getDefaultDataString(IndividualInterface individual) {
// Note that changing this method might change the hashcode of an individual
// which might interfere with some functionality.
return getDefaultDataString(individual, "; "); return getDefaultDataString(individual, "; ");
} }
@ -829,6 +805,8 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
* @return * @return
*/ */
public static String getDefaultDataString(IndividualInterface individual, String separator) { public static String getDefaultDataString(IndividualInterface individual, String separator) {
// Note that changing this method might change the hashcode of an individual
// which might interfere with some functionality.
if (individual == null) return "null"; if (individual == null) return "null";
StringBuffer sb = new StringBuffer(""); StringBuffer sb = new StringBuffer("");
char left = '['; char left = '[';

View File

@ -17,12 +17,13 @@ import eva2.server.go.operators.distancemetric.InterfaceDistanceMetric;
import eva2.server.go.operators.distancemetric.PhenotypeMetric; import eva2.server.go.operators.distancemetric.PhenotypeMetric;
import eva2.tools.EVAERROR; import eva2.tools.EVAERROR;
import eva2.tools.Mathematics; import eva2.tools.Mathematics;
import eva2.tools.Pair;
/** This is a basic implementation for a EA Population. /** This is a basic implementation for a EA Population.
* Copyright: Copyright (c) 2003 * Copyright: Copyright (c) 2003
* Company: University of Tuebingen, Computer Architecture * Company: University of Tuebingen, Computer Architecture
* @author Felix Streichert * @author Felix Streichert, Marcel Kronfeld
* @version: $Revision: 307 $ * @version: $Revision: 307 $
* $Date: 2007-12-04 14:31:47 +0100 (Tue, 04 Dec 2007) $ * $Date: 2007-12-04 14:31:47 +0100 (Tue, 04 Dec 2007) $
* $Author: mkron $ * $Author: mkron $
@ -34,9 +35,11 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
protected int m_FunctionCalls = 0; protected int m_FunctionCalls = 0;
protected int m_Size = 50; protected int m_Size = 50;
protected Population m_Archive = null; protected Population m_Archive = null;
transient private ArrayList<AbstractEAIndividual> sortedArr = null; transient private ArrayList<AbstractEAIndividual> sortedArr = null;
private int lastQModCount = -1;
transient protected InterfacePopulationChangedEventListener m_Listener = null; transient protected InterfacePopulationChangedEventListener m_Listener = null;
// the evaluation interval at which listeners are notified
protected int notifyEvalInterval = 0; protected int notifyEvalInterval = 0;
protected HashMap<String, Object> additionalPopData = null; protected HashMap<String, Object> additionalPopData = null;
@ -45,6 +48,13 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
boolean useHistory = false; boolean useHistory = false;
public ArrayList<AbstractEAIndividual> m_History = new ArrayList<AbstractEAIndividual>(); public ArrayList<AbstractEAIndividual> m_History = new ArrayList<AbstractEAIndividual>();
// remember when the last sorted queue was prepared
private int lastQModCount = -1;
// remember when the last evaluation was performed
private Pair<Integer,Integer> evaluationTimeHashes = null;
// remember when the last evaluation was performed
private int evaluationTimeModCount = -1;
public Population() { public Population() {
} }
@ -129,6 +139,8 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
this.m_History = new ArrayList(); this.m_History = new ArrayList();
this.m_Generation = 0; this.m_Generation = 0;
this.m_FunctionCalls = 0; this.m_FunctionCalls = 0;
evaluationTimeHashes = null;
evaluationTimeModCount = -1;
if (this.m_Archive != null) { if (this.m_Archive != null) {
this.m_Archive.clear(); this.m_Archive.clear();
this.m_Archive.init(); this.m_Archive.init();
@ -178,7 +190,7 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
* *
* @param d The number of function calls to increment. * @param d The number of function calls to increment.
*/ */
public void incrFunctionCallsby(int d) { public void incrFunctionCallsBy(int d) {
if (doEvalNotify()) { if (doEvalNotify()) {
// System.out.println("checking funcall event..."); // System.out.println("checking funcall event...");
int nextStep; // next interval boundary int nextStep; // next interval boundary
@ -271,7 +283,7 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
} }
/** /**
* Resets the fitness to the maximum possible value for the given individual. * Resets the fitnes to the maximum possible value for the given individual.
* *
* @param indy an individual whose fitness will be reset * @param indy an individual whose fitness will be reset
*/ */
@ -915,4 +927,39 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
public void setNotifyEvalInterval(int notifyEvalInterval) { public void setNotifyEvalInterval(int notifyEvalInterval) {
this.notifyEvalInterval = notifyEvalInterval; this.notifyEvalInterval = notifyEvalInterval;
} }
/**
* Check whether the population at the current state has been marked as
* evaluated. This allows to avoid double evaluations.
*
* @return true if the population has been marked as evaluated in its current state, else false
*/
public boolean isEvaluated() {
Pair<Integer,Integer> hashes = getIndyHashSums();
if (evaluationTimeHashes == null) return false;
else return (hashes.head()==evaluationTimeHashes.head() && (hashes.tail() == evaluationTimeHashes.tail()) && (evaluationTimeModCount == modCount));
}
/**
* Mark the population at the current state as evaluated. Changes to the modCount or hashes of individuals
* will invalidate the mark.
*
* @see isEvaluated()
*/
public void setEvaluated() {
evaluationTimeModCount = modCount;
evaluationTimeHashes = getIndyHashSums();
}
private Pair<Integer,Integer> getIndyHashSums() {
int hashSum = 0, hashSumAbs = 0;
int hash;
for (int i=0; i<size(); i++) {
hash = get(i).hashCode();
hashSum += hash;
hashSumAbs += Math.abs(hash);
}
return new Pair(hashSum, hashSumAbs);
}
} }

View File

@ -53,16 +53,21 @@ public abstract class AbstractOptimizationProblem implements InterfaceOptimizati
public void evaluate(Population population) { public void evaluate(Population population) {
AbstractEAIndividual tmpIndy; AbstractEAIndividual tmpIndy;
// @todo This is the position to implement a granular if (population.isEvaluated()) {
// @todo paralliziation scheme System.err.println("Population evaluation seems not required!");
evaluatePopulationStart(population); } else {
for (int i = 0; i < population.size(); i++) { // @todo This is the position to implement a granular
tmpIndy = (AbstractEAIndividual) population.get(i); // @todo paralliziation scheme
tmpIndy.resetConstraintViolation(); evaluatePopulationStart(population);
this.evaluate(tmpIndy); for (int i = 0; i < population.size(); i++) {
population.incrFunctionCalls(); tmpIndy = (AbstractEAIndividual) population.get(i);
tmpIndy.resetConstraintViolation();
this.evaluate(tmpIndy);
population.incrFunctionCalls();
}
evaluatePopulationEnd(population);
population.setEvaluated();
} }
evaluatePopulationEnd(population);
} }
/** /**

View File

@ -425,7 +425,7 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
} }
// reinit the surplus individuals and add these new individuals to undifferentiated // reinit the surplus individuals and add these new individuals to undifferentiated
m_Undifferentiated.addPopulation(this.initializeIndividuals(reinitCount)); m_Undifferentiated.addPopulation(this.initializeIndividuals(reinitCount));
m_Undifferentiated.incrFunctionCallsby(reinitCount); m_Undifferentiated.incrFunctionCallsBy(reinitCount);
m_Undifferentiated.setPopulationSize(this.m_Undifferentiated.getPopulationSize()+reinitCount); m_Undifferentiated.setPopulationSize(this.m_Undifferentiated.getPopulationSize()+reinitCount);
// if (this.m_Debug) { // if (this.m_Debug) {
// System.out.println("Undiff.Size: " + this.m_Undifferentiated.size() +"/"+this.m_Undifferentiated.getPopulationSize()); // System.out.println("Undiff.Size: " + this.m_Undifferentiated.size() +"/"+this.m_Undifferentiated.getPopulationSize());
@ -454,12 +454,12 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
////////////////////// //////////////////////
if (!isActive(m_Undifferentiated)) { if (!isActive(m_Undifferentiated)) {
if (TRACE) System.out.println("Inactive Undiff-pop, adding " + m_Undifferentiated.size() + " fun calls..."); if (TRACE) System.out.println("Inactive Undiff-pop, adding " + m_Undifferentiated.size() + " fun calls...");
m_Undifferentiated.incrFunctionCallsby(m_Undifferentiated.size()); m_Undifferentiated.incrFunctionCallsBy(m_Undifferentiated.size());
} }
if (this.m_Undifferentiated.getFunctionCalls() % this.m_PopulationSize != 0) { if (this.m_Undifferentiated.getFunctionCalls() % this.m_PopulationSize != 0) {
if (TRACE) System.out.println("### mismatching number of funcalls, inactive species? Correcting by " + (m_PopulationSize - (m_Undifferentiated.getFunctionCalls() % m_PopulationSize))); if (TRACE) System.out.println("### mismatching number of funcalls, inactive species? Correcting by " + (m_PopulationSize - (m_Undifferentiated.getFunctionCalls() % m_PopulationSize)));
if (TRACE) System.out.println("### undiff " + ((isActive(m_Undifferentiated)) ? "active!" : "inactive!")); if (TRACE) System.out.println("### undiff " + ((isActive(m_Undifferentiated)) ? "active!" : "inactive!"));
m_Undifferentiated.incrFunctionCallsby(m_PopulationSize - (m_Undifferentiated.getFunctionCalls() % m_PopulationSize)); m_Undifferentiated.incrFunctionCallsBy(m_PopulationSize - (m_Undifferentiated.getFunctionCalls() % m_PopulationSize));
} else if (TRACE) System.out.println("### undiff active: " + isActive(m_Undifferentiated)); } else if (TRACE) System.out.println("### undiff active: " + isActive(m_Undifferentiated));
// possible species differentiation and convergence // possible species differentiation and convergence

View File

@ -166,7 +166,7 @@ public class ClusteringHillClimbing implements InterfacePopulationChangedEventLi
// reset population while keeping function calls etc. // reset population while keeping function calls etc.
m_Population.clear(); m_Population.clear();
m_Population.addPopulation(tmpPop); m_Population.addPopulation(tmpPop);
m_Population.incrFunctionCallsby(tmpPop.size()); m_Population.incrFunctionCallsBy(tmpPop.size());
} else { // decrease step size } else { // decrease step size
mutator.setSigma(mutator.getSigma()*reduceFactor); mutator.setSigma(mutator.getSigma()*reduceFactor);

View File

@ -63,8 +63,8 @@ public interface InterfaceOptimizer {
* Return all found solutions (local optima) if they are not contained in the current population. Be * Return all found solutions (local optima) if they are not contained in the current population. Be
* sure to set the Population properties, especially function calls and generation, with respect * sure to set the Population properties, especially function calls and generation, with respect
* to the ongoing optimization. * to the ongoing optimization.
* May return the same as getPopulation if the optimizer makes no distinction, i.e. does not collect * May return the the same set as getPopulation if the optimizer makes no distinction, i.e. does
* solutions outside the current population. * not collect solutions outside the current population.
* *
* @return A population of found solutions. * @return A population of found solutions.
*/ */

View File

@ -133,7 +133,7 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
for (int i = 0; i < this.m_Islands.length; i++) { for (int i = 0; i < this.m_Islands.length; i++) {
pop = (Population)this.m_Islands[i].getPopulation().clone(); pop = (Population)this.m_Islands[i].getPopulation().clone();
this.m_Population.addPopulation(pop); this.m_Population.addPopulation(pop);
this.m_Population.incrFunctionCallsby(pop.getFunctionCalls()); this.m_Population.incrFunctionCallsBy(pop.getFunctionCalls());
} }
this.firePropertyChangedEvent("NextGenerationPerformed", this.m_Optimizer.getPopulation()); this.firePropertyChangedEvent("NextGenerationPerformed", this.m_Optimizer.getPopulation());
} }
@ -192,7 +192,7 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
for (int i = 0; i < this.m_Islands.length; i++) { for (int i = 0; i < this.m_Islands.length; i++) {
pop = (Population)this.m_Islands[i].getPopulation().clone(); pop = (Population)this.m_Islands[i].getPopulation().clone();
this.m_Population.addPopulation(pop); this.m_Population.addPopulation(pop);
this.m_Population.incrFunctionCallsby(pop.getFunctionCalls()); this.m_Population.incrFunctionCallsBy(pop.getFunctionCalls());
} }
this.firePropertyChangedEvent("NextGenerationPerformed", this.m_Optimizer.getPopulation()); this.firePropertyChangedEvent("NextGenerationPerformed", this.m_Optimizer.getPopulation());
} }
@ -246,7 +246,7 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
for (int i = 0; i < this.m_Islands.length; i++) { for (int i = 0; i < this.m_Islands.length; i++) {
pop = (Population)this.m_Islands[i].getPopulation().clone(); pop = (Population)this.m_Islands[i].getPopulation().clone();
this.m_Population.addPopulation(pop); this.m_Population.addPopulation(pop);
this.m_Population.incrFunctionCallsby(pop.getFunctionCalls()); this.m_Population.incrFunctionCallsBy(pop.getFunctionCalls());
} }
// System.out.println("Fitnesscalls :" + this.m_Population.getFunctionCalls()); // System.out.println("Fitnesscalls :" + this.m_Population.getFunctionCalls());
this.firePropertyChangedEvent("NextGenerationPerformed", this.m_Optimizer.getPopulation()); this.firePropertyChangedEvent("NextGenerationPerformed", this.m_Optimizer.getPopulation());

View File

@ -107,7 +107,7 @@ public class SteadyStateGA implements InterfaceOptimizer, java.io.Serializable {
public void optimize() { public void optimize() {
for (int i = 0; i < this.m_Population.size(); i++) this.generateChildren(); for (int i = 0; i < this.m_Population.size(); i++) this.generateChildren();
this.m_Population.incrFunctionCallsby(this.m_Population.size()); this.m_Population.incrFunctionCallsBy(this.m_Population.size());
this.m_Population.incrGeneration(); this.m_Population.incrGeneration();
this.firePropertyChangedEvent("NextGenerationPerformed"); this.firePropertyChangedEvent("NextGenerationPerformed");
} }

View File

@ -162,11 +162,11 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
// first collect all the data // first collect all the data
pop = (Population)this.m_MOOptimizer.getPopulation().clone(); pop = (Population)this.m_MOOptimizer.getPopulation().clone();
this.m_Population.addPopulation(pop); this.m_Population.addPopulation(pop);
this.m_Population.incrFunctionCallsby(pop.getFunctionCalls()); this.m_Population.incrFunctionCallsBy(pop.getFunctionCalls());
for (int i = 0; i < this.m_SOOptimizers.length; i++) { for (int i = 0; i < this.m_SOOptimizers.length; i++) {
pop = (Population)this.m_SOOptimizers[i].getPopulation().clone(); pop = (Population)this.m_SOOptimizers[i].getPopulation().clone();
this.m_Population.addPopulation(pop); this.m_Population.addPopulation(pop);
this.m_Population.incrFunctionCallsby(pop.getFunctionCalls()); this.m_Population.incrFunctionCallsBy(pop.getFunctionCalls());
} }
oldFunctionCalls = this.m_Population.getFunctionCalls(); oldFunctionCalls = this.m_Population.getFunctionCalls();
this.m_Problem.evaluate(this.m_Population); this.m_Problem.evaluate(this.m_Population);

View File

@ -150,8 +150,9 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
if (Mathematics.norm(bestCurrentIndividual.getFitness()) < this.m_StatsParams.getConvergenceRateThreshold()) { if (Mathematics.norm(bestCurrentIndividual.getFitness()) < this.m_StatsParams.getConvergenceRateThreshold()) {
convergenceCnt++; convergenceCnt++;
} }
if (printRunStoppedVerbosity()) printToTextListener(" Best solution: " + BeanInspector.toString(bestCurrentIndividual) + "\n"); if (printRunStoppedVerbosity()) printToTextListener(" Run best individual : " + BeanInspector.toString(bestCurrentIndividual) + "\n");
if (printRunStoppedVerbosity()) printToTextListener(AbstractEAIndividual.getDefaultDataString(bestCurrentIndividual) + "\n"); if (printRunStoppedVerbosity()) printToTextListener(" run solution data : " + AbstractEAIndividual.getDefaultDataString(bestCurrentIndividual) + "\n");
if (printRunStoppedVerbosity()) printToTextListener(" run solution fit : " + BeanInspector.toString(bestCurrentIndividual.getFitness()) + "\n");
} }
if (currentBestFit!= null) { if (currentBestFit!= null) {
if (printRunStoppedVerbosity()) printToTextListener(" Best Fitness: " + BeanInspector.toString(currentBestFit) + "\n"); if (printRunStoppedVerbosity()) printToTextListener(" Best Fitness: " + BeanInspector.toString(currentBestFit) + "\n");
@ -162,9 +163,9 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
protected void finalizeOutput() { protected void finalizeOutput() {
if (printFinalVerbosity()) printToTextListener("*******\n Runs performed: " + optRunsPerformed + ", reached target " + convergenceCnt + " times with threshold " + m_StatsParams.getConvergenceRateThreshold() + ", rate " + convergenceCnt/(double)m_StatsParams.getMultiRuns() + '\n'); if (printFinalVerbosity()) printToTextListener("*******\n Runs performed: " + optRunsPerformed + ", reached target " + convergenceCnt + " times with threshold " + m_StatsParams.getConvergenceRateThreshold() + ", rate " + convergenceCnt/(double)m_StatsParams.getMultiRuns() + '\n');
if (printFinalVerbosity()) printToTextListener(" Average function calls: " + (functionCallSum/optRunsPerformed) + "\n"); if (printFinalVerbosity()) printToTextListener(" Average function calls: " + (functionCallSum/optRunsPerformed) + "\n");
if (printFinalVerbosity() && (bestIndividualAllover != null)) printToTextListener("Best overall individual: " + BeanInspector.toString(bestIndividualAllover) + '\n'); if (printFinalVerbosity() && (bestIndividualAllover != null)) printToTextListener(" Overall best individual : " + BeanInspector.toString(bestIndividualAllover) + '\n');
if (printFinalVerbosity() && (bestIndividualAllover != null)) printToTextListener(" solution : " + AbstractEAIndividual.getDefaultDataString(bestIndividualAllover) + '\n'); if (printFinalVerbosity() && (bestIndividualAllover != null)) printToTextListener(" overall solution data : " + AbstractEAIndividual.getDefaultDataString(bestIndividualAllover) + '\n');
if (printFinalVerbosity() && (bestIndividualAllover != null)) printToTextListener(" fitness : " + BeanInspector.toString(bestIndividualAllover.getFitness()) + '\n'); if (printFinalVerbosity() && (bestIndividualAllover != null)) printToTextListener(" overall solution fit : " + BeanInspector.toString(bestIndividualAllover.getFitness()) + '\n');
if (refineMultiRuns && (optRunsPerformed>1) && (meanCollection != null)) { if (refineMultiRuns && (optRunsPerformed>1) && (meanCollection != null)) {
if (printFinalVerbosity()) printToTextListener("Averaged performance:\n"); if (printFinalVerbosity()) printToTextListener("Averaged performance:\n");
for (int i=0; i<meanCollection.size(); i++) divideMean(meanCollection.get(i), optRunsPerformed); for (int i=0; i<meanCollection.size(); i++) divideMean(meanCollection.get(i), optRunsPerformed);

View File

@ -29,318 +29,322 @@ import eva2.tools.Tag;
* *
*/ */
public class StatsParameter implements InterfaceStatisticsParameter, Serializable { public class StatsParameter implements InterfaceStatisticsParameter, Serializable {
public final static int PLOT_BEST = 0; public final static int PLOT_BEST = 0;
public final static int PLOT_WORST = 1; public final static int PLOT_WORST = 1;
public final static int PLOT_BEST_AND_WORST = 2; public final static int PLOT_BEST_AND_WORST = 2;
public final static int PLOT_BEST_AND_MEASURES = 3; public final static int PLOT_BEST_AND_MEASURES = 3;
public final static Tag[] TAGS_PLOT_FITNESS = { public final static Tag[] TAGS_PLOT_FITNESS = {
new Tag(PLOT_BEST, "plot best fitness"), new Tag(PLOT_BEST, "plot best fitness"),
new Tag(PLOT_WORST, "plot worst fitness"), new Tag(PLOT_WORST, "plot worst fitness"),
new Tag(PLOT_BEST_AND_WORST, "both best and worst"), new Tag(PLOT_BEST_AND_WORST, "both best and worst"),
new Tag(PLOT_BEST_AND_MEASURES, "both best and population measures") new Tag(PLOT_BEST_AND_MEASURES, "both best and population measures")
}; };
public final static int VERBOSITY_NONE = 0;
public final static int VERBOSITY_FINAL = 1;
public final static int VERBOSITY_KTH_IT = 2;
public final static int VERBOSITY_ALL = 3;
SelectedTag outputVerbosity = new SelectedTag("No output", "Final results", "K-th iterations", "All iterations");
SelectedTag outputTo = new SelectedTag("File (current dir.)", "Text-window", "Both file and text-window");
private int verboK = 10;
private int m_PlotFitness = PLOT_BEST; public final static int VERBOSITY_NONE = 0;
private int m_Textoutput = 0; public final static int VERBOSITY_FINAL = 1;
private int m_Plotoutput = 1; public final static int VERBOSITY_KTH_IT = 2;
private int m_MultiRuns = 1; public final static int VERBOSITY_ALL = 3;
private String m_ResultFilePrefix = "JE2"; SelectedTag outputVerbosity = new SelectedTag("No output", "Final results", "K-th iterations", "All iterations");
protected String m_Name = "not defined";
protected String m_InfoString = "";
private boolean m_useStatPlot = true;
private boolean showAdditionalProblemInfo = false;
private double m_ConvergenceRateThreshold=0.001;
/**
*
*/
public static StatsParameter getInstance() {
StatsParameter Instance = (StatsParameter) Serializer.loadObject("Statistics.ser");
if (Instance == null)
Instance = new StatsParameter();
return Instance;
}
/** public final static int OUTPUT_FILE = 0;
* public final static int OUTPUT_WINDOW = 1;
*/ public final static int OUTPUT_FILE_WINDOW = 2;
public StatsParameter() { SelectedTag outputTo = new SelectedTag("File (current dir.)", "Text-window", "Both file and text-window");
m_Name = "Statistics"; private int verboK = 10;
outputVerbosity.setSelectedTag(2);
outputTo.setSelectedTag(1);
}
/** private int m_PlotFitness = PLOT_BEST;
* private int m_Textoutput = 0;
*/ private int m_Plotoutput = 1;
public String toString() { private int m_MultiRuns = 1;
String ret = "\r\nStatParameter:\r\nm_MultiRuns=" + m_MultiRuns + private String m_ResultFilePrefix = "JE2";
"\r\nm_Textoutput=" + m_Textoutput + protected String m_Name = "not defined";
"\r\nm_Plotoutput=" + m_Plotoutput; protected String m_InfoString = "";
return ret; private boolean m_useStatPlot = true;
} private boolean showAdditionalProblemInfo = false;
private double m_ConvergenceRateThreshold=0.001;
/** /**
* Return a list of String arrays describing the selected plot options, e.g. {"Best"} or {"Best", "Worst"}. *
* For now, only one array is returned. */
* public static StatsParameter getInstance() {
* @return a list of String arrays describing the selected plot options StatsParameter Instance = (StatsParameter) Serializer.loadObject("Statistics.ser");
*/ if (Instance == null)
public ArrayList<String[]> getPlotDescriptions() { Instance = new StatsParameter();
ArrayList<String[]> desc = new ArrayList<String[]>(); return Instance;
switch (getPlotData().getSelectedTagID()) { }
case StatsParameter.PLOT_BEST_AND_WORST:
desc.add(new String[] {"Best", "Worst"});
break;
case StatsParameter.PLOT_BEST:
desc.add(new String[] {"Best"});
break;
case StatsParameter.PLOT_WORST:
desc.add(new String[] {"Worst"});
break;
case StatsParameter.PLOT_BEST_AND_MEASURES:
desc.add(new String[] {"Best", "AvgDist", "MaxDist"});
break;
}
return desc;
}
/**
*
*/
public void saveInstance() {
Serializer.storeObject("Statistics.ser", this);
}
/** /**
* *
*/ */
private StatsParameter(StatsParameter Source) { public StatsParameter() {
m_ConvergenceRateThreshold = Source.m_ConvergenceRateThreshold; m_Name = "Statistics";
m_useStatPlot = Source.m_useStatPlot; outputVerbosity.setSelectedTag(2);
m_Textoutput = Source.m_Textoutput; outputTo.setSelectedTag(1);
m_Plotoutput = Source.m_Plotoutput; }
m_PlotFitness = Source.m_PlotFitness;
m_MultiRuns = Source.m_MultiRuns;
m_ResultFilePrefix = Source.m_ResultFilePrefix;
verboK = Source.verboK;
}
/** /**
* *
*/ */
public Object getClone() { public String toString() {
return new StatsParameter(this); String ret = "\r\nStatParameter:\r\nm_MultiRuns=" + m_MultiRuns +
} "\r\nm_Textoutput=" + m_Textoutput +
"\r\nm_Plotoutput=" + m_Plotoutput;
return ret;
}
/** /**
* * Return a list of String arrays describing the selected plot options, e.g. {"Best"} or {"Best", "Worst"}.
*/ * For now, only one array is returned.
public String getName() { *
return m_Name; * @return a list of String arrays describing the selected plot options
} */
public ArrayList<String[]> getPlotDescriptions() {
ArrayList<String[]> desc = new ArrayList<String[]>();
switch (getPlotData().getSelectedTagID()) {
case StatsParameter.PLOT_BEST_AND_WORST:
desc.add(new String[] {"Best", "Worst"});
break;
case StatsParameter.PLOT_BEST:
desc.add(new String[] {"Best"});
break;
case StatsParameter.PLOT_WORST:
desc.add(new String[] {"Worst"});
break;
case StatsParameter.PLOT_BEST_AND_MEASURES:
desc.add(new String[] {"Best", "AvgDist", "MaxDist"});
break;
}
return desc;
}
public String globalInfo() { /**
return "Configure statistics and output of the optimization run."; *
} */
public void saveInstance() {
Serializer.storeObject("Statistics.ser", this);
}
/** /**
* *
*/ */
public void setPlotoutput(int i) { private StatsParameter(StatsParameter Source) {
m_Plotoutput = i; m_ConvergenceRateThreshold = Source.m_ConvergenceRateThreshold;
} m_useStatPlot = Source.m_useStatPlot;
m_Textoutput = Source.m_Textoutput;
m_Plotoutput = Source.m_Plotoutput;
m_PlotFitness = Source.m_PlotFitness;
m_MultiRuns = Source.m_MultiRuns;
m_ResultFilePrefix = Source.m_ResultFilePrefix;
verboK = Source.verboK;
}
/** /**
* *
*/ */
public int GetPlotoutput() { public Object getClone() {
return m_Plotoutput; return new StatsParameter(this);
} }
// /** /**
// * *
// */ */
// public String plotFrequencyTipText() { public String getName() {
// return "Frequency how often the fitness plot gets an update. plotoutput=1 -> there is a output every generation. plotoutput<0 -> there is no plot output"; return m_Name;
// } }
// /** public String globalInfo() {
// * return "Configure statistics and output of the optimization run.";
// */ }
// public String printMeanTipText() {
// return "Prints the mean of the fitness plot. Makes only sense when multiRuns > 1;";
// }
/** /**
* *
*/ */
public void setMultiRuns(int x) { public void setPlotoutput(int i) {
m_MultiRuns = x; m_Plotoutput = i;
} }
/** /**
* *
*/ */
public int getMultiRuns() { public int GetPlotoutput() {
return m_MultiRuns; return m_Plotoutput;
} }
/**
*
*/
public String multiRunsTipText() {
return "Number of independent optimization runs to evaluate.";
}
/**
*
*/
public String GetInfoString() {
return m_InfoString;
}
/**
*
*/
public void setInfoString(String s) {
m_InfoString = s;
}
/**
*
*/
public String infoStringTipText() {
return "Infostring displayed on fitness graph by prssing the right mouse button.";
}
/**
*
*/
public boolean GetuseStatPlot() {
return m_useStatPlot;
}
/**
*
*/
public void setuseStatPlot(boolean x) {
m_useStatPlot = x;
}
/**
*
*/
public String useStatPlotTipText() {
return "Plotting each fitness graph separate if multiruns > 1.";
}
/**
*
*/
public SelectedTag getPlotData() {
return new SelectedTag(m_PlotFitness, TAGS_PLOT_FITNESS);
}
/**
*
*/
public void setPlotData(SelectedTag newMethod) {
m_PlotFitness = newMethod.getSelectedTag().getID();
}
/**
*
*/
public String plotDataTipText() {
return "The data to be plotted: best fitness, worst fitness or average/max distance in population.";
}
// /**
// *
// */
// public String plotObjectivesTipText() {
// return "The individual of which the objectives are plotted.";
// }
/**
*
*/
public void SetResultFilePrefix(String x) {
if (x==null) m_ResultFilePrefix = "";
else m_ResultFilePrefix = x;
}
/**
*
*/
public String getResultFilePrefix() {
return m_ResultFilePrefix;
}
public void SetShowTextOutput(boolean show) {
// activate if not activated
if (show && outputTo.getSelectedTagID() == 0) outputTo.setSelectedTag(2);
// deactivate if activated
else if (!show && outputTo.getSelectedTagID()>0) outputTo.setSelectedTag(0);
}
public boolean isShowTextOutput() {
return outputTo.getSelectedTagID()>0;
}
//
// /**
// *
// */
// public String resultFileNameTipText() {
// return "File name for the result file. If empty or 'none', no output file will be created.";
// }
public String convergenceRateThresholdTipText() {
return "Provided the optimal fitness is at zero, give the threshold below which it is considered as 'reached'";
}
/**
*
* @param x
*/
public void setConvergenceRateThreshold(double x) {
m_ConvergenceRateThreshold = x;
}
/**
*
*/
public double getConvergenceRateThreshold() {
return m_ConvergenceRateThreshold;
}
// /** // /**
// * @return the showOutputData // *
// */ // */
// public String plotFrequencyTipText() {
// return "Frequency how often the fitness plot gets an update. plotoutput=1 -> there is a output every generation. plotoutput<0 -> there is no plot output";
// }
// /**
// *
// */
// public String printMeanTipText() {
// return "Prints the mean of the fitness plot. Makes only sense when multiRuns > 1;";
// }
/**
*
*/
public void setMultiRuns(int x) {
m_MultiRuns = x;
}
/**
*
*/
public int getMultiRuns() {
return m_MultiRuns;
}
/**
*
*/
public String multiRunsTipText() {
return "Number of independent optimization runs to evaluate.";
}
/**
*
*/
public String GetInfoString() {
return m_InfoString;
}
/**
*
*/
public void setInfoString(String s) {
m_InfoString = s;
}
/**
*
*/
public String infoStringTipText() {
return "Infostring displayed on fitness graph by prssing the right mouse button.";
}
/**
*
*/
public boolean GetuseStatPlot() {
return m_useStatPlot;
}
/**
*
*/
public void setuseStatPlot(boolean x) {
m_useStatPlot = x;
}
/**
*
*/
public String useStatPlotTipText() {
return "Plotting each fitness graph separate if multiruns > 1.";
}
/**
*
*/
public SelectedTag getPlotData() {
return new SelectedTag(m_PlotFitness, TAGS_PLOT_FITNESS);
}
/**
*
*/
public void setPlotData(SelectedTag newMethod) {
m_PlotFitness = newMethod.getSelectedTag().getID();
}
/**
*
*/
public String plotDataTipText() {
return "The data to be plotted: best fitness, worst fitness or average/max distance in population.";
}
// /**
// *
// */
// public String plotObjectivesTipText() {
// return "The individual of which the objectives are plotted.";
// }
/**
*
*/
public void SetResultFilePrefix(String x) {
if (x==null) m_ResultFilePrefix = "";
else m_ResultFilePrefix = x;
}
/**
*
*/
public String getResultFilePrefix() {
return m_ResultFilePrefix;
}
public void SetShowTextOutput(boolean show) {
// activate if not activated
if (show && outputTo.getSelectedTagID() == 0) outputTo.setSelectedTag(2);
// deactivate if activated
else if (!show && outputTo.getSelectedTagID()>0) outputTo.setSelectedTag(0);
}
public boolean isShowTextOutput() {
return outputTo.getSelectedTagID()>0;
}
// /**
// *
// */
// public String resultFileNameTipText() {
// return "File name for the result file. If empty or 'none', no output file will be created.";
// }
public String convergenceRateThresholdTipText() {
return "Provided the optimal fitness is at zero, give the threshold below which it is considered as 'reached'";
}
/**
*
* @param x
*/
public void setConvergenceRateThreshold(double x) {
m_ConvergenceRateThreshold = x;
}
/**
*
*/
public double getConvergenceRateThreshold() {
return m_ConvergenceRateThreshold;
}
// /**
// * @return the showOutputData
// */
// public boolean isShowTextOutput() { // public boolean isShowTextOutput() {
// return showTextOutput; // return showTextOutput;
// } // }
//
// /** // /**
// * // *
// * @param showOutputData the showOutputData to set // * @param showOutputData the showOutputData to set
// */ // */
// public void setShowTextOutput(boolean bShow) { // public void setShowTextOutput(boolean bShow) {
// this.showTextOutput = bShow; // this.showTextOutput = bShow;
// } // }
//
// public String showTextOutputTipText() { // public String showTextOutputTipText() {
// return "Indicates whether further text output should be printed"; // return "Indicates whether further text output should be printed";
// } // }
public boolean isOutputAdditionalInfo() { public boolean isOutputAdditionalInfo() {
@ -350,38 +354,45 @@ public class StatsParameter implements InterfaceStatisticsParameter, Serializabl
public void setOutputAdditionalInfo(boolean showAdd) { public void setOutputAdditionalInfo(boolean showAdd) {
showAdditionalProblemInfo = showAdd; showAdditionalProblemInfo = showAdd;
} }
public String outputAdditionalInfoTipText() { public String outputAdditionalInfoTipText() {
return "Activate to output additional problem information per iteration, such as the current solution representation."; return "Activate to output additional problem information per iteration, such as the current solution representation.";
} }
public void hideHideable() { public void hideHideable() {
setOutputVerbosity(getOutputVerbosity()); setOutputVerbosity(getOutputVerbosity());
} }
public void setOutputVerbosity(SelectedTag sTag) {
outputVerbosity = sTag; public void setOutputVerbosity(SelectedTag sTag) {
GenericObjectEditor.setHideProperty(this.getClass(), "outputVerbosityK", sTag.getSelectedTagID() != VERBOSITY_KTH_IT); outputVerbosity = sTag;
} GenericObjectEditor.setHideProperty(this.getClass(), "outputVerbosityK", sTag.getSelectedTagID() != VERBOSITY_KTH_IT);
public SelectedTag getOutputVerbosity() { }
return outputVerbosity;
} public void setOutputVerbosity(int i) {
outputVerbosity.setSelectedTag(i);
GenericObjectEditor.setHideProperty(this.getClass(), "outputVerbosityK", outputVerbosity.getSelectedTagID() != VERBOSITY_KTH_IT);
}
public SelectedTag getOutputVerbosity() {
return outputVerbosity;
}
public String outputVerbosityTipText() {
return "Set the data output level.";
}
public int getOutputVerbosityK() {
return verboK;
}
public void setOutputVerbosityK(int k) {
verboK = k;
}
public String outputVerbosityKTipText() {
return "Set the interval of data output for intermediate verbosity (in generations).";
}
public String outputVerbosityTipText() {
return "Set the data output level.";
}
public int getOutputVerbosityK() {
return verboK;
}
public void setOutputVerbosityK(int k) {
verboK = k;
}
public String outputVerbosityKTipText() {
return "Set the interval of data output for intermediate verbosity (in generations).";
}
public SelectedTag getOutputTo() { public SelectedTag getOutputTo() {
return outputTo; return outputTo;
} }
@ -389,9 +400,13 @@ public class StatsParameter implements InterfaceStatisticsParameter, Serializabl
public void setOutputTo(SelectedTag tag) { public void setOutputTo(SelectedTag tag) {
outputTo = tag; outputTo = tag;
} }
public void setOutputTo(int i) {
outputTo.setSelectedTag(i);
}
public String outputToTipText() { public String outputToTipText() {
return "Set the output destination; to deactivate output, set verbosity to none."; return "Set the output destination; to deactivate output, set verbosity to none.";
} }
} }

View File

@ -1,12 +1,18 @@
package eva2.tools; package eva2.tools;
import java.io.Serializable;
/** /**
* Simple pair structure of two types, Scheme style, but typed. * Simple pair structure of two types, Scheme style, but typed.
* *
* @author mkron * @author mkron
* *
*/ */
public class Pair<S, T> { public class Pair<S, T> implements Serializable {
/**
*
*/
private static final long serialVersionUID = -3620465393975181451L;
public S head; public S head;
public T tail; public T tail;