Skip to content

Commit

Permalink
Fixed code of ABC, DE and GWO to match the author's implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravby committed Aug 28, 2023
1 parent 51ca3ea commit 50b3259
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
19 changes: 15 additions & 4 deletions src/org/um/feri/ears/algorithms/so/abc/ABC.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,25 @@ public NumberSolution<Double> execute(Task<NumberSolution<Double>, DoubleProblem

private void sendScoutBees() throws StopCriterionException {

for (int i = 0; i < foodNumber; i++) {
/*for (int i = 0; i < foodNumber; i++) {
if (population.get(i).trials >= limit) {
if (task.isStopCriterion())
return;
ABCSolution newBee = new ABCSolution(task.getRandomEvaluatedSolution());
population.set(i, newBee);
}
}*/

int maxtrialindex = 0;
for (int i = 0; i < foodNumber; i++) {
if(population.get(i).trials > population.get(maxtrialindex).trials)
maxtrialindex = i;
}
if(population.get(maxtrialindex).trials >= limit) {
if (task.isStopCriterion())
return;
ABCSolution newBee = new ABCSolution(task.getRandomEvaluatedSolution());
population.set(maxtrialindex, newBee);
}

}
Expand Down Expand Up @@ -108,7 +120,7 @@ private void sendOnlookerBees() throws StopCriterionException {

phi = Util.nextDouble(-1, 1);

newValue = population.get(i).getValue(param2change) + (population.get(i).getValue(param2change) - population.get(neighbour).getValue(param2change)) * (phi - 0.5) * 2;
newValue = population.get(i).getValue(param2change) + (population.get(i).getValue(param2change) - population.get(neighbour).getValue(param2change)) * phi;
newValue = task.problem.setFeasible(newValue, param2change);

ABCSolution newBee = new ABCSolution(population.get(i));
Expand Down Expand Up @@ -167,8 +179,7 @@ private void sendEmployedBees() throws StopCriterionException {

phi = Util.nextDouble(-1, 1);

//TODO pomno�i samo z phi
newValue = population.get(i).getValue(param2change) + (population.get(i).getValue(param2change) - population.get(neighbour).getValue(param2change)) * (phi - 0.5) * 2;
newValue = population.get(i).getValue(param2change) + (population.get(i).getValue(param2change) - population.get(neighbour).getValue(param2change)) * phi;
newValue = task.problem.setFeasible(newValue, param2change);

ABCSolution newBee = new ABCSolution(population.get(i));
Expand Down
2 changes: 1 addition & 1 deletion src/org/um/feri/ears/algorithms/so/de/DEAlgorithm.java
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ else if (strategy == Strategy.JDE_RAND_1_BIN) {
CR = tmpCR;

for (L = 0; L < D; L++) /* perform D binomial trials */ {
if ((Util.rnd.nextDouble() < CR) || L == (D - 1)) {
if ((Util.rnd.nextDouble() < CR) || L == D) {
tmp[n] = pold[r1].getValue(n) + F * (pold[r2].getValue(n) - pold[r3].getValue(n));
}
n = (n + 1) % D;
Expand Down
3 changes: 1 addition & 2 deletions src/org/um/feri/ears/algorithms/so/gwo/GWO.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ public NumberSolution<Double> execute(Task<NumberSolution<Double>, DoubleProblem
NumberSolution<Double> newWolf = new NumberSolution<>(Util.toDoubleArrayList(newPosition));
task.eval(newWolf);

if (task.problem.isFirstBetter(newWolf, population.get(index)))
population.set(index, newWolf);
population.set(index, newWolf);
}
updateABD();
task.incrementNumberOfIterations();
Expand Down

0 comments on commit 50b3259

Please sign in to comment.