private void handlePlan(Plan plan) { // This calculates a best-response plan from the two options, paying area toll or not. // From what I understand, it may be simpler/better to just throw a coin and produce // one of the two options. replaceCarModeWithTolledCarMode(plan); PlanRouter untolledPlanRouter = new PlanRouter(tripRouterFactory.get()); untolledPlanRouter.run(plan); double areaToll = roadPricingScheme.getTypicalCosts().iterator().next().amount; double routeCostWithAreaToll = sumNetworkModeCosts(plan) + areaToll; replaceTolledCarModeWithCarMode(plan); new PlanRouter(tripRouterFactory.get()).run(plan); double routeCostWithoutAreaToll = sumNetworkModeCosts(plan); if (routeCostWithAreaToll < routeCostWithoutAreaToll) { replaceCarModeWithTolledCarMode(plan); untolledPlanRouter.run(plan); } }
public TripRouter getTripRouter() { return delegate.getTripRouter(); }
public JointPlanRouter( final TripRouter routingHandler, final ActivityFacilities facilities ) { delegate = new PlanRouter( routingHandler , facilities ); }
@Override @Deprecated // use TripRouter instead. kai, dec'13 public void run(final Plan plan) { planRouter.run( plan ); }
@Override public void run(final Plan plan) { final List<Trip> trips = TripStructureUtils.getTrips( plan , tripRouter.getStageActivityTypes() ); for (Trip oldTrip : trips) { final List<? extends PlanElement> newTrip = tripRouter.calcRoute( tripRouter.getMainModeIdentifier().identifyMainMode( oldTrip.getTripElements() ), toFacility( oldTrip.getOriginActivity() ), toFacility( oldTrip.getDestinationActivity() ), calcEndOfActivity( oldTrip.getOriginActivity() , plan, tripRouter.getConfig() ), plan.getPerson() ); putVehicleFromOldTripIntoNewTripIfMeaningful(oldTrip, newTrip); TripRouter.insertTrip( plan, oldTrip.getOriginActivity(), newTrip, oldTrip.getDestinationActivity()); } }
/** * Convenience method that estimates the trip departure time rather than explicitly requesting it. * * @param trip * @param plan * @param mainMode * @return */ public final boolean replanFutureTrip(Trip trip, Plan plan, String mainMode) { double departureTime = PlanRouter.calcEndOfActivity( trip.getOriginActivity(), plan, tripRouter.getConfig() ) ; return replanFutureTrip( trip, plan, mainMode, departureTime ) ; } public final boolean replanFutureTrip(Trip trip, Plan plan, String routingMode, double departureTime) {
/** * If the old trip had vehicles set in its network routes, and it used a single vehicle, * and if the new trip does not come with vehicles set in its network routes, * then put the vehicle of the old trip into the network routes of the new trip. * @param oldTrip The old trip * @param newTrip The new trip */ private static void putVehicleFromOldTripIntoNewTripIfMeaningful(Trip oldTrip, List<? extends PlanElement> newTrip) { Id<Vehicle> oldVehicleId = getUniqueVehicleId(oldTrip); if (oldVehicleId != null) { for (Leg leg : TripStructureUtils.getLegs(newTrip)) { if (leg.getRoute() instanceof NetworkRoute) { if (((NetworkRoute) leg.getRoute()).getVehicleId() == null) { ((NetworkRoute) leg.getRoute()).setVehicleId(oldVehicleId); } } } } }
@Override public PlanAlgorithm createPlanRoutingAlgorithm( final TripRouter tripRouter) { return new PlanRouter(tripRouter); } });
@Override public void run(final Person person) { for (Plan plan : person.getPlans()) { run( plan ); } }
PlanRouter planRouter = new PlanRouter(tripRouterProvider.get()); planRouter.run(person);
@Override public final PlanAlgorithm getPlanAlgoInstance() { return new PlanRouter( tripRouterProvider.get(), facilities); }
@Override public boolean doReplanning(MobsimAgent withinDayAgent) { this.planRouter.run(WithinDayAgentUtils.getModifiablePlan(withinDayAgent)); return true; } }
public TripRouter getTripRouter() { if (delegate instanceof PlanRouter) { return ((PlanRouter) delegate).getTripRouter(); } if (delegate instanceof JointPlanRouter) { return ((JointPlanRouter) delegate).getTripRouter(); } throw new IllegalStateException( ""+delegate.getClass() ); } }
@Test public void passesVehicleFromOldPlan() { final Config config = ConfigUtils.loadConfig(IOUtils.newUrl(ExamplesUtils.getTestScenarioURL("equil"), "config.xml")); config.plans().setInputFile("plans1.xml"); final Scenario scenario = ScenarioUtils.loadScenario(config); com.google.inject.Injector injector = Injector.createInjector(scenario.getConfig(), new AbstractModule() { @Override public void install() { install(new TripRouterModule()); install(new ScenarioByInstanceModule(scenario)); addTravelTimeBinding("car").toInstance(new FreespeedTravelTimeAndDisutility(config.planCalcScore())); addTravelDisutilityFactoryBinding("car").toInstance(new OnlyTimeDependentTravelDisutilityFactory()); } }); TripRouter tripRouter = injector.getInstance(TripRouter.class); PlanRouter testee = new PlanRouter(tripRouter); Plan plan = scenario.getPopulation().getPersons().get(Id.createPersonId(1)).getSelectedPlan(); Id<Vehicle> vehicleId = Id.create(1, Vehicle.class); ((NetworkRoute) TripStructureUtils.getLegs(plan).get(0).getRoute()).setVehicleId(vehicleId); testee.run(plan); if ( !config.plansCalcRoute().isInsertingAccessEgressWalk() ) { Assert.assertEquals("Vehicle Id transferred to new Plan", vehicleId, ((NetworkRoute) TripStructureUtils.getLegs(plan).get(0).getRoute()).getVehicleId()); } else { Assert.assertEquals("Vehicle Id transferred to new Plan", vehicleId, ((NetworkRoute) TripStructureUtils.getLegs(plan).get(1).getRoute()).getVehicleId()); // yy I changed get(0) to get(1) since in the input file there is no intervening walk leg, but in the output there is. kai, feb'16 } }
@Override public AbstractPersonAlgorithm getPersonAlgorithm() { return new PersonPrepareForSim(new PlanRouter(tripRouterProvider.get(), activityFacilities), scenario, carOnlyNetwork); } }
@Override public void run( final Plan plan ) { JointRouteIterator oldPlan = new JointRouteIterator( plan.getPlanElements() ); delegate.run( plan ); // "transmit" joint info before returning JointRouteIterator newPlan = new JointRouteIterator( plan.getPlanElements() ) ; Route oldRoute = oldPlan.nextJointRoute(); Route newRoute = newPlan.nextJointRoute(); while (oldRoute != null) { if (oldRoute instanceof DriverRoute) { ((DriverRoute) newRoute).setPassengerIds( ((DriverRoute) oldRoute).getPassengersIds() ); } else { ((PassengerRoute) newRoute).setDriverId( ((PassengerRoute) oldRoute).getDriverId() ); } oldRoute = oldPlan.nextJointRoute(); newRoute = newPlan.nextJointRoute(); } assert oldRoute == null; assert newRoute == null; }
/** * @param person * @param leg the leg to calculate the route for. * @param fromAct the Act the leg starts * @param toAct the Act the leg ends * @param depTime the time (seconds from midnight) the leg starts * @return the estimated travel time for this leg */ @Deprecated // use TripRouter instead. kai, dec'13 public double handleLeg( final Person person, final Leg leg, final Activity fromAct, final Activity toAct, final double depTime) { TripRouter tripRouter = this.planRouter.getTripRouter(); return handleLeg(tripRouter, person, leg, fromAct, toAct, depTime); }
TripRouter tripRouter = injector.getInstance(TripRouter.class); PlanRouter testee = new PlanRouter(tripRouter); testee.run(plan); if ( !config.plansCalcRoute().isInsertingAccessEgressWalk() ) { Assert.assertEquals("Vehicle Id from TripRouter used", newVehicleId, ((NetworkRoute) TripStructureUtils.getLegs(plan).get(0).getRoute()).getVehicleId());
@Override public AbstractPersonAlgorithm getPersonAlgorithm() { return new PersonPrepareForSim(new PlanRouter(tripRouterProvider.get(), activityFacilities), scenario, carOnlyNetwork ); } // yyyyyy This prepared network is only used for computing the distance. So the full network would
new PlanRouter(tripRouter).run(plan);