public final PlanStrategy build() { PlanStrategyImpl impl = new PlanStrategyImpl(planSelector) ; for (PlanStrategyModule module : modules) { impl.addStrategyModule(module); } return impl; } }
protected StrategyCounter(final PlanSelector<Plan, Person> selector) { planStrategyDelegate = new PlanStrategyImpl( selector ) ; }
@Override public PlanStrategy get() { PlanStrategy strategy = new PlanStrategyImpl(new BestPlanSelector()); return strategy; }
@Override public PlanStrategy get() { PlanStrategy strategy = new PlanStrategyImpl(new RandomPlanSelector()); return strategy; }
@Override public PlanStrategy get() { return new PlanStrategyImpl(new ExpBetaPlanSelector(config)); }
@Override public PlanStrategy get() { return new PlanStrategyImpl(new PathSizeLogitSelector(config, network)); }
@Override public PlanStrategy get() { PlanStrategy strategy = new PlanStrategyImpl(new KeepSelected()); return strategy; }
@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() { return new PlanStrategyImpl(new ExpBetaPlanChanger(config.getBrainExpBeta())); }
@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; } }
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)); }
@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 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 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); }
@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); }
PlanStrategy str1 = new PlanStrategyImpl(new RandomPlanSelector()); PlanStrategy str2 = new PlanStrategyImpl(new RandomPlanSelector()); PlanStrategy str3 = new PlanStrategyImpl(new RandomPlanSelector());
/** * @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()); }
manager.addStrategyForDefaultSubpopulation(new PlanStrategyImpl(new RandomPlanSelector()), 1.0);
PlanStrategyImpl strategy = new PlanStrategyImpl(new RandomPlanSelector()); StrategyManager strategyManager = new StrategyManager(); strategyManager.addStrategyForDefaultSubpopulation(strategy, 1.0); PlanStrategyImpl strategy2 = new PlanStrategyImpl(new RandomPlanSelector()); StrategyManager strategyManager2 = new StrategyManager(); strategyManager2.addStrategyForDefaultSubpopulation(strategy2, 1.0);