/** * Design comments:<ul> * <li> This is such that ControlerListenerManager does not need to be exposed. One may decide otherwise ... kai, jul'12 * </ul> */ public final void addControlerListener(ControlerListener l) { this.controlerListenerManagerImpl.addControlerListener(l); }
protected final void addCoreControlerListener(ControlerListener l) { this.controlerListenerManagerImpl.addCoreControlerListener(l); }
@Override public void run() { controlerListenerManagerImpl.fireControlerIterationStartsEvent(iteration); } });
@Test public void testAddCoreControlerListener_ClassHierarchy() { ControlerListenerManagerImpl m = new ControlerListenerManagerImpl(); CountingControlerListener ccl = new CountingControlerListener(); ExtendedControlerListener ecl = new ExtendedControlerListener(); m.addCoreControlerListener(ccl); m.addCoreControlerListener(ecl); m.fireControlerStartupEvent(); Assert.assertEquals(1, ccl.nOfStartups); Assert.assertEquals(0, ccl.nOfIterStarts); Assert.assertEquals(0, ecl.nOfShutdowns); m.fireControlerIterationStartsEvent(0); Assert.assertEquals(1, ccl.nOfStartups); Assert.assertEquals(1, ccl.nOfIterStarts); Assert.assertEquals(0, ecl.nOfShutdowns); m.fireControlerIterationStartsEvent(1); Assert.assertEquals(1, ccl.nOfStartups); Assert.assertEquals(2, ccl.nOfIterStarts); Assert.assertEquals(0, ecl.nOfShutdowns); m.fireControlerShutdownEvent(false); Assert.assertEquals(1, ccl.nOfStartups); Assert.assertEquals(2, ccl.nOfIterStarts);
@Test public void testAddControlerListener_ClassHierarchy() { ControlerListenerManagerImpl m = new ControlerListenerManagerImpl(); CountingControlerListener ccl = new CountingControlerListener(); ExtendedControlerListener ecl = new ExtendedControlerListener(); m.addControlerListener(ccl); m.addControlerListener(ecl); m.fireControlerStartupEvent(); Assert.assertEquals(1, ccl.nOfStartups); Assert.assertEquals(0, ccl.nOfIterStarts); Assert.assertEquals(0, ecl.nOfShutdowns); m.fireControlerIterationStartsEvent(0); Assert.assertEquals(1, ccl.nOfStartups); Assert.assertEquals(1, ccl.nOfIterStarts); Assert.assertEquals(0, ecl.nOfShutdowns); m.fireControlerIterationStartsEvent(1); Assert.assertEquals(1, ccl.nOfStartups); Assert.assertEquals(2, ccl.nOfIterStarts); Assert.assertEquals(0, ecl.nOfShutdowns); m.fireControlerShutdownEvent(false); Assert.assertEquals(1, ccl.nOfStartups); Assert.assertEquals(2, ccl.nOfIterStarts);
public void playEventsFile(String eventsFilename, int iterationNumber) { ((ControlerListenerManagerImpl) controlerListenerManager).fireControlerStartupEvent(); for (ControlerListener controlerListener : controlerListenersDeclaredByModules) { if (controlerListener instanceof StartupListener) { ((ControlerListenerManagerImpl) controlerListenerManager).fireControlerIterationStartsEvent(iterationNumber); for (ControlerListener controlerListener : controlerListenersDeclaredByModules) { if (controlerListener instanceof IterationStartsListener) { ((ControlerListenerManagerImpl) controlerListenerManager).fireControlerBeforeMobsimEvent(iterationNumber); for (ControlerListener controlerListener : controlerListenersDeclaredByModules) { if (controlerListener instanceof BeforeMobsimListener) { ((ControlerListenerManagerImpl) controlerListenerManager).fireControlerAfterMobsimEvent(iterationNumber); for (ControlerListener controlerListener : controlerListenersDeclaredByModules) { if (controlerListener instanceof AfterMobsimListener) { ((ControlerListenerManagerImpl) controlerListenerManager).fireControlerIterationEndsEvent(iterationNumber); for (ControlerListener controlerListener : controlerListenersDeclaredByModules) { if (controlerListener instanceof IterationEndsListener) { ((ControlerListenerManagerImpl) controlerListenerManager).fireControlerShutdownEvent(false); for (ControlerListener controlerListener : controlerListenersDeclaredByModules) { if (controlerListener instanceof ShutdownListener) {
@Test(expected = RuntimeException.class) public void exceptionInScoringFunctionPropagates() { Config config = ConfigUtils.createConfig(); Scenario scenario = ScenarioUtils.createScenario(config); Id<Person> personId = Id.createPersonId(1); scenario.getPopulation().addPerson(scenario.getPopulation().getFactory().createPerson(personId)); EventsManager events = EventsUtils.createEventsManager(config); ControlerListenerManagerImpl controlerListenerManager = new ControlerListenerManagerImpl(); ScoringFunctionFactory throwingScoringFunctionFactory = new ThrowingScoringFunctionFactory(); EventsToActivities e2acts = new EventsToActivities(controlerListenerManager); EventsToLegs e2legs = new EventsToLegs(scenario.getNetwork()); EventsToLegsAndActivities e2legsActs = new EventsToLegsAndActivities(e2legs, e2acts); events.addHandler(e2legsActs); ScoringFunctionsForPopulation scoringFunctionsForPopulation = new ScoringFunctionsForPopulation( controlerListenerManager, events, e2acts, e2legs, scenario.getPopulation(), throwingScoringFunctionFactory ); controlerListenerManager.fireControlerIterationStartsEvent(0); events.processEvent(new PersonMoneyEvent(3600.0, personId, 3.4)); scoringFunctionsForPopulation.finishScoringFunctions(); }
@Override public void shutdown(boolean unexpected) { controlerListenerManagerImpl.fireControlerShutdownEvent(unexpected); } };
protected AbstractController() { this(new ControlerListenerManagerImpl(), new IterationStopWatch(), null); }
@Override public void run() throws MatsimRuntimeModifications.UnexpectedShutdownException { loadCoreListeners(); controlerListenerManagerImpl.fireControlerStartupEvent(); ControlerUtils.checkConfigConsistencyAndWriteToLog(config, "config dump before iterations start"); prepareForSim(); doIterations(config); }
@Override public void run() { log.info(MARKER + "ITERATION " + iteration + " fires after mobsim event"); controlerListenerManagerImpl.fireControlerAfterMobsimEvent(iteration); } });
@Override public void run() { controlerListenerManagerImpl.fireControlerBeforeMobsimEvent(iteration); } });
@Override public void run() { controlerListenerManagerImpl.fireControlerReplanningEvent(iteration); } });
@Override public void run() { log.info(MARKER + "ITERATION " + iteration + " fires iteration end event"); controlerListenerManagerImpl.fireControlerIterationEndsEvent(iteration); } });
population.addPerson(p); ControlerListenerManagerImpl controlerListenerManager = new ControlerListenerManagerImpl(); EventsManager eventsManager = EventsUtils.createEventsManager(); controlerListenerManager.fireControlerIterationStartsEvent(0); ScoringFunction s = sf.getScoringFunctionForAgent(personId); Assert.assertEquals(RecordingScoringFunction.class, s.getClass());
/** * Finishes the calculation of the plans' scores and assigns the new scores * to the plans if desired. */ public void finish() { if (iteration == -1) { throw new RuntimeException("Please initialize me before the iteration starts."); } controlerListenerManager.fireControlerAfterMobsimEvent(iteration); scoringFunctionsForPopulation.finishScoringFunctions(); newScoreAssigner.assignNewScores(this.iteration, scoringFunctionsForPopulation, population); finished = true; }
Id<Person> personId = Id.createPersonId(1); scenario.getPopulation().addPerson(scenario.getPopulation().getFactory().createPerson(personId)); ControlerListenerManagerImpl controlerListenerManager = new ControlerListenerManagerImpl(); EventsManager events = EventsUtils.createEventsManager(config); ScoringFunctionFactory scoringFunctionFactory = new ScoringFunctionFactory() { scoringFunctionFactory ); controlerListenerManager.fireControlerIterationStartsEvent(0); events.initProcessing(); for (int i=0; i<MAX; i++) {
public void beginIteration(int iteration) { this.iteration = iteration; this.controlerListenerManager.fireControlerIterationStartsEvent(iteration); }
ControlerListenerManagerImpl controlerListenerManager = new ControlerListenerManagerImpl(); ScoringFunctionsForPopulation scoringFunctionsForPopulation = new ScoringFunctionsForPopulation( controlerListenerManager, scoringFunctionFactory ); controlerListenerManager.fireControlerIterationStartsEvent(0); int MAX = 10; events.initProcessing();