Agent goal-list demo
Model was written in NetLogo 5.0.3
•
Viewed 929 times
•
Downloaded 67 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
NETLOGO GOALS EXAMPLE
This example is explained in the tutorial at http://scientificgems.wordpress.com/2014/01/17/agent-goals-in-netlogo-a-list-tutorial/
RUNNING IT
Click SETUP to start. Clicking GO makes each agent execute this list of four goals:
[ "goto" 3 3 "meet" 7 "scatter" "meet" 0 ]
Use NEW-GOAL and ADD-GOALS to add entries on the end of the goal lists.
Comments and Questions
Click to Run Model
turtles-own [ id ;; agent id number or name (usually a copy of "who") speed ;; agent speed in cells per tick goal ;; goal list ] to setup clear-all crt 20 [ setxy random-xcor random-ycor set speed (0.1 + (random-float (max-agent-speed - 0.1))) set size 3 set id who set goal [ "goto" 3 3 "meet" 7 "scatter" "meet" 0 ] set label id ] reset-ticks end to add-goals ask turtles [ set goal (sentence goal (read-from-string new-goal)) if (verbose) [ show (fput "goal =" goal) ] ] end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; NetLogo code for obeying instructions ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; to obey if (goal != []) [ let kind (item 0 goal) if-else (kind = "goto") [ if (obey-goto (item 1 goal) (item 2 goal)) [ drop3-goal ] ] [ if-else (kind = "meet") [ if (obey-meet (item 1 goal)) [ drop2-goal ] ] [ if-else (kind = "scatter") [ obey-scatter ] [ obey-unknown kind ] ] ] ] end to drop-goal set goal (bf goal) end to drop2-goal set goal (bf (bf goal)) end to drop3-goal set goal (bf (bf (bf goal))) end to obey-unknown [ g ] show (list "unknown goal" g) drop-goal end to obey-scatter let new-x random-xcor let new-y random-ycor if (verbose) [ show (list "scattering to" new-x new-y) ] set goal (sentence (list "goto" new-x new-y) (bf goal)) end to-report obey-goto [ x y ] ;; obey "goto x y" command; report true when achieved let d (distancexy x y) if-else (d = 0) [ if (verbose) [ show (list "already at" x y) ] report true ] [ facexy x y if-else (d <= speed) [ setxy x y if (verbose) [ show (list "have reached" x y) ] report true ] [ fd speed report false ] ] end to-report obey-meet [ ag-id ] ;; obey "meet agent" command; report true when achieved let him (one-of (turtles with [ id = ag-id ])) if-else (him = self) [ if (verbose) [ show (list "i am" him) ] report true ] [ face him let d (distance him) if-else (d <= speed) [ move-to him if (verbose) [ show (list "have met" him) ] report true ] [ fd speed report false ] ] end to go if (count (turtles with [ goal != []]) = 0) [ stop ] ask turtles [ obey ] tick end
There is only one version of this model, created almost 11 years ago by Anthony Dekker.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Agent goal-list demo.png | preview | Preview for 'Agent goal-list demo' | almost 11 years ago, by Anthony Dekker | Download |
This model does not have any ancestors.
This model does not have any descendants.
Anthony Dekker
Explanation
This model is associated with a tutorial at http://scientificgems.wordpress.com/2014/01/17/agent-goals-in-netlogo-a-list-tutorial/
Posted almost 11 years ago
Sana Maqbool
new model , want suggestion and guidance
I want to create a model in which there are two populations of customers and providers. customers can request for service and provider fulfill it by accepting request.
Posted almost 11 years ago
Anthony Dekker
reply
Sana, I would tackle that with a global list of requests, which customers add to, and providers fulfil. The requests themselves can be lists, containing relevant details, including references to the customer agent, if needed.
Posted almost 11 years ago