private void replaceCarModeWithTolledCarMode(Plan plan) { for (PlanElement planElement : plan.getPlanElements()) { if (planElement instanceof Leg) { if (((Leg) planElement).getMode().equals(TransportMode.car)) { ((Leg) planElement).setMode(CAR_WITH_PAYED_AREA_TOLL); } } } }
private void replaceTolledCarModeWithCarMode(Plan plan) { for (PlanElement planElement : plan.getPlanElements()) { if (planElement instanceof Leg) { if (((Leg) planElement).getMode().equals(CAR_WITH_PAYED_AREA_TOLL)) { ((Leg) planElement).setMode("car"); } } } }
private void changeLegModeTo(final List<PlanElement> tour, final String newMode) { for (PlanElement pe : tour) { if (pe instanceof Leg) { Leg leg = ((Leg) pe); leg.setMode(newMode); Route route = leg.getRoute(); if(route!=null && route instanceof NetworkRoute) { ((NetworkRoute) route).setVehicleId(null); } } } }
public void run(final Plan plan, boolean treatAccessEgressAsTransit) { List<String> accessModes = new ArrayList<>(); accessModes.add(TransportMode.transit_walk); if (treatAccessEgressAsTransit){ accessModes.add(TransportMode.access_walk); accessModes.add(TransportMode.egress_walk); } List<PlanElement> planElements = plan.getPlanElements(); for (int i = 0, n = planElements.size(); i < n; i++) { PlanElement pe = planElements.get(i); if (pe instanceof Activity) { Activity act = (Activity) pe; if (PtConstants.TRANSIT_ACTIVITY_TYPE.equals(act.getType())) { final int index = i; PopulationUtils.removeActivity(((Plan) plan), index); n -= 2; i--; // i will be incremented again in next loop-iteration, so we'll check the next act } } else if (pe instanceof Leg) { Leg leg = (Leg) pe; if (accessModes.contains(leg.getMode())) { leg.setMode(TransportMode.pt); leg.setRoute(null); } } } }
public static void convertLegModes(List<String> passengerIds, String mode, Scenario scenario) { Map<Id<Person>, ? extends Person> persons = scenario.getPopulation().getPersons(); for (String id : passengerIds) { Person person = persons.get(Id.create(id, Person.class)); for (PlanElement pe : person.getSelectedPlan().getPlanElements()) { if (pe instanceof Leg) { ((Leg)pe).setMode(mode); } } } }
private void setRandomLegMode(final Leg leg, final boolean forbidCar) { leg.setMode(chooseModeOtherThan(leg.getMode(), forbidCar)); Route route = leg.getRoute() ; if ( route != null && route instanceof NetworkRoute) { ((NetworkRoute)route).setVehicleId(null); } }
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 ); } } } }
public static void copyFromTo(Leg in, Leg out) { out.setMode( in.getMode() ); out.setDepartureTime(in.getDepartureTime()); out.setTravelTime(in.getTravelTime()); if (in.getRoute() != null) { out.setRoute(in.getRoute().clone()); } AttributesUtils.copyAttributesFromTo( in , out ); }
leg.setRoute(route); if (fromFacility.getLinkId().equals(toFacility.getLinkId())) { leg.setMode(TransportMode.walk);
private static void copyPlanFieldsToFrom(Plan planTarget, LCPlan planTemplate) { planTarget.setScore(planTemplate.getScore()); int actLegIndex = 0; for (PlanElement pe : planTarget.getPlanElements()) { if (pe instanceof Activity) { LCActivity actTemplate = ((LCActivity) planTemplate.getPlanElements().get(actLegIndex)); ((Activity) pe).setEndTime(actTemplate.getEndTime()); ((Activity) pe).setCoord(actTemplate.getCoord()); ((Activity) pe).setFacilityId(actTemplate.getFacilityId()); ((Activity) pe).setLinkId(actTemplate.getLinkId()); ((Activity) pe).setMaximumDuration(actTemplate.getMaximumDuration()); ((Activity) pe).setStartTime(actTemplate.getStartTime()); ((Activity) pe).setType(actTemplate.getType()); } else if (pe instanceof Leg) { LCLeg legTemplate = ((LCLeg) planTemplate.getPlanElements().get(actLegIndex)); Leg r = ((Leg) pe); r.setTravelTime( legTemplate.getArrivalTime() - r.getDepartureTime() ); ((Leg) pe).setDepartureTime(legTemplate.getDepartureTime()); ((Leg) pe).setMode(legTemplate.getMode()); ((Leg) pe).setRoute(legTemplate.getRoute()); ((Leg) pe).setTravelTime(legTemplate.getTravelTime()); } else throw new RuntimeException("Unexpected PlanElement type was found: " + pe.getClass().toString() + ". Aborting!"); actLegIndex++; } }
private static void copyPlanFieldsToFrom1(Plan planTarget, Plan planTemplate) { planTarget.setScore(planTemplate.getScore()); int actLegIndex = 0; for (PlanElement pe : planTarget.getPlanElements()) { if (pe instanceof Activity) { Activity actTemplate = ((Activity) planTemplate.getPlanElements().get(actLegIndex)); ((Activity) pe).setEndTime(actTemplate.getEndTime()); ((Activity) pe).setCoord(actTemplate.getCoord()); ((Activity) pe).setFacilityId(actTemplate.getFacilityId()); ((Activity) pe).setLinkId(actTemplate.getLinkId()); ((Activity) pe).setMaximumDuration(actTemplate.getMaximumDuration()); ((Activity) pe).setStartTime(actTemplate.getStartTime()); ((Activity) pe).setType(actTemplate.getType()); } else if (pe instanceof Leg) { Leg legTemplate = ((Leg)planTemplate.getPlanElements().get(actLegIndex)); Leg r = ((Leg) pe); r.setTravelTime( legTemplate.getDepartureTime() + legTemplate.getTravelTime() - r.getDepartureTime() ); ((Leg) pe).setDepartureTime(legTemplate.getDepartureTime()); ((Leg) pe).setMode(legTemplate.getMode()); ((Leg) pe).setRoute(legTemplate.getRoute()); ((Leg) pe).setTravelTime(legTemplate.getTravelTime()); } else throw new RuntimeException("Unexpected PlanElement type was found: " + pe.getClass().toString() + ". Aborting!"); actLegIndex++; } }
public void testReplanCurrentLegRouteTen() { // expect EditRoutes to return false if the Route in the leg is not a NetworkRoute createScenario(); // reset scenario EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory()); int firstCarLeg = 1 ; // 1-->3 int scndCarLeg = 3 ; // 3-->9 if ( scenario.getConfig().plansCalcRoute().isInsertingAccessEgressWalk() ) { firstCarLeg = 3 ; // 1-->3 scndCarLeg = 9 ; // 3-->9 } Leg legHW = (Leg) plan.getPlanElements().get(firstCarLeg); Leg legWH = (Leg) plan.getPlanElements().get(scndCarLeg); legHW.setRoute(null); legHW.setMode(TransportMode.walk); legWH.setRoute(null); legWH.setMode(TransportMode.walk); assertEquals(false, ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(firstCarLeg), plan.getPerson(), 0, 8.0*3600 )); assertEquals(false, ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(scndCarLeg), plan.getPerson(), 0, 8.0*3600 )); }
@Test public void testUnusualMode() { Fixture f = new Fixture(); Leg leg = (Leg) f.plan.getPlanElements().get(1); leg.setMode("sackhuepfen"); boolean exception = false ; try { assertEquals(-3.0, calcScore(f), EPSILON); // default for unknown modes // no longer allowed. kai, may'17 } catch ( Exception ee ) { // this is expected exception = true ; } assertTrue( exception ) ; f.config.planCalcScore().addParam("traveling_sackhuepfen", "-30.0"); assertEquals(-15.0, calcScore(f), EPSILON); }
leg.setMode("train"); histo.handleEvent(new PersonDepartureEvent(8*3600, person1Id, linkId, leg.getMode())); histo.handleEvent(new PersonArrivalEvent(8*3600 + 11*60, person1Id, linkId, leg.getMode()));
histo.handleEvent(new PersonDepartureEvent(7*3600, person1Id, linkId, leg.getMode())); histo.handleEvent(new PersonDepartureEvent(7*3600 + 6*60, person2Id, linkId, leg.getMode())); leg.setMode(TransportMode.bike); histo.handleEvent(new PersonDepartureEvent(7*3600 + 6*60, person1Id, linkId, leg.getMode())); histo.handleEvent(new PersonDepartureEvent(7*3600 + 10*60, person2Id, linkId, leg.getMode())); leg.setMode("undefined"); histo.handleEvent(new PersonDepartureEvent(7*3600 + 10*60, person1Id, linkId, leg.getMode())); leg.setMode("undefined"); histo.handleEvent(new PersonDepartureEvent(7*3600 + 16*60, person1Id, linkId, leg.getMode()));
leg.setMode("train"); histo.handleEvent(new PersonDepartureEvent(3000, person1Id, linkId, leg.getMode())); histo.handleEvent(new PersonArrivalEvent(3001, person1Id, linkId, leg.getMode())); leg.setMode("bus"); histo.handleEvent(new PersonDepartureEvent(3600, person1Id, linkId, leg.getMode())); histo.handleEvent(new PersonArrivalEvent(7200, person1Id, linkId, leg.getMode()));