Example #1
0
  private static double sd(double[] ada_x, double ad_mean) {

    double sum = 0;

    for (int i = 0; i < ada_x.length; i++) {
      sum += Math.pow((ada_x[i] - ad_mean), 2);
    }

    return Math.sqrt(sum / ada_x.length);
  }
Example #2
0
  public static FibonacciHeap<NodeInfoHelper> initialStartSet(
      long startNode,
      long endNode,
      HashMap<Long, FibonacciHeapNode<NodeInfoHelper>> nodeHelperCache) {
    FibonacciHeap<NodeInfoHelper> openSet = new FibonacciHeap<NodeInfoHelper>();

    NodeInfo start = OSMData.nodeHashMap.get(startNode);
    NodeInfoHelper initial;
    FibonacciHeapNode<NodeInfoHelper> fInitial;
    // initial start end set
    if (start.isIntersect()) {
      // initial
      initial = new NodeInfoHelper(startNode);
      initial.setCost(0);
      initial.setHeuristic(estimateHeuristic(startNode, endNode));
      fInitial = new FibonacciHeapNode<NodeInfoHelper>(initial);
      openSet.insert(fInitial, initial.getTotalCost()); // push the start node
      nodeHelperCache.put(initial.getNodeId(), fInitial); // add cache
    } else {
      EdgeInfo edge = start.getOnEdgeList().getFirst();
      double speed = edge.getTravelSpeed();
      int travelTime = 1; // second
      int distance;
      if (!edge.isOneway()) {
        // distance from start to middle
        distance = edge.getStartDistance(startNode);
        travelTime = (int) Math.round(distance / speed * OSMParam.MILLI_PER_SECOND);
        initial = new NodeInfoHelper(edge.getStartNode());
        initial.setCost(travelTime);
        initial.setHeuristic(estimateHeuristic(edge.getStartNode(), endNode));
        fInitial = new FibonacciHeapNode<NodeInfoHelper>(initial);
        openSet.insert(fInitial, initial.getTotalCost()); // push the start node
        nodeHelperCache.put(initial.getNodeId(), fInitial); // add cache
      }
      distance = edge.getEndDistance(startNode);
      travelTime = (int) Math.round(distance / speed * OSMParam.MILLI_PER_SECOND);
      initial = new NodeInfoHelper(edge.getEndNode());
      initial.setCost(travelTime);
      initial.setHeuristic(estimateHeuristic(edge.getEndNode(), endNode));
      fInitial = new FibonacciHeapNode<NodeInfoHelper>(initial);
      openSet.insert(fInitial, initial.getTotalCost()); // push the start node
      nodeHelperCache.put(initial.getNodeId(), fInitial); // add cache
    }
    return openSet;
  }
Example #3
0
 public NodeInfoHelper getEndNodeHelper(long endNode) {
   // TODO: not time dependent now, need to modify
   NodeInfo end = OSMData.nodeHashMap.get(endNode);
   NodeInfoHelper endNodeHelper = new NodeInfoHelper(endNode);
   if (getNodeId() == end.getNodeId()) { // no need to do in edge routing
     return this;
   } else {
     EdgeInfo edge = end.getOnEdgeList().getFirst();
     int distance;
     // from start to middle
     if (getNodeId() == edge.getStartNode()) {
       distance = edge.getStartDistance(endNode);
     } else { // from end to middle
       distance = edge.getEndDistance(endNode);
     }
     double speed = edge.getTravelSpeed();
     int travelTime = 1; // second
     travelTime = (int) Math.round(distance / speed);
     endNodeHelper.setCost(getCost() + travelTime);
     endNodeHelper.setParentId(getNodeId());
   }
   return endNodeHelper;
 }