Sender: |
|
Subject: |
|
From: |
|
Date: |
Thu, 5 Sep 2013 09:55:53 -0600 |
Content-Type: |
multipart/alternative; boundary=f46d0443044ee9df2804e5a4f446 |
MIME-Version: |
1.0 |
Reply-To: |
|
Parts/Attachments: |
|
|
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);
//*/
}
}
|
|
|