remove some logic from the constructor since this is contra productive if some values...
[aco.git] / aco / strategy / EASPheromoneStrategy.java
blobf768b39d08664b6f26ef9335dd55bd323842a68d
1 package aco.strategy;
3 import aco.ant.*;
4 import aco.mediator.*;
6 public class EASPheromoneStrategy
7 extends PheromoneStrategy {
9 public EASPheromoneStrategy(ACOMediator acom) {
10 super(acom);
13 public void pheromoneUpdate(Ant[] ants) {
14 this.evaporate();
16 for (Ant ant : ants) {
17 this.depositPheromone(ant);
20 int e = acom.getNumOfCities();
21 int j = 0, l = 0;
23 /* enforcement of global best route */
24 for (int i = 0; i < acom.getNumOfCities(); i++) {
25 j = acom.getGlobalBestTour(i);
26 l = acom.getGlobalBestTour(i+1);
27 acom.setPheromone( j, l, (acom.getPheromone(j,l) +
28 e/acom.getGlobalBestTourLength()) );
31 acom.computeChoiceInformation();
34 protected void depositPheromone(Ant ant) {
35 double dt = 1.0/ant.getTourLength();
36 int j = 0;
37 int l = 0;
38 for (int i = 0; i < acom.getNumOfCities(); i++) {
39 j = ant.getTour(i);
40 l = ant.getTour(i+1);
41 /* setPheromone will update j,l and l,j */
42 acom.setPheromone( j, l, (acom.getPheromone(j,l) + dt) );
46 protected void evaporate() {
47 for (int i = 1; i < acom.getNumOfCities(); i++) {
48 for (int j = 1; j < acom.getNumOfCities(); j++) {
49 acom.setPheromone(i, j,
50 (1.0 - acom.getRoh()) * acom.getPheromone(i, j) );