Merge the last Dijkstra classes #7
No files matched your search
+11
-3
@@ -1,5 +1,7 @@
|
|||||||
import dijkstra.Dijkstra;
|
import java.util.ArrayList;
|
||||||
import maze.Maze;
|
|
||||||
|
import dijkstra.*;
|
||||||
|
import maze.*;
|
||||||
|
|
||||||
public class MainTest {
|
public class MainTest {
|
||||||
|
|
||||||
@@ -7,7 +9,13 @@ public class MainTest {
|
|||||||
|
|
||||||
Maze mazeTest = new Maze("data/labyrinthe.txt") ;
|
Maze mazeTest = new Maze("data/labyrinthe.txt") ;
|
||||||
|
|
||||||
Dijkstra.dijkstra(mazeTest, mazeTest.getMaze()[1][1]) ;
|
Previous previous = (Previous) Dijkstra.dijkstra(mazeTest, mazeTest.getMaze()[1][1]);
|
||||||
|
|
||||||
|
ArrayList<VertexInterface> shortest = previous.getShortestPathTo(mazeTest.getMaze()[5][5]);
|
||||||
|
|
||||||
|
for (VertexInterface vertex : shortest) {
|
||||||
|
System.out.println(vertex);
|
||||||
|
}
|
||||||
|
|
||||||
mazeTest.saveToTextFile("data/labyOutput.txt");
|
mazeTest.saveToTextFile("data/labyOutput.txt");
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ package dijkstra;
|
|||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
import maze.Box;
|
|
||||||
|
|
||||||
public class ASet implements ASetInterface {
|
public class ASet implements ASetInterface {
|
||||||
|
|
||||||
private HashSet<VertexInterface> vertexHashSet = new HashSet<VertexInterface>() ;
|
private HashSet<VertexInterface> vertexHashSet = new HashSet<VertexInterface>() ;
|
||||||
|
|||||||
@@ -2,16 +2,11 @@ package dijkstra;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import maze.Box;
|
|
||||||
|
|
||||||
public class Previous implements PreviousInterface {
|
public class Previous implements PreviousInterface {
|
||||||
|
|
||||||
private Hashtable<VertexInterface, VertexInterface> hashPrevious = new Hashtable<VertexInterface, VertexInterface>() ;
|
private Hashtable<VertexInterface, VertexInterface> hashPrevious = new Hashtable<VertexInterface, VertexInterface>() ;
|
||||||
private ArrayList<VertexInterface> shortestPath = new ArrayList<VertexInterface>() ;
|
private ArrayList<VertexInterface> shortestPath = new ArrayList<VertexInterface>() ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Previous(Hashtable<VertexInterface, VertexInterface> hashPrevious, ArrayList<VertexInterface> shortestPath) {
|
public Previous(Hashtable<VertexInterface, VertexInterface> hashPrevious, ArrayList<VertexInterface> shortestPath) {
|
||||||
|
|
||||||
@@ -39,8 +34,7 @@ public class Previous implements PreviousInterface {
|
|||||||
if (getPrevious(father) == null) return shortestPath ;
|
if (getPrevious(father) == null) return shortestPath ;
|
||||||
else {
|
else {
|
||||||
return getShortestPathTo(father) ;
|
return getShortestPathTo(father) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
package dijkstra;
|
package dijkstra;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface VertexInterface {
|
public interface VertexInterface {
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
package maze;
|
package maze;
|
||||||
|
|
||||||
public class ABox extends Box{
|
public class ABox extends EBox{
|
||||||
|
|
||||||
public ABox (String label, int x, int y, Maze maze) {
|
public ABox (String label, int x, int y, Maze maze) {
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -21,7 +21,7 @@ public abstract class Box
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<VertexInterface> generateNeighbors() {
|
public ArrayList<VertexInterface> generateNeighbors() {
|
||||||
return maze.generateNeighbours(this) ;
|
return maze.generateNeighbours(this) ;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -45,11 +45,11 @@ public abstract class Box
|
|||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Box> getNeighbourList() {
|
public ArrayList<Box> getNeighbourList() {
|
||||||
return neighbourList;
|
return neighbourList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNeighbourList(List<Box> neighbourList) {
|
public void setNeighbourList(ArrayList<Box> neighbourList) {
|
||||||
this.neighbourList = neighbourList;
|
this.neighbourList = neighbourList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ public abstract class Box
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return label;
|
return "Label: " + label + ", x: " + x + ", y: " + y;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
package maze;
|
package maze;
|
||||||
|
|
||||||
public class DBox extends Box{
|
public class DBox extends EBox{
|
||||||
|
|
||||||
public DBox (String label, int x, int y, Maze maze) {
|
public DBox (String label, int x, int y, Maze maze) {
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,11 @@ package maze;
|
|||||||
public class MazeReadingException
|
public class MazeReadingException
|
||||||
extends Exception {
|
extends Exception {
|
||||||
|
|
||||||
private String filename ;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public MazeReadingException (String filename) {
|
public MazeReadingException (String filename) {
|
||||||
|
|
||||||
super("Invalid maze format : " + filename) ;
|
super("Invalid maze format : " + filename) ;
|
||||||
this.filename = filename ;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user