Added packages, Previous class and ASet class.
This commit is contained in:
1 parent
f252db5e3d
commit
acab098ea1
16 files changed
+99
-5
No files matched your search
@@ -0,0 +1,45 @@
|
||||
package dijkstra;
|
||||
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 ;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user