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 POPULATION_INITIALIZED = "PopulationReinitOccured";
|
||||||
public static final String NEXT_GENERATION_PERFORMED = "NextGenerationPerformed";
|
public static final String NEXT_GENERATION_PERFORMED = "NextGenerationPerformed";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* With <code>autoAging = true</code> #incrGeneration automatically
|
||||||
|
* ages individuals.
|
||||||
|
*/
|
||||||
|
private boolean autoAging = true;
|
||||||
|
|
||||||
public Population() {
|
public Population() {
|
||||||
LOGGER.log(Level.FINER, "New population has been created.");
|
LOGGER.log(Level.FINER, "New population has been created.");
|
||||||
}
|
}
|
||||||
@ -575,6 +581,15 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
|
|||||||
return historyMaxLen != 0;
|
return historyMaxLen != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Hidden
|
||||||
|
public void setAutoAging(boolean autoAging) {
|
||||||
|
this.autoAging = autoAging;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAutoAging() {
|
||||||
|
return this.autoAging;
|
||||||
|
}
|
||||||
|
|
||||||
public void setMaxHistoryLength(int len) {
|
public void setMaxHistoryLength(int len) {
|
||||||
historyMaxLen = len;
|
historyMaxLen = len;
|
||||||
}
|
}
|
||||||
@ -711,8 +726,10 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
|
|||||||
}
|
}
|
||||||
this.historyList.add((AbstractEAIndividual) this.getBestEAIndividual().clone());
|
this.historyList.add((AbstractEAIndividual) this.getBestEAIndividual().clone());
|
||||||
}
|
}
|
||||||
for (AbstractEAIndividual individual : this) {
|
if (isAutoAging()) {
|
||||||
individual.incrAge();
|
for (AbstractEAIndividual individual : this) {
|
||||||
|
individual.incrAge();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.generationCount++;
|
this.generationCount++;
|
||||||
firePropertyChangedEvent(NEXT_GENERATION_PERFORMED);
|
firePropertyChangedEvent(NEXT_GENERATION_PERFORMED);
|
||||||
|
@ -65,6 +65,8 @@ public class ArtificialBeeColony extends AbstractOptimizer implements Serializab
|
|||||||
@Override
|
@Override
|
||||||
public void initializeByPopulation(Population pop, boolean reset) {
|
public void initializeByPopulation(Population pop, boolean reset) {
|
||||||
this.population = (Population) pop.clone();
|
this.population = (Population) pop.clone();
|
||||||
|
// We handle aging ourselves
|
||||||
|
this.population.setAutoAging(false);
|
||||||
if (reset) {
|
if (reset) {
|
||||||
this.population.initialize();
|
this.population.initialize();
|
||||||
this.evaluatePopulation(this.population);
|
this.evaluatePopulation(this.population);
|
||||||
@ -111,31 +113,25 @@ public class ArtificialBeeColony extends AbstractOptimizer implements Serializab
|
|||||||
/**
|
/**
|
||||||
* Remember best Individual
|
* Remember best Individual
|
||||||
*/
|
*/
|
||||||
if (bestIndividual != null && bestIndividual.getFitness(0) < this.population.getBestEAIndividual().getFitness(0)) {
|
memorizeBestSolution();
|
||||||
bestIndividual = this.population.getBestEAIndividual();
|
|
||||||
} else {
|
|
||||||
bestIndividual = this.population.getBestEAIndividual();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send scout bee
|
* Send scout bee
|
||||||
*/
|
*/
|
||||||
sendScoutBees();
|
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();
|
this.population.incrGeneration();
|
||||||
for (AbstractEAIndividual individual : this.population) {
|
|
||||||
individual.setAge(individual.getAge() - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
|
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() {
|
protected void sendScoutBees() {
|
||||||
AbstractEAIndividual oldestIndy = getOldestIndividual();
|
AbstractEAIndividual oldestIndy = getOldestIndividual();
|
||||||
if (oldestIndy.getAge() > this.maxTrials) {
|
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 baseIndividual
|
||||||
* @param index
|
* @param index
|
||||||
|
Loading…
x
Reference in New Issue
Block a user