Implement isAutoAging to deactivate auto-aging of individuals on incrGeneration.
Used by various instances of the ABC
This commit is contained in:
parent
d7b677c6b8
commit
d80ac15142
@ -99,6 +99,12 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
|
||||
public static final String POPULATION_INITIALIZED = "PopulationReinitOccured";
|
||||
public static final String NEXT_GENERATION_PERFORMED = "NextGenerationPerformed";
|
||||
|
||||
/**
|
||||
* With <code>autoAging = true</code> #incrGeneration automatically
|
||||
* ages individuals.
|
||||
*/
|
||||
private boolean autoAging = true;
|
||||
|
||||
public Population() {
|
||||
LOGGER.log(Level.FINER, "New population has been created.");
|
||||
}
|
||||
@ -575,6 +581,15 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
|
||||
return historyMaxLen != 0;
|
||||
}
|
||||
|
||||
@Hidden
|
||||
public void setAutoAging(boolean autoAging) {
|
||||
this.autoAging = autoAging;
|
||||
}
|
||||
|
||||
public boolean isAutoAging() {
|
||||
return this.autoAging;
|
||||
}
|
||||
|
||||
public void setMaxHistoryLength(int len) {
|
||||
historyMaxLen = len;
|
||||
}
|
||||
@ -711,8 +726,10 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
|
||||
}
|
||||
this.historyList.add((AbstractEAIndividual) this.getBestEAIndividual().clone());
|
||||
}
|
||||
for (AbstractEAIndividual individual : this) {
|
||||
individual.incrAge();
|
||||
if (isAutoAging()) {
|
||||
for (AbstractEAIndividual individual : this) {
|
||||
individual.incrAge();
|
||||
}
|
||||
}
|
||||
this.generationCount++;
|
||||
firePropertyChangedEvent(NEXT_GENERATION_PERFORMED);
|
||||
|
@ -65,6 +65,8 @@ public class ArtificialBeeColony extends AbstractOptimizer implements Serializab
|
||||
@Override
|
||||
public void initializeByPopulation(Population pop, boolean reset) {
|
||||
this.population = (Population) pop.clone();
|
||||
// We handle aging ourselves
|
||||
this.population.setAutoAging(false);
|
||||
if (reset) {
|
||||
this.population.initialize();
|
||||
this.evaluatePopulation(this.population);
|
||||
@ -111,31 +113,25 @@ public class ArtificialBeeColony extends AbstractOptimizer implements Serializab
|
||||
/**
|
||||
* Remember best Individual
|
||||
*/
|
||||
if (bestIndividual != null && bestIndividual.getFitness(0) < this.population.getBestEAIndividual().getFitness(0)) {
|
||||
bestIndividual = this.population.getBestEAIndividual();
|
||||
} else {
|
||||
bestIndividual = this.population.getBestEAIndividual();
|
||||
}
|
||||
memorizeBestSolution();
|
||||
|
||||
/**
|
||||
* Send scout bee
|
||||
*/
|
||||
sendScoutBees();
|
||||
|
||||
/**
|
||||
* ToDo: This is ugly.
|
||||
*
|
||||
* incrGeneration increments the age of all indies. Age management however happens
|
||||
* in the algorithm itself (for ABC) so we have to -1 all ages.
|
||||
*/
|
||||
this.population.incrGeneration();
|
||||
for (AbstractEAIndividual individual : this.population) {
|
||||
individual.setAge(individual.getAge() - 1);
|
||||
}
|
||||
|
||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
|
||||
}
|
||||
|
||||
protected void memorizeBestSolution() {
|
||||
if (bestIndividual != null && bestIndividual.getFitness(0) < this.population.getBestEAIndividual().getFitness(0)) {
|
||||
bestIndividual = this.population.getBestEAIndividual();
|
||||
} else {
|
||||
bestIndividual = this.population.getBestEAIndividual();
|
||||
}
|
||||
}
|
||||
|
||||
protected void sendScoutBees() {
|
||||
AbstractEAIndividual oldestIndy = getOldestIndividual();
|
||||
if (oldestIndy.getAge() > this.maxTrials) {
|
||||
@ -228,7 +224,7 @@ public class ArtificialBeeColony extends AbstractOptimizer implements Serializab
|
||||
}
|
||||
|
||||
/**
|
||||
* In the standard ABC the onlookers behave exaclty like the employed bees.
|
||||
* In the standard ABC the onlookers behave exactly like the employed bees.
|
||||
*
|
||||
* @param baseIndividual
|
||||
* @param index
|
||||
|
Loading…
x
Reference in New Issue
Block a user