Deleted original files
This commit is contained in:
1 parent
648dfc6b83
commit
e2be5f8da9
14 files changed
-541
No files matched your search
@@ -1,15 +0,0 @@
|
||||
|
||||
public class ABox extends Box{
|
||||
|
||||
public ABox (String label, int x, int y, Maze maze) {
|
||||
|
||||
super(label,x,y,maze) ;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isArrival() {
|
||||
return true ;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
|
||||
|
||||
public interface ASetInterface {
|
||||
|
||||
/** Add a vertex to the ASet */
|
||||
public void add(VertexInterface vertex) ;
|
||||
|
||||
/** Check if a vertex belongs to ASet */
|
||||
public boolean contains(VertexInterface vertex) ;
|
||||
|
||||
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Box
|
||||
implements VertexInterface {
|
||||
|
||||
private int x ;
|
||||
private int y ;
|
||||
private String label ;
|
||||
private Maze maze ;
|
||||
private List<Box> neighbourList ;
|
||||
|
||||
public Box (String label, int x, int y, Maze maze) {
|
||||
|
||||
this.label = label ;
|
||||
this.x = x ;
|
||||
this.y = y ;
|
||||
this.maze = maze ;
|
||||
|
||||
}
|
||||
|
||||
public List<Box> generateNeighbors() {
|
||||
|
||||
if (x != 0 && y != 0 && x != maze.getDimensionX() && y != maze.getDimensionY()) {
|
||||
this.neighbourList.add(maze.getMaze()[x+1][y]) ;
|
||||
this.neighbourList.add(maze.getMaze()[x-1][y]) ;
|
||||
this.neighbourList.add(maze.getMaze()[x][y+1]) ;
|
||||
this.neighbourList.add(maze.getMaze()[x][y-1]) ;
|
||||
}
|
||||
|
||||
if (x == 0) {
|
||||
this.neighbourList.add(maze.getMaze()[x+1][y]) ;
|
||||
|
||||
if (y == maze.getDimensionY()) {
|
||||
this.neighbourList.add(maze.getMaze()[x][y-1]) ;
|
||||
}
|
||||
else if (y == 0) {
|
||||
this.neighbourList.add(maze.getMaze()[x][y+1]) ;
|
||||
}
|
||||
else {
|
||||
this.neighbourList.add(maze.getMaze()[x][y-1]) ;
|
||||
this.neighbourList.add(maze.getMaze()[x][y+1]) ;
|
||||
}
|
||||
}
|
||||
|
||||
if (y == 0) {
|
||||
this.neighbourList.add(maze.getMaze()[x][y+1]) ;
|
||||
|
||||
if (x == maze.getDimensionX()) {
|
||||
this.neighbourList.add(maze.getMaze()[x-1][y]) ;
|
||||
}
|
||||
else if (x == 0) {
|
||||
this.neighbourList.add(maze.getMaze()[x+1][y]) ;
|
||||
}
|
||||
else {
|
||||
this.neighbourList.add(maze.getMaze()[x-1][y]) ;
|
||||
this.neighbourList.add(maze.getMaze()[x+1][y]) ;
|
||||
}
|
||||
}
|
||||
|
||||
if (y == maze.getDimensionY()) {
|
||||
this.neighbourList.add(maze.getMaze()[x][y-1]) ;
|
||||
|
||||
if (x == maze.getDimensionX()) {
|
||||
this.neighbourList.add(maze.getMaze()[x-1][y]) ;
|
||||
}
|
||||
else if (x == 0) {
|
||||
this.neighbourList.add(maze.getMaze()[x+1][y]) ;
|
||||
}
|
||||
else {
|
||||
this.neighbourList.add(maze.getMaze()[x-1][y]) ;
|
||||
this.neighbourList.add(maze.getMaze()[x+1][y]) ;
|
||||
}
|
||||
}
|
||||
|
||||
if (x == maze.getDimensionX()) {
|
||||
this.neighbourList.add(maze.getMaze()[x-1][y]) ;
|
||||
|
||||
if (y == maze.getDimensionY()) {
|
||||
this.neighbourList.add(maze.getMaze()[x][y-1]) ;
|
||||
}
|
||||
else if (y == 0) {
|
||||
this.neighbourList.add(maze.getMaze()[x][y+1]) ;
|
||||
}
|
||||
else {
|
||||
this.neighbourList.add(maze.getMaze()[x][y-1]) ;
|
||||
this.neighbourList.add(maze.getMaze()[x][y+1]) ;
|
||||
}
|
||||
}
|
||||
|
||||
return neighbourList ;
|
||||
}
|
||||
|
||||
public boolean compareTo(VertexInterface vertex) {
|
||||
if (this.getLabel() == vertex.getLabel()) {
|
||||
return true ;
|
||||
}
|
||||
return false ;
|
||||
}
|
||||
|
||||
public boolean isWalkable() {
|
||||
return true ;
|
||||
}
|
||||
|
||||
public boolean isArrival() {
|
||||
return false ;
|
||||
}
|
||||
|
||||
public boolean isDeparture() {
|
||||
return false ;
|
||||
}
|
||||
|
||||
public List<Box> getNeighbourList() {
|
||||
return neighbourList;
|
||||
}
|
||||
|
||||
public void setNeighbourList(List<Box> neighbourList) {
|
||||
this.neighbourList = neighbourList;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public Maze getMaze() {
|
||||
return maze;
|
||||
}
|
||||
|
||||
public void setMaze(Maze maze) {
|
||||
this.maze = maze;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
|
||||
public class DBox extends Box{
|
||||
|
||||
public DBox (String label, int x, int y, Maze maze) {
|
||||
|
||||
super(label,x,y,maze) ;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDeparture() {
|
||||
return true ;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Dijkstra {
|
||||
|
||||
private PreviousInterface dijkstra(GraphInterface g, VertexInterface r, ASetInterface a, PiInterface pi, PreviousInterface previous) {
|
||||
|
||||
a.add(r) ; ;
|
||||
VertexInterface pivot = r ;
|
||||
pi.setPi(0, r) ;
|
||||
|
||||
ArrayList<VertexInterface> vertexList = g.getVertexes() ;
|
||||
|
||||
for (VertexInterface vertex: vertexList) {
|
||||
if (vertex != r) {
|
||||
pi.setPi(Integer.MAX_VALUE, vertex);
|
||||
}
|
||||
}
|
||||
|
||||
int n = g.getVertexNumber();
|
||||
for (int j = 0; j < n; j++) {
|
||||
for (VertexInterface vertex: vertexList) {
|
||||
if (! a.contains(vertex) && previous.getPrevious(vertex).compareTo(pivot)) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int piMax = Integer.MAX_VALUE ;
|
||||
for (VertexInterface vertex: vertexList) {
|
||||
if (! a.contains(vertex) && pi.getPi(vertex) < piMax) {
|
||||
pivot = vertex ;
|
||||
piMax = pi.getPi(vertex) ;
|
||||
}
|
||||
}
|
||||
a.add(pivot);
|
||||
}
|
||||
|
||||
return previous ;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
|
||||
public class EBox extends Box{
|
||||
|
||||
|
||||
public EBox (String label, int x, int y, Maze maze) {
|
||||
|
||||
super(label,x,y,maze) ;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface GraphInterface {
|
||||
|
||||
/** Returns the number of Vertexes */
|
||||
public int getVertexNumber() ;
|
||||
|
||||
/** Return the cost between two vertexes */
|
||||
public int getCost(VertexInterface start, VertexInterface end) ;
|
||||
|
||||
/** Returns an list of Vertexes */
|
||||
public ArrayList<VertexInterface> getVertexes() ;
|
||||
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
|
||||
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);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,196 +0,0 @@
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Maze
|
||||
implements GraphInterface {
|
||||
|
||||
private int dimensionX ;
|
||||
private int dimensionY ;
|
||||
private Box[][] maze ;
|
||||
|
||||
public Maze(String filename) {
|
||||
|
||||
initFromTextFile(filename) ;
|
||||
|
||||
}
|
||||
|
||||
public int getCost(VertexInterface start, VertexInterface end) {
|
||||
|
||||
Box startBox = (Box) start ;
|
||||
Box endBox = (Box) end ;
|
||||
|
||||
if (startBox.getNeighbourList().contains(endBox)) {
|
||||
if (startBox.isWalkable() & endBox.isWalkable()) {
|
||||
return 1 ;
|
||||
}
|
||||
else {
|
||||
return 0 ;
|
||||
}
|
||||
}
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
public int getVertexNumber() {
|
||||
return dimensionX*dimensionY ;
|
||||
}
|
||||
|
||||
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]) ;
|
||||
}
|
||||
}
|
||||
return vertexList ;
|
||||
}
|
||||
|
||||
public final void initFromTextFile(String filename) {
|
||||
|
||||
FileReader fr = null ;
|
||||
BufferedReader br = null ;
|
||||
|
||||
try { //Determines the height of the maze and stores it into lineCount
|
||||
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 {
|
||||
try { br.close() ;} catch (Exception e) {}
|
||||
}
|
||||
|
||||
try { //generates the maze
|
||||
fr = new FileReader(filename) ;
|
||||
br = new BufferedReader(fr) ;
|
||||
|
||||
String currentLine = null ;
|
||||
|
||||
currentLine = br.readLine() ;
|
||||
System.out.println(currentLine);
|
||||
dimensionX = currentLine.length() ; //maze's width
|
||||
System.out.println("Line length :" + dimensionX);
|
||||
int currentLineLength ;
|
||||
int compteurLigne = 0 ;
|
||||
|
||||
this.maze = new Box[dimensionX][dimensionY] ;
|
||||
|
||||
while (currentLine != null)
|
||||
{
|
||||
|
||||
//System.out.println(currentLine);
|
||||
currentLineLength = currentLine.length() ;
|
||||
System.out.println("Current line length :" + currentLineLength);
|
||||
|
||||
for (int compteurColonne = 0 ; compteurColonne < currentLineLength ; compteurColonne++) {
|
||||
|
||||
char currentChar = currentLine.charAt(compteurColonne) ;
|
||||
|
||||
switch(currentChar) {
|
||||
|
||||
case 'W' : maze[compteurLigne][compteurColonne] = new WBox("W", compteurLigne, compteurColonne, this) ;
|
||||
break;
|
||||
|
||||
case 'E' : maze[compteurLigne][compteurColonne] = new EBox("E", compteurLigne, compteurColonne, this) ;
|
||||
break;
|
||||
|
||||
case 'D' : maze[compteurLigne][compteurColonne] = new DBox("D", compteurLigne, compteurColonne, this) ;
|
||||
break;
|
||||
|
||||
case 'A' : maze[compteurLigne][compteurColonne] = new ABox("A", compteurLigne, compteurColonne, this) ;
|
||||
break;
|
||||
|
||||
default : throw new MazeReadingException(filename) ;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (currentLineLength != dimensionX) {
|
||||
throw new MazeReadingException(filename) ;
|
||||
}
|
||||
|
||||
currentLine = br.readLine() ;
|
||||
compteurLigne++ ;
|
||||
}
|
||||
} catch (MazeReadingException mre) {
|
||||
mre.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try { br.close() ;} catch (Exception e) {}
|
||||
}
|
||||
|
||||
System.out.println("dimX :" + dimensionX);
|
||||
System.out.println("dimY :" + dimensionY);
|
||||
|
||||
|
||||
//neighbour generation for each box in the maze
|
||||
for (int i = 0 ; i < dimensionX ; i++) {
|
||||
for (int j = 0 ; j < dimensionY ; j++) {
|
||||
System.out.println(maze[i][j].getLabel());
|
||||
System.out.println(maze[i][j].getMaze());
|
||||
System.out.println("x : " + maze[i][j].getX() +" y : " + maze[i][j].getY());
|
||||
|
||||
maze[i][j].generateNeighbors() ;
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
public final void saveToTextFile(String fileName) {
|
||||
|
||||
FileOutputStream fos = null ;
|
||||
PrintWriter pw = null ;
|
||||
|
||||
try {
|
||||
|
||||
fos = new FileOutputStream(fileName) ;
|
||||
pw = new PrintWriter(fos) ;
|
||||
|
||||
for (int i = 0; i < dimensionX ; i++) {
|
||||
for (int j = 0 ; j < dimensionY ; j++) {
|
||||
|
||||
pw.print(maze[i][j].getLabel());
|
||||
|
||||
}
|
||||
pw.print("\n");
|
||||
}
|
||||
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try { pw.close();} catch(Exception e) {}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int getDimensionX() {
|
||||
return dimensionX;
|
||||
}
|
||||
|
||||
public void setDimensionX(int dimensionX) {
|
||||
this.dimensionX = dimensionX;
|
||||
}
|
||||
|
||||
public int getDimensionY() {
|
||||
return dimensionY;
|
||||
}
|
||||
|
||||
public void setDimensionY(int dimensionY) {
|
||||
this.dimensionY = dimensionY;
|
||||
}
|
||||
|
||||
public Box[][] getMaze() {
|
||||
return maze;
|
||||
}
|
||||
|
||||
public void setMaze(Box[][] maze) {
|
||||
this.maze = maze;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
|
||||
public class MazeReadingException
|
||||
extends Exception {
|
||||
|
||||
private String filename ;
|
||||
|
||||
public MazeReadingException (String filename) {
|
||||
|
||||
super("Invalid maze format : " + filename) ;
|
||||
this.filename = filename ;
|
||||
|
||||
}
|
||||
|
||||
public String getFilename() {
|
||||
return filename ;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
|
||||
public interface PiInterface {
|
||||
|
||||
/** Returns the value of pi(v) */
|
||||
public int getPi(VertexInterface vertex) ;
|
||||
|
||||
/** Sets the Pi value of an element */
|
||||
public void setPi(int i, VertexInterface vertex) ;
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
|
||||
public interface PreviousInterface {
|
||||
|
||||
/** Returns the father of an element */
|
||||
public VertexInterface getPrevious(VertexInterface vertex) ;
|
||||
|
||||
/** Sets the father of an element to another element */
|
||||
public void setPrevious(VertexInterface father, VertexInterface son) ;
|
||||
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
|
||||
public interface VertexInterface {
|
||||
|
||||
/** Compare a Vertex to another */
|
||||
public boolean compareTo(VertexInterface vertex) ;
|
||||
|
||||
public String getLabel() ;
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user