/** * A pointer to material in TripStructureUtils * */ public static List<Leg> getLegs( Plan plan ) { return TripStructureUtils.getLegs( plan ) ; }
public static List<Leg> getLegs(final Plan plan) { return getLegs( plan.getPlanElements() ); }
@Override public void handlePlan(Plan plan) { for (Leg leg : TripStructureUtils.getLegs(plan)) { if (leg.getRoute() instanceof NetworkRoute) { switch ( leg.getMode() ) { case TransportMode.car: case TransportMode.bike: case TransportMode.walk: break; default: Logger.getLogger(this.getClass()).warn( "route is of type=" + leg.getRoute().getClass() ) ; Logger.getLogger(this.getClass()).warn( "mode=" + leg.getMode() ) ; throw new RuntimeException("inconsistent"); } } } }
/* package-private, for testing */ double similarity( Plan plan1, Plan plan2 ) { double simil = 0. ; { List<Activity> activities1 = TripStructureUtils.getActivities(plan1, stageActivities) ; List<Activity> activities2 = TripStructureUtils.getActivities(plan2, stageActivities) ; simil += PopulationUtils.calculateSimilarity(activities1, activities2, actTypeWeight, locationWeight, actTimeWeight ) ; if ( Double.isNaN(simil) ) { log.warn("simil is NaN; id: " + plan1.getPerson().getId() ) ; } } { List<Leg> legs1 = TripStructureUtils.getLegs(plan1 ) ; List<Leg> legs2 = TripStructureUtils.getLegs(plan2 ) ; simil += PopulationUtils.calculateSimilarity(legs1, legs2, network, this.sameModePenalty, this.sameRoutePenalty ) ; if ( Double.isNaN(simil) ) { log.warn("simil is NaN; id: " + plan1.getPerson().getId() ) ; } } return simil ; }
/** * 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); } } } } }
for ( Leg leg : TripStructureUtils.getLegs(person.getSelectedPlan()) ) {
@Override public double computeContributionOfOpportunity(ActivityFacility origin, final AggregationObject destination, Double departureTime) { Person person = null ; // I think that this is ok ActivityFacilitiesFactory activityFacilitiesFactory = new ActivityFacilitiesFactoryImpl(); ActivityFacility destinationFacility = activityFacilitiesFactory.createActivityFacility(null, destination.getNearestNode().getCoord()); Gbl.assertNotNull(tripRouter); List<? extends PlanElement> plan = tripRouter.calcRoute(mode, origin, destinationFacility, departureTime, person); // Vehicle vehicle = null ; // I think that this is ok double utility = 0.; List<Leg> legs = TripStructureUtils.getLegs(plan); // TODO Doing it like this, the pt interaction (e.g. waiting) times will be omitted! Gbl.assertIf(!legs.isEmpty()); for (Leg leg : legs) { // Add up all utility components of leg utility += leg.getRoute().getDistance() * this.planCalcScoreConfigGroup.getModes().get(leg.getMode()).getMarginalUtilityOfDistance(); utility += leg.getRoute().getTravelTime() * this.planCalcScoreConfigGroup.getModes().get(leg.getMode()).getMarginalUtilityOfTraveling() / 3600.; utility += -leg.getRoute().getTravelTime() * this.planCalcScoreConfigGroup.getPerforming_utils_hr() / 3600.; } // Utility based on opportunities that are attached to destination node double sumExpVjkWalk = destination.getSum(); // exp(beta * a) * exp(beta * b) = exp(beta * (a+b)) return Math.exp(this.planCalcScoreConfigGroup.getBrainExpBeta() * utility) * sumExpVjkWalk; } }
@Override public List<? extends PlanElement> calcRoute(Facility fromFacility, Facility toFacility, double departureTime, Person person) { List<? extends PlanElement> trip = DefaultRoutingModules.createPureNetworkRouter("car", scenario.getPopulation().getFactory(), scenario.getNetwork(), leastCostAlgoFactory.createPathCalculator(scenario.getNetwork(), disutilityFactory.createTravelDisutility(travelTime), travelTime) ).calcRoute(fromFacility, toFacility, departureTime, person); ((NetworkRoute) TripStructureUtils.getLegs(trip).get(0).getRoute()).setVehicleId(newVehicleId); return trip; }
@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 } }
((NetworkRoute) TripStructureUtils.getLegs(plan).get(0).getRoute()).setVehicleId(oldVehicleId); testee.run(plan); if ( !config.plansCalcRoute().isInsertingAccessEgressWalk() ) { Assert.assertEquals("Vehicle Id from TripRouter used", newVehicleId, ((NetworkRoute) TripStructureUtils.getLegs(plan).get(0).getRoute()).getVehicleId()); } else { Assert.assertEquals("Vehicle Id from TripRouter used", newVehicleId, ((NetworkRoute) TripStructureUtils.getLegs(plan).get(1).getRoute()).getVehicleId());