private static void unregisterPassengerFromDriverRoutes(final JointTrip toRemove) { for (Leg driverLeg : toRemove.getDriverLegs()) { final DriverRoute route = (DriverRoute) driverLeg.getRoute(); route.removePassenger(toRemove.getPassengerId()); if (route.getPassengersIds().isEmpty()) { driverLeg.setMode(TransportMode.car); driverLeg.setRoute(null); } } }
private List<TripStructureUtils.Trip> getDriverTrip( final JointTrip toRemove, final Plan driverPlan) { final TripStructureUtils.Trip driverTrip = getTripWithLeg(driverPlan, toRemove.getDriverLegs().get(0), stagesWithJointTypes); assert driverTrip.getTripElements().containsAll(toRemove.getDriverLegs()); final List<PlanElement> elements = new ArrayList<PlanElement>(); elements.add(driverTrip.getOriginActivity()); elements.addAll(driverTrip.getTripElements()); elements.add(driverTrip.getDestinationActivity()); return TripStructureUtils.getTrips(elements, stages); }
// 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()); }
private static List<JointTrip> getChoiceSet( final JointTravelStructure structure, final Collection<Id<Person>> agentsToIgnore) { if (agentsToIgnore.isEmpty()) return structure.getJointTrips(); final List<JointTrip> choiceSet = new ArrayList<JointTrip>(); for (JointTrip t : structure.getJointTrips()) { if (agentsToIgnore.contains(t.getDriverId())) continue; if (agentsToIgnore.contains(t.getPassengerId())) continue; choiceSet.add(t); } return choiceSet; }
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()); }
public ActedUponInformation run( final JointPlan plan, final Collection<Id<Person>> agentsToIgnore) { final JointTravelStructure structure = JointTravelUtils.analyseJointTravel(plan); if (structure.getJointTrips().size() == 0) { log.warn( getClass().getSimpleName() + " was called on a plan with no joint trips." + " Make sure it is what you want!"); return null; } final List<JointTrip> choiceSet = getChoiceSet(structure, agentsToIgnore); if (choiceSet.isEmpty()) return null; final JointTrip toRemove = choiceSet.get(random.nextInt(choiceSet.size())); removePassengerTrip(toRemove, plan); removeDriverTrip(toRemove, plan); return new ActedUponInformation(toRemove.getDriverId(), toRemove.getPassengerId()); }