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();
  }
  public ArrayList<VisitedObject> getKNN(int srcVID, int k) throws IOException {
    TreeSet<VisitedObject> queue = new TreeSet<VisitedObject>();
    ArrayList<VisitedObject> kNNs = new ArrayList<VisitedObject>();
    HashSet<Integer> visitedN = new HashSet<Integer>();
    HashSet<Integer> visitedO = new HashSet<Integer>();

    int expNodeCnt = 0;

    VisitedObject obj = new VisitedObject(srcVID, -1, 0);
    queue.add(obj);
    int popsize = 0;
    while ((queue.size() > 0) && (kNNs.size() < k)) {
      if (expNodeCnt % 50 == 0) { // simulate reading data from page
        String input = "test.txt";
        BufferedReader in = new BufferedReader(new FileReader(input));
        String str;
        while ((str = in.readLine()) != null) {
          int lng = str.length();
          if (lng == 0) System.out.println("The string is empty.");
        }
        in.close();
      }
      VisitedObject popObj = queue.pollFirst();
      // popsize++;
      if ((visitedN.contains(popObj.getVID())) || (visitedO.contains(popObj.getMsgID()))) {
        continue;
      }
      if (popObj.getVID() >= 0) { // pop up object is a node
        Vertex popVertex = GraphPool.getSignleton().getVertex(popObj.getVID());
        LinkedList<Integer> msgObj = popVertex.getAssocMsgObj();
        for (int i = 0; i < msgObj.size(); i++) {
          VisitedObject oneObj = new VisitedObject(-1, msgObj.get(i), popObj.getDist());
          queue.add(oneObj);
        }
        ChoosePath(queue, popVertex, popObj.getDist(), visitedN, visitedO);
        expNodeCnt++;
        visitedN.add(popObj.getVID());
        /*
        if (visitNodeMap.containsKey(popObj.getVID())) {
        	int cnt = visitNodeMap.get(popObj.getVID());
        	cnt++;
        	visitNodeMap.put(popObj.getVID(), cnt);
        }
        else {
        	visitNodeMap.put(popObj.getVID(), 1);
        }*/
      } else { // pop up object is a msgObj
        kNNs.add(popObj);
        visitedO.add(popObj.getMsgID());
      }
    }

    return kNNs;
  }
  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);
    }
  }
  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);
    }
  }
  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;
  }
 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);
     }
   }
 }