示例#1
0
 private int getShortestDistanceByTable(
     LinkedList<DiscoveredVertex> fwd, LinkedList<DiscoveredVertex> bwd, DistanceTable dt) {
   int d = Integer.MAX_VALUE;
   DiscoveredVertex u, v;
   u = v = null;
   for (DiscoveredVertex s : fwd) {
     for (DiscoveredVertex t : bwd) {
       int d_st = dt.get(s.vertex.getId(), t.vertex.getId());
       int d_ = d_st + s.key.distance + t.key.distance;
       if (d_st == Integer.MAX_VALUE) {
         continue;
       }
       if (d_ < d) {
         u = s;
         v = t;
         d = d_;
       }
     }
   }
   fwd.clear();
   bwd.clear();
   if (u != null) {
     fwd.add(u);
     bwd.add(v);
   }
   return d;
 }
示例#2
0
  private void getShortestPathByTable(
      HHStaticGraph graph,
      HHStaticVertex s,
      HHStaticVertex t,
      DistanceTable dt,
      LinkedList<HHStaticEdge> buff) {
    int distance = dt.get(s.getId(), t.getId());
    int lvl = graph.numLevels() - 1;
    HHStaticVertex s_ = s;

    while (s_.getId() != t.getId()) {
      for (HHStaticEdge e : s.getAdjacentEdges(lvl)) {
        s_ = e.getTarget();
        if (s_.getNeighborhood(lvl) < INFINITY_1
            && distance - e.getWeight() == dt.get(s_.getId(), t.getId())) {
          s = s_;
          distance = distance - e.getWeight();
          buff.addLast(e);
          break;
        }
      }
    }
  }