@Override public void setScore(Double score) { this.delegate.setScore(score); }
private static void setScore( final Person p, final Double score) { if ( score == null ) throw new NullPointerException( "got null score for person "+p ); if ( score.isNaN() ) throw new RuntimeException( "got NaN score for person "+p ); p.getSelectedPlan().setScore( score ); }
private void startPlan(final Attributes atts) { String sel = atts.getValue("selected"); boolean selected; if (sel.equals("yes")) { selected = true; } else if (sel.equals("no")) { selected = false; } else { throw new NumberFormatException("Attribute 'selected' of Element 'Plan' is neither 'yes' nor 'no'."); } this.currplan = PersonUtils.createAndAddPlan(this.currperson, selected); this.routeNodes = null; String scoreString = atts.getValue("score"); if (scoreString != null) { double score = Double.parseDouble(scoreString); this.currplan.setScore(score); } }
@Override public final void finishIteration() { // I separated this from "writeExperiencedPlans" so that it can be called separately even when nothing is written. Can't say // if the design might be better served by an iteration ends listener. kai, feb'17 for (Map.Entry<Id<Person>, Plan> entry : this.agentRecords.entrySet()) { Plan plan = entry.getValue(); if (scoringFunctionsForPopulation != null) { plan.setScore(scoringFunctionsForPopulation.getScoringFunctionForAgent(entry.getKey()).getScore()); if (plan.getScore().isNaN()) { log.warn("score is NaN; plan:" + plan.toString()); } } } }
private void startPlan(final Attributes atts) { String sel = atts.getValue("selected"); boolean selected; if (sel.equals("yes")) { selected = true; } else if (sel.equals("no")) { selected = false; } else { throw new NumberFormatException( "Attribute 'selected' of Element 'Plan' is neither 'yes' nor 'no'."); } this.currplan = PersonUtils.createAndAddPlan(this.currperson, selected); this.routeNodes = null; String scoreString = atts.getValue("score"); if (scoreString != null) { double score = Double.parseDouble(scoreString); this.currplan.setScore(score); } }
@Override public void notifyIterationEnds(IterationEndsEvent event) { if (this.isQSimIteration()) return; Iterator<Map.Entry<Id<Person>, Double>> iterator = selectedPlanScoreMemory.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<Id<Person>, Double> entry = iterator.next(); scenario.getPopulation().getPersons().get(entry.getKey()).getSelectedPlan().setScore(entry.getValue()); } }
@Override public void notifyIterationEnds(IterationEndsEvent event) { Iterator<Map.Entry<Id<Person>, Double>> iterator = selectedPlanScoreMemory.entrySet().iterator(); StopStopTimeCalculatorSerializable.printCallStatisticsAndReset(); WaitTimeCalculatorSerializable.printCallStatisticsAndReset(); while (iterator.hasNext()) { Map.Entry<Id<Person>, Double> entry = iterator.next(); scenario.getPopulation().getPersons().get(entry.getKey()).getSelectedPlan().setScore(entry.getValue()); } }
private void startPlan(final Attributes atts) { String sel = atts.getValue("selected"); boolean selected; if (sel.equals("yes")) { selected = true; } else if (sel.equals("no")) { selected = false; } else { throw new NumberFormatException("Attribute 'selected' of Element 'Plan' is neither 'yes' nor 'no'."); } this.routeDescription = null; this.currplan = PersonUtils.createAndAddPlan(this.currperson, selected); String scoreString = atts.getValue("score"); if (scoreString != null) { double score = Double.parseDouble(scoreString); this.currplan.setScore(score); } String type = atts.getValue(ATTR_TYPE); this.currplan.setType(type); }
private void startPlan(final Attributes atts) { String sel = atts.getValue(ATTR_PLAN_SELECTED); boolean selected; if (VALUE_YES.equals(sel)) { selected = true; } else if (VALUE_NO.equals(sel)) { selected = false; } else { throw new IllegalArgumentException( "Attribute 'selected' of Element 'Plan' is neither 'yes' nor 'no'."); } this.routeDescription = null; this.currplan = PersonUtils.createAndAddPlan(this.currperson, selected); String scoreString = atts.getValue(ATTR_PLAN_SCORE); if (scoreString != null) { double score = Double.parseDouble(scoreString); this.currplan.setScore(score); } String type = atts.getValue(ATTR_PLAN_TYPE); if (type != null) { this.currplan.setType(type); } }
private void startPlan(final Attributes atts) { String sel = atts.getValue(ATTR_PLAN_SELECTED); boolean selected; if (VALUE_YES.equals(sel)) { selected = true; } else if (VALUE_NO.equals(sel)) { selected = false; } else { throw new IllegalArgumentException( "Attribute 'selected' of Element 'Plan' is neither 'yes' nor 'no'."); } this.routeDescription = null; this.currplan = PersonUtils.createAndAddPlan(this.currperson, selected); String scoreString = atts.getValue(ATTR_PLAN_SCORE); if (scoreString != null) { double score = Double.parseDouble(scoreString); this.currplan.setScore(score); } String type = atts.getValue(ATTR_PLAN_TYPE); if (type != null) { this.currplan.setType(type); } }
@Override public void run(Person person) { person.getPlans().get(0).setScore(null); // this will result in an IndexOutOfBoundsException } });
/** loads a copy of an existing plan, but keeps the person reference * * @param in a plan who's data will be loaded into this plan * @param out **/ public static void copyFromTo(final Plan in, Plan out) { out.getPlanElements().clear(); out.setScore(in.getScore()); out.setType(in.getType()); for (PlanElement pe : in.getPlanElements()) { if (pe instanceof Activity) { out.getPlanElements().add(createActivity((Activity) pe)); } else if (pe instanceof Leg) { out.getPlanElements().add( createLeg( (Leg) pe ) ) ; } else { throw new IllegalArgumentException("unrecognized plan element type discovered"); } } AttributesUtils.copyAttributesFromTo(in, out ); }
/** * @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); }
/** * @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); }
private static void copyPlanFieldsToFrom1(Plan planTarget, Plan planTemplate) { planTarget.setScore(planTemplate.getScore()); int actLegIndex = 0; for (PlanElement pe : planTarget.getPlanElements()) { if (pe instanceof Activity) { Activity actTemplate = ((Activity) planTemplate.getPlanElements().get(actLegIndex)); ((Activity) pe).setEndTime(actTemplate.getEndTime()); ((Activity) pe).setCoord(actTemplate.getCoord()); ((Activity) pe).setFacilityId(actTemplate.getFacilityId()); ((Activity) pe).setLinkId(actTemplate.getLinkId()); ((Activity) pe).setMaximumDuration(actTemplate.getMaximumDuration()); ((Activity) pe).setStartTime(actTemplate.getStartTime()); ((Activity) pe).setType(actTemplate.getType()); } else if (pe instanceof Leg) { Leg legTemplate = ((Leg)planTemplate.getPlanElements().get(actLegIndex)); Leg r = ((Leg) pe); r.setTravelTime( legTemplate.getDepartureTime() + legTemplate.getTravelTime() - r.getDepartureTime() ); ((Leg) pe).setDepartureTime(legTemplate.getDepartureTime()); ((Leg) pe).setMode(legTemplate.getMode()); ((Leg) pe).setRoute(legTemplate.getRoute()); ((Leg) pe).setTravelTime(legTemplate.getTravelTime()); } else throw new RuntimeException("Unexpected PlanElement type was found: " + pe.getClass().toString() + ". Aborting!"); actLegIndex++; } }
private static void copyPlanFieldsToFrom(Plan planTarget, LCPlan planTemplate) { planTarget.setScore(planTemplate.getScore()); int actLegIndex = 0; for (PlanElement pe : planTarget.getPlanElements()) { if (pe instanceof Activity) { LCActivity actTemplate = ((LCActivity) planTemplate.getPlanElements().get(actLegIndex)); ((Activity) pe).setEndTime(actTemplate.getEndTime()); ((Activity) pe).setCoord(actTemplate.getCoord()); ((Activity) pe).setFacilityId(actTemplate.getFacilityId()); ((Activity) pe).setLinkId(actTemplate.getLinkId()); ((Activity) pe).setMaximumDuration(actTemplate.getMaximumDuration()); ((Activity) pe).setStartTime(actTemplate.getStartTime()); ((Activity) pe).setType(actTemplate.getType()); } else if (pe instanceof Leg) { LCLeg legTemplate = ((LCLeg) planTemplate.getPlanElements().get(actLegIndex)); Leg r = ((Leg) pe); r.setTravelTime( legTemplate.getArrivalTime() - r.getDepartureTime() ); ((Leg) pe).setDepartureTime(legTemplate.getDepartureTime()); ((Leg) pe).setMode(legTemplate.getMode()); ((Leg) pe).setRoute(legTemplate.getRoute()); ((Leg) pe).setTravelTime(legTemplate.getTravelTime()); } else throw new RuntimeException("Unexpected PlanElement type was found: " + pe.getClass().toString() + ". Aborting!"); actLegIndex++; } }
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); }
/** * Test how a plan selector reacts when a plan has a score of zero (0.0). * This test only ensures that a plan is returned and no Exception occurred when selecting a plan. */ public void testZeroScore() { PlanSelector<Plan, Person> selector = getPlanSelector(); Plan plan; Person person = PopulationUtils.getFactory().createPerson(Id.create(1, Person.class)); plan = PersonUtils.createAndAddPlan(person, false); plan.setScore(0.0); assertNotNull(selector.selectPlan(person)); }
/** * Test that really the already selected plan is returned. * * @author mrieser */ public void testSelected() { Person person = PopulationUtils.getFactory().createPerson(Id.create(1, Person.class)); Plan plan1 = PersonUtils.createAndAddPlan(person, false); Plan plan2 = PersonUtils.createAndAddPlan(person, true); plan2.setScore(10.0); Plan plan3 = PersonUtils.createAndAddPlan(person, false); plan3.setScore(-50.0); KeepSelected selector = new KeepSelected(); // test default selected plan assertEquals(plan2, selector.selectPlan(person)); // test selected plan with negative score person.setSelectedPlan(plan3); assertEquals(plan3, selector.selectPlan(person)); // test selected plan with undefined score person.setSelectedPlan(plan1); assertEquals(plan1, selector.selectPlan(person)); }
/** * @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); }