Little fixes in LTGA (Logging, deprecated method)

Refactored InterfaceOptimizer (Set* to set*)
This commit is contained in:
Fabian Becker 2012-12-22 12:27:10 +00:00
parent 7a6c814a56
commit 0f553039e4
32 changed files with 385 additions and 385 deletions

View File

@ -373,7 +373,7 @@ public class OptimizerFactory {
setTemplateOperators(problem, mutator, 1., new NoCrossover(), 0); setTemplateOperators(problem, mutator, 1., new NoCrossover(), 0);
HillClimbing hc = new HillClimbing(); HillClimbing hc = new HillClimbing();
hc.SetIdentifier("-"+popSize+"-"+mutator.getStringRepresentation()); hc.setIdentifier("-"+popSize+"-"+mutator.getStringRepresentation());
hc.getPopulation().setTargetSize(popSize); hc.getPopulation().setTargetSize(popSize);
hc.addPopulationChangedEventListener(listener); hc.addPopulationChangedEventListener(listener);
hc.SetProblem(problem); hc.SetProblem(problem);

View File

@ -592,7 +592,7 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
return new SolutionSet(this.population); return new SolutionSet(this.population);
} }
public void SetIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.m_Identifier = name;
} }

View File

@ -723,7 +723,7 @@ public class BinaryScatterSearch implements InterfaceOptimizer, java.io.Serializ
return new SolutionSet(this.refSet); return new SolutionSet(this.refSet);
} }
public void SetIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.m_Identifier = name;
} }

View File

@ -261,7 +261,7 @@ public class CHCAdaptiveSearchAlgorithm implements InterfaceOptimizer, java.io.S
/** This method allows you to set an identifier for the algorithm /** This method allows you to set an identifier for the algorithm
* @param name The indenifier * @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() {

View File

@ -996,7 +996,7 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
/** This method allows you to set an identifier for the algorithm /** This method allows you to set an identifier for the algorithm
* @param name The indenifier * @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() {

View File

@ -97,7 +97,7 @@ InterfaceOptimizer, Serializable, InterfaceAdditionalPopulationInformer {
setLocalSearchMethod(getLocalSearchMethod()); setLocalSearchMethod(getLocalSearchMethod());
} }
public void SetIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.m_Identifier = name;
} }
public String getIdentifier() { public String getIdentifier() {

View File

@ -687,7 +687,7 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
/** This method allows you to set an identifier for the algorithm /** This method allows you to set an identifier for the algorithm
* @param name The identifier * @param name The identifier
*/ */
public void SetIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.m_Identifier = name;
} }
public String getIdentifier() { public String getIdentifier() {

View File

@ -1062,7 +1062,7 @@ public class EsDpiNiching implements InterfaceOptimizer, Serializable, Interface
return identifier; return identifier;
} }
public void SetIdentifier(String name) { public void setIdentifier(String name) {
identifier = name; identifier = name;
} }

View File

@ -323,7 +323,7 @@ public class EvolutionStrategies implements InterfaceOptimizer, java.io.Serializ
* *
* @param name The indenifier * @param name The indenifier
*/ */
public void SetIdentifier(String name) { public void setIdentifier(String name) {
this.identifier = name; this.identifier = name;
} }

View File

@ -153,7 +153,7 @@ public class EvolutionaryProgramming implements InterfaceOptimizer, java.io.Seri
/** This method allows you to set an identifier for the algorithm /** This method allows you to set an identifier for the algorithm
* @param name The indenifier * @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() {

View File

@ -200,7 +200,7 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
/** This method allows you to set an identifier for the algorithm /** This method allows you to set an identifier for the algorithm
* @param name The indenifier * @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() {

View File

@ -225,7 +225,7 @@ public class GeneticAlgorithm implements InterfaceOptimizer, java.io.Serializabl
/** This method allows you to set an identifier for the algorithm /** This method allows you to set an identifier for the algorithm
* @param name The indenifier * @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() {

View File

@ -316,7 +316,7 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
/** This method allows you to set an identifier for the algorithm /** This method allows you to set an identifier for the algorithm
* @param name The indenifier * @param name The indenifier
*/ */
public void SetIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.m_Identifier = name;
} }

View File

