@Override public PlanAlgorithm getPlanAlgoInstance() { final TripRouter tripRouter = tripRouterProvider.get(); final ChooseRandomLegModeForSubtour chooseRandomLegMode = new ChooseRandomLegModeForSubtour( tripRouter.getStageActivityTypes(), tripRouter.getMainModeIdentifier(), this.permissibleModesCalculator, this.modes, this.chainBasedModes, MatsimRandom.getLocalInstance(), behavior, probaForChangeSingleTripMode); return chooseRandomLegMode; }
private void testCarDoesntTeleport(ActivityFacilities facilities, String originalMode, String otherMode) { String[] modes = new String[] {originalMode, otherMode}; ChooseRandomLegModeForSubtour testee = new ChooseRandomLegModeForSubtour( EmptyStageActivityTypes.INSTANCE , new MainModeIdentifierImpl() ,new AllowTheseModesForEveryone(modes), modes, CHAIN_BASED_MODES, MatsimRandom.getRandom(), SubtourModeChoice.Behavior.fromSpecifiedModesToSpecifiedModes, probaForRandomSingleTripMode);
private void testCarDoesntTeleport(Network network, String originalMode, String otherMode) { String[] modes = new String[] {originalMode, otherMode}; ChooseRandomLegModeForSubtour testee = new ChooseRandomLegModeForSubtour( EmptyStageActivityTypes.INSTANCE , new MainModeIdentifierImpl() ,new AllowTheseModesForEveryone(modes), modes, CHAIN_BASED_MODES, MatsimRandom.getRandom(), SubtourModeChoice.Behavior.fromSpecifiedModesToSpecifiedModes, probaForRandomSingleTripMode);
@Test public void testMutatedTrips() { final ChooseRandomLegModeForSubtour testee = new ChooseRandomLegModeForSubtour( stagesActivities, new MainModeIdentifierImpl(),
@Test public void testMutatedTrips() { final ChooseRandomLegModeForSubtour testee = new ChooseRandomLegModeForSubtour( stagesActivities, new MainModeIdentifierImpl(),
@Test public void testHandleEmptyPlan() { String[] modes = new String[] {TransportMode.car, TransportMode.pt, TransportMode.walk}; ChooseRandomLegModeForSubtour algo = new ChooseRandomLegModeForSubtour( EmptyStageActivityTypes.INSTANCE , new MainModeIdentifierImpl() , new AllowTheseModesForEveryone(modes), modes, CHAIN_BASED_MODES, MatsimRandom.getRandom(), SubtourModeChoice.Behavior.fromSpecifiedModesToSpecifiedModes, probaForRandomSingleTripMode); Plan plan = PopulationUtils.createPlan(null); algo.run(plan); // no specific assert, but there should also be no NullPointerException or similar stuff that could theoretically happen }
@Test public void testHandlePlanWithoutLeg() { String[] modes = new String[] {TransportMode.car, TransportMode.pt, TransportMode.walk}; ChooseRandomLegModeForSubtour algo = new ChooseRandomLegModeForSubtour( EmptyStageActivityTypes.INSTANCE , new MainModeIdentifierImpl() ,new AllowTheseModesForEveryone(modes), modes, CHAIN_BASED_MODES, MatsimRandom.getRandom(), SubtourModeChoice.Behavior.fromSpecifiedModesToSpecifiedModes, probaForRandomSingleTripMode); Plan plan = PopulationUtils.createPlan(null); PopulationUtils.createAndAddActivityFromCoord(plan, "home", new Coord((double) 0, (double) 0)); algo.run(plan); // no specific assert, but there should also be no NullPointerException or similar stuff that could theoretically happen }
String[] modes = new String[] {"car", "pt", "walk"}; ChooseRandomLegModeForSubtour testee = new ChooseRandomLegModeForSubtour( EmptyStageActivityTypes.INSTANCE , new MainModeIdentifierImpl() ,new AllowTheseModesForEveryone(modes), modes, CHAIN_BASED_MODES, new Random(15102011), SubtourModeChoice.Behavior.fromSpecifiedModesToSpecifiedModes, probaForRandomSingleTripMode); Person person = PopulationUtils.getFactory().createPerson(Id.create("1000", Person.class)); Plan plan = PopulationUtils.createPlan();
private void testSubTourMutationToCar(ActivityFacilities facilities) { String expectedMode = TransportMode.car; String originalMode = TransportMode.pt; String[] modes = new String[] {expectedMode, originalMode}; ChooseRandomLegModeForSubtour testee = new ChooseRandomLegModeForSubtour( EmptyStageActivityTypes.INSTANCE , new MainModeIdentifierImpl() ,new AllowTheseModesForEveryone(modes), modes, CHAIN_BASED_MODES, MatsimRandom.getRandom(), SubtourModeChoice.Behavior.fromSpecifiedModesToSpecifiedModes, probaForRandomSingleTripMode); Person person = PopulationUtils.getFactory().createPerson(Id.create("1000", Person.class)); for (String activityChainString : activityChainStrings) { Plan plan = createPlan(facilities, activityChainString, originalMode); Plan originalPlan = PopulationUtils.createPlan(person); PopulationUtils.copyFromTo(plan, originalPlan); assertTrue(TestsUtil.equals(plan.getPlanElements(), originalPlan.getPlanElements())); testee.run(plan); assertSubTourMutated(plan, originalPlan, expectedMode, true); } }
private void testSubTourMutationToCar(Network network) { String expectedMode = TransportMode.car; String originalMode = TransportMode.pt; String[] modes = new String[] {expectedMode, originalMode}; ChooseRandomLegModeForSubtour testee = new ChooseRandomLegModeForSubtour( EmptyStageActivityTypes.INSTANCE , new MainModeIdentifierImpl() ,new AllowTheseModesForEveryone(modes), modes, CHAIN_BASED_MODES, MatsimRandom.getRandom(), SubtourModeChoice.Behavior.fromSpecifiedModesToSpecifiedModes, probaForRandomSingleTripMode); Person person = PopulationUtils.getFactory().createPerson(Id.create("1000", Person.class)); for (String activityChainString : activityChainStrings) { Plan plan = createPlan(network, activityChainString, originalMode); Plan originalPlan = PopulationUtils.createPlan(person); PopulationUtils.copyFromTo(plan, originalPlan); assertTrue(TestsUtil.equals(plan.getPlanElements(), originalPlan.getPlanElements())); testee.run(plan); assertSubTourMutated(plan, originalPlan, expectedMode, false); } }
private void testSubTourMutationToPt(ActivityFacilities facilities) { String expectedMode = TransportMode.pt; String originalMode = TransportMode.car; String[] modes = new String[] {expectedMode, originalMode}; ChooseRandomLegModeForSubtour testee = new ChooseRandomLegModeForSubtour( EmptyStageActivityTypes.INSTANCE , new MainModeIdentifierImpl() ,new AllowTheseModesForEveryone(modes), modes, CHAIN_BASED_MODES, MatsimRandom.getRandom(), SubtourModeChoice.Behavior.fromSpecifiedModesToSpecifiedModes, probaForRandomSingleTripMode); Person person = PopulationUtils.getFactory().createPerson(Id.create("1000", Person.class)); for (String activityChainString : activityChainStrings) { Plan plan = createPlan(facilities, activityChainString, originalMode); Plan originalPlan = PopulationUtils.createPlan(person); PopulationUtils.copyFromTo(plan, originalPlan); assertTrue(TestsUtil.equals(plan.getPlanElements(), originalPlan.getPlanElements())); testee.run(plan); assertSubTourMutated(plan, originalPlan, expectedMode, true); } }
private void testSubTourMutationToPt(Network network) { String expectedMode = TransportMode.pt; String originalMode = TransportMode.car; String[] modes = new String[] {expectedMode, originalMode}; ChooseRandomLegModeForSubtour testee = new ChooseRandomLegModeForSubtour( EmptyStageActivityTypes.INSTANCE , new MainModeIdentifierImpl() ,new AllowTheseModesForEveryone(modes), modes, CHAIN_BASED_MODES, MatsimRandom.getRandom(), SubtourModeChoice.Behavior.fromSpecifiedModesToSpecifiedModes, probaForRandomSingleTripMode); Person person = PopulationUtils.getFactory().createPerson(Id.create("1000", Person.class)); for (String activityChainString : activityChainStrings) { Plan plan = createPlan(network, activityChainString, originalMode); Plan originalPlan = PopulationUtils.createPlan(person); PopulationUtils.copyFromTo(plan, originalPlan); assertTrue(TestsUtil.equals(plan.getPlanElements(), originalPlan.getPlanElements())); testee.run(plan); assertSubTourMutated(plan, originalPlan, expectedMode, false); } }
private void testUnknownModeDoesntMutate(ActivityFacilities facilities) { String originalMode = TransportMode.walk; String[] modes = new String[] {TransportMode.car, TransportMode.pt}; ChooseRandomLegModeForSubtour testee = new ChooseRandomLegModeForSubtour( EmptyStageActivityTypes.INSTANCE , new MainModeIdentifierImpl() ,new AllowTheseModesForEveryone(modes), modes, CHAIN_BASED_MODES, MatsimRandom.getRandom(), SubtourModeChoice.Behavior.fromSpecifiedModesToSpecifiedModes, probaForRandomSingleTripMode); Person person = PopulationUtils.getFactory().createPerson(Id.create("1000", Person.class)); for (String activityChainString : activityChainStrings) { Plan plan = createPlan(facilities, activityChainString, originalMode); Plan originalPlan = PopulationUtils.createPlan(person); PopulationUtils.copyFromTo(plan, originalPlan); assertTrue(TestsUtil.equals(plan.getPlanElements(), originalPlan.getPlanElements())); testee.run(plan); assertTrue(TestsUtil.equals(plan.getPlanElements(), originalPlan.getPlanElements())); } }
private void testUnknownModeDoesntMutate(Network network) { String originalMode = TransportMode.walk; String[] modes = new String[] {TransportMode.car, TransportMode.pt}; ChooseRandomLegModeForSubtour testee = new ChooseRandomLegModeForSubtour( EmptyStageActivityTypes.INSTANCE , new MainModeIdentifierImpl() ,new AllowTheseModesForEveryone(modes), modes, CHAIN_BASED_MODES, MatsimRandom.getRandom(), SubtourModeChoice.Behavior.fromSpecifiedModesToSpecifiedModes, probaForRandomSingleTripMode); Person person = PopulationUtils.getFactory().createPerson(Id.create("1000", Person.class)); for (String activityChainString : activityChainStrings) { Plan plan = createPlan(network, activityChainString, originalMode); Plan originalPlan = PopulationUtils.createPlan(person); PopulationUtils.copyFromTo(plan, originalPlan); assertTrue(TestsUtil.equals(plan.getPlanElements(), originalPlan.getPlanElements())); testee.run(plan); assertTrue(TestsUtil.equals(plan.getPlanElements(), originalPlan.getPlanElements())); } }