From d6ea14aebf2caad352de1e87dc6b3381434746e4 Mon Sep 17 00:00:00 2001 From: Jochen Keil Date: Mon, 21 Jun 2010 19:40:30 +0200 Subject: [PATCH] replace more direct access with getter/setter methods --- Ant.java | 11 ++++++----- Graph.java | 2 +- Pheromone.java | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Ant.java b/Ant.java index 03f1e05..88f5baf 100644 --- a/Ant.java +++ b/Ant.java @@ -12,8 +12,8 @@ class Ant { TourLength = 0; - Tour = new int[graph.NumOfCities]; - Visited = new boolean[graph.NumOfCities]; + Tour = new int[graph.getNumOfCities()]; + Visited = new boolean[graph.getNumOfCities()]; clearTour(); clearMemory(); @@ -37,15 +37,16 @@ class Ant { int CurrentCity = Step - 1; double SumProbabilities = 0.0; - double SelectionProbability[] = new double[graph.NearestNeighboursDepth]; + double SelectionProbability[] = new double[graph.getNearestNeighboursDepth()]; - for (int j = 0; j < graph.NearestNeighboursDepth; j++) { + for (int j = 0; j < graph.getNearestNeighboursDepth(); j++) { if ( Visited[ graph.getNearestNeighbour(CurrentCity,j) ] ) { SelectionProbability[j] = 0.0; } else { SelectionProbability[j] = - graph.getChoiceInformation( CurrentCity, graph.getNearestNeighbour(CurrentCity,j) ); + graph.getChoiceInformation( CurrentCity, + graph.getNearestNeighbour(CurrentCity,j) ); SumProbabilities += SelectionProbability[j]; } diff --git a/Graph.java b/Graph.java index 6042e61..f4e888e 100644 --- a/Graph.java +++ b/Graph.java @@ -172,7 +172,7 @@ class Graph { protected void mirrorDistances() { for (int i = 0; i < NumOfCities; i++) { for (int j = 0; j < NumOfCities; j++) { - if (distance.getDistance(i,j) != INFINITY) { + if (distance.getDistance(i,j) != getINFINITY()) { distance.setDistance(j,i, distance.getDistance(i,j)); } else { distance.setDistance(i,j, distance.getDistance(j,i)); diff --git a/Pheromone.java b/Pheromone.java index 6266ab5..9354349 100644 --- a/Pheromone.java +++ b/Pheromone.java @@ -37,8 +37,8 @@ class Pheromone { public void depositPheromone(Ant ant) { double dt = 1.0/ant.getTourLength(); for (int i = 0; i < graph.getNumOfCities() - 1; i++) { - int j = ant.Tour[i]; - int l = ant.Tour[i+1]; + int j = ant.getTour(i); + int l = ant.getTour(i+1); Pheromone[j][l] = Pheromone[j][l] + dt; Pheromone[l][j] = Pheromone[j][l]; } -- 2.11.4.GIT