@ -208,7 +208,7 @@ public class HillClimbing implements InterfaceOptimizer, java.io.Serializable {
/** This method allows you to set an identifier for the algorithm /** This method allows you to set an identifier for the algorithm
* @param name The indenifier * @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() {

View File

@ -83,8 +83,9 @@ public interface InterfaceOptimizer {
/** /**
* This method allows you to set an identifier for the algorithm * This method allows you to set an identifier for the algorithm
* @param name The identifier * @param name The identifier
* @deprecated
*/ */
public void SetIdentifier(String name); public void setIdentifier(String name);
public String getIdentifier(); public String getIdentifier();
/** /**

View File

@ -109,7 +109,7 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
this.m_Islands = new InterfaceOptimizer[this.m_numLocalCPUs]; this.m_Islands = new InterfaceOptimizer[this.m_numLocalCPUs];
for (int i = 0; i < this.m_numLocalCPUs; i++) { for (int i = 0; i < this.m_numLocalCPUs; i++) {
this.m_Islands[i] = (InterfaceOptimizer) this.m_Optimizer.clone(); this.m_Islands[i] = (InterfaceOptimizer) this.m_Optimizer.clone();
this.m_Islands[i].SetIdentifier(""+i); this.m_Islands[i].setIdentifier(""+i);
this.m_Islands[i].init(); this.m_Islands[i].init();
if (this.m_LogLocalChanges) if (this.m_LogLocalChanges)
this.m_Islands[i].addPopulationChangedEventListener(this); this.m_Islands[i].addPopulationChangedEventListener(this);
@ -129,7 +129,7 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
this.m_Islands = new InterfaceOptimizer[nodesList.length]; this.m_Islands = new InterfaceOptimizer[nodesList.length];
for (int i = 0; i < nodesList.length; i++) { for (int i = 0; i < nodesList.length; i++) {
this.m_Islands[i] = (InterfaceOptimizer) RMIProxyRemoteThread.newInstance(this.m_Optimizer, nodesList[i]); this.m_Islands[i] = (InterfaceOptimizer) RMIProxyRemoteThread.newInstance(this.m_Optimizer, nodesList[i]);
this.m_Islands[i].SetIdentifier(""+i); this.m_Islands[i].setIdentifier(""+i);
this.m_Islands[i].init(); this.m_Islands[i].init();
if (this.m_LogLocalChanges) if (this.m_LogLocalChanges)
this.m_Islands[i].addPopulationChangedEventListener(myLocal); this.m_Islands[i].addPopulationChangedEventListener(myLocal);
@ -178,7 +178,7 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
this.m_Islands = new InterfaceOptimizer[this.m_numLocalCPUs]; this.m_Islands = new InterfaceOptimizer[this.m_numLocalCPUs];
for (int i = 0; i < this.m_numLocalCPUs; i++) { for (int i = 0; i < this.m_numLocalCPUs; i++) {
this.m_Islands[i] = (InterfaceOptimizer) this.m_Optimizer.clone(); this.m_Islands[i] = (InterfaceOptimizer) this.m_Optimizer.clone();
this.m_Islands[i].SetIdentifier(""+i); this.m_Islands[i].setIdentifier(""+i);
this.m_Islands[i].init(); this.m_Islands[i].init();
if (this.m_LogLocalChanges) if (this.m_LogLocalChanges)
this.m_Islands[i].addPopulationChangedEventListener(this); this.m_Islands[i].addPopulationChangedEventListener(this);
@ -196,7 +196,7 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
this.m_Islands = new InterfaceOptimizer[nodesList.length]; this.m_Islands = new InterfaceOptimizer[nodesList.length];
for (int i = 0; i < nodesList.length; i++) { for (int i = 0; i < nodesList.length; i++) {
this.m_Islands[i] = (InterfaceOptimizer) RMIProxyRemoteThread.newInstance(this.m_Optimizer, nodesList[i]); this.m_Islands[i] = (InterfaceOptimizer) RMIProxyRemoteThread.newInstance(this.m_Optimizer, nodesList[i]);
this.m_Islands[i].SetIdentifier(""+i); this.m_Islands[i].setIdentifier(""+i);
this.m_Islands[i].init(); this.m_Islands[i].init();
if (this.m_LogLocalChanges) if (this.m_LogLocalChanges)
this.m_Islands[i].addPopulationChangedEventListener(myLocal); this.m_Islands[i].addPopulationChangedEventListener(myLocal);
@ -390,7 +390,7 @@ public class IslandModelEA implements InterfacePopulationChangedEventListener, I
/** This method allows you to set an identifier for the algorithm /** This method allows you to set an identifier for the algorithm
* @param name The indenifier * @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() {

View File

@ -23,375 +23,374 @@ import eva2.server.go.problems.InterfaceOptimizationProblem;
import eva2.tools.Pair; import eva2.tools.Pair;
import eva2.tools.math.SpecialFunction; import eva2.tools.math.SpecialFunction;
public class LTGA implements InterfaceOptimizer, java.io.Serializable, InterfacePopulationChangedEventListener{ public class LTGA implements InterfaceOptimizer, java.io.Serializable, InterfacePopulationChangedEventListener {
private static final Logger LOGGER = Logger.getLogger(BOA.class.getName()); private static final Logger LOGGER = Logger.getLogger(LTGA.class.getName());
transient private InterfacePopulationChangedEventListener m_Listener = null; transient private InterfacePopulationChangedEventListener m_Listener = null;
private String m_Identifier = "LTGA"; private String m_Identifier = "LTGA";
private int probDim = 8;
private int probDim = 8; private int fitCrit = -1;
private int fitCrit = -1; private int popSize = 50;
private int popSize = 50; private Population population = new Population();
private Population population = new Population(); private AbstractOptimizationProblem problem = new BKnapsackProblem();
private AbstractOptimizationProblem problem = new BKnapsackProblem(); private AbstractEAIndividual template = null;
private AbstractEAIndividual template = null; private int generationCycle = 500;
private int generationCycle = 500;
public LTGA() {
public LTGA(){ }
}
public LTGA(LTGA l) {
public LTGA(LTGA l){ this.m_Listener = l.m_Listener;
this.m_Listener = l.m_Listener; this.m_Identifier = l.m_Identifier;
this.m_Identifier = l.m_Identifier; this.probDim = l.probDim;
this.probDim = l.probDim; this.popSize = l.popSize;
this.popSize = l.popSize; this.population = (Population) l.population.clone();
this.population = (Population)l.population.clone(); this.problem = (AbstractOptimizationProblem) l.problem.clone();
this.problem = (AbstractOptimizationProblem)l.problem.clone();
this.template = (AbstractEAIndividual) template.clone(); this.template = (AbstractEAIndividual) template.clone();
} }
public Object clone() {
return new LTGA(this);
}
@Override @Override
public String getName() { public Object clone() {
return "Linkage Tree Genetic Algorithm"; return new LTGA(this);
} }
public static String globalInfo() {
return "Basic implementation of the Linkage Tree Genetic Algorithm based on the works by Dirk Thierens.";
}
@Override @Override
public void addPopulationChangedEventListener( public String getName() {
InterfacePopulationChangedEventListener ea) { return "Linkage Tree Genetic Algorithm";
this.m_Listener = ea; }
}
@Override public static String globalInfo() {
public boolean removePopulationChangedEventListener( return "Basic implementation of the Linkage Tree Genetic Algorithm based on the works by Dirk Thierens.";
InterfacePopulationChangedEventListener ea) { }
if (m_Listener == ea) {
m_Listener = null;
return true;
} else
return false;
}
private void defaultInit(){
if (population == null) {
this.population = new Population(this.popSize);
} else {
this.population.setTargetPopSize(this.popSize);
}
this.template = this.problem.getIndividualTemplate();
if (!(template instanceof InterfaceDataTypeBinary)) {
LOGGER.log(Level.WARNING, "Requiring binary data!");
} else {
Object dim = BeanInspector.callIfAvailable(problem,
"getProblemDimension", null);
if (dim == null)
LOGGER.log(Level.WARNING, "Coudn't get problem dimension!");
probDim = (Integer) dim;
((InterfaceDataTypeBinary) this.template).SetBinaryGenotype(new BitSet(probDim));
}
this.population.addPopulationChangedEventListener(this);
this.population.setNotifyEvalInterval(this.generationCycle);
}
private static BitSet getBinaryData(AbstractEAIndividual indy) {
if (indy instanceof InterfaceGAIndividual)
return ((InterfaceGAIndividual) indy).getBGenotype();
else if (indy instanceof InterfaceDataTypeBinary)
return ((InterfaceDataTypeBinary) indy).getBinaryData();
else {
throw new RuntimeException(
"Unable to get binary representation for "
+ indy.getClass());
}
}
@Override @Override
public void init() { public void addPopulationChangedEventListener(
defaultInit(); InterfacePopulationChangedEventListener ea) {
this.problem.initPopulation(this.population); this.m_Listener = ea;
this.evaluatePopulation(this.population);
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
private void evaluatePopulation(Population pop) {
for (int i = 0; i < pop.size(); i++) {
evaluate(pop.getEAIndividual(i));
}
}
/**
* evaluate the given Individual and increments the counter. if the
* individual is null, only the counter is incremented
*
* @param indy
* the individual you want to evaluate
*/
private void evaluate(AbstractEAIndividual indy) {
// evaluate the given individual if it is not null
if (indy == null) {
LOGGER.log(Level.WARNING, "tried to evaluate null");
return;
}
this.problem.evaluate(indy);
// increment the number of evaluations
this.population.incrFunctionCalls();
}
@Override }
public void initByPopulation(Population pop, boolean reset) {
if (reset) { @Override
init(); public boolean removePopulationChangedEventListener(
} else { InterfacePopulationChangedEventListener ea) {
defaultInit(); if (m_Listener == ea) {
this.population = pop; m_Listener = null;
} return true;
} } else {
return false;
private Stack<Set<Integer>> buildLinkageTree(){ }
// the final tree }
Stack<Set<Integer>> linkageTree = new Stack<Set<Integer>>();
// the stack to cluster here clusters can be removed private void defaultInit() {
Stack<Set<Integer>> workingStack = new Stack<Set<Integer>>(); if (population == null) {
// add the problem variables to the stacks this.population = new Population(this.popSize);
for(int i=0; i<this.probDim; i++){ } else {
Set<Integer> s1 = new HashSet<Integer>(); this.population.setTargetPopSize(this.popSize);
Set<Integer> s2 = new HashSet<Integer>(); }
s1.add(i); this.template = this.problem.getIndividualTemplate();
s2.add(i); if (!(template instanceof InterfaceDataTypeBinary)) {
linkageTree.add(s1); LOGGER.log(Level.WARNING, "Requiring binary data!");
workingStack.add(s2); } else {
} Object dim = BeanInspector.callIfAvailable(problem,
"getProblemDimension", null);
if (dim == null) {
LOGGER.log(Level.WARNING, "Couldn't get problem dimension!");
}
probDim = (Integer) dim;
((InterfaceDataTypeBinary) this.template).SetBinaryGenotype(new BitSet(probDim));
}
this.population.addPopulationChangedEventListener(this);
this.population.setNotifyEvalInterval(this.generationCycle);
}
private static BitSet getBinaryData(AbstractEAIndividual indy) {
if (indy instanceof InterfaceGAIndividual) {
return ((InterfaceGAIndividual) indy).getBGenotype();
} else if (indy instanceof InterfaceDataTypeBinary) {
return ((InterfaceDataTypeBinary) indy).getBinaryData();
} else {
throw new RuntimeException(
"Unable to get binary representation for "
+ indy.getClass());
}
}
@Override
public void init() {
defaultInit();
this.problem.initPopulation(this.population);
this.evaluatePopulation(this.population);
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
private void evaluatePopulation(Population pop) {
for (int i = 0; i < pop.size(); i++) {
evaluate(pop.getEAIndividual(i));
}
}
/**
* evaluate the given Individual and increments the counter. if the
* individual is null, only the counter is incremented
*
* @param indy the individual you want to evaluate
*/
private void evaluate(AbstractEAIndividual indy) {
// evaluate the given individual if it is not null
if (indy == null) {
LOGGER.log(Level.WARNING, "tried to evaluate null");
return;
}
this.problem.evaluate(indy);
// increment the number of evaluations
this.population.incrFunctionCalls();
}
@Override
public void initByPopulation(Population pop, boolean reset) {
if (reset) {
init();
} else {
defaultInit();
this.population = pop;
}
}
private Stack<Set<Integer>> buildLinkageTree() {
// the final tree
Stack<Set<Integer>> linkageTree = new Stack<Set<Integer>>();
// the stack to cluster here clusters can be removed
Stack<Set<Integer>> workingStack = new Stack<Set<Integer>>();
// add the problem variables to the stacks
for (int i = 0; i < this.probDim; i++) {
Set<Integer> s1 = new HashSet<Integer>();
Set<Integer> s2 = new HashSet<Integer>();
s1.add(i);
s2.add(i);
linkageTree.add(s1);
workingStack.add(s2);
}
// double[] probMass = calculateProbabilityMassFunction(); // double[] probMass = calculateProbabilityMassFunction();
// until there is only one cluster left // until there is only one cluster left
while(workingStack.size()>1){ while (workingStack.size() > 1) {
Pair<Set<Integer>, Set<Integer>> toCluster = findNearestClusters(workingStack); Pair<Set<Integer>, Set<Integer>> toCluster = findNearestClusters(workingStack);
// remove the second cluster from the working set // remove the second cluster from the working set
workingStack.remove(toCluster.tail); workingStack.remove(toCluster.tail);
// add all elements from the second cluster to the first one // add all elements from the second cluster to the first one
toCluster.head.addAll(toCluster.tail); toCluster.head.addAll(toCluster.tail);
// add the combined cluster to the linkage tree // add the combined cluster to the linkage tree
linkageTree.add(toCluster.head); linkageTree.add(toCluster.head);
} }
return linkageTree; return linkageTree;
} }
private Pair<Set<Integer>, Set<Integer>> findNearestClusters(Stack<Set<Integer>> stack) {
Set<Integer> bestI = new HashSet<Integer>();
Set<Integer> bestJ = new HashSet<Integer>();
double bestScore = Double.MAX_VALUE;
for(int i=0; i<stack.size(); i++){
Set<Integer> s1 = stack.get(i);
for(int j=i+1; j<stack.size(); j++){
Set<Integer> s2 = stack.get(j);
double currDist = calculateDistance(s1, s2);
// better cluster found
if(currDist < bestScore){
bestI = s1;
bestJ = s2;
bestScore = currDist;
}
}
}
// return the best pair
return new Pair<Set<Integer>, Set<Integer>>(bestI, bestJ);
}
private double calculateDistance(Set<Integer> s1, Set<Integer> s2) { private Pair<Set<Integer>, Set<Integer>> findNearestClusters(Stack<Set<Integer>> stack) {
double entropy1 = calculateEntropy(s1); Set<Integer> bestI = new HashSet<Integer>();
double entropy2 = calculateEntropy(s2); Set<Integer> bestJ = new HashSet<Integer>();
Set<Integer> combined = new HashSet<Integer>(); double bestScore = Double.MAX_VALUE;
combined.addAll(s1); for (int i = 0; i < stack.size(); i++) {
combined.addAll(s2); Set<Integer> s1 = stack.get(i);
double entropy3 = calculateEntropy(combined); for (int j = i + 1; j < stack.size(); j++) {
return 2 - ((entropy1 + entropy2) / (entropy3)); Set<Integer> s2 = stack.get(j);
} double currDist = calculateDistance(s1, s2);
// better cluster found
if (currDist < bestScore) {
bestI = s1;
bestJ = s2;
bestScore = currDist;
}
}
}
// return the best pair
return new Pair<Set<Integer>, Set<Integer>>(bestI, bestJ);
}
private double calculateEntropy(Set<Integer> s){ private double calculateDistance(Set<Integer> s1, Set<Integer> s2) {
double entropy = 0.0; double entropy1 = calculateEntropy(s1);
// for possible states {0,1} do double entropy2 = calculateEntropy(s2);
for(int i=0; i<=1; i++){ Set<Integer> combined = new HashSet<Integer>();
int count = 0; combined.addAll(s1);
// for every individual combined.addAll(s2);
for(int k=0; k<this.popSize; k++){ double entropy3 = calculateEntropy(combined);
BitSet b = getBinaryData(this.population.getEAIndividual(k)); return 2 - ((entropy1 + entropy2) / (entropy3));
boolean addCount = true; }
// for every specified Bit
for(Integer value: s){
// is the bit not set correctly
if(b.get(value) != (i==1)){
addCount = false;
break;
}
}
if(addCount){
count++;
}
addCount = true;
}
entropy += ((double)count) * SpecialFunction.logb((double)count, 2.0);
count = 0;
}
return entropy;
}
@Override private double calculateEntropy(Set<Integer> s) {
public void optimize() { double entropy = 0.0;
this.problem.evaluatePopulationStart(this.population); // for possible states {0,1} do
Stack<Set<Integer>> linkageTree = buildLinkageTree(); for (int i = 0; i <= 1; i++) {
Population newPop = new Population(this.popSize); int count = 0;
for(int i=0; i<(this.popSize/2); i++){ // for every individual
Population indies = this.population.getRandNIndividuals(2); for (int k = 0; k < this.popSize; k++) {
Population newIndies = buildNewIndies(indies, linkageTree); BitSet b = getBinaryData(this.population.getEAIndividual(k));
newPop.addAll(newIndies); boolean addCount = true;
} // for every specified Bit
this.population.clear(); for (Integer value : s) {
this.population.addAll(newPop); // is the bit not set correctly
this.problem.evaluatePopulationEnd(this.population); if (b.get(value) != (i == 1)) {
} addCount = false;
break;
private Population buildNewIndies(Population indies, }
Stack<Set<Integer>> linkageTree) { }
if(indies.size() != 2){ if (addCount) {
return indies; count++;
} }
AbstractEAIndividual indy1 = indies.getEAIndividual(0); addCount = true;
AbstractEAIndividual indy2 = indies.getEAIndividual(1); }
BitSet gen1 = getBinaryData(indy1); entropy += ((double) count) * SpecialFunction.logb((double) count, 2.0);
BitSet gen2 = getBinaryData(indy2); count = 0;
for(Set<Integer> mask: linkageTree){ }
BitSet newGene1 = (BitSet) gen1.clone(); return entropy;
BitSet newGene2 = (BitSet) gen2.clone(); }
boolean same = true;
for(Integer exchange: mask){
if(newGene1.get(exchange) != newGene2.get(exchange)){
same = false;
}
newGene1.set(exchange, gen2.get(exchange));
newGene2.set(exchange, gen1.get(exchange));
}
if(!same){
AbstractEAIndividual newIndy1 = (AbstractEAIndividual) this.template.clone();
AbstractEAIndividual newIndy2 = (AbstractEAIndividual) this.template.clone();
((InterfaceDataTypeBinary) newIndy1).SetBinaryGenotype(newGene1);
((InterfaceDataTypeBinary) newIndy2).SetBinaryGenotype(newGene2);
evaluate(newIndy1);
evaluate(newIndy2);
if(Math.min(newIndy1.getFitness(0), newIndy2.getFitness(0)) < Math.min(indy1.getFitness(0), indy2.getFitness(0))){
indy1 = newIndy1;
indy2 = newIndy2;
}
}
}
Population result = new Population(2);
result.add(indy1);
result.add(indy2);
return result;
}
/** @Override
* Something has changed public void optimize() {
*/ this.problem.evaluatePopulationStart(this.population);
protected void firePropertyChangedEvent(String name) { Stack<Set<Integer>> linkageTree = buildLinkageTree();
if (this.m_Listener != null) Population newPop = new Population(this.popSize);
this.m_Listener.registerPopulationStateChanged(this, name); for (int i = 0; i < (this.popSize / 2); i++) {
} Population indies = this.population.getRandNIndividuals(2);
Population newIndies = buildNewIndies(indies, linkageTree);
newPop.addAll(newIndies);
}
this.population.clear();
this.population.addAll(newPop);
this.problem.evaluatePopulationEnd(this.population);
}
@Override private Population buildNewIndies(Population indies,
public Population getPopulation() { Stack<Set<Integer>> linkageTree) {
return this.population; if (indies.size() != 2) {
} return indies;
}
AbstractEAIndividual indy1 = indies.getEAIndividual(0);
AbstractEAIndividual indy2 = indies.getEAIndividual(1);
BitSet gen1 = getBinaryData(indy1);
BitSet gen2 = getBinaryData(indy2);
for (Set<Integer> mask : linkageTree) {
BitSet newGene1 = (BitSet) gen1.clone();
BitSet newGene2 = (BitSet) gen2.clone();
boolean same = true;
for (Integer exchange : mask) {
if (newGene1.get(exchange) != newGene2.get(exchange)) {
same = false;
}
newGene1.set(exchange, gen2.get(exchange));
newGene2.set(exchange, gen1.get(exchange));
}
if (!same) {
AbstractEAIndividual newIndy1 = (AbstractEAIndividual) this.template.clone();
AbstractEAIndividual newIndy2 = (AbstractEAIndividual) this.template.clone();
((InterfaceDataTypeBinary) newIndy1).SetBinaryGenotype(newGene1);
((InterfaceDataTypeBinary) newIndy2).SetBinaryGenotype(newGene2);
evaluate(newIndy1);
evaluate(newIndy2);
if (Math.min(newIndy1.getFitness(0), newIndy2.getFitness(0)) < Math.min(indy1.getFitness(0), indy2.getFitness(0))) {
indy1 = newIndy1;
indy2 = newIndy2;
}
}
}
Population result = new Population(2);
result.add(indy1);
result.add(indy2);
return result;
}
@Override /**
public void setPopulation(Population pop) { * Something has changed
this.population = pop; */
} protected void firePropertyChangedEvent(String name) {
if (this.m_Listener != null) {
this.m_Listener.registerPopulationStateChanged(this, name);
}
}
@Override @Override
public InterfaceSolutionSet getAllSolutions() { public Population getPopulation() {
return new SolutionSet(this.population); return this.population;
} }
@Override @Override
public void SetIdentifier(String name) { public void setPopulation(Population pop) {
this.m_Identifier = name; this.population = pop;
} }
@Override @Override
public String getIdentifier() { public InterfaceSolutionSet getAllSolutions() {
return this.m_Identifier; return new SolutionSet(this.population);
} }
@Override @Override
public void SetProblem(InterfaceOptimizationProblem problem) { public void setIdentifier(String name) {
this.problem = (AbstractOptimizationProblem) problem; this.m_Identifier = name;
} }
@Override @Override
public InterfaceOptimizationProblem getProblem() { public String getIdentifier() {
return this.problem; return this.m_Identifier;
} }
@Override @Override
public String getStringRepresentation() { public void SetProblem(InterfaceOptimizationProblem problem) {
return "Linkage Tree GA"; this.problem = (AbstractOptimizationProblem) problem;
} }
@Override @Override
public void freeWilly() { public InterfaceOptimizationProblem getProblem() {
return this.problem;
} }
@SuppressWarnings("deprecation") @Override
@Override public String getStringRepresentation() {
public void registerPopulationStateChanged(Object source, String name) { return "Linkage Tree GA";
// The events of the interim hill climbing population will be caught here }
if (name.compareTo(Population.funCallIntervalReached) == 0) {
// set funcalls to real value
this.population.SetFunctionCalls(((Population)source).getFunctionCalls());
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
}
public static void main(String[] args) {
LTGA ltga = new LTGA();
ltga.init();
ltga.optimize();
System.out.println(ltga.popSize);
Population p = ltga.getPopulation();
System.out.println(p.getFunctionCalls()+"\t"+p.size());
System.out.println(p.getBestEAIndividual().getStringRepresentation());
ltga.optimize();
p = ltga.getPopulation();
System.out.println(p.getFunctionCalls()+"\t"+p.size());
System.out.println(p.getBestEAIndividual().getStringRepresentation());
ltga.optimize();
p = ltga.getPopulation();
System.out.println(p.getFunctionCalls()+"\t"+p.size());
System.out.println(p.getBestEAIndividual().getStringRepresentation());
ltga.optimize();
p = ltga.getPopulation();
System.out.println(p.getFunctionCalls()+"\t"+p.size());
System.out.println(p.getBestEAIndividual().getStringRepresentation());
ltga.optimize();
p = ltga.getPopulation();
System.out.println(p.getFunctionCalls()+"\t"+p.size());
System.out.println(p.getBestEAIndividual().getStringRepresentation());
ltga.optimize();
p = ltga.getPopulation();
System.out.println(p.getFunctionCalls()+"\t"+p.size());
System.out.println(p.getBestEAIndividual().getStringRepresentation());
ltga.optimize();
p = ltga.getPopulation();
System.out.println(p.getFunctionCalls()+"\t"+p.size());
System.out.println(p.getBestEAIndividual().getStringRepresentation());
}
@Override
public void freeWilly() {
}
@Override
public void registerPopulationStateChanged(Object source, String name) {
// The events of the interim hill climbing population will be caught here
if (name.compareTo(Population.funCallIntervalReached) == 0) {
// set funcalls to real value
this.population.setFunctionCalls(((Population) source).getFunctionCalls());
this.firePropertyChangedEvent(Population.nextGenerationPerformed);
}
}
public static void main(String[] args) {
LTGA ltga = new LTGA();
ltga.init();
ltga.optimize();
System.out.println(ltga.popSize);
Population p = ltga.getPopulation();
System.out.println(p.getFunctionCalls() + "\t" + p.size());
System.out.println(p.getBestEAIndividual().getStringRepresentation());
ltga.optimize();
p = ltga.getPopulation();
System.out.println(p.getFunctionCalls() + "\t" + p.size());
System.out.println(p.getBestEAIndividual().getStringRepresentation());
ltga.optimize();
p = ltga.getPopulation();
System.out.println(p.getFunctionCalls() + "\t" + p.size());
System.out.println(p.getBestEAIndividual().getStringRepresentation());
ltga.optimize();
p = ltga.getPopulation();
System.out.println(p.getFunctionCalls() + "\t" + p.size());
System.out.println(p.getBestEAIndividual().getStringRepresentation());
ltga.optimize();
p = ltga.getPopulation();
System.out.println(p.getFunctionCalls() + "\t" + p.size());
System.out.println(p.getBestEAIndividual().getStringRepresentation());
ltga.optimize();
p = ltga.getPopulation();
System.out.println(p.getFunctionCalls() + "\t" + p.size());
System.out.println(p.getBestEAIndividual().getStringRepresentation());
ltga.optimize();
p = ltga.getPopulation();
System.out.println(p.getFunctionCalls() + "\t" + p.size());
System.out.println(p.getBestEAIndividual().getStringRepresentation());
}
} }

