Comit before renaming
This commit is contained in:
parent
7633618f59
commit
1614d205ef
@ -57,7 +57,7 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
|
|||||||
// from which size on is a species considered active
|
// from which size on is a species considered active
|
||||||
private int m_actSpecSize = 2;
|
private int m_actSpecSize = 2;
|
||||||
private int m_minGroupSize = 3;
|
private int m_minGroupSize = 3;
|
||||||
private boolean m_UseClearing = false;
|
// private boolean m_UseClearing = false;
|
||||||
private boolean m_UseArchive = true;
|
private boolean m_UseArchive = true;
|
||||||
private boolean m_UseSpeciesDifferentation = true;
|
private boolean m_UseSpeciesDifferentation = true;
|
||||||
private boolean m_UseSpeciesConvergence = true;
|
private boolean m_UseSpeciesConvergence = true;
|
||||||
@ -88,7 +88,7 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
|
|||||||
this.m_SpeciesCycle = a.m_SpeciesCycle;
|
this.m_SpeciesCycle = a.m_SpeciesCycle;
|
||||||
this.m_actSpecSize = a.m_actSpecSize;
|
this.m_actSpecSize = a.m_actSpecSize;
|
||||||
this.m_minGroupSize = a.m_minGroupSize;
|
this.m_minGroupSize = a.m_minGroupSize;
|
||||||
this.m_UseClearing = a.m_UseClearing;
|
// this.m_UseClearing = a.m_UseClearing;
|
||||||
this.m_UseSpeciesDifferentation = a.m_UseSpeciesDifferentation;
|
this.m_UseSpeciesDifferentation = a.m_UseSpeciesDifferentation;
|
||||||
this.m_UseSpeciesConvergence = a.m_UseSpeciesConvergence;
|
this.m_UseSpeciesConvergence = a.m_UseSpeciesConvergence;
|
||||||
// this.m_UseHaltingWindow = a.m_UseHaltingWindow;
|
// this.m_UseHaltingWindow = a.m_UseHaltingWindow;
|
||||||
@ -278,19 +278,22 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
|
|||||||
* @return True if converged.
|
* @return True if converged.
|
||||||
*/
|
*/
|
||||||
private boolean testSpeciesForConvergence(Population pop) {
|
private boolean testSpeciesForConvergence(Population pop) {
|
||||||
ArrayList tmpA = pop.m_History;
|
ArrayList<AbstractEAIndividual> tmpA = pop.m_History;
|
||||||
int length = pop.m_History.size();
|
int length = pop.m_History.size();
|
||||||
|
|
||||||
if (length <= haltingWindow) {
|
if (length <= haltingWindow) {
|
||||||
// System.out.println("not long enough... gen " + pop.getGeneration());
|
// System.out.println("not long enough... gen " + pop.getGeneration());
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
AbstractEAIndividual historic = ((AbstractEAIndividual)pop.m_History.get(length-haltingWindow));
|
AbstractEAIndividual historicHWAgo = ((AbstractEAIndividual)pop.m_History.get(length-haltingWindow));
|
||||||
for (int i = 1; i < haltingWindow; i++) { // TODO
|
for (int i = 1; i < haltingWindow; i++) {
|
||||||
if (historic.getFitness(0) > ((AbstractEAIndividual)pop.m_History.get(length-haltingWindow+i)).getFitness(0)) {
|
// if historic[-hW] is worse than historic[-hW+] return false
|
||||||
|
AbstractEAIndividual historicIter = pop.m_History.get(length-haltingWindow+i);
|
||||||
|
if (historicIter.isDominatingDebConstraints(historicHWAgo)) return false;
|
||||||
|
// if (historicHWAgo.getFitness(0) > ((AbstractEAIndividual)pop.m_History.get(length-haltingWindow+i)).getFitness(0)) {
|
||||||
// System.out.println("( " + historic.getFitness(0) + "/" + ((AbstractEAIndividual)pop.m_History.get(length-haltingWindow+i)).getFitness(0));
|
// System.out.println("( " + historic.getFitness(0) + "/" + ((AbstractEAIndividual)pop.m_History.get(length-haltingWindow+i)).getFitness(0));
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (TRACE) {
|
if (TRACE) {
|
||||||
@ -397,10 +400,7 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
|
|||||||
} else {
|
} else {
|
||||||
// now reset the converged species to inactivity size = 1
|
// now reset the converged species to inactivity size = 1
|
||||||
reinitCount = curSpecies.size()-1; // add all but one as new
|
reinitCount = curSpecies.size()-1; // add all but one as new
|
||||||
curSpecies.setPopulationSize(1);
|
deactivateSpecies(curSpecies, best);
|
||||||
// m_Undifferentiated.incrFunctionCallsby(1); // TODO not so good
|
|
||||||
curSpecies.clear();
|
|
||||||
curSpecies.add(best);
|
|
||||||
}
|
}
|
||||||
// reinit the surplus individuals and add these new individuals to undifferentiated
|
// reinit the surplus individuals and add these new individuals to undifferentiated
|
||||||
m_Undifferentiated.addPopulation(this.initializeIndividuals(reinitCount));
|
m_Undifferentiated.addPopulation(this.initializeIndividuals(reinitCount));
|
||||||
@ -415,9 +415,6 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
|
|||||||
} else {
|
} else {
|
||||||
// actually optimize D_i
|
// actually optimize D_i
|
||||||
this.capMutationRate(curSpecies, 0.05);
|
this.capMutationRate(curSpecies, 0.05);
|
||||||
//this.m_Optimizer.setPopulation(curSpecies);
|
|
||||||
//this.m_Optimizer.optimize();
|
|
||||||
//this.m_Species.set(i, this.m_Optimizer.getPopulation());
|
|
||||||
this.m_Species.set(i, optimizeSpecies(curSpecies));
|
this.m_Species.set(i, optimizeSpecies(curSpecies));
|
||||||
curSpecies = ((Population)this.m_Species.get(i)); // reset to expected population, just to be sure
|
curSpecies = ((Population)this.m_Species.get(i)); // reset to expected population, just to be sure
|
||||||
}
|
}
|
||||||
@ -448,7 +445,7 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
|
|||||||
if (TRACE) System.out.println("Species cycle:");
|
if (TRACE) System.out.println("Species cycle:");
|
||||||
|
|
||||||
if (this.m_UseSpeciesDifferentation) {
|
if (this.m_UseSpeciesDifferentation) {
|
||||||
// species differentation phase
|
///////////////////////////// species differentation phase
|
||||||
if (TRACE) System.out.println("-Species Differentation:");
|
if (TRACE) System.out.println("-Species Differentation:");
|
||||||
Population[] ClusterResult;
|
Population[] ClusterResult;
|
||||||
ArrayList<Population> newSpecies = new ArrayList<Population>();
|
ArrayList<Population> newSpecies = new ArrayList<Population>();
|
||||||
@ -458,7 +455,7 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
|
|||||||
for (int j = 1; j < ClusterResult.length; j++) {
|
for (int j = 1; j < ClusterResult.length; j++) {
|
||||||
ClusterResult[j].setUseHistory(true);
|
ClusterResult[j].setUseHistory(true);
|
||||||
ClusterResult[j].setGenerationTo(0);
|
ClusterResult[j].setGenerationTo(0);
|
||||||
ClusterResult[j].m_History = new ArrayList();
|
ClusterResult[j].m_History = new ArrayList<AbstractEAIndividual>();
|
||||||
newSpecies.add(ClusterResult[j]);
|
newSpecies.add(ClusterResult[j]);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < this.m_Species.size(); i++) {
|
for (int i = 0; i < this.m_Species.size(); i++) {
|
||||||
@ -469,11 +466,11 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
|
|||||||
this.m_Undifferentiated.addPopulation(ClusterResult[0]);
|
this.m_Undifferentiated.addPopulation(ClusterResult[0]);
|
||||||
// ClusterResult[0].setUseHistory(true);
|
// ClusterResult[0].setUseHistory(true);
|
||||||
this.m_Undifferentiated.setPopulationSize(this.m_Undifferentiated.getPopulationSize() + ClusterResult[0].size());
|
this.m_Undifferentiated.setPopulationSize(this.m_Undifferentiated.getPopulationSize() + ClusterResult[0].size());
|
||||||
for (int j = 1; j < ClusterResult.length; j++) {
|
for (int j = 1; j < ClusterResult.length; j++) { // set up new species
|
||||||
ClusterResult[j].setPopulationSize(ClusterResult[j].size());
|
ClusterResult[j].setPopulationSize(ClusterResult[j].size());
|
||||||
ClusterResult[j].setUseHistory(true);
|
ClusterResult[j].setUseHistory(true);
|
||||||
// if (ClusterResult.length > 2) ClusterResult[j].m_History = new ArrayList(); // mk: why min 3? Ill copy the history from the original pop for any j...
|
// if (ClusterResult.length > 2) ClusterResult[j].m_History = new ArrayList(); // mk: why min 3? Ill copy the history from the original pop for any j...
|
||||||
ClusterResult[j].m_History = (ArrayList) curSpecies.m_History.clone();
|
ClusterResult[j].m_History = (ArrayList<AbstractEAIndividual>) curSpecies.m_History.clone();
|
||||||
newSpecies.add(ClusterResult[j]);
|
newSpecies.add(ClusterResult[j]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -493,7 +490,7 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.m_UseSpeciesConvergence) {
|
if (this.m_UseSpeciesConvergence) {
|
||||||
//species convergence phase
|
///////////////////////////// species convergence phase
|
||||||
if (TRACE) {
|
if (TRACE) {
|
||||||
System.out.println("-Species convergence:");
|
System.out.println("-Species convergence:");
|
||||||
System.out.println("-Funcalls: " + m_Undifferentiated.getFunctionCalls());
|
System.out.println("-Funcalls: " + m_Undifferentiated.getFunctionCalls());
|
||||||
@ -516,7 +513,7 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
|
|||||||
this.m_Undifferentiated.setPopulationSize(this.m_Undifferentiated.getPopulationSize()-1);
|
this.m_Undifferentiated.setPopulationSize(this.m_Undifferentiated.getPopulationSize()-1);
|
||||||
i--; // needs to be reduced because D0 size has decreased
|
i--; // needs to be reduced because D0 size has decreased
|
||||||
} else {
|
} else {
|
||||||
// the species is inactive, reinitialize the individual (MK: why?)
|
// the species is inactive and seen as converged, so reinitialize the individual
|
||||||
this.m_Undifferentiated.add(i, this.initializeIndividuals(1).get(0));
|
this.m_Undifferentiated.add(i, this.initializeIndividuals(1).get(0));
|
||||||
// m_Undifferentiated.incrFunctionCallsby(1);
|
// m_Undifferentiated.incrFunctionCallsby(1);
|
||||||
}
|
}
|
||||||
@ -526,32 +523,31 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
|
|||||||
}
|
}
|
||||||
// Now test if species converge
|
// Now test if species converge
|
||||||
Population spec1, spec2;
|
Population spec1, spec2;
|
||||||
for (int i = 0; i < this.m_Species.size(); i++) {
|
for (int i1 = 0; i1 < this.m_Species.size(); i1++) {
|
||||||
spec1 = (Population)this.m_Species.get(i);
|
spec1 = (Population)this.m_Species.get(i1);
|
||||||
for (int j = i+1; j < this.m_Species.size(); j++) {
|
for (int i2 = i1+1; i2 < this.m_Species.size(); i2++) {
|
||||||
spec2 = (Population)this.m_Species.get(j);
|
spec2 = (Population)this.m_Species.get(i2);
|
||||||
if (this.m_CAForSpeciesConvergence.convergingSpecies(spec1, spec2)) {
|
if (this.m_CAForSpeciesConvergence.convergingSpecies(spec1, spec2)) {
|
||||||
if (TRACE) System.out.println("--------------------Merging species (" + i +", " +j +") ["+spec1.size()+"/"+spec2.size()+"]");
|
if (TRACE) System.out.println("--------------------Merging species (" + i1 +", " +i2 +") ["+spec1.size()+"/"+spec2.size()+"]");
|
||||||
// this.m_CAForSpeciesConvergence.convergingSpecies(spec1, spec2);
|
// this.m_CAForSpeciesConvergence.convergingSpecies(spec1, spec2);
|
||||||
if (isActive(spec1) && isActive(spec2)) {
|
if (isActive(spec1) && isActive(spec2)) {
|
||||||
if (TRACE) System.out.println("---Active merge");
|
if (TRACE) System.out.println("---Active merge");
|
||||||
|
|
||||||
spec1.addPopulation(spec2);
|
spec1.addPopulation(spec2);
|
||||||
|
// keep longer history
|
||||||
if (spec2.m_History.size() > spec1.m_History.size()) spec1.m_History = spec2.m_History;
|
if (spec2.m_History.size() > spec1.m_History.size()) spec1.m_History = spec2.m_History;
|
||||||
this.m_Species.remove(j);
|
this.m_Species.remove(i2);
|
||||||
j--;
|
i2--;
|
||||||
} else {
|
} else {
|
||||||
|
// one of the species is converged, so we interpret the best as the optimum found
|
||||||
if (TRACE) System.out.println("---Inactive merge");
|
if (TRACE) System.out.println("---Inactive merge");
|
||||||
// save best in singular species and reinit the rest of the individuals
|
// save best in singular species and reinit the rest of the individuals
|
||||||
spec1.addPopulation(spec2);
|
spec1.addPopulation(spec2);
|
||||||
this.m_Species.remove(j);
|
this.m_Species.remove(i2);
|
||||||
j--;
|
i2--;
|
||||||
AbstractEAIndividual best = (AbstractEAIndividual)spec1.getBestEAIndividual().getClone();
|
|
||||||
int reinitCount = spec1.size()-1;
|
int reinitCount = spec1.size()-1;
|
||||||
// now reset the converged species to inactivity size = 0
|
// now reset the converged species to inactivity DEACTIVATE!
|
||||||
spec1.setPopulationSize(1);
|
deactivateSpecies(spec1, spec1.getBestEAIndividual());
|
||||||
spec1.clear();
|
|
||||||
spec1.add(best);
|
|
||||||
// reinitialized individuals and add them to undifferentiated
|
// reinitialized individuals and add them to undifferentiated
|
||||||
this.m_Undifferentiated.addPopulation(this.initializeIndividuals(reinitCount));
|
this.m_Undifferentiated.addPopulation(this.initializeIndividuals(reinitCount));
|
||||||
// m_Undifferentiated.incrFunctionCallsby(reinitCount);
|
// m_Undifferentiated.incrFunctionCallsby(reinitCount);
|
||||||
@ -602,6 +598,28 @@ public class ClusterBasedNichingEA implements InterfacePopulationChangedEventLis
|
|||||||
return (pop.size() >= m_actSpecSize);
|
return (pop.size() >= m_actSpecSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deactivate a given species by removing all individuals and inserting
|
||||||
|
* only the given survivor, sets the population size to one.
|
||||||
|
*
|
||||||
|
* @param spec
|
||||||
|
*/
|
||||||
|
protected void deactivateSpecies(Population spec, AbstractEAIndividual survivor) {
|
||||||
|
spec.setPopulationSize(1);
|
||||||
|
spec.clear();
|
||||||
|
spec.add(survivor);
|
||||||
|
}
|
||||||
|
// /**
|
||||||
|
// * Deactivate a given species by removing all but the best individual as representative and
|
||||||
|
// * setting the population size to one.
|
||||||
|
// *
|
||||||
|
// * @param spec
|
||||||
|
// */
|
||||||
|
// protected void deactivateSpecies(Population spec) {
|
||||||
|
//// deactivate a species keeping a representative
|
||||||
|
// deactivateSpecies(spec, spec.getBestEAIndividual());
|
||||||
|
// }
|
||||||
|
|
||||||
/** This method allows an optimizer to register a change in the optimizer.
|
/** This method allows an optimizer to register a change in the optimizer.
|
||||||
* @param source The source of the event.
|
* @param source The source of the event.
|
||||||
* @param name Could be used to indicate the nature of the event.
|
* @param name Could be used to indicate the nature of the event.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user