Print

Print


I am having trouble scheduling events in the SimState.  I'm guessing I'm missing something basic here -- perhaps the schedule has to be initialized?  When I add steppable agents or anonymous steppable objects, the step function does not get called.  Below is a simplified version to show the problem.  Using doLoop() or calling schedule.step() myself, the print statement in masterStep() does not execute.

This setup seems to mirror that in the tutorials and documentation, so I'm not sure what I'm missing here.

-frank


package schedPackage;

import sim.engine.SimState;
import sim.engine.Steppable;

public class ScheduleTest extends SimState {
    private static final long serialVersionUID = 1L;
    
public ScheduleTest(long seed) {
super(seed);
Steppable masterStep = new Steppable() {
            private static final long serialVersionUID = 1;
            @Override
            public void step(SimState state) {
            masterStep();
            }
        };
if (schedule.scheduleRepeating(masterStep) == null) {
System.out.println("ERROR: scheduling of masterStep failed");
}

}

public void masterStep() {
System.out.println("Master step executing");
}

public static void main(String[] args) {
//doLoop(ScheduleTest.class, args);
//System.exit(0);
//*
SimState state = new ScheduleTest(System.currentTimeMillis());
System.out.println("Starting sim...");
state.start();
do {
if (!state.schedule.step(state)) break;
} while(state.schedule.getSteps() < 50);
state.finish();
System.exit(0);
//*/
}

}