implement the gui interface
[aco.git] / Pheromone.java
blob12607e0b88d11eed5ebe4f15efd6cb49ef54a112
1 class Pheromone {
3 protected Graph graph;
4 protected double[][] Pheromone;
6 Pheromone(Graph graph) {
7 this.graph = graph;
8 this.Pheromone = new double[graph.getNumOfCities()][graph.getNumOfCities()];
10 double tauzero =
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) {
23 evaporate();
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();
43 int j = 0;
44 int l = 0;
45 for (int i = 0; i < graph.getNumOfCities() - 1; i++) {
46 j = ant.getTour(i);
47 l = ant.getTour(i+1);
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;