6 protected double[][] Pheromone
;
8 Pheromone(Graph graph
) {
10 this.Pheromone
= new double[graph
.getNumOfCities()][graph
.getNumOfCities()];
13 (double)(graph
.getNumOfCities()) /
14 graph
.nearestNeighbourHeuristicRandomStart();
16 for (int i
= 0; i
< graph
.getNumOfCities(); i
++) {
17 for (int j
= 0; j
< graph
.getNumOfCities(); j
++) {
18 setPheromone(i
,j
, tauzero
);
24 public void pheromoneUpdate(Ant
[] ants
) {
27 for (Ant ant
: ants
) {
28 depositPheromone(ant
);
31 graph
.computeChoiceInformation();
34 public void evaporate() {
35 for (int i
= 1; i
< graph
.getNumOfCities(); i
++) {
36 for (int j
= 1; j
< graph
.getNumOfCities(); j
++) {
37 Pheromone
[i
][j
] = (1.0 - graph
.getROH()) * Pheromone
[i
][j
];
38 Pheromone
[j
][i
] = Pheromone
[i
][j
];
43 public void depositPheromone(Ant ant
) {
44 double dt
= 1.0/ant
.getTourLength();
47 for (int i
= 0; i
< graph
.getNumOfCities() - 1; i
++) {
50 Pheromone
[j
][l
] = Pheromone
[j
][l
] + dt
;
51 Pheromone
[l
][j
] = Pheromone
[j
][l
];
55 public double[][] getPheromone() {
56 return this.Pheromone
;
59 public double getPheromone(int x
, int y
) {
60 return this.Pheromone
[x
][y
];
63 public void setPheromone(double[][] Pheromone
) {
64 this.Pheromone
= Pheromone
;
67 public void setPheromone(int x
, int y
, double Pheromone
) {
68 this.Pheromone
[x
][y
] = Pheromone
;