@Override public double computeContributionOfOpportunity(ActivityFacility origin, AggregationObject destination, Double departureTime) { LeastCostPathCalculator.Path path = leastCostPathCalculator.calcLeastCostPath(fromNode, destination.getNearestNode(), departureTime, null, null); return destination.getSum() * Math.exp(planCalcScoreConfigGroup.getBrainExpBeta() * path.travelCost); } }
/** * ASSUMPTION: A vehicle enters and exits links at their ends (link.getToNode()) */ public static VrpPathWithTravelData calcAndCreatePath(Link fromLink, Link toLink, double departureTime, LeastCostPathCalculator router, TravelTime travelTime) { Path path = null; if (fromLink != toLink) { // calc path for departureTime+1 (we need 1 second to move over the node) path = router.calcLeastCostPath(fromLink.getToNode(), toLink.getFromNode(), departureTime + 1, null, null); } return VrpPaths.createPath(fromLink, toLink, departureTime, path, travelTime); }
private void insertWenden(Id<Link> fromLinkId, Id<Link> toLinkId, Umlauf umlauf) { Node startNode = this.network.getLinks().get(fromLinkId).getToNode(); Node endNode = this.network.getLinks().get(toLinkId).getFromNode(); double depTime = 0.0; Path wendenPath = routingAlgo.calcLeastCostPath(startNode, endNode, depTime, null, null); if (wendenPath == null) { throw new RuntimeException("No route found from node " + startNode.getId() + " to node " + endNode.getId() + "."); } NetworkRoute route = RouteUtils.createLinkNetworkRouteImpl(fromLinkId, toLinkId); route.setLinkIds(fromLinkId, NetworkUtils.getLinkIds(wendenPath.links), toLinkId); umlauf.getUmlaufStuecke().add(new Wenden(route)); }
Path path = this.pathCalculator.calcLeastCostPath(startLink.getToNode(), endLink.getFromNode(), time, person, vehicle) ;
@Override public Path calcLeastCostPath(Node fromNode, Node toNode, double startTime, Person person, Vehicle vehicle) { Table<Id<Node>, Id<Node>, Path> spCacheSlice = pathCache[timeDiscretizer.getIdx(startTime)]; Path path = spCacheSlice.get(fromNode.getId(), toNode.getId()); if (path == null) { cacheStats.incMisses(); path = calculator.calcLeastCostPath(fromNode, toNode, timeDiscretizer.discretize(startTime), person, vehicle); spCacheSlice.put(fromNode.getId(), toNode.getId(), path); } else { cacheStats.incHits(); } return path; }
Path path = this.routingAlgo.calcLeastCostPath(this.net.getLinks().get(lastLinkId).getToNode(), this.net.getLinks().get(stop.getLinkId()).getFromNode(), 0.0, null, null);
Path path = this.routingAlgo.calcLeastCostPath(this.net.getLinks().get(lastLinkId).getToNode(), this.net.getLinks().get(stop.getLinkId()).getFromNode(), 0.0, null, null);
Path forth = this.routingAlgo.calcLeastCostPath(startNode, intermediateEndNode, startTime, null, null); Path back = this.routingAlgo.calcLeastCostPath(intermediateStartNode, endNode, startTime + forth.travelTime, null, null);
private void route(Leg prevLeg, Id<Link> fromLinkId, Id<Link> toLinkId, Person person, Vehicle vehicle) { if(fromLinkId.equals(toLinkId)){ prevLeg.setExpectedTransportTime(0); NetworkRoute route = RouteUtils.createLinkNetworkRouteImpl(fromLinkId, toLinkId); route.setDistance(0.0); route.setTravelTime(0.0); // route.setVehicleId(vehicle.getId()); prevLeg.setRoute(route); return; } Path path = router.calcLeastCostPath(network.getLinks().get(fromLinkId).getToNode(), network.getLinks().get(toLinkId).getFromNode(), prevLeg.getExpectedDepartureTime(), person, vehicle); double travelTime = path.travelTime; /* *ACHTUNG. Konsistenz zu VRP */ double toLinkTravelTime = this.travelTime.getLinkTravelTime(network.getLinks().get(toLinkId),prevLeg.getExpectedDepartureTime()+travelTime, person, vehicle); travelTime += toLinkTravelTime; prevLeg.setExpectedTransportTime(travelTime); NetworkRoute route = createRoute(fromLinkId,path,toLinkId); // route.setVehicleId(vehicle.getId()); prevLeg.setRoute(route); }
/** * Re-locates a future route. The route is given by its leg. It just replaces the route for the given leg, without looking after * overall plan consistency. * * @return true when replacing the route worked, false when something went wrong * */ @Deprecated // not consistent with access/egress approach; can only be used if you know exactly what you are doing. // Maybe replanXxx (which does not have these problems) is already sufficient? Otherwise use EditTrips or EditPlans. kai, nov'17 public boolean relocateFutureLegRoute(Leg leg, Id<Link> fromLinkId, Id<Link> toLinkId, Person person ) { Link fromLink = network.getLinks().get(fromLinkId); Link toLink = network.getLinks().get(toLinkId); Vehicle vehicle = null ; Node startNode = fromLink.getToNode() ; Node endNode = toLink.getFromNode() ; double starttime = leg.getDepartureTime() ; Path path = pathCalculator.calcLeastCostPath(startNode, endNode, starttime, person, vehicle) ; if (path == null) throw new RuntimeException("No route found from node " + startNode.getId() + " to node " + endNode.getId() + "."); NetworkRoute route = this.routeFactories.createRoute(NetworkRoute.class, fromLink.getId(), toLink.getId()); route.setLinkIds(fromLink.getId(), NetworkUtils.getLinkIds(path.links), toLink.getId()); route.setTravelTime((int) path.travelTime); // yyyy why int? kai, dec'15 route.setTravelCost(path.travelCost); route.setDistance(RouteUtils.calcDistance(route,1.,1., this.network)); leg.setRoute(route); return true; }
public void testCalcLeastCostPath_SameFromTo() throws SAXException, ParserConfigurationException, IOException { Scenario scenario = ScenarioUtils.createScenario(loadConfig(null)); Network network = scenario.getNetwork(); new MatsimNetworkReader(scenario.getNetwork()).readFile("test/scenarios/equil/network.xml"); Node node12 = network.getNodes().get(Id.create("12", Node.class)); LeastCostPathCalculator routerAlgo = getLeastCostPathCalculator(network); Path path = routerAlgo.calcLeastCostPath(node12, node12, 8.0*3600, null, null); assertEquals("number of nodes wrong.", 1, path.nodes.size()); assertEquals("number of links wrong.", 0, path.links.size()); assertEquals(network.getNodes().get(Id.create("12", Node.class)), path.nodes.get(0)); }
Path path = routingAlgo.calcLeastCostPath(startNode, endNode, startTime, null, null); NetworkRoute route = RouteUtils.createLinkNetworkRouteImpl(startStop.getLinkId(), endStop.getLinkId()); route.setLinkIds(startStop.getLinkId(), NetworkUtils.getLinkIds(path.links), endStop.getLinkId());
@Test public void testPersonAvailableForDisutility_FastDijkstra() { Fixture f = new Fixture(); LeastCostPathCalculatorFactory routerFactory = new FastDijkstraFactory(); LeastCostPathCalculator router = routerFactory.createPathCalculator(f.network, f.costFunction, new FreeSpeedTravelTime()); router.calcLeastCostPath( f.network.getNodes().get(Id.create("2", Node.class)), f.network.getNodes().get(Id.create("1", Node.class)), 07*3600, f.person, f.vehicle); // hopefully there was no Exception until here... Assert.assertEquals(22, f.costFunction.cnt); // make sure the costFunction was actually used }
@Test public void testPersonAvailableForDisutility_AStarLandmarks() { Fixture f = new Fixture(); LeastCostPathCalculatorFactory routerFactory = new FastAStarEuclideanFactory(); LeastCostPathCalculator router = routerFactory.createPathCalculator(f.network, f.costFunction, new FreeSpeedTravelTime()); router.calcLeastCostPath( f.network.getNodes().get(Id.create("2", Node.class)), f.network.getNodes().get(Id.create("1", Node.class)), 07*3600, f.person, f.vehicle); // hopefully there was no Exception until here... Assert.assertEquals(22, f.costFunction.cnt); // make sure the costFunction was actually used }
@Test public void testPersonAvailableForDisutility_FastAStarLandmarks() { Fixture f = new Fixture(); LeastCostPathCalculatorFactory routerFactory = new FastAStarLandmarksFactory(); LeastCostPathCalculator router = routerFactory.createPathCalculator(f.network, f.costFunction, new FreeSpeedTravelTime()); router.calcLeastCostPath( f.network.getNodes().get(Id.create("2", Node.class)), f.network.getNodes().get(Id.create("1", Node.class)), 07*3600, f.person, f.vehicle); // hopefully there was no Exception until here... Assert.assertEquals(22, f.costFunction.cnt); // make sure the costFunction was actually used }
public void testCalcLeastCostPath_Normal() throws SAXException, ParserConfigurationException, IOException { Config config = loadConfig(null); Scenario scenario = ScenarioUtils.createScenario(config); Network network = scenario.getNetwork(); new MatsimNetworkReader(scenario.getNetwork()).readFile("test/scenarios/equil/network.xml"); Node node12 = network.getNodes().get(Id.create("12", Node.class)); Node node15 = network.getNodes().get(Id.create("15", Node.class)); LeastCostPathCalculator routerAlgo = getLeastCostPathCalculator(network); Path path = routerAlgo.calcLeastCostPath(node12, node15, 8.0*3600, null, null); assertEquals("number of nodes wrong.", 4, path.nodes.size()); assertEquals("number of links wrong.", 3, path.links.size()); assertEquals(network.getNodes().get(Id.create("12", Node.class)), path.nodes.get(0)); assertEquals(network.getNodes().get(Id.create("13", Node.class)), path.nodes.get(1)); assertEquals(network.getNodes().get(Id.create("14", Node.class)), path.nodes.get(2)); assertEquals(network.getNodes().get(Id.create("15", Node.class)), path.nodes.get(3)); assertEquals(network.getLinks().get(Id.create("20", Link.class)), path.links.get(0)); assertEquals(network.getLinks().get(Id.create("21", Link.class)), path.links.get(1)); assertEquals(network.getLinks().get(Id.create("22", Link.class)), path.links.get(2)); }
informStartCalc(); org.matsim.vehicles.Vehicle matsimVehicle = getMatsimVehicle(vehicle); Path path = router.calcLeastCostPath(fromLink.getToNode(), toLink.getFromNode(), departureTime, null, matsimVehicle);
LeastCostPathCalculator.Path result = this.replanner.editRoutes(RoutingMode.carFreespeed).getPathCalculator().calcLeastCostPath( currentLink.getFromNode(), destLink.getFromNode(), now, null, null );
org.matsim.vehicles.Vehicle matsimVehicle = getMatsimVehicle(vehicle); LeastCostPathCalculator router = createLeastCostPathCalculator(); Path path = router.calcLeastCostPath(fromLink.getToNode(), toLink.getFromNode(), departureTime, null, matsimVehicle);
plan.addActivity(act1); Leg leg1 = popFactory.createLeg(TransportMode.car); Path path1 = lcpa.calcLeastCostPath(scenario.getNetwork().getLinks().get(homeId).getToNode(), scenario.getNetwork().getLinks().get(workId).getFromNode(), act1.getEndTime(), person, null); NetworkRoute linkNetworkRoute = RouteUtils.createLinkNetworkRouteImpl(homeId, getLinkIds(path1), workId); leg1.setRoute(linkNetworkRoute); Path path2 = lcpa.calcLeastCostPath(scenario.getNetwork().getLinks().get(workId).getToNode(), scenario.getNetwork().getLinks().get(homeId).getFromNode(), act1.getEndTime(), person, null); NetworkRoute linkNetworkRoute2 = RouteUtils.createLinkNetworkRouteImpl(workId, getLinkIds(path2), homeId); leg2.setRoute(linkNetworkRoute2);