make the mediator object an abstract class
[aco.git] / aco / strategy / eas / EASPheromoneStrategy.java
blobbf3aded0d530bb418422f65de672617b0edc21b7
1 package aco.strategy.eas;
3 import aco.ant.*;
4 import aco.strategy.*;
5 import aco.mediator.*;
6 import aco.mediator.eas.*;
8 public class EASPheromoneStrategy
9 extends PheromoneStrategy {
11 protected EASMediator acom;
13 public EASPheromoneStrategy(ACOMediator acom) {
14 super(acom);
17 public void pheromoneUpdate(Ant[] ants) {
18 this.evaporate();
20 for (Ant ant : ants) {
21 this.depositPheromone(ant);
24 enforceGlobalBest();
26 acom.computeChoiceInformation();
29 protected void enforceGlobalBest() {
30 /* enforcement of global best route */
31 int j = 0, l = 0;
32 for (int i = 0; i < acom.getNumOfCities(); i++) {
33 j = acom.getGlobalBestTour(i);
34 l = acom.getGlobalBestTour(i+1);
35 acom.setPheromone( j, l, (acom.getPheromone(j,l) +
36 acom.getE()/(double)acom.getGlobalBestTourLength()) );
40 protected void depositPheromone(Ant ant) {
41 double dt = 1.0/(double)ant.getTourLength();
42 int j = 0;
43 int l = 0;
44 for (int i = 0; i < acom.getNumOfCities(); i++) {
45 j = ant.getTour(i);
46 l = ant.getTour(i+1);
47 /* setPheromone will update j,l and l,j */
48 acom.setPheromone( j, l, (acom.getPheromone(j,l) + dt) );
52 protected void evaporate() {
53 for (int i = 1; i < acom.getNumOfCities(); i++) {
54 for (int j = 1; j < acom.getNumOfCities(); j++) {
55 acom.setPheromone(i, j,
56 (1.0 - acom.getRoh()) * acom.getPheromone(i, j) );