4 protected double[][] Pheromone
;
6 Pheromone(Graph graph
) {
8 this.Pheromone
= new double[graph
.getNumOfCities()][graph
.getNumOfCities()];
11 (double)(graph
.getNumOfCities()) /
12 graph
.nearestNeighbourHeuristicRandomStart();
14 for (int i
= 0; i
< graph
.getNumOfCities(); i
++) {
15 for (int j
= 0; j
< graph
.getNumOfCities(); j
++) {
16 setPheromone(i
,j
, tauzero
);
22 public void pheromoneUpdate(Ant
[] ants
) {
25 for (Ant ant
: ants
) {
26 depositPheromone(ant
);
29 graph
.computeChoiceInformation();
32 public void evaporate() {
33 for (int i
= 1; i
< graph
.getNumOfCities(); i
++) {
34 for (int j
= 1; j
< graph
.getNumOfCities(); j
++) {
35 Pheromone
[i
][j
] = (1.0 - graph
.getROH()) * Pheromone
[i
][j
];
36 Pheromone
[j
][i
] = Pheromone
[i
][j
];
41 public void depositPheromone(Ant ant
) {
42 double dt
= 1.0/ant
.getTourLength();
45 for (int i
= 0; i
< graph
.getNumOfCities() - 1; i
++) {
48 Pheromone
[j
][l
] = Pheromone
[j
][l
] + dt
;
49 Pheromone
[l
][j
] = Pheromone
[j
][l
];
53 public double[][] getPheromone() {
54 return this.Pheromone
;
57 public double getPheromone(int x
, int y
) {
58 return this.Pheromone
[x
][y
];
61 public void setPheromone(double[][] Pheromone
) {
62 this.Pheromone
= Pheromone
;
65 public void setPheromone(int x
, int y
, double Pheromone
) {
66 this.Pheromone
[x
][y
] = Pheromone
;