Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init with event list clears the list #5

Closed
matthewsowders opened this issue Feb 9, 2017 · 9 comments
Closed

init with event list clears the list #5

matthewsowders opened this issue Feb 9, 2017 · 9 comments
Assignees
Labels

Comments

@matthewsowders
Copy link

https://github.com/umontreal-simul/ssj/blob/master/src/main/java/umontreal/ssj/simevents/Simulator.java#L122

The method comment says 'To initialize the current Simulator with a not empty eventList is also possible, but the events scheduled in the eventList will be linked with the current simulator only.', but the method calls init() on line 129 which in turn clears the event list on line 110 so it does not look like it is possible to initialize the simulator with a non-empty event list.

@chwyean
Copy link
Member

chwyean commented Feb 10, 2017

Good catch @matthewsowders !

@pierrelecuyer: Do you know why it is coded this way? We can call init() earlier, so the evlist won't be emptied. However, the old eventList will be emptied.

  public void init (EventList evlist) {
      if (evlist == null)
         throw new NullPointerException();
      init();
      eventList = evlist;

Otherwise, we'll have to remove that sentence from the javadoc.

@chwyean
Copy link
Member

chwyean commented Feb 13, 2017

@matthewsowders : Could you describe/explain the reason you would need to initialize the simulator with a non-empty event list (instead of adding the events after initialization)?
We are trying to assess the need to allow init to keep a non-empty event list, because the events can be added after the initialization. We could create a new method that would allow the user to replace the event list.

@matthewsowders
Copy link
Author

I would like to run simulations that will run for 12 hours or more. I would like to make the system fault tolerant so I'd like to be able to serialize the state of the simulator (time, event data and schedule) at certain events. I would store the intermediate state in some service like S3 and use SimpleWorkflowService to manage the long running process that way if the simulation fails 11 hours into a 12 hour simulation, I can take the most recent state and continue the simulation from that point. I've attached some sample code. Let me know if I'm trying to do this a dumb way.

sample-code.zip

@pierrelecuyer
Copy link
Member

pierrelecuyer commented Feb 13, 2017 via email

@pierrelecuyer
Copy link
Member

pierrelecuyer commented Feb 13, 2017 via email

@matthewsowders
Copy link
Author

pierrelecuyer@

It could be made as an extension point such that the client is responsible for passing in a serializer/deserializer (I used jackson, but other users might want java serialization or something else). Then again, it was easy to write so maybe it is best left out of the simulation package. Maybe it would be better as an extension package outside SSJ, something like SSJ-serialization. Do you think it will be useful to others?

@pierrelecuyer
Copy link
Member

pierrelecuyer commented Feb 15, 2017 via email

@chwyean
Copy link
Member

chwyean commented Feb 21, 2017

I have corrected the javadoc: 2d82af5
It now states that the event list evlist will be cleared. If the user wants to initialize with a non-empty list, then he can extend the class Simulator and implement his initialization method.

There are many ways to manage serialization, and it is likely implementation dependent. It is best left for advanced user to extend the Simulator, which is not too difficult as shown by @matthewsowders.

@chwyean chwyean closed this as completed Feb 21, 2017
@matthewsowders
Copy link
Author

Thanks to both of you for looking into this!

@chwyean chwyean reopened this Feb 21, 2017
@chwyean chwyean closed this as completed Feb 21, 2017
pierrelecuyer added a commit that referenced this issue Sep 12, 2020
Merge pull request #45 from pierrelecuyer/master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants