Loading ...
Sorry, an error occurred while loading the content.

Schedule Prodecures Dynamically

Expand Messages
  • mr_colin_shep
    Hello, I m coming to Netlogo from Swarm and Repast, both systems that allow you to dynamically schedule agent actions for arbitrary future times. While it s
    Message 1 of 7 , Feb 29 11:25 AM
    • 0 Attachment
      Hello, I'm coming to Netlogo from Swarm and Repast, both systems that allow you to dynamically schedule agent actions for arbitrary future times.  While it's not much trouble to accomplish the same effect in Netlogo (e.g. conditionally execute procedures for turtles if they meet certain criteria), there are circumstances where it seems like a computational liability.

      I'm working on a model that needs a relatively high temporal resolution (1-5 minutes) but the turtles only do something a couple/few times per day.  The rest of the time, they sit still.  There will be tens of thousands of turtles and the criteria for deciding whether they do something will be relatively complicated.  Yet, for any turtle, I know based on their state exactly when they need to "activate" later in the day.  So naturally it would make sense to schedule turtles to execute procedures at specific times and let a schedule manager dispatch those actions at the appropriate time and in the appropriate order without repetitively querying and  .

      I've seen some discussion of this desire here  and here, and I can think of some ways to work around the issue (such as adding a variable to the turtle called "do-nothing-until-tick" which can be set to a future time until which the agent's procedures are never executed).

      But I'm wondering if dynamic scheduling is in the pipeline for Netlogo, or if anyone has developed or plans to develop an extension?  Ideally, you could do something like:

      schedule-action procedure-name turtle-agent future-tick

      Which would pass the turtle in "turtle-agent" to the procedure named "procedure-name" at the future time "future-tick".

      Thanks for your thoughts!

    • Seth Tisue
      ... colin But I m wondering if dynamic scheduling is in the pipeline for colin Netlogo, or if anyone has developed or plans to develop an colin extension?
      Message 2 of 7 , Mar 1, 2012
      • 0 Attachment
        >>>>> "colin" == colin shep <colinthegaunt@...> writes:

        colin> But I'm wondering if dynamic scheduling is in the pipeline for
        colin> Netlogo, or if anyone has developed or plans to develop an
        colin> extension? Ideally, you could do something like:

        I think it'd make a great extension.

        We're not working on this ourselves at Northwestern.

        The extension could make good use of the "tasks" feature in NetLogo 5.0.
        It's one of the main use cases I had in mind for tasks, actually.
        <http://ccl.northwestern.edu/netlogo/docs/programming.html#tasks>

        Ken Kahn has done something similar in the context of his Behaviour
        Composer project; see "Behaviour Composer Scheduling Extensions to
        NetLogo" at
        <http://modelling4all.wikidot.com/modelling4all-programming-guide>

        --
        Seth Tisue | Northwestern University | http://tisue.net
        lead developer, NetLogo: http://ccl.northwestern.edu/netlogo/
      • James Steiner
        breed[ events event ] events-own[ %tick %task %prior %next %recurring? %recurrance-logic-reporter ] breed[ queues queue] Queues-own [ first-event ;; aka next
        Message 3 of 7 , Mar 1, 2012
        • 0 Attachment

          breed[  events event ]
          events-own[ %tick %task %prior %next %recurring? %recurrance-logic-reporter ]
          breed[ queues queue]
          Queues-own
          [ first-event ;; aka next event
             ;; any other vars needed for
             ;; queue or tree management
             ;; maybe table extension could
             ;; do it...

          To-report new[ #breed ]
                 ;; caller agnostic turtle factory
                Let $this nobody
                Ask patch min-pxcor min-pycor
                [ sprout 1 [ set $this self. Hide-turtle ] ]
                Report $this
          End

          to-report new-queue
              Let $this new queue
              Ask $this
              [ set first-event nobody
                 ;; other queue/tree initialization, as needed
               ]
               Report $this
          ]

          OK, so, an event is a turtle that owns a tick or whatever time stamp triggers it, and a task,  which could be *anything*, pfrom a procedure call, to an ask against a fixed or variable agent set, to whatever. Also, owns references to the previous and next events in its queue. They can be for the same tick. Also, a flag for recurrence, and a reporter task to calculate the recurrance tick.

          A queue is a turtle that manages a doubly linked list (or tree, or whatever is best) of events.

          You could *not* use a queue turtle,  but I think this is tidier,  and builds in the ability to have arbitrary numbers of event queues.

          You assign 'new-queue' to a global,  then later you use that global as a parameter to the schedule-event procedure(left as an exersize, lol) , which takes a queue reference and a task ( and recurrence info, if you need that), creates the task turtle and inserts the task turtle into the event list (which should probably be a tree, not a list, for efficient insertions without scanning or resorting the whole event list).

          In go, you call do-scheduled-tasks or whatever: it peeks at the first event in the queue, and if the time is right, pops it off the queue, executes the task, and destroys the event (or if recurring, reschedules it), and updates the pointer to first-event. This is repeated until all events for the tick are executed.

          Note that while you could use this to schedule single tasks for indivudual turtles, it can also be used to schedule tasks that refer to whole agentsets, or even *agentset criteria*. So, you can schedule an event for turtles that are currently red to perform , or an event for turtles that are red /at that time/.

          Awesome.

          The full implementation is too much for me to type on my phone right now... But if this seems useful, we can work on fleshing it out.

          ~~James
          www.turtlezero.com

          On Mar 1, 2012 9:38 AM, "mr_colin_shep" <colinthegaunt@...> wrote:


          Hello, I'm coming to Netlogo from Swarm and Repast, both systems that allow you to dynamically schedule agent actions for arbitrary future times.  While it's not much trouble to accomplish the same effect in Netlogo (e.g. conditionally execute procedures for turtles if they meet certain criteria), there are circumstances where it seems like a computational liability.

          I'm working on a model that needs a relatively high temporal resolution (1-5 minutes) but the turtles only do something a couple/few times per day.  The rest of the time, they sit still.  There will be tens of thousands of turtles and the criteria for deciding whether they do something will be relatively complicated.  Yet, for any turtle, I know based on their state exactly when they need to "activate" later in the day.  So naturally it would make sense to schedule turtles to execute procedures at specific times and let a schedule manager dispatch those actions at the appropriate time and in the appropriate order without repetitively querying and  .

          I've seen some discussion of this desire here  and here, and I can think of some ways to work around the issue (such as adding a variable to the turtle called "do-nothing-until-tick" which can be set to a future time until which the agent's procedures are never executed).

          But I'm wondering if dynamic scheduling is in the pipeline for Netlogo, or if anyone has developed or plans to develop an extension?  Ideally, you could do something like:

          schedule-action procedure-name turtle-agent future-tick

          Which would pass the turtle in "turtle-agent" to the procedure named "procedure-name" at the future time "future-tick".

          Thanks for your thoughts!



        • James Steiner
          Whoops. To-report new[ #breed ] ;; caller agnostic turtle factory Let $this nobody Ask patch min-pxcor min-pycor [ sprout 1 [ set $this self set breed #breed
          Message 4 of 7 , Mar 1, 2012
          • 0 Attachment

            Whoops.

            To-report new[ #breed ] ;; caller agnostic turtle factory Let $this nobody Ask patch min-pxcor min-pycor [ sprout 1 [ set $this self set breed #breed  Hide-turtle ] ] Report $this End

            ~~James

            On Mar 1, 2012 6:19 PM, "James Steiner" <gregortroll@...> wrote:

            breed[  events event ]
            events-own[ %tick %task %prior %next %recurring? %recurrance-logic-reporter ]
            breed[ queues queue]
            Queues-own
            [ first-event ;; aka next event
               ;; any other vars needed for
               ;; queue or tree management
               ;; maybe table extension could
               ;; do it...

            To-report new[ #breed ]
                   ;; caller agnostic turtle factory
                  Let $this nobody
                  Ask patch min-pxcor min-pycor
                  [ sprout 1 [ set $this self. Hide-turtle ] ]
                  Report $this
            End

            to-report new-queue
                Let $this new queue
                Ask $this
                [ set first-event nobody
                   ;; other queue/tree initialization, as needed
                 ]
                 Report $this
            ]

            OK, so, an event is a turtle that owns a tick or whatever time stamp triggers it, and a task,  which could be *anything*, pfrom a procedure call, to an ask against a fixed or variable agent set, to whatever. Also, owns references to the previous and next events in its queue. They can be for the same tick. Also, a flag for recurrence, and a reporter task to calculate the recurrance tick.

            A queue is a turtle that manages a doubly linked list (or tree, or whatever is best) of events.

            You could *not* use a queue turtle,  but I think this is tidier,  and builds in the ability to have arbitrary numbers of event queues.

            You assign 'new-queue' to a global,  then later you use that global as a parameter to the schedule-event procedure(left as an exersize, lol) , which takes a queue reference and a task ( and recurrence info, if you need that), creates the task turtle and inserts the task turtle into the event list (which should probably be a tree, not a list, for efficient insertions without scanning or resorting the whole event list).

            In go, you call do-scheduled-tasks or whatever: it peeks at the first event in the queue, and if the time is right, pops it off the queue, executes the task, and destroys the event (or if recurring, reschedules it), and updates the pointer to first-event. This is repeated until all events for the tick are executed.

            Note that while you could use this to schedule single tasks for indivudual turtles, it can also be used to schedule tasks that refer to whole agentsets, or even *agentset criteria*. So, you can schedule an event for turtles that are currently red to perform , or an event for turtles that are red /at that time/.

            Awesome.

            The full implementation is too much for me to type on my phone right now... But if this seems useful, we can work on fleshing it out.

            ~~James
            www.turtlezero.com

            On Mar 1, 2012 9:38 AM, "mr_colin_shep" <colinthegaunt@...> wrote:


            Hello, I'm coming to Netlogo from Swarm and Repast, both systems that allow you to dynamically schedule agent actions for arbitrary future times.  While it's not much trouble to accomplish the same effect in Netlogo (e.g. conditionally execute procedures for turtles if they meet certain criteria), there are circumstances where it seems like a computational liability.

            I'm working on a model that needs a relatively high temporal resolution (1-5 minutes) but the turtles only do something a couple/few times per day.  The rest of the time, they sit still.  There will be tens of thousands of turtles and the criteria for deciding whether they do something will be relatively complicated.  Yet, for any turtle, I know based on their state exactly when they need to "activate" later in the day.  So naturally it would make sense to schedule turtles to execute procedures at specific times and let a schedule manager dispatch those actions at the appropriate time and in the appropriate order without repetitively querying and  .

            I've seen some discussion of this desire here  and here, and I can think of some ways to work around the issue (such as adding a variable to the turtle called "do-nothing-until-tick" which can be set to a future time until which the agent's procedures are never executed).

            But I'm wondering if dynamic scheduling is in the pipeline for Netlogo, or if anyone has developed or plans to develop an extension?  Ideally, you could do something like:

            schedule-action procedure-name turtle-agent future-tick

            Which would pass the turtle in "turtle-agent" to the procedure named "procedure-name" at the future time "future-tick".

            Thanks for your thoughts!



          • Ken Kahn
            And as soon as NetLogo 5.0 was released the Behaviour Composer was changed to generate NetLogo code that uses tasks for scheduling. Much nicer than the older
            Message 5 of 7 , Mar 2, 2012
            • 0 Attachment
              And as soon as NetLogo 5.0 was released the Behaviour Composer was changed to generate NetLogo code that uses tasks for scheduling. Much nicer than the older scheme of generating procedures for each scheduled bit of code.

              The implementation of the scheduler is inside of this file (along with lots of other things, sorry):

              http://m.modelling4all.org/p/bc_auxillary_file_from_download_tab_version_15.nls 

              -ken kahn

              On 1 March 2012 18:54, Seth Tisue <seth@...> wrote:

              Ken Kahn has done something similar in the context of his Behaviour
              Composer project; see "Behaviour Composer Scheduling Extensions to
              NetLogo" at
              <http://modelling4all.wikidot.com/modelling4all-programming-guide>


            • mr_colin_shep
              Hi Seth and the rest who responded to this thread. TLDR: Can I use the netlogo API to create a context for an agent which I can pass to the perform method of a
              Message 6 of 7 , May 27, 2012
              • 0 Attachment
                Hi Seth and the rest who responded to this thread.

                TLDR:

                Can I use the netlogo API to create a context for an agent which I can pass to the perform method of a task in order to dispatch that task for that agent?

                More explanation:

                First, thanks for your responses back in March. I didn't have time to revisit this issues until now. I began by following James' advice and quickly decided that all of the overhead to manage a queue of events as a tree (instead of a sorted list) was a bit onerous and cumbersome in Netlogo and unlikely to be something anyone else would ever use, so I decided to attempt writing an extension which could have a very simple, intuitive interface:

                https://github.com/colinsheppard/Dynamic-Scheduler-Extension

                I've got the extension developed to the point where it can create a schedule and accept events in the form of an agent (not agentsets yet), a task, and a tick. It stores them in a TreeSet which orders them by tick, then id in the case of "simultaneous" events. The dynamic-schedule:go command then dispatches all of the events in the current tick including events dynamically scheduled during that tick.

                See the examples sub-directory for a sample run.

                The big issue I'm having is I can't figure out how to perform a task from the agent context, only from the context passed into the "perform" method of the go command which in my sample model is the observer context. You can see in DynamicSchedulerExtension.java on lines 294-297 some commented attempts to make an AgentSet and/or a new Context to pass to Task.perform, but these don't seem to be possible via the API.

                Is it possible to do what I'm seeking via the netlogo API or some other way?

                Thanks!
                Colin


                --- In netlogo-users@yahoogroups.com, Seth Tisue <seth@...> wrote:
                >
                > >>>>> "colin" == colin shep <colinthegaunt@...> writes:
                >
                > colin> But I'm wondering if dynamic scheduling is in the pipeline for
                > colin> Netlogo, or if anyone has developed or plans to develop an
                > colin> extension? Ideally, you could do something like:
                >
                > I think it'd make a great extension.
                >
                > We're not working on this ourselves at Northwestern.
                >
                > The extension could make good use of the "tasks" feature in NetLogo 5.0.
                > It's one of the main use cases I had in mind for tasks, actually.
                > <http://ccl.northwestern.edu/netlogo/docs/programming.html#tasks>
                >
                > Ken Kahn has done something similar in the context of his Behaviour
                > Composer project; see "Behaviour Composer Scheduling Extensions to
                > NetLogo" at
                > <http://modelling4all.wikidot.com/modelling4all-programming-guide>
                >
                > --
                > Seth Tisue | Northwestern University | http://tisue.net
                > lead developer, NetLogo: http://ccl.northwestern.edu/netlogo/
                >
              • Seth Tisue
                ... colin Can I use the netlogo API to create a context for an agent which colin I can pass to the perform method of a task in order to dispatch colin that
                Message 7 of 7 , May 29, 2012
                • 0 Attachment
                  >>>>> "colin" == colin shep <colinthegaunt@...> writes:

                  colin> Can I use the netlogo API to create a context for an agent which
                  colin> I can pass to the perform method of a task in order to dispatch
                  colin> that task for that agent?

                  I've replied here:
                  https://groups.google.com/d/topic/netlogo-devel/4q7T_KlCse4/discussion

                  --
                  Seth Tisue | Northwestern University | http://tisue.net
                  lead developer, NetLogo: http://ccl.northwestern.edu/netlogo/
                Your message has been successfully submitted and would be delivered to recipients shortly.