/** * Returns the score of a single agent. This method only returns useful * values if the method {@link #finish() } was called before. description * * @param agentId * The id of the agent the score is requested for. * @return The score of the specified agent. */ public Double getAgentScore(final Id<Person> agentId) { if (!finished) { throw new IllegalStateException("Must call finish first."); } ScoringFunction scoringFunction = scoringFunctionsForPopulation.getScoringFunctionForAgent(agentId); if (scoringFunction == null) return null; return scoringFunction.getScore(); }
@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()); } } } }
public void finishScoringFunctions() { // Rethrow an exception in a scoring function (user code) if there was one. Throwable throwable = this.exception.get(); if (throwable != null) { if (throwable instanceof RuntimeException) { throw ((RuntimeException) throwable); } else { throw new RuntimeException(throwable); } } for (ScoringFunction sf : this.agentScorers.values()) { sf.finish(); } for (Entry<Id<Person>, TDoubleCollection> entry : this.partialScores.entrySet()) { entry.getValue().add(this.getScoringFunctionForAgent(entry.getKey()).getScore()); } }
public void scoreSelectedPlan() { if (carrier.getSelectedPlan() == null) { return; } scoringFunction.finish(); carrier.getSelectedPlan().setScore(scoringFunction.getScore()); }
@Override synchronized public void handleLeg(PersonExperiencedLeg o) { Id<Person> agentId = o.getAgentId(); Leg leg = o.getLeg(); ScoringFunction scoringFunction = ScoringFunctionsForPopulation.this.getScoringFunctionForAgent(agentId); if (scoringFunction != null) { scoringFunction.handleLeg(leg); TDoubleCollection partialScoresForAgent = this.partialScores.get(agentId); partialScoresForAgent.add(scoringFunction.getScore()); } Plan plan = this.tripRecords.get( agentId ) ; // as container for trip if ( plan!=null ) { plan.addLeg( leg ); } }
double score = sf.getScore(); Plan plan = person.getSelectedPlan(); Double oldScore = plan.getScore();
scoringFunction.handleActivity(activity); TDoubleCollection partialScoresForAgent = this.partialScores.get(agentId); partialScoresForAgent.add(scoringFunction.getScore());
return scoringFunction.getScore();
@Test public void testActivitiesScoredDifferently() { final Scenario sc = createTestScenario(); final CharyparNagelScoringFunctionFactory functionFactory = new CharyparNagelScoringFunctionFactory( sc ); final ScoringFunction function1 = functionFactory.createNewScoringFunction( sc.getPopulation().getPersons().get( Id.createPersonId( 1 ) ) ); final ScoringFunction function2 = functionFactory.createNewScoringFunction( sc.getPopulation().getPersons().get( Id.createPersonId( 2 ) ) ); final Activity act = PopulationUtils.createActivityFromCoordAndLinkId("chill", null, null); act.setStartTime( 8 * 3600d ); act.setEndTime( 18 * 3600d ); function1.handleActivity( act ); function1.finish(); function2.handleActivity( act ); function2.finish(); Assert.assertFalse( "same score for legs of agents in different subpopulations", Math.abs( function1.getScore() - function2.getScore() ) < 1E-9 ); }
private double calcScore(final Fixture f) { CharyparNagelScoringFunctionFactory charyparNagelScoringFunctionFactory = new CharyparNagelScoringFunctionFactory( f.scenario ); ScoringFunction testee = charyparNagelScoringFunctionFactory.createNewScoringFunction(PopulationUtils.getFactory().createPerson(Id.create("1", Person.class))); for (PlanElement planElement : f.plan.getPlanElements()) { if (planElement instanceof Activity) { testee.handleActivity((Activity) planElement); } else if (planElement instanceof Leg) { testee.handleLeg((Leg) planElement); } } testee.finish(); return testee.getScore(); }
@Test public void testLegsScoredDifferently() { final Scenario sc = createTestScenario(); final CharyparNagelScoringFunctionFactory functionFactory = new CharyparNagelScoringFunctionFactory( sc ); final ScoringFunction function1 = functionFactory.createNewScoringFunction( sc.getPopulation().getPersons().get( Id.createPersonId( 1 ) ) ); final ScoringFunction function2 = functionFactory.createNewScoringFunction( sc.getPopulation().getPersons().get( Id.createPersonId( 2 ) ) ); final Leg leg = PopulationUtils.createLeg("skateboard"); leg.setDepartureTime( 10 ); leg.setTravelTime(10); final Route route = RouteUtils.createGenericRouteImpl(null, null); route.setDistance( 10 ); route.setTravelTime( 10 ); leg.setRoute( route ); function1.handleLeg(leg); function1.finish(); function2.handleLeg(leg); function2.finish(); Assert.assertFalse( "same score for legs of agents in different subpopulations", Math.abs( function1.getScore() - function2.getScore() ) < 1E-9 ); }
perf * 3.0 * Math.log(2.5 / zeroUtilDurW) + perf * 7.0 * Math.log(7.0 / zeroUtilDurH), testee.getScore(), EPSILON);
assertEquals(1.0/6.0 * MAX, scoringFunctionsForPopulation.getScoringFunctionForAgent(personId).getScore(), 1.0);
assertEquals(1.0/6.0 * MAX, scoringFunctionsForPopulation.getScoringFunctionForAgent(personId).getScore(), 1.0);