Example #1
0
 static void initialize(Graph graph, Vertex source) {
   for (Vertex v : graph.vertexSet) {
     v.distance = INT_MAX;
     v.predecessor = null;
   }
   source.distance = 0;
 }
Example #2
0
  static void relax(Vertex u, Vertex v, Map<Edge, Integer> weight) {
    Edge edge = new Edge(u, v);
    if (isBoundOutOfLimit(u.distance, weight.get(edge))) {
      return;
    }

    if (v.distance > u.distance + weight.get(edge)) {
      v.distance = u.distance + weight.get(edge);
      v.predecessor = u;
    }
  }