View File

@ -255,7 +255,7 @@ public class MemeticAlgorithm implements InterfaceOptimizer,
* @param name * @param name
* The indenifier * The indenifier
*/ */
public void SetIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.m_Identifier = name;
} }

View File

@ -182,7 +182,7 @@ public class MonteCarloSearch implements InterfaceOptimizer, java.io.Serializabl
/** This method allows you to set an identifier for the algorithm /** This method allows you to set an identifier for the algorithm
* @param name The indenifier * @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() {

View File

@ -74,10 +74,10 @@ public class MultiObjectiveCMAES implements InterfaceOptimizer, Serializable {
* (non-Javadoc) * (non-Javadoc)
* *
* @see * @see
* eva2.server.go.strategies.InterfaceOptimizer#SetIdentifier(java.lang. * eva2.server.go.strategies.InterfaceOptimizer#setIdentifier(java.lang.
* String) * String)
*/ */
public void SetIdentifier(String name) { public void setIdentifier(String name) {
m_Identifier = name; m_Identifier = name;
} }

View File

@ -201,7 +201,7 @@ public class MultiObjectiveEA implements InterfaceOptimizer, java.io.Serializabl
/** This method allows you to set an identifier for the algorithm /** This method allows you to set an identifier for the algorithm
* @param name The indenifier * @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() {

View File

@ -58,7 +58,7 @@ public class NelderMeadSimplex implements InterfaceOptimizer, Serializable, Inte
return new NelderMeadSimplex(this); return new NelderMeadSimplex(this);
} }
public void SetIdentifier(String name) { public void setIdentifier(String name) {
m_Identifier = name; m_Identifier = name;
} }

View File

@ -1234,7 +1234,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
* This method allows you to set an identifier for the algorithm * This method allows you to set an identifier for the algorithm
* @param name The indenifier * @param name The indenifier
*/ */
public void SetIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.m_Identifier = name;
} }

