diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5e1d7a3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.html +*.css +src/package-list +src/script.js diff --git a/src/dijkstra/ASetInterface.java b/src/dijkstra/ASetInterface.java index c09024c..4bc12d0 100644 --- a/src/dijkstra/ASetInterface.java +++ b/src/dijkstra/ASetInterface.java @@ -2,14 +2,31 @@ package dijkstra; import java.util.HashSet; +/** + * This is the ASet class as described in the INF101 course of Telecom Paristech. + * The ASet contains vertexes for which the shortest path has already been found (vertexes already examined by the dijkstra algorithm). + */ public interface ASetInterface { - /** Add a vertex to the ASet */ + /** + * Adds a vertex to the set. + * @param vertex + * The element to be added to the set. + */ public void add(VertexInterface vertex) ; - /** Check if a vertex belongs to ASet */ + /** + * Checks if a vertex belongs to the set. + * @param vertex + * The element we must check if it belongs to the set. + * @return true if the element is in the set, false if not. + */ public boolean contains(VertexInterface vertex) ; - + + /** + * Returns the HashSet which represents the ASet. + * @return A HashSet containing the same elements as in the set. + */ public HashSet getVertexHashSet(); diff --git a/src/dijkstra/Dijkstra.java b/src/dijkstra/Dijkstra.java index e91af31..1ed1786 100644 --- a/src/dijkstra/Dijkstra.java +++ b/src/dijkstra/Dijkstra.java @@ -26,7 +26,7 @@ public class Dijkstra { 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) ; - previous.setPrevious(pivot, vertex); + previous.setPrevious(pivot, vertex) ; } } } @@ -38,7 +38,7 @@ public class Dijkstra { piMax = pi.getPi(vertex) ; } } - a.add(pivot); + a.add(pivot) ; } return previous ; diff --git a/src/dijkstra/GraphInterface.java b/src/dijkstra/GraphInterface.java index 5c8c8e6..256a211 100644 --- a/src/dijkstra/GraphInterface.java +++ b/src/dijkstra/GraphInterface.java @@ -1,18 +1,40 @@ package dijkstra; import java.util.ArrayList; +/** + * This is the Graph class as described in the INF101 course of Telecom Paristech. + * Graph contains the representation of all the vertexes, with the information on which vertex(es) a vertex is linked to and at what cost. + */ public interface GraphInterface { - /** Returns the number of Vertexes **/ + /** + * Gets the number of VertexInterface in the graph. + * @return An integer giving the number of VertexInterface in the graph. + */ public int getVertexNumber() ; - /** Return the cost between two vertexes **/ + /** + * Gets the cost of the link (if it exists) between two vertexes. + * @param start + * The departure vertex. + * @param end + * The vertex from which we must see the cost of the link to start. + * @return An integer giving the cost of the link between the given VertexInterface. + */ public int getCost(VertexInterface start, VertexInterface end) ; - /** Returns an list of Vertexes **/ + /** + * Returns all VertexInterface contained in the graph. + * @return An ArrayList of VertexInterface. + */ public ArrayList getVertexes() ; - /** Returns the neighbour list for a given box */ + /** + * Returns the neighbour list for a given VertexInterface. + * @param vertex + * The VertexInterface from which we will seek for neighbours. + * @return An ArrayList of VertexInterface. + */ public ArrayList generateNeighbours(VertexInterface vertex) ; } diff --git a/src/dijkstra/PiInterface.java b/src/dijkstra/PiInterface.java index 87fce98..3c96101 100644 --- a/src/dijkstra/PiInterface.java +++ b/src/dijkstra/PiInterface.java @@ -1,11 +1,27 @@ package dijkstra; +/** + * This is the Pi class as described in the INF101 course of Telecom Paristech. + * It contains the path's cost to reach vertexes (typically, from the root of the graph). + */ public interface PiInterface { - /** Returns the value of pi(v) */ + /** + * Gets the cost to reach the given VertexInterface + * @param vertex + * The VertexInterface from which we get the Pi value (cost) to reach it. + * @return An integer giving the Pi value (cost) the reach the VertexInterface. + * + */ public int getPi(VertexInterface vertex) ; - /** Sets the Pi value of an element */ + /** + * Sets the Pi value of an element + * @param i + * The Pi value (cost) to set. + * @param vertex + * The VertexInterface on which the Pi value (cost) is to be set. + */ public void setPi(int i, VertexInterface vertex) ; } diff --git a/src/dijkstra/Previous.java b/src/dijkstra/Previous.java index b6acaeb..527b8af 100644 --- a/src/dijkstra/Previous.java +++ b/src/dijkstra/Previous.java @@ -2,9 +2,6 @@ package dijkstra; import java.util.ArrayList; import java.util.Hashtable; -import java.util.List; - -import maze.Box; public class Previous implements PreviousInterface { diff --git a/src/dijkstra/PreviousInterface.java b/src/dijkstra/PreviousInterface.java index 02c08b9..c06dd6d 100644 --- a/src/dijkstra/PreviousInterface.java +++ b/src/dijkstra/PreviousInterface.java @@ -2,15 +2,36 @@ package dijkstra; import java.util.ArrayList; +/** + * The PreviousInterface contains information about the father (as in the graph's theory) of some VertexInterface. + * The father of a VertexInterface is the VertexInterface used to reach it. + * Typically in Dijkstra, it's the VertexInterface used to reach vertex with the lowest cost. + */ public interface PreviousInterface { - /** Returns the father of an element */ + /** + * Returns the father of a VertexInterface. + * @param vertex + * The VertexInterface from which we get the father (previous VertexInterface). + * @return The direct previous element used to reach vertex. + */ public VertexInterface getPrevious(VertexInterface vertex) ; - /** Sets the father of an element to another element */ + /** + * Sets the father of an element to another element. + * @param father + * The element that will become the father of the other element. + * @param son + * The element that will be assigned a new father. + */ public void setPrevious(VertexInterface father, VertexInterface son) ; - /**Shortest path from root to a vertex */ + /** + * Shortest path from root to a vertex. + * @param vertex + * The vertex to which the shortest path will be computed. + * @return An ArrayList of the VertexInterface used to reach vertex with the lowest cost. + */ public ArrayList getShortestPathTo(VertexInterface vertex) ; } diff --git a/src/dijkstra/VertexInterface.java b/src/dijkstra/VertexInterface.java index e62827c..e047a9a 100644 --- a/src/dijkstra/VertexInterface.java +++ b/src/dijkstra/VertexInterface.java @@ -1,10 +1,21 @@ package dijkstra; -import java.util.List; +/** + * This describes a vertex as seen in graphs (see INF101 course). + * + */ public interface VertexInterface { - /** Compare a Vertex to another */ + /** + * Compares a VertexInterface to another. + * @param vertex + * The vertex to which the equality will be tested. + * @return true is the two VertexInterface are the same, false if not. + */ public boolean compareTo(VertexInterface vertex) ; + /** + * @return The label of the element. + */ public String getLabel() ; } diff --git a/src/maze/ABox.java b/src/maze/ABox.java index 1b875d0..ef72aa2 100644 --- a/src/maze/ABox.java +++ b/src/maze/ABox.java @@ -1,5 +1,8 @@ package maze; +/** + * ABox is an arrival Box. It's the last Box to be walked through and it's an exit to the Maze. + */ public class ABox extends Box{ public ABox (String label, int x, int y, Maze maze) { diff --git a/src/maze/Box.java b/src/maze/Box.java index 2326e21..9219de9 100644 --- a/src/maze/Box.java +++ b/src/maze/Box.java @@ -4,6 +4,18 @@ import java.util.List; import dijkstra.VertexInterface; +/**

Box class

+ *

+ * + * This class describes a Box and implements {@link dijkstra.VertexInterface}. + *

+ * A Box is represented with its coordinates, its label, and its neighbourList. It also has a reference on the Maze. + * + * @author Antonin Godard + * @author Sylvain Rager + * + */ + public abstract class Box implements VertexInterface { diff --git a/src/maze/DBox.java b/src/maze/DBox.java index 6bcdc8e..3b62e7c 100644 --- a/src/maze/DBox.java +++ b/src/maze/DBox.java @@ -1,5 +1,9 @@ package maze; +/** + * A DBox is the Box on which the user is first in the Maze. + */ + public class DBox extends Box{ public DBox (String label, int x, int y, Maze maze) { diff --git a/src/maze/EBox.java b/src/maze/EBox.java index 88c63d5..b2d968b 100644 --- a/src/maze/EBox.java +++ b/src/maze/EBox.java @@ -1,5 +1,9 @@ package maze; +/** + * An EBox is a Box that can be walked through (an empty box). + */ + public class EBox extends Box{ diff --git a/src/maze/Maze.java b/src/maze/Maze.java index 93ce736..6d1c32a 100644 --- a/src/maze/Maze.java +++ b/src/maze/Maze.java @@ -8,6 +8,14 @@ import java.util.ArrayList; import dijkstra.GraphInterface; import dijkstra.VertexInterface; +/**

Maze class

+ *

+ * This class describes the maze as a matrix of Boxes ({@link maze.Box}). + * + * @author Antonin Godard + * @author Sylvain Rager + * + */ public class Maze implements GraphInterface { @@ -21,6 +29,9 @@ public class Maze } + /** + * + */ public int getCost(VertexInterface start, VertexInterface end) { Box startBox = (Box) start ; @@ -81,16 +92,20 @@ public class Maze } + /**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. + */ + public final void initFromTextFile(String filename) { FileReader fr = null ; BufferedReader br = null ; - try { //Determines the height of the maze and stores it into lineCount + try { fr = new FileReader(filename) ; br = new BufferedReader(fr) ; while (br.readLine() != null) dimensionY++; - //System.out.println("Line count :" + lineCount); } catch (Exception e) { e.printStackTrace(); } finally { diff --git a/src/maze/MazeReadingException.java b/src/maze/MazeReadingException.java index 0bfd24c..4cc5822 100644 --- a/src/maze/MazeReadingException.java +++ b/src/maze/MazeReadingException.java @@ -1,5 +1,12 @@ package maze; +/**

MazeReadingException exception

+ *

+ * This class is used to throw exception when reading and initiating the maze from a text file. + * + * + */ + public class MazeReadingException extends Exception { diff --git a/src/maze/WBox.java b/src/maze/WBox.java index d0adc4b..29a1107 100644 --- a/src/maze/WBox.java +++ b/src/maze/WBox.java @@ -1,5 +1,9 @@ package maze; +/** + * A WBox is a Box that can't be walked through (a wall). + */ + public class WBox extends Box {