discrete time scheduler

No preview image

1 collaborator

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.1.0 • Viewed 205 times • Downloaded 21 times • Run 0 times
Download the 'discrete time scheduler' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

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 over 9 years ago by Geerten Hengeveld.

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.