Added packages, Previous class and ASet class.

This commit is contained in:
antograb authored and Sylvain Rager (regar42) committed 2017-12-03 20:41:05 +01:00
1 parent f252db5e3d
commit acab098ea1
16 files changed
+99 -5

No files matched your search

+2 -2
View File
@@ -1,11 +1,11 @@
import maze.Maze;
public class MainTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
Maze mazeTest = new Maze("data/labyrinthe.txt") ;
//mazeTest.saveToTextFile("data/out.txt");
System.out.println("\n" + mazeTest);
mazeTest.saveToTextFile("data/labyOutput.txt");
+33
View File
@@ -0,0 +1,33 @@
package dijkstra;
import java.util.HashSet;
import maze.Box;
public class ASet implements ASetInterface {
private HashSet<Box> vertexHashSet = new HashSet<Box>() ;
public ASet(HashSet<Box> vertexHashSet) {
this.vertexHashSet = vertexHashSet;
}
public void add(VertexInterface vertex) {
vertexHashSet.add((Box)vertex) ;
}
public boolean contains(VertexInterface vertex) {
for (VertexInterface v: vertexHashSet) {
if (v == vertex) return true ;
}
return false ;
}
}
@@ -1,3 +1,4 @@
package dijkstra;
public interface ASetInterface {
@@ -1,3 +1,4 @@
package dijkstra;
import java.util.ArrayList;
public class Dijkstra {
@@ -1,3 +1,4 @@
package dijkstra;
import java.util.ArrayList;
public interface GraphInterface {
@@ -1,3 +1,4 @@
package dijkstra;
public interface PiInterface {
+35
View File
@@ -0,0 +1,35 @@
package dijkstra;
import java.util.ArrayList;
import java.util.Hashtable;
public class Previous implements PreviousInterface {
private Hashtable<VertexInterface, VertexInterface> hashPrevious = new Hashtable<VertexInterface, VertexInterface>() ;
private ArrayList<VertexInterface> shortestPath = new ArrayList<VertexInterface>() ;
public VertexInterface getPrevious(VertexInterface vertex) {
return hashPrevious.get(vertex) ;
}
public void setPrevious(VertexInterface father, VertexInterface son) {
hashPrevious.put(son, father) ;
}
public ArrayList<VertexInterface> getShortestPathTo(VertexInterface vertex) {
VertexInterface father = getPrevious(vertex) ;
shortestPath.add(father) ;
if (getPrevious(father) == null) return shortestPath ;
else {
return getShortestPathTo(father) ;
}
}
}
@@ -1,3 +1,6 @@
package dijkstra;
import java.util.ArrayList;
public interface PreviousInterface {
@@ -6,5 +9,9 @@ public interface PreviousInterface {
/** Sets the father of an element to another element */
public void setPrevious(VertexInterface father, VertexInterface son) ;
/**Shortest path from root to a vertex */
public ArrayList<VertexInterface> getShortestPathTo(VertexInterface vertex) ;
}
@@ -1,3 +1,4 @@
package dijkstra;
public interface VertexInterface {
+1
View File
@@ -1,3 +1,4 @@
package maze;
public class ABox extends Box{
+3
View File
@@ -1,6 +1,9 @@
package maze;
import java.util.ArrayList;
import java.util.List;
import dijkstra.VertexInterface;
public abstract class Box
implements VertexInterface {
+1
View File
@@ -1,3 +1,4 @@
package maze;
public class DBox extends Box{
+1
View File
@@ -1,3 +1,4 @@
package maze;
public class EBox extends Box{
+9 -3
View File
@@ -1,9 +1,13 @@
package maze;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import dijkstra.GraphInterface;
import dijkstra.VertexInterface;
public class Maze
implements GraphInterface {
@@ -40,9 +44,11 @@ public class Maze
public ArrayList<VertexInterface> getVertexes() {
ArrayList<VertexInterface> vertexList = new ArrayList<VertexInterface>() ;
for (int i = 0 ; i <= dimensionX ; i++) {
for (int j = 0 ; j <= dimensionY ; j++) {
vertexList.add(maze[i][j]) ;
for (int i = 0 ; i < dimensionX ; i++) {
for (int j = 0 ; j < dimensionY ; j++) {
if (maze[i][j].isWalkable()) {
vertexList.add(maze[i][j]) ;
}
}
}
return vertexList ;
@@ -1,3 +1,4 @@
package maze;
public class MazeReadingException
extends Exception {
+1
View File
@@ -1,3 +1,4 @@
package maze;
public class WBox extends Box {