@Override public PlanStrategy get() { PlanStrategy strategy = new PlanStrategyImpl(new BestPlanSelector()); return strategy; }
/** * @author mrieser */ public void testGetBestPlan_allWithoutScore() { Person person = PopulationUtils.getFactory().createPerson(Id.create(1, Person.class)); Plan p1 = PopulationUtils.createPlan(); Plan p2 = PopulationUtils.createPlan(); person.addPlan(p1); person.addPlan(p2); Plan p = new BestPlanSelector<Plan, Person>().selectPlan(person); assertTrue(p == p1 || p == p2); } }
/** * @author mrieser */ public void testGetBestPlan_oneWithoutScore() { Person person = PopulationUtils.getFactory().createPerson(Id.create(1, Person.class)); Plan p1 = PopulationUtils.createPlan(); Plan p2 = PopulationUtils.createPlan(); p2.setScore(80.0); person.addPlan(p1); person.addPlan(p2); Plan p = new BestPlanSelector<Plan, Person>().selectPlan(person); assertEquals(p2, p); }
@Override protected PlanSelector<Plan, Person> getPlanSelector() { return new BestPlanSelector(); }
/** * @author mrieser */ public void testGetBestPlan() { Person person = PopulationUtils.getFactory().createPerson(Id.create(1, Person.class)); Plan p1 = PopulationUtils.createPlan(); p1.setScore(90.0); Plan p2 = PopulationUtils.createPlan(); p2.setScore(89.0); person.addPlan(p1); person.addPlan(p2); Plan p = new BestPlanSelector<Plan, Person>().selectPlan(person); assertEquals(p1, p); }
public GenericPlanStrategy<CarrierPlan, Carrier> createStrategy(){ GenericPlanStrategyImpl<CarrierPlan, Carrier> replanningStrat = new GenericPlanStrategyImpl<CarrierPlan, Carrier>( new BestPlanSelector<CarrierPlan, Carrier>() ) ;
/** * @author mrieser */ public void testGetBestPlan_multipleBest() { Person person = PopulationUtils.getFactory().createPerson(Id.create(1, Person.class)); Plan p1 = PopulationUtils.createPlan(); p1.setScore(11.0); Plan p2 = PopulationUtils.createPlan(); p2.setScore(5.0); Plan p3 = PopulationUtils.createPlan(); p3.setScore(11.0); person.addPlan(p1); person.addPlan(p2); person.addPlan(p3); Plan p = new BestPlanSelector<Plan, Person>().selectPlan(person); assertTrue(p == p1 || p == p3); }
private static CarrierPlanStrategyManagerFactory createStrategyManagerFactory(final CarrierVehicleTypes types, final MatsimServices controler) { return () -> { final GenericStrategyManager<CarrierPlan, Carrier> strategyManager = new GenericStrategyManager<>(); strategyManager.addStrategy(new GenericPlanStrategyImpl<>(new BestPlanSelector<>()), null, 0.95); strategyManager.addStrategy(new SelectBestPlanAndOptimizeItsVehicleRouteFactory(controler.getScenario().getNetwork(), types, controler.getLinkTravelTimes()).createStrategy(), null, 0.05); return strategyManager; }; }
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 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); }
manager.setPlanSelectorForRemoval(new BestPlanSelector<Plan, Person>()); manager.setMaxPlansPerAgent(plans.length - 4); manager.run(pop, null);
plan.setScore(-20.0); PlanSelector<Plan, Person> selector = new BestPlanSelector<Plan, Person>();