private void repareDriverTrips(final JointTrip toRemove, final JointPlan plan) { final List<TripStructureUtils.Trip> subtrips = getDriverTrip(toRemove, plan.getIndividualPlan(toRemove.getDriverId())); final List<PlanElement> newTrip = new ArrayList<PlanElement>(); newTrip.add(PopulationUtils.createLeg(TransportMode.car)); // "state" variables, changed in the loop: // - keeps track of the passengers currently in the vehicle. // Pick-up or drop-offs are created at each change Set<Id> currentPassengers = Collections.<Id>emptySet(); for (TripStructureUtils.Trip subtrip : subtrips) { final Leg leg = getDriverLegIfItIs(subtrip); final Route route = leg == null ? null : leg.getRoute(); final Set<Id> newPassengers = route != null ? new HashSet<Id>(((DriverRoute) route).getPassengersIds()) : Collections.<Id>emptySet(); // note that no check of the mode is done... if (!newPassengers.equals(currentPassengers)) { newTrip.add( PopulationUtils.createActivityFromLinkId( JointActingTypes.INTERACTION, route != null ? route.getStartLinkId() : subtrip.getOriginActivity().getLinkId())); // as the spatial structure of the trip is modified, it is possible // that some pre-existing subtours are removed. Thus, a driver that may // have walked to a pick up (because at the same location as its departure) // may then have to drive to pick up the second passenger directly if // the first passenger was removed. Setting all non-driver legs // to car ensures to have a consistent mode chain. // XXX It could be done in a smarter way, so that if no subtour is removed, no modification // is done // For instance, when removing an "intern" trip, first PU and last DO are // left untouched, and thus access and egress leg need not be touched. newTrip.add(leg != null ? leg : PopulationUtils.createLeg(TransportMode.car)); currentPassengers = newPassengers; } } TripRouter.insertTrip( plan.getIndividualPlan(toRemove.getDriverId()), subtrips.get(0).getOriginActivity(), newTrip, subtrips.get(subtrips.size() - 1).getDestinationActivity()); }
// package protected for tests final void removePassengerTrip(final JointTrip toRemove, final JointPlan jointPlan) { final Plan passengerPlan = jointPlan.getIndividualPlan(toRemove.getPassengerId()); final Trip tripWithLeg = getTripWithLeg(passengerPlan, toRemove.getPassengerLeg(), stagesWithJointTypes); TripRouter.insertTrip( passengerPlan, tripWithLeg.getOriginActivity(), Collections.singletonList(PopulationUtils.createLeg(TransportMode.pt)), tripWithLeg.getDestinationActivity()); }
@Test @Ignore public void testAveraging() { // yy this test is probably not doing anything with respect to some of the newer statistics, // such as money. kai, mar'14 KNAnalysisEventsHandler testee = new KNAnalysisEventsHandler(this.scenario); EventsManager events = EventsUtils.createEventsManager(); events.addHandler(testee); Leg leg = PopulationUtils.createLeg(TransportMode.car); leg.setDepartureTime(Time.parseTime("07:10:00")); leg.setTravelTime(Time.parseTime("07:30:00") - leg.getDepartureTime()); testee.handleEvent( new PersonDepartureEvent( leg.getDepartureTime(), DEFAULT_PERSON_ID, DEFAULT_LINK_ID, leg.getMode())); testee.handleEvent( new PersonArrivalEvent( leg.getDepartureTime() + leg.getTravelTime(), DEFAULT_PERSON_ID, DEFAULT_LINK_ID, leg.getMode())); leg = PopulationUtils.createLeg(TransportMode.car); leg.setDepartureTime(Time.parseTime("07:00:00")); leg.setTravelTime(Time.parseTime("07:10:00") - leg.getDepartureTime()); testee.handleEvent( new PersonDepartureEvent( leg.getDepartureTime(), DEFAULT_PERSON_ID, DEFAULT_LINK_ID, leg.getMode())); testee.handleEvent( new PersonArrivalEvent( leg.getDepartureTime() + leg.getTravelTime(), DEFAULT_PERSON_ID, DEFAULT_LINK_ID, leg.getMode())); leg = PopulationUtils.createLeg(TransportMode.car); leg.setDepartureTime(Time.parseTime("31:12:00")); leg.setTravelTime(Time.parseTime("31:22:00") - leg.getDepartureTime()); testee.handleEvent( new PersonDepartureEvent( leg.getDepartureTime(), DEFAULT_PERSON_ID, DEFAULT_LINK_ID, leg.getMode())); testee.handleEvent( new PersonArrivalEvent( leg.getDepartureTime() + leg.getTravelTime(), DEFAULT_PERSON_ID, DEFAULT_LINK_ID, leg.getMode())); leg = PopulationUtils.createLeg(TransportMode.car); leg.setDepartureTime(Time.parseTime("30:12:00")); leg.setTravelTime(Time.parseTime("30:12:01") - leg.getDepartureTime()); testee.handleEvent( new PersonDepartureEvent( leg.getDepartureTime(), DEFAULT_PERSON_ID, DEFAULT_LINK_ID, leg.getMode())); testee.handleEvent( new PersonArrivalEvent( leg.getDepartureTime() + leg.getTravelTime(), DEFAULT_PERSON_ID, DEFAULT_LINK_ID, leg.getMode())); this.runTest(testee); }