View File

@ -282,7 +282,7 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
/** This method allows you to set an identifier for the algorithm /** This method allows you to set an identifier for the algorithm
* @param name The indenifier * @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() {

View File

@ -1712,7 +1712,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
* *
* @param name The indenifier * @param name The indenifier
*/ */
public void SetIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.m_Identifier = name;
} }

View File

@ -180,7 +180,7 @@ public class PopulationBasedIncrementalLearning implements InterfaceOptimizer, j
/** This method allows you to set an identifier for the algorithm /** This method allows you to set an identifier for the algorithm
* @param name The indenifier * @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() {

View File

@ -664,7 +664,7 @@ public class ScatterSearch implements InterfaceOptimizer, java.io.Serializable,
///////////// Trivials... ///////////// Trivials...
public void SetIdentifier(String name) { public void setIdentifier(String name) {
m_Identifier = name; m_Identifier = name;
} }

View File

@ -201,7 +201,7 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
/** This method allows you to set an identifier for the algorithm /** This method allows you to set an identifier for the algorithm
* @param name The indenifier * @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() {

View File

@ -152,7 +152,7 @@ public class SteadyStateGA implements InterfaceOptimizer, java.io.Serializable {
/** This method allows you to set an identifier for the algorithm /** This method allows you to set an identifier for the algorithm
* @param name The indenifier * @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() {

View File

@ -192,7 +192,7 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
/** This method allows you to set an identifier for the algorithm /** This method allows you to set an identifier for the algorithm
* @param name The indenifier * @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() {

View File

@ -715,7 +715,7 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
public void freeWilly() {} public void freeWilly() {}
public void SetIdentifier(String name) { public void setIdentifier(String name) {
this.m_Identifier = name; this.m_Identifier = name;
} }
public String getIdentifier() { public String getIdentifier() {

View File

@ -246,7 +246,7 @@ public class WingedMultiObjectiveEA implements InterfaceOptimizer, java.io.Seria
/** This method allows you to set an identifier for the algorithm /** This method allows you to set an identifier for the algorithm
* @param name The indenifier * @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() {