Refactoring, renaming and better comments.
This commit is contained in:
Fabian Becker 2013-01-29 11:18:39 +00:00
parent 27f94e088e
commit d3ea94fe5c
5 changed files with 413 additions and 331 deletions

View File

@ -36,13 +36,16 @@ public class PBILPopulation extends Population implements Cloneable, java.io.Ser
}
}
@Override
public Object clone() {
return (Object) new PBILPopulation(this);
}
/** This method inits the state of the population AFTER the individuals
* have been inited by a problem
/**
* This method inits the state of the population AFTER the individuals
* have been inited by a problem.
*/
@Override
public void init() {
this.generationCount = 0;
this.functionCallCount = 0;
@ -56,7 +59,8 @@ public class PBILPopulation extends Population implements Cloneable, java.io.Ser
}
}
/** This method allows you to learn from several examples
/**
* This method allows you to learn from several examples
* @param examples A population of examples.
* @param learnRate The learning rate.
*/
@ -74,7 +78,8 @@ public class PBILPopulation extends Population implements Cloneable, java.io.Ser
}
}
/** This method creates a new population based on the bit probability vector
/**
* This method creates a new population based on the bit probability vector.
*/
public void initPBIL() {
InterfaceGAIndividual tmpIndy, template = (InterfaceGAIndividual)((AbstractEAIndividual)this.get(0)).clone();
@ -93,7 +98,8 @@ public class PBILPopulation extends Population implements Cloneable, java.io.Ser
}
}
/** This method allows you to mutate the bit probability vector
/**
* This method allows you to mutate the bit probability vector
* @param mutationRate The mutation rate.
*/
public void mutateProbabilityVector(double mutationRate, double sigma) {
@ -104,7 +110,8 @@ public class PBILPopulation extends Population implements Cloneable, java.io.Ser
}
}
/** This method will build a probability vector from the current population
/**
* This method will build a probability vector from the current population.
*/
public void buildProbabilityVector() {
int dim = ((InterfaceGAIndividual)this.get(0)).getGenotypeLength();
@ -125,20 +132,24 @@ public class PBILPopulation extends Population implements Cloneable, java.io.Ser
}
}
/** This method allows you to set the current probability vector.
/**
* This method allows you to set the current probability vector.
* @param pv The new probability vector.
*/
public void SetProbabilityVector(double[] pv) {
public void setProbabilityVector(double[] pv) {
this.m_ProbabilityVector = pv;
}
public double[] getProbabilityVector() {
return this.m_ProbabilityVector;
}
/** This method will return a string description of the GAIndividal
* noteably the Genotype.
/**
* This method will return a string description of the GAIndividal
* notably the Genotype.
* @return A descriptive string
*/
@Override
public String getStringRepresentation() {
String result = "";
result += "PBIL-Population:\n";

View File

@ -41,29 +41,66 @@ import java.util.logging.Logger;
public class Population extends ArrayList implements PopulationInterface, Cloneable, java.io.Serializable {
private static final Logger LOGGER = Logger.getLogger(Population.class.getName());
/**
* Number of generations.
*/
protected int generationCount = 0;
/**
* Number of function calls.
*/
protected int functionCallCount = 0;
/**
* Size of the target population.
*/
protected int targetPopSize = 50;
protected Population populationArchive = null;
/**
* Method by which the Population gets initialized.
*/
PopulationInitMethod initMethod = PopulationInitMethod.individualDefault;
private double[] seedPos = new double[10];
private Pair<Integer, Integer> seedCardinality = new Pair<Integer, Integer>(5, 1);
private double aroundDist = 0.1;
transient private ArrayList<InterfacePopulationChangedEventListener> listeners = null;
// the evaluation interval at which listeners are notified
/**
* The evaluation interval at which listeners are notified.
*/
protected int notifyEvalInterval = 0;
// additional data connected to the population
/**
* Additional data connected to the population.
*/
protected HashMap<String, Object> additionalPopData = null;
// historical best indidivuals may be traced for a given number of generations. Set to -1 to trace all, set to 0 to not trace at all
/**
* historical best individuals may be traced for a given number of generations.
* Set to -1 to trace all, set to 0 to not trace at all
*/
int historyMaxLen = 0;
/**
* Best n Individuals in the history.
*/
private transient LinkedList<AbstractEAIndividual> m_History = new LinkedList<AbstractEAIndividual>();
// remember when the last sorted queue was prepared
/**
* Remember when the last sorted queue was prepared.
*/
private int lastQModCount = -1;
// a sorted queue (for efficiency)
/**
* A sorted queue (for efficiency).
*/
transient private ArrayList<AbstractEAIndividual> sortedArr = null;
private Comparator<Object> lastSortingComparator = null;
private InterfaceDistanceMetric popDistMetric = null; // an associated metric
// private AbstractEAIndividualComparator historyComparator = null;
public static final String funCallIntervalReached = "FunCallIntervalReached";
public static final String populationInitialized = "PopulationReinitOccured";
public static final String nextGenerationPerformed = "NextGenerationPerformed";
@ -195,7 +232,6 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
if (population.seedPos != null) {
this.seedPos = population.seedPos.clone();
}
// this.m_Listener = population.m_Listener;
if (population.listeners != null) {
this.listeners = (ArrayList<InterfacePopulationChangedEventListener>) population.listeners.clone();
} else {
@ -1654,7 +1690,7 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
*
* @param size
*/
public void setTargetSize(int size) {
public final void setTargetSize(int size) {
this.targetPopSize = size;
}
@ -1665,7 +1701,7 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
* @return
*/
public Population setTargetPopSize(int size) {
setTargetSize(size);
this.setTargetSize(size);
return this;
}
@ -2328,7 +2364,7 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
* Calculate the fitness sum over all individuals for one criterion.
*
* @param criterion
* @return the fitness sum over all individuals for one criterio
* @return the fitness sum over all individuals for one criteria
*/
public double getFitSum(int criterion) {
double fSum = 0.;

View File

@ -12,329 +12,360 @@ import eva2.server.go.populations.SolutionSet;
import eva2.server.go.problems.F1Problem;
import eva2.server.go.problems.InterfaceOptimizationProblem;
/** The traditional genetic algorithms as devised by Holland. To only special here
* it the plague factor which reduces the population size to tune from a global to
* a more local search. But you have to be careful with that else the GA might not
* converge.
* This is a implementation of Genetic Algorithms.
* Copyright: Copyright (c) 2003
* Company: University of Tuebingen, Computer Architecture
* @author Felix Streichert
* @version: $Revision: 307 $
* $Date: 2007-12-04 14:31:47 +0100 (Tue, 04 Dec 2007) $
* $Author: mkron $
/**
* The traditional genetic algorithms as devised by Holland. To only special
* here it the plague factor which reduces the population size to tune from a
* global to a more local search. But you have to be careful with that else the
* GA might not converge. This is a implementation of Genetic Algorithms.
* Copyright: Copyright (c) 2003 Company: University of Tuebingen, Computer
* Architecture
*
* @author Felix Streichert
* @version: $Revision: 307 $ $Date: 2007-12-04 14:31:47 +0100 (Tue, 04 Dec
* 2007) $ $Author: mkron $
*/
public class GeneticAlgorithm implements InterfaceOptimizer, java.io.Serializable {
private Population m_Population = new Population();
private InterfaceOptimizationProblem m_Problem = new F1Problem();
private InterfaceSelection m_ParentSelection = new SelectXProbRouletteWheel();
private InterfaceSelection m_PartnerSelection = new SelectRandom();
private boolean m_UseElitism = true;
private int m_Plague = 0;
private int m_NumberOfPartners = 1;
private Population population = new Population();
private InterfaceOptimizationProblem optimizationProblem = new F1Problem();
private InterfaceSelection parentSelection = new SelectXProbRouletteWheel();
private InterfaceSelection partnerSelection = new SelectRandom();
private boolean useElitism = true;
private int plague = 0;
private int numberOfPartners = 1;
private String identifier = "";
transient private InterfacePopulationChangedEventListener popChangedListener;
private String m_Identifier = "";
transient private InterfacePopulationChangedEventListener m_Listener;
public GeneticAlgorithm() {
}
public GeneticAlgorithm() {
}
public GeneticAlgorithm(GeneticAlgorithm ga) {
this.population = (Population) ga.population.clone();
this.optimizationProblem = (InterfaceOptimizationProblem) ga.optimizationProblem.clone();
this.identifier = ga.identifier;
this.plague = ga.plague;
this.numberOfPartners = ga.numberOfPartners;
this.useElitism = ga.useElitism;
this.parentSelection = (InterfaceSelection) ga.parentSelection.clone();
this.partnerSelection = (InterfaceSelection) ga.partnerSelection.clone();
}
public GeneticAlgorithm(GeneticAlgorithm a) {
this.m_Population = (Population)a.m_Population.clone();
this.m_Problem = (InterfaceOptimizationProblem)a.m_Problem.clone();
this.m_Identifier = a.m_Identifier;
this.m_Plague = a.m_Plague;
this.m_NumberOfPartners = a.m_NumberOfPartners;
this.m_UseElitism = a.m_UseElitism;
this.m_ParentSelection = (InterfaceSelection)a.m_ParentSelection.clone();
this.m_PartnerSelection = (InterfaceSelection)a.m_PartnerSelection.clone();
}
@Override
public Object clone() {
return (Object) new GeneticAlgorithm(this);
}
public Object clone() {
return (Object) new GeneticAlgorithm(this);
}
@Override
public void init() {
this.optimizationProblem.initPopulation(this.population);
this.evaluatePopulation(this.population);
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
public void init() {
this.m_Problem.initPopulation(this.m_Population);
this.evaluatePopulation(this.m_Population);
/**
* This method will init the optimizer with a given population
*
* @param reset If true the population is reset.
*/
@Override
public void initByPopulation(Population pop, boolean reset) {
this.population = (Population) pop.clone();
if (reset) {
this.optimizationProblem.initPopulation(population);
this.population.init();
this.evaluatePopulation(this.population);
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
}
/** This method will init the optimizer with a given population
* @param reset If true the population is reset.
*/
public void initByPopulation(Population pop, boolean reset) {
this.m_Population = (Population)pop.clone();
if (reset) {
this.m_Problem.initPopulation(m_Population);
this.m_Population.init();
this.evaluatePopulation(this.m_Population);
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/**
* This method will evaluate the current population using the given problem.
*
* @param population The population that is to be evaluated
*/
private void evaluatePopulation(Population population) {
this.optimizationProblem.evaluate(population);
population.incrGeneration();
}
/**
* This method will generate the offspring population from the given
* population of evaluated individuals.
*/
private Population generateChildren() {
Population result = population.cloneWithoutInds();
Population parents;
AbstractEAIndividual[] offSprings;
AbstractEAIndividual tmpIndy;
this.parentSelection.prepareSelection(this.population);
this.partnerSelection.prepareSelection(this.population);
parents = this.parentSelection.selectFrom(this.population, this.population.getTargetSize());
if (parents.getEAIndividual(0).getMutationOperator() instanceof InterfaceAdaptOperatorGenerational) {
((InterfaceAdaptOperatorGenerational) parents.getEAIndividual(0).getMutationOperator()).adaptAfterSelection(population, parents);
}
if (parents.getEAIndividual(0).getCrossoverOperator() instanceof InterfaceAdaptOperatorGenerational) {
((InterfaceAdaptOperatorGenerational) parents.getEAIndividual(0).getCrossoverOperator()).adaptAfterSelection(population, parents);
}
/** This method will evaluate the current population using the
* given problem.
* @param population The population that is to be evaluated
*/
private void evaluatePopulation(Population population) {
this.m_Problem.evaluate(population);
population.incrGeneration();
for (int i = 0; i < parents.size(); i++) {
tmpIndy = ((AbstractEAIndividual) parents.get(i));
if (tmpIndy == null) {
System.out.println("Individual null " + i + " Population size: " + parents.size());
}
if (this.population == null) {
System.out.println("population null " + i);
}
// ToDo: tmpIndy can be null. We shouldn't call a method on null..
offSprings = tmpIndy.mateWith(this.partnerSelection.findPartnerFor(tmpIndy, this.population, this.numberOfPartners));
offSprings[0].mutate();
result.add(i, offSprings[0]);
}
this.evaluatePopulation(result);
// /** This method will assign fitness values to all individual in the
// * current population.
// * @param population The population that is to be evaluated
// */
// private void defaultEvaluatePopulation(Population population) {
// GAIndividualBinaryData tmpIndy;
// for (int i = 0; i < population.size(); i++) {
// tmpIndy = (GAIndividualBinaryData) population.get(i);
// tmpIndy.SetFitness(0, tmpIndy.defaultEvaulateAsMiniBits());
// population.incrFunctionCalls();
// }
// population.incrGeneration();
// }
/** This method will generate the offspring population from the
* given population of evaluated individuals.
*/
private Population generateChildren() {
Population result = m_Population.cloneWithoutInds();
Population parents;
AbstractEAIndividual[] offSprings;
AbstractEAIndividual tmpIndy;
//this.m_NormationOperator.computeSelectionProbability(this.m_Population, "Fitness");
//System.out.println("Population:"+this.m_Population.getSolutionRepresentationFor());
this.m_ParentSelection.prepareSelection(this.m_Population);
this.m_PartnerSelection.prepareSelection(this.m_Population);
parents = this.m_ParentSelection.selectFrom(this.m_Population, this.m_Population.getTargetSize());
// System.out.println("Parents:"+parents.getStringRepresentation());
// double[] meas = parents.getPopulationMeasures();
if (parents.getEAIndividual(0).getMutationOperator() instanceof InterfaceAdaptOperatorGenerational) {
((InterfaceAdaptOperatorGenerational)parents.getEAIndividual(0).getMutationOperator()).adaptAfterSelection(m_Population, parents);
}
if (parents.getEAIndividual(0).getCrossoverOperator() instanceof InterfaceAdaptOperatorGenerational) {
((InterfaceAdaptOperatorGenerational)parents.getEAIndividual(0).getCrossoverOperator()).adaptAfterSelection(m_Population, parents);
}
for (int i = 0; i < parents.size(); i++) {
tmpIndy = ((AbstractEAIndividual)parents.get(i));
if (tmpIndy == null) System.out.println("Individual null " + i + " Population size: "+ parents.size());
if (this.m_Population == null) System.out.println("population null "+i);
offSprings = tmpIndy.mateWith(this.m_PartnerSelection.findPartnerFor(tmpIndy, this.m_Population, this.m_NumberOfPartners));
// for (int j = 0; j < offSprings.length; j++) {
// offSprings[j].mutate(); // quite useless if n-1 are thrown away...
// }
offSprings[0].mutate();
result.add(i, offSprings[0]);
}
this.evaluatePopulation(result);
if (parents.getEAIndividual(0).getMutationOperator() instanceof InterfaceAdaptOperatorGenerational) {
((InterfaceAdaptOperatorGenerational)parents.getEAIndividual(0).getMutationOperator()).adaptGenerational(m_Population, parents, result, true);
}
if (parents.getEAIndividual(0).getCrossoverOperator() instanceof InterfaceAdaptOperatorGenerational) {
((InterfaceAdaptOperatorGenerational)parents.getEAIndividual(0).getCrossoverOperator()).adaptGenerational(m_Population, parents, result, true);
}
return result;
if (parents.getEAIndividual(0).getMutationOperator() instanceof InterfaceAdaptOperatorGenerational) {
((InterfaceAdaptOperatorGenerational) parents.getEAIndividual(0).getMutationOperator()).adaptGenerational(population, parents, result, true);
}
if (parents.getEAIndividual(0).getCrossoverOperator() instanceof InterfaceAdaptOperatorGenerational) {
((InterfaceAdaptOperatorGenerational) parents.getEAIndividual(0).getCrossoverOperator()).adaptGenerational(population, parents, result, true);
}
return result;
}
public void optimize() {
Population nextGeneration;
nextGeneration = this.generateChildren();
@Override
public void optimize() {
Population nextGeneration;
nextGeneration = this.generateChildren();
if (this.m_UseElitism) {
AbstractEAIndividual elite = this.m_Population.getBestEAIndividual();
if (elite != null) {
this.m_Population = nextGeneration;
this.m_Population.remove(0);// This implements a random replacement strategy for the elite
this.m_Population.add(elite);
if (this.useElitism) {
AbstractEAIndividual elite = this.population.getBestEAIndividual();
if (elite != null) {
this.population = nextGeneration;
this.population.remove(0);// This implements a random replacement strategy for the elite
this.population.add(elite);
}
} else {
this.population = nextGeneration;
}
if (this.plague > 0) {
for (int i = 0; i < this.plague; i++) {
if (this.population.size() > 2) {
this.population.remove(this.population.getWorstEAIndividual());
}
} else {
this.m_Population = nextGeneration;
}
if (this.m_Plague > 0) {
for (int i = 0; i < this.m_Plague; i++) if (this.m_Population.size() > 2) this.m_Population.remove(this.m_Population.getWorstEAIndividual());
this.m_Population.setTargetSize(this.m_Population.size());
}
// System.out.println("Population size: " + this.m_Population.size());
// System.out.println("Population: " + m_Population.getStringRepresentation());
// if (this.m_Population.getArchive() != null) {
// if (this.m_Population.getArchive().getArchive() != null) {
// System.out.println("Zwei Archive!");
// this.m_Population.getArchive().SetArchive(null);
// }
// }
// this.m_Population.incrGeneration();
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
this.population.setTargetSize(this.population.size());
}
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
/** This method allows you to add the LectureGUI as listener to the Optimizer
* @param ea
*/
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea;
}
public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
if (m_Listener==ea) {
m_Listener=null;
return true;
} else return false;
}
/** Something has changed
*/
protected void firePropertyChangedEvent (String name) {
if (this.m_Listener != null) this.m_Listener.registerPopulationStateChanged(this, name);
}
/**
* This method allows you to add the LectureGUI as listener to the Optimizer
*
* @param ea
*/
@Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.popChangedListener = ea;
}
/** This method will set the problem that is to be optimized
* @param problem
*/
public void setProblem (InterfaceOptimizationProblem problem) {
this.m_Problem = problem;
}
public InterfaceOptimizationProblem getProblem () {
return this.m_Problem;
@Override
public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) {
if (popChangedListener == ea) {
popChangedListener = null;
return true;
} else {
return false;
}
}
/** This method will return a string describing all properties of the optimizer
* and the applied methods.
* @return A descriptive string
*/
public String getStringRepresentation() {
String result = "";
result += "Genetic Algorithm:\n";
result += "Using:\n";
result += " Population Size = " + this.m_Population.getTargetSize() + "/" + this.m_Population.size() + "\n";
result += " Parent Selection = " + this.m_ParentSelection.getClass().toString() + "\n";
result += " Partner Selection = " + this.m_PartnerSelection.getClass().toString() + "\n";
result += " Number of Partners = " + this.m_NumberOfPartners + "\n";
result += " Elitism = " + this.m_UseElitism + "\n";
result += "=> The Optimization Problem: ";
result += this.m_Problem.getStringRepresentationForProblem(this) +"\n";
//result += this.m_Population.getStringRepresentation();
return result;
/**
* Something has changed.
*/
protected void firePropertyChangedEvent(String name) {
if (this.popChangedListener != null) {
this.popChangedListener.registerPopulationStateChanged(this, name);
}
/** This method allows you to set an identifier for the algorithm
* @param name The indenifier
*/
public void setIdentifier(String name) {
this.m_Identifier = name;
}
public String getIdentifier() {
return this.m_Identifier;
}
}
/** This method is required to free the memory on a RMIServer,
* but there is nothing to implement.
*/
public void freeWilly() {
/**
* This method will set the problem that is to be optimized
*
* @param problem
*/
@Override
public void setProblem(InterfaceOptimizationProblem problem) {
this.optimizationProblem = problem;
}
}
/**********************************************************************************************************************
@Override
public InterfaceOptimizationProblem getProblem() {
return this.optimizationProblem;
}
/**
* This method will return a string describing all properties of the
* optimizer and the applied methods.
*
* @return A descriptive string
*/
@Override
public String getStringRepresentation() {
String result = "";
result += "Genetic Algorithm:\n";
result += "Using:\n";
result += " Population Size = " + this.population.getTargetSize() + "/" + this.population.size() + "\n";
result += " Parent Selection = " + this.parentSelection.getClass().toString() + "\n";
result += " Partner Selection = " + this.partnerSelection.getClass().toString() + "\n";
result += " Number of Partners = " + this.numberOfPartners + "\n";
result += " Elitism = " + this.useElitism + "\n";
result += "=> The Optimization Problem: ";
result += this.optimizationProblem.getStringRepresentationForProblem(this) + "\n";
return result;
}
/**
* This method allows you to set an identifier for the algorithm.
*
* @param name The identifier
*/
@Override
public void setIdentifier(String name) {
this.identifier = name;
}
@Override
public String getIdentifier() {
return this.identifier;
}
/**
* This method is required to free the memory on a RMIServer, but there is
* nothing to implement.
*/
public void freeWilly() {
}
/**
* ********************************************************************************************************************
* These are for GUI
*/
/** This method returns a global info string
* @return description
*/
public static String globalInfo() {
return "This is a basic generational Genetic Algorithm.";
}
/** This method will return a naming String
* @return The name of the algorithm
*/
public String getName() {
return "GA";
}
/**
* This method returns a global info string
*
* @return description
*/
public static String globalInfo() {
return "This is a basic generational Genetic Algorithm.";
}
/** Assuming that all optimizer will store thier data in a population
* we will allow acess to this population to query to current state
* of the optimizer.
* @return The population of current solutions to a given problem.
*/
public Population getPopulation() {
return this.m_Population;
}
public void setPopulation(Population pop){
this.m_Population = pop;
}
public String populationTipText() {
return "Edit the properties of the population used.";
}
/**
* This method will return a naming String
*
* @return The name of the algorithm
*/
@Override
public String getName() {
return "GA";
}
public InterfaceSolutionSet getAllSolutions() {
return new SolutionSet(getPopulation());
}
// /** This method will set the normation method that is to be used.
// * @param normation
// */
// public void setNormationMethod (InterfaceNormation normation) {
// this.m_NormationOperator = normation;
// }
// public InterfaceNormation getNormationMethod () {
// return this.m_NormationOperator;
// }
// public String normationMethodTipText() {
// return "Select the normation method.";
// }
/**
* Assuming that all optimizer will store thier data in a population we will
* allow acess to this population to query to current state of the
* optimizer.
*
* @return The population of current solutions to a given problem.
*/
@Override
public Population getPopulation() {
return this.population;
}
/** Choose a parent selection method.
* @param selection
*/
public void setParentSelection(InterfaceSelection selection) {
this.m_ParentSelection = selection;
}
public InterfaceSelection getParentSelection() {
return this.m_ParentSelection;
}
public String parentSelectionTipText() {
return "Choose a parent selection method.";
}
@Override
public void setPopulation(Population pop) {
this.population = pop;
}
/** Enable/disable elitism.
* @param elitism
*/
public void setElitism (boolean elitism) {
this.m_UseElitism = elitism;
}
public boolean getElitism() {
return this.m_UseElitism;
}
public String elitismTipText() {
return "Enable/disable elitism.";
}
public String populationTipText() {
return "Edit the properties of the population used.";
}
/** The number of mating partners needed to create offsprings.
* @param partners
*/
public void setNumberOfPartners(int partners) {
if (partners < 0) partners = 0;
this.m_NumberOfPartners = partners;
}
public int getNumberOfPartners() {
return this.m_NumberOfPartners;
}
public String numberOfPartnersTipText() {
return "The number of mating partners needed to create offsprings.";
}
@Override
public InterfaceSolutionSet getAllSolutions() {
return new SolutionSet(getPopulation());
}
/** Choose a selection method for selecting recombination partners for given parents.
* @param selection
*/
public void setPartnerSelection(InterfaceSelection selection) {
this.m_PartnerSelection = selection;
}
public InterfaceSelection getPartnerSelection() {
return this.m_PartnerSelection;
}
public String partnerSelectionTipText() {
return "Choose a selection method for selecting recombination partners for given parents.";
/**
* Choose a parent selection method.
*
* @param selection
*/
public void setParentSelection(InterfaceSelection selection) {
this.parentSelection = selection;
}
public InterfaceSelection getParentSelection() {
return this.parentSelection;
}
public String parentSelectionTipText() {
return "Choose a parent selection method.";
}
/**
* Enable/disable elitism.
*
* @param elitism
*/
public void setElitism(boolean elitism) {
this.useElitism = elitism;
}
public boolean getElitism() {
return this.useElitism;
}
public String elitismTipText() {
return "Enable/disable elitism.";
}
/**
* The number of mating partners needed to create offsprings.
*
* @param partners
*/
public void setNumberOfPartners(int partners) {
if (partners < 0) {
partners = 0;
}
this.numberOfPartners = partners;
}
public int getNumberOfPartners() {
return this.numberOfPartners;
}
public String numberOfPartnersTipText() {
return "The number of mating partners needed to create offsprings.";
}
/**
* Choose a selection method for selecting recombination partners for given
* parents.
*
* @param selection
*/
public void setPartnerSelection(InterfaceSelection selection) {
this.partnerSelection = selection;
}
public InterfaceSelection getPartnerSelection() {
return this.partnerSelection;
}
public String partnerSelectionTipText() {
return "Choose a selection method for selecting recombination partners for given parents.";
}
}

View File

@ -66,7 +66,7 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
public void init() {
this.m_Problem.initPopulation(this.m_Population);
if ((m_initialProbabilities!=null) && (m_initialProbabilities.length==((PBILPopulation)m_Population).getProbabilityVector().length)) {
((PBILPopulation)m_Population).SetProbabilityVector(m_initialProbabilities);
((PBILPopulation)m_Population).setProbabilityVector(m_initialProbabilities);
} else {
if (m_initialProbabilities!=null) System.err.println("Warning: initial probability vector doesnt match in length!");
}

View File

@ -44,24 +44,25 @@ import javax.swing.JOptionPane;
public class Processor extends Thread implements InterfaceProcessor, InterfacePopulationChangedEventListener {
private static final Logger LOGGER = Logger.getLogger(Processor.class.getName());
private volatile boolean m_optRunning;
private volatile boolean isOptimizationRunning;
private InterfaceStatistics m_Statistics;
private InterfaceGOParameters goParams;
private boolean m_createInitialPopulations = true;
private boolean saveParams = true;
private RemoteStateListener m_ListenerModule;
private RemoteStateListener remoteStateListener;
private boolean wasRestarted = false;
private int runCounter = 0;
private Population resPop = null;
private boolean userAborted = false;
@Override
public void addListener(RemoteStateListener module) {
LOGGER.log(
Level.FINEST,
"Processor: setting module as listener: " + ((module == null)
? "null" : module.toString()));
m_ListenerModule = module;
remoteStateListener = module;
}
/**
@ -70,10 +71,10 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
*
* @see InterfaceNotifyOnInformers
*/
public Processor(InterfaceStatistics Stat, ModuleAdapter Adapter, InterfaceGOParameters params) {
public Processor(InterfaceStatistics Stat, ModuleAdapter moduleAdapter, InterfaceGOParameters params) {
goParams = params;
m_Statistics = Stat;
m_ListenerModule = Adapter;
remoteStateListener = moduleAdapter;
// the statistics want to be informed if the strategy or the optimizer (which provide statistical data as InterfaceAdditionalInformer) change.
if (Stat != null && (params != null)) {
@ -85,11 +86,11 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
}
public boolean isOptRunning() {
return m_optRunning;
return isOptimizationRunning;
}
protected void setOptRunning(boolean bRun) {
m_optRunning = bRun;
isOptimizationRunning = bRun;
}
/**
@ -129,6 +130,7 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
/**
*
*/
@Override
public void restartOpt() {
m_createInitialPopulations = false;
if (isOptRunning()) {
@ -143,6 +145,7 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
/**
*
*/
@Override
public void stopOpt() { // this means user break
setOptRunning(false);
}
@ -150,8 +153,9 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
/**
*
*/
@Override
public void run() {
setPriority(1);
this.setPriority(1);
while (true) {
try {
Thread.sleep(200);
@ -191,9 +195,9 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
}
//m_Statistics.stopOptPerformed(false);
setOptRunning(false); // normal finish
if (m_ListenerModule != null) {
m_ListenerModule.performedStop(); // is only needed in client server mode
m_ListenerModule.updateProgress(0, errMsg);
if (remoteStateListener != null) {
remoteStateListener.performedStop(); // is only needed in client server mode
remoteStateListener.updateProgress(0, errMsg);
}
}
return resPop;
@ -213,11 +217,11 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
RNG.setRandomSeed(goParams.getSeed());
if (m_ListenerModule != null) {
if (remoteStateListener != null) {
if (wasRestarted) {
m_ListenerModule.performedRestart(getInfoString());
remoteStateListener.performedRestart(getInfoString());
} else {
m_ListenerModule.performedStart(getInfoString());
remoteStateListener.performedStart(getInfoString());
}
}
@ -238,8 +242,8 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
}
//m_Statistics.createNextGenerationPerformed((PopulationInterface)this.m_ModulParameter.getOptimizer().getPopulation());
if (m_ListenerModule != null) {
m_ListenerModule.updateProgress(getStatusPercent(goParams.getOptimizer().getPopulation(), runCounter, m_Statistics.getStatisticsParameter().getMultiRuns()), null);
if (remoteStateListener != null) {
remoteStateListener.updateProgress(getStatusPercent(goParams.getOptimizer().getPopulation(), runCounter, m_Statistics.getStatisticsParameter().getMultiRuns()), null);
}
if (popLog != null) {
EVAHELP.clearLog(popLog);
@ -274,11 +278,11 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
}
setOptRunning(false); // normal finish
if (m_ListenerModule != null) {
m_ListenerModule.performedStop(); // is only needed in client server mode
if (remoteStateListener != null) {
remoteStateListener.performedStop(); // is only needed in client server mode
}
if (m_ListenerModule != null) {
m_ListenerModule.updateProgress(0, null);
if (remoteStateListener != null) {
remoteStateListener.updateProgress(0, null);
}
goParams.getOptimizer().removePopulationChangedEventListener(this);
return resultPop;
@ -380,8 +384,8 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
(PopulationInterface) this.goParams.getOptimizer().getPopulation(),
this.goParams.getOptimizer(),
getInformerList());
if (m_ListenerModule != null) {
m_ListenerModule.updateProgress(
if (remoteStateListener != null) {
remoteStateListener.updateProgress(
getStatusPercent(
goParams.getOptimizer().getPopulation(),
runCounter,