Added signature method for Dijkstra class. Fixed Previous et Pi class.

This commit is contained in:
antograb committed 2017-12-04 13:36:14 +01:00
1 parent 3b674f6049
commit 5d7c970e1b
3 files changed
+35 -1

No files matched your search

+21 -1
View File
@@ -1,9 +1,13 @@
package dijkstra; package dijkstra;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.Hashtable;
import maze.Box;
public class Dijkstra { public class Dijkstra {
private PreviousInterface dijkstra(GraphInterface g, VertexInterface r, ASetInterface a, PiInterface pi, PreviousInterface previous) { private static PreviousInterface dijkstra(GraphInterface g, VertexInterface r, ASetInterface a, PiInterface pi, PreviousInterface previous) {
a.add(r) ; ; a.add(r) ; ;
VertexInterface pivot = r ; VertexInterface pivot = r ;
@@ -42,5 +46,21 @@ public class Dijkstra {
} }
public static PreviousInterface dijkstra(GraphInterface g, VertexInterface r) {
HashSet<Box> vertexHashSet = new HashSet<Box>() ;
ASet aSet = new ASet(vertexHashSet) ;
Hashtable<VertexInterface, Integer> hashPi = new Hashtable<VertexInterface, Integer>() ;
Pi pi = new Pi(hashPi) ;
Hashtable<VertexInterface, VertexInterface> hashPrevious = new Hashtable<VertexInterface, VertexInterface>() ;
ArrayList<VertexInterface> shortestPath = new ArrayList<VertexInterface>() ;
Previous previous = new Previous(hashPrevious, shortestPath) ;
return dijkstra(g, r, aSet, pi, previous) ;
}
} }
+6
View File
@@ -6,6 +6,12 @@ public class Pi implements PiInterface {
private Hashtable<VertexInterface, Integer> hashPi = new Hashtable<VertexInterface, Integer>() ; private Hashtable<VertexInterface, Integer> hashPi = new Hashtable<VertexInterface, Integer>() ;
public Pi(Hashtable<VertexInterface, Integer> hashPi) {
this.hashPi = hashPi ;
}
public int getPi(VertexInterface vertex) { public int getPi(VertexInterface vertex) {
return hashPi.get(vertex) ; return hashPi.get(vertex) ;
+8
View File
@@ -7,6 +7,14 @@ 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) {
super();
this.hashPrevious = hashPrevious;
this.shortestPath = shortestPath;
}
public VertexInterface getPrevious(VertexInterface vertex) { public VertexInterface getPrevious(VertexInterface vertex) {