@Override public PlanStrategy get() { PlanStrategy strategy = new PlanStrategyImpl(new RandomPlanSelector()); return strategy; }
@Override protected PlanSelector<Plan, Person> getPlanSelector() { return new RandomPlanSelector<Plan, Person>(); }
@Inject public PReRoute(Scenario scenario, Provider<TripRouter> tripRouterProvider) { this.strategy = new PlanStrategyImpl(new RandomPlanSelector()); this.strategy.addStrategyModule(new PReRouteStrategyModule(tripRouterProvider, scenario)) ; }
@Override public PlanStrategy get() { PlanStrategyImpl strategy = new PlanStrategyImpl(new RandomPlanSelector()); org.matsim.core.replanning.modules.TimeAllocationMutator tam = new org.matsim.core.replanning.modules.TimeAllocationMutator(this.tripRouterProvider, this.plansConfigGroup, this.timeAllocationMutatorConfigGroup, this.globalConfigGroup, population); strategy.addStrategyModule(tam); return strategy; } }
@Override public PlanStrategy get() { PlanStrategyImpl.Builder builder = new PlanStrategyImpl.Builder(new RandomPlanSelector<Plan, Person>()); builder.addStrategyModule(new ExternalModule(exePath, "ext" + externalCounter, controlerIO, scenario)); return builder.build(); } }
@Override public PlanStrategy get() { Builder builder = new PlanStrategyImpl.Builder(new RandomPlanSelector<Plan,Person>()) ; builder.addStrategyModule(new org.matsim.core.replanning.modules.KeepLastExecuted(config, executedPlans) ) ; return builder.build() ; } }
@Override public PlanStrategy get() { Builder builder = new PlanStrategyImpl.Builder(new RandomPlanSelector<Plan,Person>()) ; builder.addStrategyModule(new org.matsim.core.replanning.modules.ReRoute(facilities, tripRouterProvider, globalConfigGroup)); return builder.build() ; }
@Override public PlanStrategy get() { PlanStrategyImpl.Builder builder = new PlanStrategyImpl.Builder(new RandomPlanSelector<Plan, Person>()); builder.addStrategyModule(new AbstractMultithreadedModule(config.global()) { @Override public PlanAlgorithm getPlanAlgoInstance() { return factory.get(); } }); return builder.build(); } }
@Override public PlanStrategy get() { final PlanStrategyImpl strategy = new PlanStrategyImpl(new RandomPlanSelector()); strategy.addStrategyModule(new TimeAllocationMutator(this.tripRouterProvider, this.plansConfigGroup, this.timeAllocationMutatorConfigGroup, this.globalConfigGroup, this.population)); strategy.addStrategyModule(new ReRoute(this.activityFacilities, this.tripRouterProvider, this.globalConfigGroup)); return strategy; } }
@Override public PlanStrategy get() { PlanStrategyImpl strategy = new PlanStrategyImpl(new RandomPlanSelector()); strategy.addStrategyModule(new org.matsim.core.replanning.modules.SubtourModeChoice(tripRouterProvider, globalConfigGroup, subtourModeChoiceConfigGroup)); strategy.addStrategyModule(new ReRoute(facilities, tripRouterProvider, globalConfigGroup)); return strategy; }
@Override public boolean removePlan(final Plan plan) { boolean result = this.getPlans().remove(plan); if ((this.getSelectedPlan() == plan) && result) { this.setSelectedPlan(new RandomPlanSelector<Plan, Person>().selectPlan(this)); } return result; }
private void removePlans(final HasPlansAndId<PL, AG> person, final int maxNumberOfPlans) { while (person.getPlans().size() > maxNumberOfPlans) { PL plan = this.removalPlanSelector.selectPlan(person); person.removePlan(plan); if (plan == person.getSelectedPlan()) { final PL newPlanToSelect = new RandomPlanSelector<PL, AG>().selectPlan(person) ; if ( newPlanToSelect == null ) { throw new IllegalStateException( "could not find a plan to select for person "+person ); } person.setSelectedPlan( newPlanToSelect ); } } }
@Override public PlanStrategy get() { PlanStrategyImpl.Builder builder = new PlanStrategyImpl.Builder(new RandomPlanSelector<>()); builder.addStrategyModule(new TripsToLegsModule(tripRouterProvider, globalConfigGroup)); builder.addStrategyModule(new ChangeSingleLegMode(globalConfigGroup, changeLegModeConfigGroup)); builder.addStrategyModule(new ReRoute(activityFacilities, tripRouterProvider, globalConfigGroup)); return builder.build(); }
@Override public PlanStrategy get() { PlanStrategyImpl.Builder builder = new PlanStrategyImpl.Builder(new RandomPlanSelector<>()); builder.addStrategyModule(new TripsToLegsModule(tripRouterProvider, globalConfigGroup)); builder.addStrategyModule(new ChangeLegMode(globalConfigGroup, changeLegModeConfigGroup)); builder.addStrategyModule(new ReRoute(activityFacilities, tripRouterProvider, globalConfigGroup)); return builder.build(); }
@Test public void testGetStrategies() { // init StrategyManager StrategyManager manager = new StrategyManager(); PlanStrategy str1 = new PlanStrategyImpl(new RandomPlanSelector()); PlanStrategy str2 = new PlanStrategyImpl(new RandomPlanSelector()); PlanStrategy str3 = new PlanStrategyImpl(new RandomPlanSelector()); manager.addStrategyForDefaultSubpopulation(str1, 1.0); manager.addStrategyForDefaultSubpopulation(str2, 2.0); manager.addStrategyForDefaultSubpopulation(str3, 0.5); List<GenericPlanStrategy<Plan, Person>> strategies = manager.getStrategiesOfDefaultSubpopulation(); Assert.assertEquals(3, strategies.size()); Assert.assertEquals(str1, strategies.get(0)); Assert.assertEquals(str2, strategies.get(1)); Assert.assertEquals(str3, strategies.get(2)); }
@Test public void testGetWeights() { // init StrategyManager StrategyManager manager = new StrategyManager(); PlanStrategy str1 = new PlanStrategyImpl(new RandomPlanSelector()); PlanStrategy str2 = new PlanStrategyImpl(new RandomPlanSelector()); PlanStrategy str3 = new PlanStrategyImpl(new RandomPlanSelector()); manager.addStrategyForDefaultSubpopulation(str1, 1.0); manager.addStrategyForDefaultSubpopulation(str2, 2.0); manager.addStrategyForDefaultSubpopulation(str3, 0.5); List<Double> weights = manager.getWeightsOfDefaultSubpopulation(); Assert.assertEquals(3, weights.size()); Assert.assertEquals(1.0, weights.get(0), 1e-8); Assert.assertEquals(2.0, weights.get(1), 1e-8); Assert.assertEquals(0.5, weights.get(2), 1e-8); }
@Test( expected=IllegalStateException.class ) public void testAddTwiceStrategy() { final StrategyManager manager = new StrategyManager(); final PlanStrategy s = new PlanStrategyImpl.Builder( new RandomPlanSelector() ).build(); manager.addStrategy( s , null , 1 ); manager.addStrategy( s , null , 10 ); }
public LocationChoicePlanStrategy(Scenario scenario, Provider<TripRouter> tripRouterProvider) { this.tripRouterProvider = tripRouterProvider; if ( DestinationChoiceConfigGroup.Algotype.bestResponse==((DestinationChoiceConfigGroup)scenario.getConfig().getModule("locationchoice")).getAlgorithm() ) { throw new RuntimeException("best response location choice not supported as part of LocationChoicePlanStrategy. " + "Use BestReplyLocationChoicePlanStrategy instead, but be aware that as of now some Java coding is necessary to do that. kai, feb'13") ; } DestinationChoiceConfigGroup dccg = (DestinationChoiceConfigGroup) scenario.getConfig().getModule(DestinationChoiceConfigGroup.GROUP_NAME); String planSelector = dccg.getPlanSelector(); if (planSelector.equals("BestScore")) { delegate = new PlanStrategyImpl(new BestPlanSelector()); } else if (planSelector.equals("ChangeExpBeta")) { delegate = new PlanStrategyImpl(new ExpBetaPlanChanger(scenario.getConfig().planCalcScore().getBrainExpBeta())); } else if (planSelector.equals("SelectRandom")) { delegate = new PlanStrategyImpl(new RandomPlanSelector()); } else { delegate = new PlanStrategyImpl(new ExpBetaPlanSelector(scenario.getConfig().planCalcScore())); } delegate.addStrategyModule(new DestinationChoice(this.tripRouterProvider, scenario)); delegate.addStrategyModule(new ReRoute(scenario, tripRouterProvider)); }
/** * @author mrieser */ public void testGetNumberOfStrategyModules() { final PlanStrategyImpl strategy = new PlanStrategyImpl(new RandomPlanSelector()); assertEquals(0, strategy.getNumberOfStrategyModules()); strategy.addStrategyModule(new DummyStrategyModule()); assertEquals(1, strategy.getNumberOfStrategyModules()); strategy.addStrategyModule(new DummyStrategyModule()); assertEquals(2, strategy.getNumberOfStrategyModules()); }
@Override public void init(ReplanningContext replanningContext) { /* * Somehow this is ugly. Should be initialized in the constructor. But I do not know, how to initialize the lc scenario elements * such that they are already available at the time of constructing this object. ah feb'13 */ DestinationChoiceContext lcContext = (DestinationChoiceContext) scenario.getScenarioElement(DestinationChoiceContext.ELEMENT_NAME); Config config = lcContext.getScenario().getConfig(); DestinationChoiceConfigGroup dccg = (DestinationChoiceConfigGroup) config.getModule(DestinationChoiceConfigGroup.GROUP_NAME); MaxDCScoreWrapper maxDcScoreWrapper = (MaxDCScoreWrapper)scenario.getScenarioElement(MaxDCScoreWrapper.ELEMENT_NAME); if ( !DestinationChoiceConfigGroup.Algotype.bestResponse.equals(dccg.getAlgorithm())) { throw new RuntimeException("wrong class for selected location choice algorithm type; aborting ...") ; } String planSelector = dccg.getPlanSelector(); if (planSelector.equals("BestScore")) { delegate = new PlanStrategyImpl(new BestPlanSelector<Plan, Person>()); } else if (planSelector.equals("ChangeExpBeta")) { delegate = new PlanStrategyImpl(new ExpBetaPlanChanger(config.planCalcScore().getBrainExpBeta())); } else if (planSelector.equals("SelectRandom")) { delegate = new PlanStrategyImpl(new RandomPlanSelector()); } else { delegate = new PlanStrategyImpl(new ExpBetaPlanSelector(config.planCalcScore())); } delegate.addStrategyModule(new TripsToLegsModule(tripRouterProvider, config.global())); delegate.addStrategyModule(new BestReplyDestinationChoice(tripRouterProvider, lcContext, maxDcScoreWrapper.getPersonsMaxDCScoreUnscaled(), scoringFunctionFactory, travelTimes, travelDisutilities)); delegate.addStrategyModule(new ReRoute(lcContext.getScenario(), tripRouterProvider)); delegate.init(replanningContext); }