コード例 #1
0
  public ArrayList<MsgObjPath> getRoadKNN(int srcVID) {
    Vertex srcV = GraphPool.getSignleton().getVertex(srcVID);
    RNet leafR = RNetHierarchy.getSignleton().getRNet(srcV.getLeafRnetID());
    TreeSet<Path> queue = new TreeSet<Path>();
    TreeSet<MsgObjPath> settleSet = new TreeSet<MsgObjPath>();
    TreeSet<MsgObjPath> unSettleSet = new TreeSet<MsgObjPath>();

    boolean finish = false;

    if (leafR.hasMsgObjInside()) {
      Dijkstra dijkstra = new Dijkstra(leafR.getGraph());
      dijkstra.execute(srcVID);
      TreeSet<MsgObjPath> msgset = dijkstra.getPath2Objects(leafR);

      finish = doSettle(settleSet, unSettleSet, msgset);

      if (!finish) {
        TreeSet<MsgObjPath> borset = dijkstra.getPath2Borders(leafR);
        finish = doSettle(settleSet, unSettleSet, borset);
      }
    } else {
      Dijkstra dijkstra = new Dijkstra(leafR.getGraph());
      dijkstra.execute(srcVID);
      TreeSet<MsgObjPath> borset = dijkstra.getPath2Borders(leafR);
      finish = doSettle(settleSet, unSettleSet, borset);
    }

    TreeSet<ChoosePathUnit> pqueue = new TreeSet<ChoosePathUnit>();
    while (!finish) {
      MsgObjPath first = unSettleSet.pollFirst();
      int visitedLevel = first.currentVisitedRNetLevel;
      int vID = first.getTailVID();
      Vertex v = GraphPool.getSignleton().getVertex(vID);
      if (v.getHighestBorderLevel() < 0) {
        System.out.println("v must be a border");
        System.exit(0);
      }

      RNet highR =
          RNetHierarchy.getSignleton().getRNet(v.getInsideRNetID(v.getHighestBorderLevel()));

      if (!highR.isLeafRNet()) {
        ChoosePathUnit unit = new ChoosePathUnit();
        unit.rnet = highR.getRNetID();
        unit.path = first.clone();
        pqueue.add(unit);
      } else {
        /*leaf, search silbing*/
        List<Integer> nlist = v.getNeighbors();
        for (int i = 0; i < nlist.size(); i++) {
          Vertex anoV = GraphPool.getSignleton().getVertex(nlist.get(i));
        }
      }
    }

    return null;
  }
コード例 #2
0
  private void deleteObject(int vID) {
    // TODO Auto-generated method stub
    Vertex v = GraphPool.getSignleton().getVertex(vID);

    v.deleteOneAssocMsgObj();

    int maxLevel = RNetHierarchy.getSignleton().getMaxLevel();
    for (int i = 0; i <= maxLevel; i++) {
      int rID = v.getInsideRNetID(i);
      RNet rnet = RNetHierarchy.getSignleton().getRNet(rID);
      // rnet.setContainObj(true);
      rnet.decreaseObjCnt(1);
    }
  }
コード例 #3
0
  public ROADUpdateTurnAround(
      String networkFn, String hierFn, String msgFn, String queryFn, String updateFn)
      throws IOException {
    GraphPool.loadGraph(networkFn);
    RNetHierarchy.loadHierarchy(hierFn);
    MsgObjPool.loadMsgPool(msgFn);

    String fn = queryFn + ".loc.txt";
    BufferedWriter writer = new BufferedWriter(new FileWriter(new File(fn)));
    writer.write("x,y" + "\n");

    queryList = new ArrayList<Integer>();
    BufferedReader in = new BufferedReader(new FileReader(queryFn));
    String str;
    while ((str = in.readLine()) != null) {
      Integer vID = Integer.valueOf(str);
      queryList.add(vID);
      Vertex v = GraphPool.getSignleton().getVertex(vID);
      double[] xy = v.getloc().m_pCoords;
      writer.write(String.valueOf(xy[0]));
      writer.write(",");
      writer.write(String.valueOf(xy[1]));
      writer.write("\n");
    }
    in.close();
    writer.close();

    insertList = new ArrayList<Integer>();
    in = new BufferedReader(new FileReader(updateFn));
    while ((str = in.readLine()) != null) {
      Integer vID = Integer.valueOf(str);
      insertList.add(vID);
    }
    in.close();
  }
