discrete time scheduler
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
an example of how discrete time simulation would work using a turtle breed as events and using the task operator
HOW IT WORKS
the breed [events event] keeps track of the who-when-what of each action each action can result in a next action, then a new event should be initiated
put the speed to slow to see what is happening.
THINGS TO NOTICE
the rabbits are just in here to proof the concept. so is the pause switch
THINGS TO TRY
see if you can make a different breed (say sheep) move through
EXTENDING THE MODEL
there is a difficulty with calling observer context actions in trutle context e.g. tick ask patches []
would be good to be able to use ticks for some parts (e.g. plotting or something) while using the event-scheduling for other parts.
NETLOGO FEATURES
there is the use of taks to define the what. this has the advantage that a turtle can have multiple actions scheduled. it has the disadvantage that is a turlte dies, there can still be events scheduled for it.
it also has the disadvantage that if the context of a turtle changes, this might not be reflected in the next action taken.
so one should be clear that actions affecting eachother in the timeline, should be placed in the scheduler one-after-another, while actions not-affecting eachother in the timeline, can be place in the scheudle simultaneously.
CREDITS AND REFERENCES
geerten.hengeveld@wur.nl with thanks to James Steiner for the suggestion on tasks
Comments and Questions
globals [current_time Rabbit_hunger_time Rabbit_fear_time ] breed [events event] breed [rabbits rabbit] events-own [ event_time event_target event_task] ;#Thanks @James, this is indeed a smart thing. now a turtle can schedule multiple future activities, independent of each othter ; eventscheduler to event_initiate [I_time I_target I_task] ;define the when-who-what of the vent set hidden? true set event_time current_time + I_time set event_target I_target set event_task I_task end to event_do_event ;the execution of an event set current_time event_time ;adjust the global time to the time at which this event takes place ask event_target [run [event_task] of myself] ;make the event happen die ;remove this event from the world end to go ;the event scheduler, take the first event and execute it while [any? events] [ if(PAUSE = true)[stop] ;this is to stop the while=loop. ask min-one-of events [event_time][event_do_event] ;the core of the scheduler ] end ;//##rabbit activity procedures## just some funny procedures to setup ca set Rabbit_hunger_time 3 set Rabbit_fear_time 20 create-rabbits 25 ;create 25 rabbits, call all the activities to put them on the events list... might probably be smarter [rabbit_eat rabbit_lookout rabbit_hop ] end to rabbit_eat set shape "rabbit_eat" hatch-events 1 [ event_initiate random-float rabbit_hunger_time myself task rabbit_eat] end to rabbit_lookout set shape "rabbit_lookout" hatch-events 1 [ event_initiate random-float Rabbit_fear_time myself task rabbit_lookout] end to rabbit_hop set shape "rabbit_hop" set heading random 360 fd 1 hatch-events 1 [event_initiate 1 myself task rabbit_hop] end
There is only one version of this model, created almost 11 years ago by Geerten Hengeveld.
Attached files
No files
This model does not have any ancestors.
This model does not have any descendants.