private List<? extends PlanElement> newTripToNewActivity(Activity newAct, String mainMode, double now, MobsimAgent agent, Person person, Scenario scenario) { log.debug("entering newTripToNewActivity") ; Link currentLink = scenario.getNetwork().getLinks().get( agent.getCurrentLinkId() ) ; Facility fromFacility = new LinkWrapperFacility( currentLink ) ; Facility toFacility = scenario.getActivityFacilities().getFacilities().get( newAct.getFacilityId() ) ; if ( toFacility == null ) { toFacility = new ActivityWrapperFacility( newAct ) ; } List<? extends PlanElement> newTrip = tripRouter.calcRoute(mainMode, fromFacility, toFacility, now, person) ; return newTrip; } // replan from stage activity:
/** * Re-locates a future route. The route is given by its leg. * * @return true when replacing the route worked, false when something went wrong * * @deprecated switch this to relocateFutureTrip, since with egress legs relocating the destination of a single leg leads to disconnected trips. kai, dec'15 */ @Deprecated // not consistent with access/egress approach; can only be used if you know exactly what you are doing. // Maybe replanXxx is already sufficient? Otherwise use EditTrips or EditPlans. kai, nov'17 public static boolean relocateFutureLegRoute(Leg leg, Id<Link> fromLinkId, Id<Link> toLinkId, Person person, Network network, TripRouter tripRouter) { // TripRouter variant; everything else uses the PathCalculator Link fromLink = network.getLinks().get(fromLinkId); Link toLink = network.getLinks().get(toLinkId); Facility fromFacility = new LinkWrapperFacility(fromLink); Facility toFacility = new LinkWrapperFacility(toLink); List<? extends PlanElement> planElements = tripRouter.calcRoute(leg.getMode(), fromFacility, toFacility, leg.getDepartureTime(), person); if (planElements.size() != 1) { throw new RuntimeException("Expected a list of PlanElements containing exactly one element, " + "but the returned list contained " + planElements.size() + " elements."); } Leg newLeg = (Leg) planElements.get(0); leg.setTravelTime(newLeg.getTravelTime()); leg.setRoute(newLeg.getRoute()); return true; }
/** * In contrast to the other replanFutureLegRoute(...) method, the leg at the given index is replaced * by a new one. This is e.g. necessary when replacing a pt trip which might consists of multiple legs * and pt_interaction activities. */ public static boolean replanFutureTrip(Trip trip, Plan plan, String routingMode, double departureTime, TripRouter tripRouter) { Person person = plan.getPerson(); Facility fromFacility = new ActivityWrapperFacility( trip.getOriginActivity() ) ; Facility toFacility = new ActivityWrapperFacility( trip.getDestinationActivity() ) ; final List<? extends PlanElement> newTrip = tripRouter.calcRoute(routingMode, fromFacility, toFacility, departureTime, person); log.debug("new trip:" + newTrip ) ; for ( PlanElement pe : newTrip ) { log.debug( pe ) ; } TripRouter.insertTrip(plan, trip.getOriginActivity(), newTrip, trip.getDestinationActivity()); return true; }
@Override public void run(final Plan plan) { Iterator<PlanElement> pes = plan.getPlanElements().iterator(); Activity origin = (Activity) pes.next(); double now = 0; while (pes.hasNext()) { // FIXME: relies on the assumption of strict alternance leg/act Leg l = (Leg) pes.next(); Activity dest = (Activity) pes.next(); now = updateTime( now , origin ); if (l.getRoute() != null && l.getRoute() instanceof DriverRoute) { List<? extends PlanElement> trip = router.calcRoute( l.getMode(), new ActivityWrapperFacility( origin ), new ActivityWrapperFacility( dest ), now, plan.getPerson()); if (trip.size() != 1) { throw new RuntimeException( "unexpected trip length "+trip.size()+" for "+trip+" for mode "+l.getMode()); } DriverRoute newRoute = (DriverRoute) ((Leg) trip.get( 0 )).getRoute(); newRoute.setPassengerIds( ((DriverRoute) l.getRoute()).getPassengersIds() ); l.setRoute( newRoute ); } now = updateTime( now , l ); origin = dest; } }
private List<? extends PlanElement> computeTravelTimeFromCompleteRouting( final Person person, final Activity fromAct, final Activity toAct, final String mode) { final List<? extends PlanElement> trip = this.router.calcRoute( mode, new ActivityWrapperFacility( fromAct ), new ActivityWrapperFacility( toAct ), fromAct.getEndTime(), person ); fillInLegTravelTimes( fromAct.getEndTime() , trip ); return trip; } }
@Deprecated // use TripRouter instead. kai, dec'13 public static double handleLeg(TripRouter tripRouter, final Person person, final Leg leg, final Activity fromAct, final Activity toAct, final double depTime) { List<? extends PlanElement> trip = tripRouter.calcRoute( leg.getMode(), new ActivityWrapperFacility( fromAct ), new ActivityWrapperFacility( toAct ), depTime, person); if ( trip.size() != 1 ) { throw new IllegalStateException( "This method can only be used with "+ "routing modules returning single legs. Got the following trip "+ "for mode "+leg.getMode()+": "+trip ); } Leg tripLeg = (Leg) trip.get( 0 ); leg.setRoute( tripLeg.getRoute() ); leg.setTravelTime( tripLeg.getTravelTime() ); leg.setDepartureTime( tripLeg.getDepartureTime() ); return tripLeg.getRoute() != null && tripLeg.getRoute().getTravelTime() != Time.UNDEFINED_TIME ? tripLeg.getRoute().getTravelTime() : tripLeg.getTravelTime(); }
@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 void run(final Plan plan) { final List<Trip> trips = TripStructureUtils.getTrips( plan , routingHandler.getStageActivityTypes() ); for (Trip trip : trips) { /** That's the only check that got added.... **/ if (routingHandler.getMainModeIdentifier().identifyMainMode(trip.getTripElements()).equals(TransportMode.pt)) { final List<? extends PlanElement> newTrip = routingHandler.calcRoute( routingHandler.getMainModeIdentifier().identifyMainMode( trip.getTripElements() ), toFacility( trip.getOriginActivity() ), toFacility( trip.getDestinationActivity() ), calcEndOfActivity( trip.getOriginActivity() , plan ), plan.getPerson() ); TripRouter.insertTrip( plan, trip.getOriginActivity(), newTrip, trip.getDestinationActivity()); } } }
@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()); } }
List<? extends PlanElement> trip = router.calcRoute( TransportMode.car, new LinkFacility( l1 ),
List<? extends PlanElement> trip = router.calcRoute( TransportMode.car, new LinkFacility( l1 ),
Facility toFacility = new ActivityWrapperFacility(toAct) ; List<? extends PlanElement> result = tripRouter.calcRoute("mode", fromFacility, toFacility, 7.0*3600., person) ; Gbl.assertIf( result.size()==1); Leg newLeg = (Leg) result.get(0) ;