コード例 #4
0
  private void insertObject(int vID) {
    // TODO Auto-generated method stub
    Vertex v = GraphPool.getSignleton().getVertex(vID);

    int msgSize = MsgObjPool.getSignleton().getMsgSize();

    MsgObj obj = new MsgObj(msgSize, v.getloc().getCoord(0), v.getloc().getCoord(1));
    obj.setAssocVertex(vID);
    MsgObjPool.getSignleton().insertMsg(obj);
    v.insertAssocMsgObj(msgSize);

    int maxLevel = RNetHierarchy.getSignleton().getMaxLevel();
    for (int i = 0; i <= maxLevel; i++) {
      int rID = v.getInsideRNetID(i);
      RNet rnet = RNetHierarchy.getSignleton().getRNet(rID);
      // rnet.setContainObj(true);
      rnet.increaseObjCnt(1);
    }
  }
コード例 #5
0
 private void ChoosePath(
     TreeSet<VisitedObject> queue,
     Vertex popVertex,
     double dist,
     HashSet<Integer> visitedN,
     HashSet<Integer> visitedO) {
   // TODO Auto-generated method stub
   int leafRID = popVertex.getLeafRnetID();
   RNet leafRnet = RNetHierarchy.getSignleton().getRNet(leafRID);
   int leafLevel = leafRnet.getLevel();
   if (popVertex.isBorderNode(leafLevel)) {
     int highestLevel = popVertex.getHighestBorderLevel();
     for (int i = highestLevel; i <= leafLevel; i++) {
       int tmpRID = popVertex.getInsideRNetID(i);
       RNet tmpRNet = RNetHierarchy.getSignleton().getRNet(tmpRID);
       if (tmpRNet.hasMsgObjInside()) {
         if (tmpRNet.isLeafRNet()) {
           List<Integer> neighbors = popVertex.getNeighbors();
           for (int j = 0; j < neighbors.size(); j++) {
             int id = neighbors.get(j).intValue();
             Edge e = GraphPool.getSignleton().getEdge(popVertex.getId(), id);
             double newDist = dist + e.getWeight();
             VisitedObject oneObj = new VisitedObject(id, -1, newDist);
             queue.add(oneObj);
           }
         }
         continue;
       } else {
         ShortCutSet scSet = tmpRNet.getShortCutSet(popVertex.getId());
         if (scSet == null) break;
         HashMap<Integer, Path> scMap = scSet.getSCMap();
         Iterator<Integer> scMIter = scMap.keySet().iterator();
         while (scMIter.hasNext()) {
           Integer destID = (Integer) scMIter.next();
           double newDist = dist + scMap.get(destID).cost;
           VisitedObject oneObj = new VisitedObject(destID.intValue(), -1, newDist);
           queue.add(oneObj);
         }
         List<Integer> neighbors = popVertex.getNeighbors();
         for (int j = 0; j < neighbors.size(); j++) {
           int id = neighbors.get(j).intValue();
           Vertex neiVertex = GraphPool.getSignleton().getVertex(id);
           if (neiVertex.getInsideRNetID(i) != popVertex.getInsideRNetID(i)) {
             Edge e = GraphPool.getSignleton().getEdge(popVertex.getId(), id);
             double newDist = dist + e.getWeight();
             VisitedObject oneObj = new VisitedObject(id, -1, newDist);
             queue.add(oneObj);
           }
         }
         break;
       }
     }
   } else {
     List<Integer> neighbors = popVertex.getNeighbors();
     for (int i = 0; i < neighbors.size(); i++) {
       int id = neighbors.get(i).intValue();
       Edge e = GraphPool.getSignleton().getEdge(popVertex.getId(), id);
       double newDist = dist + e.getWeight();
       VisitedObject oneObj = new VisitedObject(id, -1, newDist);
       queue.add(oneObj);
     }
   }
 }