jasmineRepo / LabourForceParticipation

A microsimulation model developed for the project "Anticipating the future trend of female labour market participation and its impact on economic growth", prepared for the European Foundation for the Improvement of Living and Working Conditions as Lot 3 of "The gender and employment gap: Challenges and Solutions", awarded to LABORatorio Revelli Centre for Employment Studies, Moncalieri, Italy.
2 stars 0 forks source link

event generation #3

Closed Crisgo11 closed 4 years ago

Crisgo11 commented 5 years ago

good day professor Ross, I'm looking for the use of the engine events generator just for specific moments on the run, this it, not to trigger the events generator at every step of the simulation, but in a line of time. how I can do this? thanks

rer98 commented 5 years ago

Hi Crisgo11,

The way to schedule events is discussed in the documentation section of the JAS-mine website here: http://www.jas-mine.net/home/documentation/cookbook/the-model-and-the-schedule

You can schedule a single event to take place using the 'scheduleOnce()' method of the EventQueue class from the event package. As specified in the Javadocs (see https://htmlpreview.github.io/?https://raw.githubusercontent.com/jasmineRepo/JAS-mine-core/master/microsim-core/doc/microsim/event/EventQueue.html), the method signature is:

public EventQueue scheduleOnce(Event event, double atTime, int withOrdering)

The parameters are:

event - the event to be fired.

atTime - The time when event will be fired.

withOrdering - The order that the event will be fired: for two events e1 and e2 scheduled to occur at the same time (e1.time == e2.time), if e1.ordering < e2.ordering, then e1 will be fired first. If e1.time == e2.time AND e1.ordering == e2.ordering, the first event that was scheduled (added to the EventQueue) will be fired first.

You can see an example of this being used in the documentation of the JAS-mine website in the link above, and also if you are using the 'JAS-mine plugin for Eclipse IDE' to create a new JAS-mine project:- in the model class there is a method called buildSchedule(). In the buildSchedule() method, we schedule a single event to trigger the termination of the simulation using the scheduleOnce() method of the eventQueue class, as in the following line:

getEngine().getEventQueue().scheduleOnce(new SingleTargetEvent(this, Processes.End), endTime, Order.AFTER_ALL.getOrdering());

So the first argument of scheduleOnce is used to specify the event that will be fired, the second argument is the time at which the event is to be fired, and the final argument determines the order in which this event is fired, if there are events that are also due to be fired at the same time.

Note how this compares to repeated events, which are scheduled using the scheduleRepeat() method as follows:

public EventQueue scheduleRepeat(Event event, double atTime, int withOrdering, double timeBetweenEvents)

which has an additional parameter called:

timeBetweenEvents - The time period between repeated firing of the event. If this parameter is set to 0, this event will not be fired more than once.

Finally, to perform what we call 'dynamic scheduling', which may actually be what you want to do, i.e. to schedule an event within any method of your code, you can use the following line to schedule a single event:

SimulationEngine.getInstance().getEventQueue().scheduleOnce(event, atTime, withOrdering);

and the following line to schedule a repeated event:

SimulationEngine.getInstance().getEventQueue().scheduleRepeat(event, atTime, withOrdering, timeBetweenEvents);

Then all you need to do is specify the appropriate arguments for event, atTime, withOrdering, and timeBetweenEvents.

I hope this answers your question, but please let me know if you need any more help!

Best wishes,

Ross

Crisgo11 commented 5 years ago

Dear professor Thank you very much for your answer, now I'm clear about the use of this methods

best regards

El mar., 22 ene. 2019 a las 18:10, Ross Richardson (< notifications@github.com>) escribió:

Hi Crisgo11,

The way to schedule events is discussed in the documentation section of the JAS-mine website here:

http://www.jas-mine.net/home/documentation/cookbook/the-model-and-the-schedule

You can schedule a single event to take place using the 'scheduleOnce()' method of the EventQueue class from the event package. As specified in the Javadocs, the method signature is:

public EventQueue scheduleOnce(Event event, double atTime, int withOrdering)

The parameters are:

event - the event to be fired.

atTime - The time when event will be fired.

withOrdering - The order that the event will be fired: for two events e1 and e2 scheduled to occur at the same time (e1.time == e2.time), if e1.ordering < e2.ordering, then e1 will be fired first. If e1.time == e2.time AND e1.ordering == e2.ordering, the first event that was scheduled (added to the EventQueue) will be fired first.

You can see an example of this being used in the documentation of the JAS-mine website in the link above, and also if you are using the 'JAS-mine plugin for Eclipse IDE' to create a new JAS-mine project:- in the model class there is a method called buildSchedule(). In the buildSchedule() method, we schedule a single event to trigger the termination of the simulation using the scheduleOnce() method of the eventQueue class, as in the following line:

getEngine().getEventQueue().scheduleOnce(new SingleTargetEvent(this, Processes.End), endTime, Order.AFTER_ALL.getOrdering());

So the first argument of scheduleOnce is used to specify the event that will be fired, the second argument is the time at which the event is to be fired, and the final argument determines the order in which this event is fired, if there are events that are also due to be fired at the same time.

Note how this compares to repeated events, which are scheduled using the scheduleRepeat() method as follows:

public EventQueue scheduleRepeat(Event event, double atTime, int withOrdering, double timeBetweenEvents)

which has an additional parameter called:

timeBetweenEvents - The time period between repeated firing of the event. If this parameter is set to 0, this event will not be fired more than once.

I hope this answers your question, but please let me know if you need any more help!

Best wishes,

Ross

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jasmineRepo/LabourForceParticipation/issues/3#issuecomment-456599211, or mute the thread https://github.com/notifications/unsubscribe-auth/AckQNxlbvsKRalYWhze5fjlaXmkvXcvaks5vF5pWgaJpZM4aDP9m .

-- Cristian G Gómez Marín PhD (c) Universidad Nacional de Colombia cell phone +39 351 5950100 whatsapp +57 3006106153 crggomezma@unal.edu.co