/** * initial for routing, if the start node is an intersect, then it should already in the adjlist, * than we just add it. If the start node is not intersect, then the node will not in adjlist, we * need find the node's two edge entrance if the edge is bidirection or one edge entrance if the * edge is oneway. * * @param startNode * @param endNode * @param startTime * @param dayIndex * @param nodeHelperCache */ public static PriorityQueue<NodeInfoHelper> initialStartSet( long startNode, long endNode, int startTime, int dayIndex, HashMap<Long, NodeInfoHelper> nodeHelperCache) { PriorityQueue<NodeInfoHelper> openSet = new PriorityQueue<NodeInfoHelper>( 10000, new Comparator<NodeInfoHelper>() { public int compare(NodeInfoHelper n1, NodeInfoHelper n2) { return (int) (n1.getTotalCost() - n2.getTotalCost()); } }); NodeInfo start = OSMData.nodeHashMap.get(startNode); NodeInfoHelper current; // initial start end set if (start.isIntersect()) { // initial current = new NodeInfoHelper(startNode); current.setCost(0); current.setCurrentLevel(10); current.setHeuristic(OSMRouting.estimateHeuristic(startNode, endNode)); openSet.offer(current); // push the start node nodeHelperCache.put(current.getNodeId(), current); // add cache } else { EdgeInfo edge = start.getOnEdgeList().getFirst(); double travelTime = 1; // second int distance; // feet int totalDistance = edge.getDistance(); // feet if (!edge.isOneway()) { // distance from start to middle distance = edge.getStartDistance(startNode); travelTime = edge.getTravelTime(startTime, dayIndex, false); travelTime *= (double) distance / totalDistance; travelTime /= OSMParam.MILLI_PER_SECOND; current = new NodeInfoHelper(edge.getStartNode()); current.setCost(travelTime); current.setCurrentLevel(10); current.setHeuristic(OSMRouting.estimateHeuristic(edge.getStartNode(), endNode)); openSet.offer(current); // push the start node nodeHelperCache.put(current.getNodeId(), current); // add cache } // distance from middle to end distance = edge.getEndDistance(startNode); travelTime = edge.getTravelTime(startTime, dayIndex, true); travelTime *= (double) distance / totalDistance; current = new NodeInfoHelper(edge.getEndNode()); current.setCost(travelTime); current.setCurrentLevel(10); current.setHeuristic(OSMRouting.estimateHeuristic(edge.getEndNode(), endNode)); openSet.offer(current); // push the start node nodeHelperCache.put(current.getNodeId(), current); // add cache } return openSet; }
/** * initial the end node set, if the end node is intersect, add it directly or we find the end * node's edge's entrance(s) * * @param nodeId * @return */ public static HashSet<Long> initialEndSet(long nodeId) { HashSet<Long> endSet = new HashSet<Long>(); NodeInfo end = OSMData.nodeHashMap.get(nodeId); // initial start end set if (end.isIntersect()) { endSet.add(nodeId); } else { EdgeInfo edge = end.getOnEdgeList().getFirst(); if (!edge.isOneway()) { endSet.add(edge.getEndNode()); } endSet.add(edge.getStartNode()); } return endSet; }
/** * using low bound for travel time, for reverse searching * * @param endNode * @param startNode * @param openSet * @param nodeHelperCache */ public void initialEndSet( long startNode, long endNode, PriorityQueue<NodeInfoHelper> openSet, HashMap<Long, NodeInfoHelper> nodeHelperCache) { NodeInfo start = OSMData.nodeHashMap.get(startNode); NodeInfoHelper current; // initial start end set if (start.isIntersect()) { // initial current = new NodeInfoHelper(startNode); current.setCost(0); current.setCurrentLevel(10); current.setHeuristic(OSMRouting.estimateHeuristic(startNode, endNode)); openSet.offer(current); // push the start node nodeHelperCache.put(current.getNodeId(), current); // add cache } else { EdgeInfo edge = start.getOnEdgeList().getFirst(); double travelTime = 1; // second int distance; // feet int totalDistance = edge.getDistance(); // feet if (!edge.isOneway()) { // distance from start to middle distance = edge.getStartDistance(startNode); // get low bound of travel time travelTime = edge.getTravelTimeMin(false); travelTime *= (double) distance / totalDistance; current = new NodeInfoHelper(edge.getStartNode()); current.setCost(travelTime); current.setCurrentLevel(10); current.setHeuristic(OSMRouting.estimateHeuristic(edge.getStartNode(), endNode)); openSet.offer(current); // push the start node nodeHelperCache.put(current.getNodeId(), current); // add cache } // distance from middle to end distance = edge.getEndDistance(startNode); travelTime = edge.getTravelTimeMin(true); travelTime *= (double) distance / totalDistance; current = new NodeInfoHelper(edge.getEndNode()); current.setCost(travelTime); current.setCurrentLevel(10); current.setHeuristic(OSMRouting.estimateHeuristic(edge.getEndNode(), endNode)); openSet.offer(current); // push the start node nodeHelperCache.put(current.getNodeId(), current); // add cache } }
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; }