path = new Path(path.nodes, path.links, path.travelTime - initialTime, path.travelCost - initialCost);
DijkstraNodeData toNodeData = getData(minCostNode); return new Path(nodes, links, toNodeData.getTime() - startNodeData.getTime(), toNodeData.getCost() - startNodeData.getCost());
path = new Path(nodes, links, arrivalTime - startTime, toNodeData.getCost());
Path path = new Path(nodes, links, startTime - arrivalTime, toNodeData.getCost());
return new Path(nodes, links, arrivalTime - startTime, toNodeData.getCost());
/** * Constructs the path after the algorithm has been run. * * @param fromNode * The node where the path starts. * @param toNode * The node where the path ends. * @param startTime * The time when the trip starts. */ protected Path constructPath(Node fromNode, Node toNode, double startTime, double arrivalTime) { List<Node> nodes = new ArrayList<>(); List<Link> links = new ArrayList<>(); nodes.add(0, toNode); Link tmpLink = getData(toNode).getPrevLink(); if (tmpLink != null) { while (tmpLink.getFromNode() != fromNode) { links.add(0, tmpLink); nodes.add(0, tmpLink.getFromNode()); tmpLink = getData(tmpLink.getFromNode()).getPrevLink(); } links.add(0, tmpLink); nodes.add(0, tmpLink.getFromNode()); } DijkstraNodeData toNodeData = getData(toNode); Path path = new Path(nodes, links, arrivalTime - startTime, toNodeData.getCost()); return path; }
Path path = new Path(nodes, links, travelTime, toNodeData.getCost());
private Path invertPath(Path invPath) { int invLinkCount = invPath.links.size();//==> normal node count //path search is called only if fromLinkId != toLinkId //see: org.matsim.core.router.NetworkRoutingModule.routeLeg() //implies: fromInvNode != toInvNode if (invLinkCount == 0) { throw new RuntimeException( "The path in the inverted network should consist of at least one link."); } List<Link> links = new ArrayList<>(invLinkCount - 1); for (int i = 1; i < invLinkCount; i++) { Id<Link> linkId = Id.create(invPath.nodes.get(i).getId(), Link.class); links.add(network.getLinks().get(linkId)); } List<Node> nodes = new ArrayList<>(invLinkCount); // nodes.add(links.get(0).getFromNode()); /* use the first link of the inverted path instead of the first node of the just created link list. also works for invLinkCount 1. theresa, jan'17 */ nodes.add(network.getNodes().get(Id.create(invPath.links.get(0).getId(), Node.class))); for (Link l : links) { nodes.add(l.getToNode()); } return new Path(nodes, links, invPath.travelTime, invPath.travelCost); }
@Override public Path calcLeastCostPath(final Node fromNode, final Node toNode, final double startTime, final Person person, final Vehicle vehicle) { // yyyyyy could you please explain why this needs to be re-implemented? I would feel better if this would just use the method of // the original class. kai, jan'13 // now construct the path ArrayList<Node> nodes = new ArrayList<Node>(); ArrayList<Link> links = new ArrayList<Link>(); nodes.add(0, toNode); Link tmpLink = getData(toNode).getPrevLink(); if (tmpLink != null) { while (tmpLink.getFromNode() != fromNode) { links.add(0, tmpLink); nodes.add(0, tmpLink.getFromNode()); tmpLink = getData(tmpLink.getFromNode()).getPrevLink(); } links.add(0, tmpLink); nodes.add(0, tmpLink.getFromNode()); } // arrival time was not ok in earlier versions! DijkstraNodeData toNodeData = getData(toNode); double arrivalTime = toNodeData.getTime(); Path path = new Path(nodes, links, arrivalTime - startTime, toNodeData.getCost()); return path; }
@Override protected Path constructPath(Node fromNode, Node toNode, double startTime, double arrivalTime) { ArrayList<Node> nodes = new ArrayList<Node>(); ArrayList<Link> links = new ArrayList<Link>(); nodes.add(0, toNode); Link tmpLink = getData(toNode).getPrevLink(); // Only this part has been adapted. Could probably also be changed in the super class. while (tmpLink != null) { links.add(0, tmpLink); nodes.add(0, tmpLink.getFromNode()); tmpLink = getData(tmpLink.getFromNode()).getPrevLink(); } // Ignore the initial time and cost of the start node! DijkstraNodeData startNodeData = getData(nodes.get(0)); DijkstraNodeData toNodeData = getData(toNode); Path path = new Path(nodes, links, toNodeData.getTime() - startNodeData.getTime(), toNodeData.getCost() - startNodeData.getCost()); // double travelTime = arrivalTime - startTime; // Path path = new Path(nodes, links, travelTime, toNodeData.getCost()); return path; }
@Override public Path calcLeastCostPath(Node fromNode, Node toNode, double starttime, Person person, Vehicle vehicle) { // travel time with pt: double ptTravelTime_h = getPtTravelTime_seconds(fromNode.getCoord(), toNode.getCoord()) / 3600.; // total walking time including (i) to get to pt stop and (ii) to get from destination pt stop to destination location: double ptTotalWalkTime_h = getTotalWalkTravelTime_seconds(fromNode.getCoord(), toNode.getCoord()) / 3600.; // total travel distance including walking and pt distance from/to origin/destination location: double ptTravelDistance_meter = getTotalWalkTravelDistance_meter(fromNode.getCoord(), toNode.getCoord()); // total walk distance including (i) to get to pt stop and (ii) to get from destination pt stop to destination location: double ptTotalWalkDistance_meter = getPtTravelDistance_meter(fromNode.getCoord(), toNode.getCoord()); return new Path( Arrays.asList(fromNode, toNode), Collections.<Link>emptyList(), getTotalTravelTime_seconds(fromNode.getCoord(), toNode.getCoord()), constPt + (ptTotalWalkTime_h * betaWalkTT) + (ptTravelTime_h * betaPtTT) + (ptTotalWalkDistance_meter * betaWalkTD) + (ptTravelDistance_meter * betaPtTD) ); } };
public Path calcPathRoute(final Coord fromCoord, final Coord toCoord, final double departureTime, final Person person) { // find possible start stops // find possible start stops Map<Node, InitialNode> wrappedFromNodes = this.locateWrappedNearestTransitNodes(person, fromCoord, departureTime); // find possible end stops Map<Node, InitialNode> wrappedToNodes = this.locateWrappedNearestTransitNodes(person, toCoord, departureTime); // find routes between start and end stops Path path = this.dijkstra.calcLeastCostPath(wrappedFromNodes, wrappedToNodes, person); if (path == null) { return null; } double directWalkTime = CoordUtils.calcEuclideanDistance(fromCoord, toCoord) / this.config.getBeelineWalkSpeed(); double directWalkCost = directWalkTime * ( 0 - this.config.getMarginalUtilityOfTravelTimeWalk_utl_s()); double pathCost = path.travelCost + wrappedFromNodes.get(path.nodes.get(0)).initialCost + wrappedToNodes.get(path.nodes.get(path.nodes.size() - 1)).initialCost; if (directWalkCost < pathCost) { return new Path(new ArrayList<Node>(), new ArrayList<Link>(), directWalkTime, directWalkCost); } double pathTime = path.travelTime + wrappedFromNodes.get(path.nodes.get(0)).initialTime + wrappedToNodes.get(path.nodes.get(path.nodes.size() - 1)).initialTime - 2*departureTime; return new Path(path.nodes, path.links, pathTime, pathCost); }
@Override protected Path constructPath(Node fromNode, Node toNode, double startTime, double arrivalTime) { LinkedList<Link> links = new LinkedList<>(); Link tmpLink = getData(toNode).getPrevLink(); if (tmpLink != null) { while (tmpLink.getFromNode() != fromNode) { links.add(tmpLink); tmpLink = getData(tmpLink.getFromNode()).getPrevLink(); } links.add(tmpLink); } return new Path(null, ImmutableList.copyOf(links.descendingIterator()), arrivalTime - startTime, getData(toNode).getCost()); } }
public PathData(Path path, double firstAndLastLinkTT) { this.path = new Path(null, ImmutableList.copyOf(path.links), path.travelTime, path.travelCost); this.firstAndLastLinkTT = firstAndLastLinkTT; }
private PathData createZeroPathData(Link fromLink) { List<Node> singleNodeList = Collections.singletonList(getFromNode(fromLink)); List<Link> emptyLinkList = Collections.emptyList(); return new PathData(new Path(singleNodeList, emptyLinkList, 0, 0), 0); }