remove some logic from the constructor since this is contra productive if some values...
[aco.git] / aco / strategy / ACOStrategy.java
bloba62ed4504f7949b615455e0092185e199d351980
1 package aco.strategy;
3 import aco.ant.*;
4 import aco.mediator.*;
6 public abstract class ACOStrategy {
8 protected ACOMediator acom;
10 public ACOStrategy(ACOMediator acom) {
11 this.acom = acom;
14 public void computeTourLength(Ant ant) {
15 ant.setTour(acom.getNumOfCities(), ant.getTour(0));
16 for (int i = 0; i < acom.getNumOfCities(); i++) {
17 /* tourlength = tourlength + distance(i, i+1) */
18 ant.setTourLength(
19 ant.getTourLength() +
20 acom.getDistance(ant.getTour(i), ant.getTour(i+1)));
24 public void pickInitialRandomCity(Ant ant) {
25 int r = (int)(Math.random() * acom.getNumOfCities());
26 ant.setTour(0, r);
27 ant.setVisited(r, true);
30 public abstract void neighbourListASDecisionRule(Ant ant, int Step);
32 protected void chooseBestNext(Ant ant, int Step) {
33 int nc = 0;
34 /* this seems to be neccessary because some choice information
35 * tends to become zero after a while */
36 double v = -1.0;
37 int CurrentCity = ant.getTour(Step - 1);
39 for (int j = 0; j < acom.getNumOfCities(); j++) {
40 if (! ant.getVisited(j)) {
41 if (acom.getChoiceInformation(CurrentCity,j) > v) {
42 nc = j;
43 v = acom.getChoiceInformation(CurrentCity,j);
48 ant.setTour(Step, nc);
49 ant.setVisited(nc, true);