@Override public PlanStrategy get() { return new PlanStrategyImpl(new ExpBetaPlanSelector(config)); }
@Override public ExpBetaPlanSelector<Plan, Person> get() { return new ExpBetaPlanSelector<>( - config.getBrainExpBeta()); } }
@Override protected ExpBetaPlanSelector<Plan, Person> getPlanSelector() { return new ExpBetaPlanSelector<Plan, Person>(this.config.planCalcScore()); }
@Override public Plan selectPlan(HasPlansAndId<Plan, Person> person) { List<cadyts.demand.Plan<T>> plans = new ArrayList<cadyts.demand.Plan<T>>() ; Vector choiceProbs = new Vector( person.getPlans().size() ) ; int pos = 0 ; for ( Plan plan : person.getPlans() ) { plans.add( cContext.getPlansTranslator().getCadytsPlan(plan) ) ; choiceProbs.add(pos, ExpBetaPlanSelector.getSelectionProbability(new ExpBetaPlanSelector(beta), plan.getPerson(), plan) ); // I guess these are supposed to be the prior probabilities. If so, than the above shoudl be correct (albeit a bit expensive). // I would have expected that these are internally ignored when brute force is switched on, but they are not. // I think that what it does is to use them when plans are equal according to cadyts. kai, dec'13 pos++ ; } int idx = cContext.getCalibrator().selectPlan(plans, choiceProbs) ; // cContext.getCalibrator().addToDemand(cadytsPlan) ; // I _think_ that's done inside calibrator.selectPlan. kai, dec'13 return person.getPlans().get(idx) ; }
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); }
plan5.setScore(100.0); ExpBetaPlanSelector<Plan, Person> selector = new ExpBetaPlanSelector<Plan, Person>(this.config.planCalcScore()); int cnt1 = 0; int cnt2 = 0;
ExpBetaPlanSelector<Plan, Person> selector = new ExpBetaPlanSelector<Plan, Person>(this.config.planCalcScore()); int cnt1 = 0; int cnt2 = 0;
public void testGetSelectionProbability() { /* * the expected results were computed with R. The standard output of double precision numbers in R has 7 digits. */ final double EPSILON_R = 1e-7; this.config.planCalcScore().setBrainExpBeta(2.0); Person person = PopulationUtils.getFactory().createPerson(Id.create(1, Person.class)); Plan plan1 = PersonUtils.createAndAddPlan(person, false); plan1.setScore(180.0); Plan plan2 = PersonUtils.createAndAddPlan(person, false); plan2.setScore(180.1); Plan plan3 = PersonUtils.createAndAddPlan(person, false); plan3.setScore(180.5); Plan plan4 = PersonUtils.createAndAddPlan(person, false); plan4.setScore(169.9); ExpBetaPlanSelector testee = new ExpBetaPlanSelector(this.config.planCalcScore()); assertEquals(0.2024421, ExpBetaPlanSelector.getSelectionProbability(testee, person, plan1), EPSILON_R); assertEquals(0.2472634, ExpBetaPlanSelector.getSelectionProbability(testee, person, plan2), EPSILON_R); assertEquals(0.5502947, ExpBetaPlanSelector.getSelectionProbability(testee, person, plan3), EPSILON_R); assertEquals(6.208075e-10, ExpBetaPlanSelector.getSelectionProbability(testee, person, plan4), EPSILON_R); }