@Override synchronized public void handleActivity(PersonExperiencedActivity o) { // Has to be synchronized because the thing which sends Legs and the thing which sends Activities can run // on different threads. Will go away when/if we get a more Actor or Reactive Streams like event infrastructure. Id<Person> agentId = o.getAgentId(); Activity activity = o.getActivity(); Plan plan = agentRecords.get(agentId); if (plan != null) { agentRecords.get(agentId).addActivity(activity); } }
@Override synchronized public void handleActivity(PersonExperiencedActivity o) { Id<Person> agentId = o.getAgentId(); Activity activity = o.getActivity(); ScoringFunction scoringFunction = ScoringFunctionsForPopulation.this.getScoringFunctionForAgent(agentId); if (scoringFunction != null) {
@Test public void testCreateNightActivity() { EventsToActivities testee = new EventsToActivities(); MockActivityHandler ah = new MockActivityHandler(); testee.addActivityHandler(ah); testee.reset(0); testee.handleEvent(new ActivityEndEvent(10.0, Id.create("1", Person.class), Id.create("l1", Link.class), Id.create("l1", ActivityFacility.class), "home")); Assert.assertNotNull(ah.handledActivity); Assert.assertEquals(Time.UNDEFINED_TIME, ah.handledActivity.getActivity().getStartTime(), 1e-8); Assert.assertEquals(10.0, ah.handledActivity.getActivity().getEndTime(), 1e-8); ah.reset(); testee.handleEvent(new ActivityStartEvent(90.0, Id.create("1", Person.class), Id.create("l1", Link.class), Id.create("l1", ActivityFacility.class), "home")); testee.finish(); Assert.assertNotNull(ah.handledActivity); Assert.assertEquals(Time.UNDEFINED_TIME, ah.handledActivity.getActivity().getEndTime(), 1e-8); Assert.assertEquals(90.0, ah.handledActivity.getActivity().getStartTime(), 1e-8); }
@Test public void testDontCreateNightActivityIfNoneIsBeingPerformedWhenSimulationEnds() { EventsToActivities testee = new EventsToActivities(); MockActivityHandler ah = new MockActivityHandler(); testee.addActivityHandler(ah); testee.reset(0); testee.handleEvent(new ActivityEndEvent(10.0, Id.create("1", Person.class), Id.create("l1", Link.class), Id.create("f1", ActivityFacility.class), "home")); Assert.assertNotNull(ah.handledActivity); Assert.assertEquals(Time.UNDEFINED_TIME, ah.handledActivity.getActivity().getStartTime(), 1e-8); Assert.assertEquals(10.0, ah.handledActivity.getActivity().getEndTime(), 1e-8); ah.reset(); testee.finish(); Assert.assertNull(ah.handledActivity); }
@Test public void testCreatesActivty() { EventsToActivities testee = new EventsToActivities(); MockActivityHandler ah = new MockActivityHandler(); testee.addActivityHandler(ah); testee.reset(0); testee.handleEvent(new ActivityStartEvent(10.0, Id.create("1", Person.class), Id.create("l1", Link.class), Id.create("l1", ActivityFacility.class), "work")); testee.handleEvent(new ActivityEndEvent(30.0, Id.create("1", Person.class), Id.create("l1", Link.class), Id.create("l1", ActivityFacility.class), "work")); Assert.assertNotNull(ah.handledActivity); Assert.assertEquals(10.0, ah.handledActivity.getActivity().getStartTime(), 1e-8); Assert.assertEquals(30.0, ah.handledActivity.getActivity().getEndTime(), 1e-8); }