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()); } }
@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 ); } }
if (scoringFunction != null) { if (o instanceof PersonStuckEvent) { scoringFunction.agentStuck(o.getTime()); } else if (o instanceof PersonMoneyEvent) { scoringFunction.addMoney(((PersonMoneyEvent) o).getAmount()); scoringFunction.handleEvent(o); scoringFunction.handleEvent(o) ;
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 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 ); }
@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 ); }
ScoringFunction scoringFunction = ScoringFunctionsForPopulation.this.getScoringFunctionForAgent(agentId); if (scoringFunction != null) { scoringFunction.handleActivity(activity); TDoubleCollection partialScoresForAgent = this.partialScores.get(agentId); partialScoresForAgent.add(scoringFunction.getScore()); scoringFunction.handleTrip( trip );
/** * 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(); }
public void handleEvent(ActivityStartEvent event) { Activity activity = PopulationUtils.createActivityFromLinkId(event.getActType(), event.getLinkId()); activity.setFacilityId(event.getFacilityId()); activity.setStartTime(event.getTime()); if(event.getActType().equals(FreightConstants.END)){ activity.setEndTime(Time.UNDEFINED_TIME); scoringFunction.handleActivity(activity); } else{ TourActivity tourActivity = getTourActivity(); assert activity.getLinkId().toString().equals(tourActivity.getLocation().toString()) : "linkId of activity is not equal to linkId of tourActivity. This must not be."; FreightActivity freightActivity = new FreightActivity(activity, tourActivity.getTimeWindow()); currentActivity = freightActivity; } }
/** * * @param event */ public void handleEvent(PersonArrivalEvent event) { currentLeg.setTravelTime( event.getTime() - currentLeg.getDepartureTime() ); double travelTime = currentLeg.getDepartureTime() + currentLeg.getTravelTime() - currentLeg.getDepartureTime(); currentLeg.setTravelTime(travelTime); if (currentRoute.size() > 1) { NetworkRoute networkRoute = RouteUtils.createNetworkRoute(currentRoute, null); networkRoute.setTravelTime(travelTime); networkRoute.setVehicleId(getVehicle().getVehicleId()); currentLeg.setRoute(networkRoute); currentRoute = null; } else { Id<Link> startLink; if(currentRoute.size() != 0){ startLink = currentRoute.get(0); } else{ startLink = event.getLinkId(); } Route genericRoute = RouteUtils.createGenericRouteImpl(startLink, event.getLinkId()); genericRoute.setDistance(0.0); currentLeg.setRoute(genericRoute); } scoringFunction.handleLeg(currentLeg); }
public void handleEvent(LinkEnterEvent event) { scoringFunction.handleEvent(new LinkEnterEvent(event.getTime(),getVehicle().getVehicleId(),event.getLinkId())); /* why can't we do something like: scoringFunction.handleEvent(event); (causes test failures in playground kturner), Theresa Dec'2015 */ currentRoute.add(event.getLinkId()); }
testee.handleActivity((Activity) f.plan.getPlanElements().get(0)); testee.handleLeg((Leg) f.plan.getPlanElements().get(1)); testee.handleActivity((Activity) f.plan.getPlanElements().get(2)); testee.handleLeg((Leg) f.plan.getPlanElements().get(3)); testee.agentStuck(16*3600 + 7.5*60); testee.finish(); testee.getScore(); assertEquals(24 * -18.0 - 6.0 * 0.50, testee.getScore(), EPSILON); // stuck penalty + 30min traveling testee.handleActivity((Activity) f.plan.getPlanElements().get(0)); testee.handleLeg((Leg) f.plan.getPlanElements().get(1)); testee.handleActivity((Activity) f.plan.getPlanElements().get(2)); testee.handleLeg((Leg) f.plan.getPlanElements().get(3)); testee.agentStuck(16*3600 + 7.5*60); testee.finish(); testee.getScore(); assertEquals(24 * -6.0 - 6.0 * 0.50, testee.getScore(), EPSILON); // stuck penalty + 30min traveling
@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 handleEvent(ActivityEndEvent event) { if (currentActivity == null) { Activity firstActivity = PopulationUtils.createActivityFromLinkId(event.getActType(), event.getLinkId()); firstActivity.setFacilityId(event.getFacilityId()); currentActivity = firstActivity; } currentActivity.setEndTime(event.getTime()); scoringFunction.handleActivity(currentActivity); activityFinished(event.getActType(), event.getTime()); }
act1b.setStartTime(f.secondLegStartTime + f.secondLegTravelTime); ScoringFunction sf1 = getScoringFunctionInstance(f, person1); sf1.handleActivity(act1a); sf1.handleLeg(leg1); sf1.handleActivity(act1b); sf1.finish(); double score1 = sf1.getScore(); sf2.handleActivity(act1a); sf2.addMoney(1.23); sf2.handleLeg(leg1); sf2.addMoney(-2.46); sf2.handleActivity(act1b); sf2.addMoney(4.86); sf2.addMoney(-0.28); sf2.finish(); double score2 = sf2.getScore();
double score = sf.getScore(); Plan plan = person.getSelectedPlan(); Double oldScore = plan.getScore();
scoringFunction.handleActivity( actTmp ); continue; scoringFunction.handleLeg( (Leg) pe ); scoringFunction.handleActivity( actTmp ); actTmp.setEndTime( Time.UNDEFINED_TIME ); scoringFunction.handleActivity( actTmp ); scoringFunction.finish(); return scoringFunction.getScore();
assertEquals(1.0/6.0 * MAX, scoringFunctionsForPopulation.getScoringFunctionForAgent(personId).getScore(), 1.0);
testee.handleActivity((Activity) f.plan.getPlanElements().get(0)); testee.handleLeg((Leg) f.plan.getPlanElements().get(1)); testee.handleActivity((Activity) f.plan.getPlanElements().get(2)); testee.finish(); testee.getScore(), EPSILON);