diff --git a/src/dijkstra/Dijkstra.java b/src/dijkstra/Dijkstra.java index 1ed1786..5dc2371 100644 --- a/src/dijkstra/Dijkstra.java +++ b/src/dijkstra/Dijkstra.java @@ -22,7 +22,7 @@ public class Dijkstra { int n = g.getVertexNumber(); for (int j = 0; j < n; j++) { - for (VertexInterface vertex: g.generateNeighbours(pivot)) { + for (VertexInterface vertex: pivot.generateNeighbours()) { if (!a.contains(vertex)) { if (pi.getPi(pivot) + g.getCost(pivot, vertex) < pi.getPi(vertex)) { pi.setPi(pi.getPi(pivot) + g.getCost(pivot, vertex), vertex) ; diff --git a/src/dijkstra/VertexInterface.java b/src/dijkstra/VertexInterface.java index 51d147d..32e1e44 100644 --- a/src/dijkstra/VertexInterface.java +++ b/src/dijkstra/VertexInterface.java @@ -1,5 +1,7 @@ package dijkstra; +import java.util.ArrayList; + /** * This describes a vertex as seen in graphs (see INF101 course). * @@ -10,5 +12,10 @@ public interface VertexInterface { * @return The label of the element. */ public String getLabel() ; - + + /** + * Updates the attribute of the element. + * @return The neighbourList of the element. + */ + public ArrayList generateNeighbours(); } diff --git a/src/maze/Box.java b/src/maze/Box.java index 3a665e7..0c17d17 100644 --- a/src/maze/Box.java +++ b/src/maze/Box.java @@ -22,7 +22,7 @@ public abstract class Box private int y ; private String label = null ; private Maze maze ; - private ArrayList neighbourList = new ArrayList() ; + private ArrayList neighbourList; public Box (String label, int y , int x, Maze maze) { //y first because of graphical maze representation @@ -33,9 +33,9 @@ public abstract class Box } - public ArrayList generateNeighbors() { + public ArrayList generateNeighbours() { + this.neighbourList = maze.generateNeighbours(this); return maze.generateNeighbours(this) ; - } public boolean isWalkable() { @@ -50,7 +50,7 @@ public abstract class Box return false ; } - public ArrayList getNeighbourList() { + public ArrayList getNeighbourList() { return neighbourList; } diff --git a/src/maze/Maze.java b/src/maze/Maze.java index 8e6edad..2f22ccb 100644 --- a/src/maze/Maze.java +++ b/src/maze/Maze.java @@ -141,7 +141,7 @@ public class Maze return neighbourList ; } - + /**Constructs the maze from a text file, according to each single character on each line. * @param filename * The path to the file containing the representation of the maze.