6 public abstract class ACOStrategy
{
8 protected ACOMediator acom
;
10 public ACOStrategy(ACOMediator 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) */
20 acom
.getDistance(ant
.getTour(i
), ant
.getTour(i
+1)));
24 public void pickInitialRandomCity(Ant ant
) {
25 int r
= (int)(Math
.random() * acom
.getNumOfCities());
27 ant
.setVisited(r
, true);
30 public abstract void neighbourListASDecisionRule(Ant ant
, int Step
);
32 protected void chooseBestNext(Ant ant
, int Step
) {
34 /* this seems to be neccessary because some choice information
35 * tends to become zero after a while */
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
) {
43 v
= acom
.getChoiceInformation(CurrentCity
,j
);
48 ant
.setTour(Step
, nc
);
49 ant
.setVisited(nc
, true);