OptimizerFactory now contains several new methods.
This commit is contained in:
parent
cbc6992ac5
commit
83cd026722
File diff suppressed because it is too large
Load Diff
@ -9,81 +9,110 @@ import javaeva.server.go.tools.RandomNumberGenerator;
|
|||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by IntelliJ IDEA.
|
* Created by IntelliJ IDEA. User: streiche Date: 03.04.2003 Time: 10:34:17 To
|
||||||
* User: streiche
|
* change this template use Options | File Templates.
|
||||||
* Date: 03.04.2003
|
|
||||||
* Time: 10:34:17
|
|
||||||
* To change this template use Options | File Templates.
|
|
||||||
*/
|
*/
|
||||||
public class CrossoverGADefault implements InterfaceCrossover, java.io.Serializable {
|
public class CrossoverGADefault implements InterfaceCrossover,
|
||||||
|
java.io.Serializable {
|
||||||
private InterfaceOptimizationProblem m_OptimizationProblem;
|
private InterfaceOptimizationProblem m_OptimizationProblem;
|
||||||
|
|
||||||
public CrossoverGADefault() {
|
public CrossoverGADefault() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CrossoverGADefault(CrossoverGADefault c) {
|
public CrossoverGADefault(CrossoverGADefault c) {
|
||||||
this.m_OptimizationProblem = c.m_OptimizationProblem;
|
this.m_OptimizationProblem = c.m_OptimizationProblem;
|
||||||
}
|
}
|
||||||
/** This method will enable you to clone a given mutation operator
|
|
||||||
|
/**
|
||||||
|
* This method will enable you to clone a given mutation operator
|
||||||
|
*
|
||||||
* @return The clone
|
* @return The clone
|
||||||
*/
|
*/
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
return new CrossoverGADefault(this);
|
return new CrossoverGADefault(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method performs crossover on two individuals. If the individuals do
|
/**
|
||||||
|
* This method performs crossover on two individuals. If the individuals do
|
||||||
* not implement InterfaceGAIndividual, then nothing will happen.
|
* not implement InterfaceGAIndividual, then nothing will happen.
|
||||||
* @param indy1 The first individual
|
*
|
||||||
* @param partners The second individual
|
* @param indy1
|
||||||
|
* The first individual
|
||||||
|
* @param partners
|
||||||
|
* The second individual
|
||||||
*/
|
*/
|
||||||
public AbstractEAIndividual[] mate(AbstractEAIndividual indy1, Population partners) {
|
public AbstractEAIndividual[] mate(AbstractEAIndividual indy1,
|
||||||
|
Population partners) {
|
||||||
AbstractEAIndividual[] result = null;
|
AbstractEAIndividual[] result = null;
|
||||||
result = new AbstractEAIndividual[partners.size()+1];
|
result = new AbstractEAIndividual[partners.size() + 1];
|
||||||
result[0] = (AbstractEAIndividual) (indy1).clone();
|
result[0] = (AbstractEAIndividual) (indy1).clone();
|
||||||
for (int i = 0; i < partners.size(); i++) result[i+1] = (AbstractEAIndividual) ((AbstractEAIndividual)partners.get(i)).clone();
|
for (int i = 0; i < partners.size(); i++)
|
||||||
//for (int i = 0; i < result.length; i++) System.out.println("Before Crossover: " +result[i].getSolutionRepresentationFor());
|
result[i + 1] = (AbstractEAIndividual) ((AbstractEAIndividual) partners
|
||||||
|
.get(i)).clone();
|
||||||
|
// for (int i = 0; i < result.length; i++) System.out.println("Before
|
||||||
|
// Crossover: " +result[i].getSolutionRepresentationFor());
|
||||||
if (partners.size() == 0) return result;
|
if (partners.size() == 0) return result;
|
||||||
if ((indy1 instanceof InterfaceGAIndividual) && (partners.get(0) instanceof InterfaceGAIndividual)) {
|
if ((indy1 instanceof InterfaceGAIndividual)
|
||||||
|
&& (partners.get(0) instanceof InterfaceGAIndividual)) {
|
||||||
// Currently we will only handle two parents
|
// Currently we will only handle two parents
|
||||||
int crossoverpoint = RandomNumberGenerator.randomInt(0,((InterfaceGAIndividual)indy1).getGenotypeLength()-1);
|
int crossoverpoint = RandomNumberGenerator.randomInt(0,
|
||||||
|
((InterfaceGAIndividual) indy1).getGenotypeLength() - 1);
|
||||||
boolean tmpValue;
|
boolean tmpValue;
|
||||||
BitSet[] tmpBitSets = new BitSet[2];
|
BitSet[] tmpBitSets = new BitSet[2];
|
||||||
tmpBitSets[0] = ((InterfaceGAIndividual)result[0]).getBGenotype();
|
tmpBitSets[0] = ((InterfaceGAIndividual) result[0]).getBGenotype();
|
||||||
tmpBitSets[1] = ((InterfaceGAIndividual)result[1]).getBGenotype();
|
tmpBitSets[1] = ((InterfaceGAIndividual) result[1]).getBGenotype();
|
||||||
for (int i = crossoverpoint; i < ((InterfaceGAIndividual)result[0]).getGenotypeLength(); i++) {
|
for (int i = crossoverpoint; i < ((InterfaceGAIndividual) result[0])
|
||||||
if (tmpBitSets[0].get(i)) tmpValue = true;
|
.getGenotypeLength(); i++) {
|
||||||
|
if (tmpBitSets[0].get(i))
|
||||||
|
tmpValue = true;
|
||||||
else tmpValue = false;
|
else tmpValue = false;
|
||||||
if (tmpBitSets[1].get(i)) tmpBitSets[0].set(i);
|
if (tmpBitSets[1].get(i))
|
||||||
|
tmpBitSets[0].set(i);
|
||||||
else tmpBitSets[0].clear(i);
|
else tmpBitSets[0].clear(i);
|
||||||
if (tmpValue) tmpBitSets[1].set(i);
|
if (tmpValue)
|
||||||
|
tmpBitSets[1].set(i);
|
||||||
else tmpBitSets[1].clear(i);
|
else tmpBitSets[1].clear(i);
|
||||||
}
|
}
|
||||||
((InterfaceGAIndividual)result[0]).SetBGenotype(tmpBitSets[0]);
|
((InterfaceGAIndividual) result[0]).SetBGenotype(tmpBitSets[0]);
|
||||||
((InterfaceGAIndividual)result[1]).SetBGenotype(tmpBitSets[1]);
|
((InterfaceGAIndividual) result[1]).SetBGenotype(tmpBitSets[1]);
|
||||||
}
|
}
|
||||||
//in case the crossover was successfull lets give the mutation operators a chance to mate the strategy parameters
|
// in case the crossover was successfull lets give the mutation operators a
|
||||||
for (int i = 0; i < result.length; i++) result[i].getMutationOperator().crossoverOnStrategyParameters(indy1, partners);
|
// chance to mate the strategy parameters
|
||||||
//for (int i = 0; i < result.length; i++) System.out.println("After Crossover: " +result[i].getSolutionRepresentationFor());
|
for (int i = 0; i < result.length; i++)
|
||||||
|
result[i].getMutationOperator().crossoverOnStrategyParameters(indy1,
|
||||||
|
partners);
|
||||||
|
// for (int i = 0; i < result.length; i++) System.out.println("After
|
||||||
|
// Crossover: " +result[i].getSolutionRepresentationFor());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method allows you to evaluate wether two crossover operators
|
/**
|
||||||
* are actually the same.
|
* This method allows you to evaluate wether two crossover operators are
|
||||||
* @param crossover The other crossover operator
|
* actually the same.
|
||||||
|
*
|
||||||
|
* @param crossover
|
||||||
|
* The other crossover operator
|
||||||
*/
|
*/
|
||||||
public boolean equals(Object crossover) {
|
public boolean equals(Object crossover) {
|
||||||
if (crossover instanceof CrossoverGADefault) return true;
|
if (crossover instanceof CrossoverGADefault)
|
||||||
|
return true;
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will allow the crossover operator to be initialized depending on the
|
/**
|
||||||
* individual and the optimization problem. The optimization problem is to be stored
|
* This method will allow the crossover operator to be initialized depending
|
||||||
* since it is to be called during crossover to calculate the exogene parameters for
|
* on the individual and the optimization problem. The optimization problem is
|
||||||
* the offsprings.
|
* to be stored since it is to be called during crossover to calculate the
|
||||||
* @param individual The individual that will be mutated.
|
* exogene parameters for the offsprings.
|
||||||
* @param opt The optimization problem.
|
*
|
||||||
|
* @param individual
|
||||||
|
* The individual that will be mutated.
|
||||||
|
* @param opt
|
||||||
|
* The optimization problem.
|
||||||
*/
|
*/
|
||||||
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) {
|
public void init(AbstractEAIndividual individual,
|
||||||
|
InterfaceOptimizationProblem opt) {
|
||||||
this.m_OptimizationProblem = opt;
|
this.m_OptimizationProblem = opt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,17 +120,22 @@ public class CrossoverGADefault implements InterfaceCrossover, java.io.Serializa
|
|||||||
return this.getName();
|
return this.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************************************************************************************************************
|
/*****************************************************************************
|
||||||
* These are for GUI
|
* These are for GUI
|
||||||
*/
|
*/
|
||||||
/** This method allows the CommonJavaObjectEditorPanel to read the
|
/**
|
||||||
* name to the current object.
|
* This method allows the CommonJavaObjectEditorPanel to read the name to the
|
||||||
|
* current object.
|
||||||
|
*
|
||||||
* @return The name.
|
* @return The name.
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "GA default crossover";
|
return "GA default crossover";
|
||||||
}
|
}
|
||||||
/** This method returns a global info string
|
|
||||||
|
/**
|
||||||
|
* This method returns a global info string
|
||||||
|
*
|
||||||
* @return description
|
* @return description
|
||||||
*/
|
*/
|
||||||
public String globalInfo() {
|
public String globalInfo() {
|
||||||
|
@ -1,45 +1,67 @@
|
|||||||
package javaeva.server.go.strategies;
|
package javaeva.server.go.strategies;
|
||||||
|
|
||||||
|
import java.util.Hashtable;
|
||||||
|
|
||||||
import javaeva.server.go.InterfacePopulationChangedEventListener;
|
import javaeva.server.go.InterfacePopulationChangedEventListener;
|
||||||
import javaeva.server.go.PopulationInterface;
|
|
||||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||||
import javaeva.server.go.operators.selection.InterfaceSelection;
|
import javaeva.server.go.operators.selection.InterfaceSelection;
|
||||||
import javaeva.server.go.operators.selection.SelectBest;
|
|
||||||
import javaeva.server.go.operators.selection.SelectBestIndividuals;
|
import javaeva.server.go.operators.selection.SelectBestIndividuals;
|
||||||
import javaeva.server.go.populations.Population;
|
import javaeva.server.go.populations.Population;
|
||||||
import javaeva.server.go.problems.F1Problem;
|
import javaeva.server.go.problems.F1Problem;
|
||||||
import javaeva.server.go.problems.InterfaceLocalSearchable;
|
import javaeva.server.go.problems.InterfaceLocalSearchable;
|
||||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||||
import java.util.Hashtable;
|
|
||||||
|
|
||||||
|
/**
|
||||||
/** A memetic algorithm by hannes planatscher. The local search strategy can only be applied
|
* A memetic algorithm by hannes planatscher. The local search strategy can only
|
||||||
* to problems which implement the InterfaceLocalSearchable else the local search will not be
|
* be applied to problems which implement the InterfaceLocalSearchable else the
|
||||||
* activated at all.
|
* local search will not be activated at all.
|
||||||
* <p>Title: The JavaEvA</p>
|
* <p>
|
||||||
* <p>Description: </p>
|
* Title: The JavaEvA
|
||||||
* <p>Copyright: Copyright (c) 2003</p>
|
* </p>
|
||||||
* <p>Company: </p>
|
* <p>
|
||||||
|
* Description:
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* Copyright: Copyright (c) 2003
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* Company:
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
* @author not attributable
|
* @author not attributable
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class MemeticAlgorithm implements InterfaceOptimizer, java.io.Serializable {
|
public class MemeticAlgorithm implements InterfaceOptimizer,
|
||||||
|
java.io.Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* serial version uid.
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = -1730086430763348568L;
|
||||||
|
|
||||||
private int localSearchSteps = 1;
|
private int localSearchSteps = 1;
|
||||||
|
|
||||||
private int subsetsize = 5;
|
private int subsetsize = 5;
|
||||||
|
|
||||||
private int globalSearchSteps = 1;
|
private int globalSearchSteps = 1;
|
||||||
|
|
||||||
private boolean lamarckism = true;
|
private boolean lamarckism = true;
|
||||||
|
|
||||||
// int counter = 0; !?
|
// int counter = 0; !?
|
||||||
// int maxfunctioncalls = 1000; !?
|
// int maxfunctioncalls = 1000; !?
|
||||||
|
|
||||||
private boolean TRACE = false;
|
private boolean TRACE = false;
|
||||||
private String m_Identifier = "";
|
|
||||||
private InterfaceOptimizationProblem m_Problem = new F1Problem();
|
|
||||||
private InterfaceOptimizer m_GlobalOptimizer = new GeneticAlgorithm();
|
|
||||||
private InterfaceSelection selectorPlug = new SelectBestIndividuals();
|
|
||||||
transient private InterfacePopulationChangedEventListener m_Listener;
|
|
||||||
|
|
||||||
|
private String m_Identifier = "";
|
||||||
|
|
||||||
|
private InterfaceOptimizationProblem m_Problem = new F1Problem();
|
||||||
|
|
||||||
|
private InterfaceOptimizer m_GlobalOptimizer = new GeneticAlgorithm();
|
||||||
|
|
||||||
|
private InterfaceSelection selectorPlug = new SelectBestIndividuals();
|
||||||
|
|
||||||
|
transient private InterfacePopulationChangedEventListener m_Listener;
|
||||||
|
|
||||||
public MemeticAlgorithm() {
|
public MemeticAlgorithm() {
|
||||||
|
|
||||||
@ -47,9 +69,9 @@ public class MemeticAlgorithm implements InterfaceOptimizer, java.io.Serializabl
|
|||||||
|
|
||||||
public MemeticAlgorithm(MemeticAlgorithm a) {
|
public MemeticAlgorithm(MemeticAlgorithm a) {
|
||||||
// this.m_Population = (Population)a.m_Population.clone();
|
// this.m_Population = (Population)a.m_Population.clone();
|
||||||
this.m_Problem = (InterfaceLocalSearchable)a.m_Problem.clone();
|
this.m_Problem = (InterfaceLocalSearchable) a.m_Problem.clone();
|
||||||
this.m_GlobalOptimizer = (InterfaceOptimizer)a.m_GlobalOptimizer;
|
this.m_GlobalOptimizer = (InterfaceOptimizer) a.m_GlobalOptimizer;
|
||||||
this.selectorPlug = (InterfaceSelection)a.selectorPlug;
|
this.selectorPlug = (InterfaceSelection) a.selectorPlug;
|
||||||
this.m_Identifier = a.m_Identifier;
|
this.m_Identifier = a.m_Identifier;
|
||||||
this.localSearchSteps = a.localSearchSteps;
|
this.localSearchSteps = a.localSearchSteps;
|
||||||
this.subsetsize = a.subsetsize;
|
this.subsetsize = a.subsetsize;
|
||||||
@ -57,28 +79,31 @@ public class MemeticAlgorithm implements InterfaceOptimizer, java.io.Serializabl
|
|||||||
this.lamarckism = a.lamarckism;
|
this.lamarckism = a.lamarckism;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
return (Object) new MemeticAlgorithm(this);
|
return new MemeticAlgorithm(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initByPopulation(Population pop, boolean reset) {
|
public void initByPopulation(Population pop, boolean reset) {
|
||||||
this.setPopulation((Population) pop.clone());
|
this.setPopulation((Population) pop.clone());
|
||||||
if (reset)this.getPopulation().init();
|
if (reset) this.getPopulation().init();
|
||||||
this.m_Problem.evaluate(this.getPopulation());
|
this.m_Problem.evaluate(this.getPopulation());
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent("NextGenerationPerformed");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
//counter = 0;
|
// counter = 0;
|
||||||
this.m_GlobalOptimizer.SetProblem(this.m_Problem);
|
this.m_GlobalOptimizer.SetProblem(this.m_Problem);
|
||||||
this.m_GlobalOptimizer.init();
|
this.m_GlobalOptimizer.init();
|
||||||
this.evaluatePopulation(this.m_GlobalOptimizer.getPopulation());
|
this.evaluatePopulation(this.m_GlobalOptimizer.getPopulation());
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent("NextGenerationPerformed");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will evaluate the current population using the
|
/**
|
||||||
* given problem.
|
* This method will evaluate the current population using the given problem.
|
||||||
* @param population The population that is to be evaluated
|
*
|
||||||
|
* @param population
|
||||||
|
* The population that is to be evaluated
|
||||||
*/
|
*/
|
||||||
private void evaluatePopulation(Population population) {
|
private void evaluatePopulation(Population population) {
|
||||||
this.m_Problem.evaluate(population);
|
this.m_Problem.evaluate(population);
|
||||||
@ -90,38 +115,48 @@ public class MemeticAlgorithm implements InterfaceOptimizer, java.io.Serializabl
|
|||||||
if (TRACE) System.out.println("global search");
|
if (TRACE) System.out.println("global search");
|
||||||
this.m_GlobalOptimizer.optimize();
|
this.m_GlobalOptimizer.optimize();
|
||||||
|
|
||||||
if ((this.m_GlobalOptimizer.getPopulation().getGeneration()%this.globalSearchSteps == 0)
|
if ((this.m_GlobalOptimizer.getPopulation().getGeneration()
|
||||||
|
% this.globalSearchSteps == 0)
|
||||||
&& (this.localSearchSteps != 0)
|
&& (this.localSearchSteps != 0)
|
||||||
&& (this.m_Problem instanceof InterfaceLocalSearchable)){
|
&& (this.m_Problem instanceof InterfaceLocalSearchable)) {
|
||||||
// here the local search is performed
|
// here the local search is performed
|
||||||
if (TRACE) System.out.println("Performing local search on " +subsetsize+ " individuals.");
|
if (TRACE)
|
||||||
|
System.out.println("Performing local search on " + subsetsize
|
||||||
|
+ " individuals.");
|
||||||
Population gop = this.m_GlobalOptimizer.getPopulation();
|
Population gop = this.m_GlobalOptimizer.getPopulation();
|
||||||
Population subset = selectorPlug.selectFrom(gop, subsetsize);
|
Population subset = selectorPlug.selectFrom(gop, subsetsize);
|
||||||
Population subsetclone = new Population();
|
Population subsetclone = new Population();
|
||||||
for (int i = 0; i < subset.size(); i++) {
|
for (int i = 0; i < subset.size(); i++) {
|
||||||
subsetclone.add(((AbstractEAIndividual)subset.get(i)).clone());
|
subsetclone.add(((AbstractEAIndividual) subset.get(i)).clone());
|
||||||
}
|
}
|
||||||
if (subset.size() != subsetsize) System.out.println("ALERT! identic individual instances in subset");
|
if (subset.size() != subsetsize)
|
||||||
|
System.err.println("ALERT! identical individual instances in subset");
|
||||||
Hashtable antilamarckismcache = new Hashtable();
|
Hashtable antilamarckismcache = new Hashtable();
|
||||||
if (!this.lamarckism) {
|
if (!this.lamarckism) {
|
||||||
for (int i = 0; i < subset.size(); i++) {
|
for (int i = 0; i < subset.size(); i++) {
|
||||||
AbstractEAIndividual indy = (AbstractEAIndividual) subset.get(i);
|
AbstractEAIndividual indy = (AbstractEAIndividual) subset.get(i);
|
||||||
AbstractEAIndividual indyclone = (AbstractEAIndividual) subsetclone.get(i);
|
AbstractEAIndividual indyclone = (AbstractEAIndividual) subsetclone
|
||||||
|
.get(i);
|
||||||
antilamarckismcache.put(indy, indyclone);
|
antilamarckismcache.put(indy, indyclone);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//int dosearchsteps = this.localSearchSteps;
|
// int dosearchsteps = this.localSearchSteps;
|
||||||
double cost = ((InterfaceLocalSearchable)this.m_Problem).getLocalSearchStepFunctionCallEquivalent();
|
double cost = ((InterfaceLocalSearchable) this.m_Problem)
|
||||||
//int calls = gop.getFunctionCalls() + (int) Math.round(localSearchSteps * cost * subset.size());
|
.getLocalSearchStepFunctionCallEquivalent();
|
||||||
// nett aber total unn<EFBFBD>tig-falsch man kann nicht davon ausgehen, dass man einen Fitnesscall Terminator hat..
|
// int calls = gop.getFunctionCalls() + (int) Math.round(localSearchSteps
|
||||||
// if (calls > this.maxfunctioncalls) {
|
// * cost * subset.size());
|
||||||
// int remainingfunctioncalls = this.maxfunctioncalls - gop.getFunctionCalls();
|
// nett aber total unn<EFBFBD>tig-falsch man kann nicht davon ausgehen, dass man
|
||||||
// dosearchsteps = (int)Math.floor(((double) remainingfunctioncalls) / (cost * subsetsize));
|
// einen Fitnesscall Terminator hat..
|
||||||
// stopit = true;
|
// if (calls > this.maxfunctioncalls) {
|
||||||
// }
|
// int remainingfunctioncalls = this.maxfunctioncalls -
|
||||||
for (int i = 0; i < localSearchSteps ; i++) {
|
// gop.getFunctionCalls();
|
||||||
((InterfaceLocalSearchable)this.m_Problem).doLocalSearch(subsetclone);
|
// dosearchsteps = (int)Math.floor(((double) remainingfunctioncalls) /
|
||||||
|
// (cost * subsetsize));
|
||||||
|
// stopit = true;
|
||||||
|
// }
|
||||||
|
for (int i = 0; i < localSearchSteps; i++) {
|
||||||
|
((InterfaceLocalSearchable) this.m_Problem).doLocalSearch(subsetclone);
|
||||||
}
|
}
|
||||||
this.m_Problem.evaluate(subsetclone);
|
this.m_Problem.evaluate(subsetclone);
|
||||||
if (this.lamarckism) {
|
if (this.lamarckism) {
|
||||||
@ -131,115 +166,144 @@ public class MemeticAlgorithm implements InterfaceOptimizer, java.io.Serializabl
|
|||||||
for (int i = 0; i < subset.size(); i++) {
|
for (int i = 0; i < subset.size(); i++) {
|
||||||
AbstractEAIndividual indy = (AbstractEAIndividual) subset.get(i);
|
AbstractEAIndividual indy = (AbstractEAIndividual) subset.get(i);
|
||||||
try {
|
try {
|
||||||
AbstractEAIndividual newindy = (AbstractEAIndividual) antilamarckismcache.get(indy);
|
AbstractEAIndividual newindy = (AbstractEAIndividual) antilamarckismcache
|
||||||
|
.get(indy);
|
||||||
indy.SetFitness(newindy.getFitness());
|
indy.SetFitness(newindy.getFitness());
|
||||||
}
|
} catch (Exception ex) {
|
||||||
catch (Exception ex) {
|
System.err.println("individual not found in antilamarckismcache");
|
||||||
System.out.println("indy not found in antilamarckismcache");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// eigentlich muss hier noch subsetsize drauf, aber lassen wir das
|
// eigentlich muss hier noch subsetsize drauf, aber lassen wir das
|
||||||
gop.SetFunctionCalls(gop.getFunctionCalls() + (int) Math.round(localSearchSteps * cost * subset.size()));
|
gop.SetFunctionCalls(gop.getFunctionCalls()
|
||||||
|
+ (int) Math.round(localSearchSteps * cost * subset.size()));
|
||||||
|
|
||||||
if (TRACE) System.out.println("Population size after local search:" + gop.size());
|
if (TRACE)
|
||||||
|
System.out.println("Population size after local search:" + gop.size());
|
||||||
|
|
||||||
this.setPopulation(gop);
|
this.setPopulation(gop);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TRACE) System.out.println("function calls" + this.m_GlobalOptimizer.getPopulation().getFunctionCalls());
|
if (TRACE)
|
||||||
|
System.out.println("function calls"
|
||||||
|
+ this.m_GlobalOptimizer.getPopulation().getFunctionCalls());
|
||||||
this.firePropertyChangedEvent("NextGenerationPerformed");
|
this.firePropertyChangedEvent("NextGenerationPerformed");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method allows you to add the LectureGUI as listener to the Optimizer
|
/**
|
||||||
|
* This method allows you to add the LectureGUI as listener to the Optimizer
|
||||||
|
*
|
||||||
* @param ea
|
* @param ea
|
||||||
*/
|
*/
|
||||||
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
|
public void addPopulationChangedEventListener(
|
||||||
|
InterfacePopulationChangedEventListener ea) {
|
||||||
this.m_Listener = ea;
|
this.m_Listener = ea;
|
||||||
}
|
}
|
||||||
/** Something has changed
|
|
||||||
|
/**
|
||||||
|
* Something has changed
|
||||||
*/
|
*/
|
||||||
protected void firePropertyChangedEvent (String name) {
|
protected void firePropertyChangedEvent(String name) {
|
||||||
if (this.m_Listener != null) {
|
if (this.m_Listener != null) {
|
||||||
if (TRACE) System.out.println("firePropertyChangedEvent MA");
|
if (TRACE) System.out.println("firePropertyChangedEvent MA");
|
||||||
this.m_Listener.registerPopulationStateChanged(this, name);
|
this.m_Listener.registerPopulationStateChanged(this, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will set the problem that is to be optimized
|
/**
|
||||||
|
* This method will set the problem that is to be optimized
|
||||||
|
*
|
||||||
* @param problem
|
* @param problem
|
||||||
*/
|
*/
|
||||||
public void SetProblem (InterfaceOptimizationProblem problem) {
|
public void SetProblem(InterfaceOptimizationProblem problem) {
|
||||||
this.m_Problem = problem;
|
this.m_Problem = problem;
|
||||||
this.m_GlobalOptimizer.SetProblem(this.m_Problem);
|
this.m_GlobalOptimizer.SetProblem(this.m_Problem);
|
||||||
}
|
}
|
||||||
public InterfaceOptimizationProblem getProblem () {
|
|
||||||
|
public InterfaceOptimizationProblem getProblem() {
|
||||||
return this.m_Problem;
|
return this.m_Problem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will return a string describing all properties of the optimizer
|
/**
|
||||||
|
* This method will return a string describing all properties of the optimizer
|
||||||
* and the applied methods.
|
* and the applied methods.
|
||||||
|
*
|
||||||
* @return A descriptive string
|
* @return A descriptive string
|
||||||
*/
|
*/
|
||||||
public String getStringRepresentation() {
|
public String getStringRepresentation() {
|
||||||
String result = "";
|
String result = "";
|
||||||
result += "Memetic Algorithm:\n";
|
result += "Memetic Algorithm:\n";
|
||||||
result += "Optimization Problem: ";
|
result += "Optimization Problem: ";
|
||||||
result += this.m_Problem.getStringRepresentationForProblem(this) +"\n";
|
result += this.m_Problem.getStringRepresentationForProblem(this) + "\n";
|
||||||
result += this.m_GlobalOptimizer.getStringRepresentation();
|
result += this.m_GlobalOptimizer.getStringRepresentation();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
/** This method allows you to set an identifier for the algorithm
|
|
||||||
* @param name The indenifier
|
/**
|
||||||
|
* This method allows you to set an identifier for the algorithm
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* The indenifier
|
||||||
*/
|
*/
|
||||||
public void SetIdentifier(String name) {
|
public void SetIdentifier(String name) {
|
||||||
this.m_Identifier = name;
|
this.m_Identifier = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIdentifier() {
|
public String getIdentifier() {
|
||||||
return this.m_Identifier;
|
return this.m_Identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method is required to free the memory on a RMIServer,
|
/**
|
||||||
* but there is nothing to implement.
|
* This method is required to free the memory on a RMIServer, but there is
|
||||||
|
* nothing to implement.
|
||||||
*/
|
*/
|
||||||
public void freeWilly() {
|
public void freeWilly() {
|
||||||
|
|
||||||
}
|
}
|
||||||
/**********************************************************************************************************************
|
|
||||||
* These are for GUI
|
/*
|
||||||
*/
|
* ========================================================================================
|
||||||
/** This method returns a global info string
|
* These are for GUI
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* This method returns a global info string
|
||||||
|
*
|
||||||
* @return description
|
* @return description
|
||||||
*/
|
*/
|
||||||
public String globalInfo() {
|
public String globalInfo() {
|
||||||
return "This is a basic generational Memetic Algorithm.";
|
return "This is a basic generational Memetic Algorithm.";
|
||||||
}
|
}
|
||||||
/** This method will return a naming String
|
|
||||||
|
/**
|
||||||
|
* This method will return a naming String
|
||||||
|
*
|
||||||
* @return The name of the algorithm
|
* @return The name of the algorithm
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "Memetic-Algorithm";
|
return "Memetic-Algorithm";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Assuming that all optimizer will store thier data in a population
|
/**
|
||||||
* we will allow acess to this population to query to current state
|
* Assuming that all optimizer will store thier data in a population we will
|
||||||
* of the optimizer.
|
* allow acess to this population to query to current state of the optimizer.
|
||||||
|
*
|
||||||
* @return The population of current solutions to a given problem.
|
* @return The population of current solutions to a given problem.
|
||||||
*/
|
*/
|
||||||
public Population getPopulation() {
|
public Population getPopulation() {
|
||||||
return this.m_GlobalOptimizer.getPopulation();
|
return this.m_GlobalOptimizer.getPopulation();
|
||||||
}
|
}
|
||||||
public void setPopulation(Population pop){
|
|
||||||
|
public void setPopulation(Population pop) {
|
||||||
this.m_GlobalOptimizer.setPopulation(pop);
|
this.m_GlobalOptimizer.setPopulation(pop);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String populationTipText() {
|
public String populationTipText() {
|
||||||
return "Edit the properties of the population used.";
|
return "Edit the properties of the population used.";
|
||||||
}
|
}
|
||||||
|
|
||||||
public Population getAllSolutions() {
|
/**
|
||||||
return getPopulation();
|
* Choose the global optimization strategy to use
|
||||||
}
|
*
|
||||||
/** Choose the global optimization strategy to use
|
|
||||||
* @param m_GlobalOptimizer
|
* @param m_GlobalOptimizer
|
||||||
*/
|
*/
|
||||||
public void setGlobalOptimizer(InterfaceOptimizer m_GlobalOptimizer) {
|
public void setGlobalOptimizer(InterfaceOptimizer m_GlobalOptimizer) {
|
||||||
@ -247,64 +311,86 @@ public class MemeticAlgorithm implements InterfaceOptimizer, java.io.Serializabl
|
|||||||
this.m_GlobalOptimizer.SetProblem(this.getProblem());
|
this.m_GlobalOptimizer.SetProblem(this.getProblem());
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public InterfaceOptimizer getGlobalOptimizer() {
|
public InterfaceOptimizer getGlobalOptimizer() {
|
||||||
return m_GlobalOptimizer;
|
return m_GlobalOptimizer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String globalOptimizerTipText() {
|
public String globalOptimizerTipText() {
|
||||||
return "Choose the global optimization strategy to use.";
|
return "Choose the global optimization strategy to use.";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Choose the number of local search steps to perform per selected individual
|
/**
|
||||||
|
* Choose the number of local search steps to perform per selected individual
|
||||||
|
*
|
||||||
* @param localSearchSteps
|
* @param localSearchSteps
|
||||||
*/
|
*/
|
||||||
public void setLocalSearchSteps(int localSearchSteps) {
|
public void setLocalSearchSteps(int localSearchSteps) {
|
||||||
this.localSearchSteps = localSearchSteps;
|
this.localSearchSteps = localSearchSteps;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLocalSearchSteps() {
|
public int getLocalSearchSteps() {
|
||||||
return localSearchSteps;
|
return localSearchSteps;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String localSearchStepsTipText() {
|
public String localSearchStepsTipText() {
|
||||||
return "Choose the number of local search steps to perform per selected individual.";
|
return "Choose the number of local search steps to perform per selected individual.";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Choose the interval between the application of the local search
|
/**
|
||||||
|
* Choose the interval between the application of the local search
|
||||||
|
*
|
||||||
* @param globalSearchSteps
|
* @param globalSearchSteps
|
||||||
*/
|
*/
|
||||||
public void setGlobalSearchSteps(int globalSearchSteps) {
|
public void setGlobalSearchSteps(int globalSearchSteps) {
|
||||||
this.globalSearchSteps = globalSearchSteps;
|
this.globalSearchSteps = globalSearchSteps;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getGlobalSearchSteps() {
|
public int getGlobalSearchSteps() {
|
||||||
return globalSearchSteps;
|
return globalSearchSteps;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String globalSearchStepsTipText() {
|
public String globalSearchStepsTipText() {
|
||||||
return "Choose the interval between the application of the local search.";
|
return "Choose the interval between the application of the local search.";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Choose the number of individual to be locally optimized
|
/**
|
||||||
|
* Choose the number of individual to be locally optimized
|
||||||
|
*
|
||||||
* @param subsetsize
|
* @param subsetsize
|
||||||
*/
|
*/
|
||||||
public void setSubsetsize(int subsetsize) {
|
public void setSubsetsize(int subsetsize) {
|
||||||
this.subsetsize = subsetsize;
|
this.subsetsize = subsetsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Population getAllSolutions() {
|
||||||
|
return getPopulation();
|
||||||
|
}
|
||||||
public int getSubsetsize() {
|
public int getSubsetsize() {
|
||||||
return subsetsize;
|
return subsetsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String subsetsizeTipText() {
|
public String subsetsizeTipText() {
|
||||||
return "Choose the number of individual to be locally optimized.";
|
return "Choose the number of individual to be locally optimized.";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Toggel between Lamarcksim and the Baldwin Effect
|
/**
|
||||||
|
* Toggel between Lamarcksim and the Baldwin Effect
|
||||||
|
*
|
||||||
* @param lamarckism
|
* @param lamarckism
|
||||||
*/
|
*/
|
||||||
public void setLamarckism(boolean lamarckism) {
|
public void setLamarckism(boolean lamarckism) {
|
||||||
this.lamarckism = lamarckism;
|
this.lamarckism = lamarckism;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getLamarckism() {
|
public boolean getLamarckism() {
|
||||||
return this.lamarckism;
|
return this.lamarckism;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String lamarckismTipText() {
|
public String lamarckismTipText() {
|
||||||
return "Toggel between Lamarcksim and the Baldwin Effect.";
|
return "Toggel between Lamarcksim and the Baldwin Effect.";
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLamarckism() {
|
public boolean isLamarckism() {
|
||||||
return lamarckism;
|
return lamarckism;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user