Fix Artificial Bee Colony by using inverse fitness probability
This commit is contained in:
parent
6ae2aa28b9
commit
08f7b92f86
@ -81,6 +81,16 @@ public class ArtificialBeeColony extends AbstractOptimizer implements Serializab
|
|||||||
population.incrGeneration();
|
population.incrGeneration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected double getFitnessProportion(AbstractEAIndividual indy) {
|
||||||
|
double fitness = indy.getFitness(0);
|
||||||
|
if (fitness >= 0) {
|
||||||
|
fitness = 1.0 / (1.0 + fitness);
|
||||||
|
} else {
|
||||||
|
fitness = 1.0 + Math.abs(fitness);
|
||||||
|
}
|
||||||
|
return fitness;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void optimize() {
|
public void optimize() {
|
||||||
/**
|
/**
|
||||||
@ -131,8 +141,8 @@ public class ArtificialBeeColony extends AbstractOptimizer implements Serializab
|
|||||||
*/
|
*/
|
||||||
int t = 0, i = 0;
|
int t = 0, i = 0;
|
||||||
double sumFitness = 0.0;
|
double sumFitness = 0.0;
|
||||||
for (Object individual : this.population) {
|
for (AbstractEAIndividual individual : this.population) {
|
||||||
sumFitness += ((AbstractEAIndividual) individual).getFitness(0);
|
sumFitness += getFitnessProportion(individual);
|
||||||
}
|
}
|
||||||
while (t < this.population.size()) {
|
while (t < this.population.size()) {
|
||||||
double r = RNG.randomDouble();
|
double r = RNG.randomDouble();
|
||||||
@ -141,7 +151,7 @@ public class ArtificialBeeColony extends AbstractOptimizer implements Serializab
|
|||||||
* Choose a food source depending on its probability to be chosen. The probability
|
* Choose a food source depending on its probability to be chosen. The probability
|
||||||
* is proportional to the
|
* is proportional to the
|
||||||
*/
|
*/
|
||||||
double pI = 1 - (this.population.getEAIndividual(i).getFitness(0) / sumFitness);
|
double pI = getFitnessProportion(this.population.getEAIndividual(i))/sumFitness;
|
||||||
if (r < pI) {
|
if (r < pI) {
|
||||||
t++;
|
t++;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user