Simone, I suggest you do not write your own loop, period. Instead, use doLoop().
All initialization (or re-initialization) of your model should be done in start().
There is no need for schedule.getTime()==-1 (and you should not use -1 anyway, use a proper constant), since start() is always called before the simulation, you know, starts.
Sean
On Aug 1, 2014, at 6:22 PM, Simone Gabbriellini <[log in to unmask]> wrote:
> Hello,
>
> I need to setup my agents before entering the big loop, and I am wondering where to call an initialize() method... right now I have this code:
>
> public void start() {
> super.start(); //use the previously defined code, then we add our own.
> if(schedule.getTime()==-1){
> initialize();
> }
> mach();
> totcredit();
> }
>
> is there a better approach to this? I tried this in my main, but initialize() is not called:
>
> static void main(String[] args) throws Exception {
> SimulationEnvironment state = new SimulationEnvironment(System.currentTimeMillis());
> state.nameThread();
> for (int job = 0; job < MC; job++) {
> state.setJob(job);
> state.initialize();
> state.start();
> do {
> if (!state.schedule.step(state)) {
> break;
> }
> } while (state.schedule.getSteps() < T);
> state.finish();
> }
> System.exit(0);
> }
>
> best,
> Simone
> --
> -----------------------------------------------------------------
>
> Simone Gabbriellini, PhD
>
> Post-doctoral Researcher
> ANR founded research project "DIFFCERAM"
> GEMASS, CNRS & Paris-Sorbonne.
>
> mobile: +39 340 39 75 626
> email: [log in to unmask]
|