distance between an individual patch and a list of agents

520 views
Skip to first unread message

M_ Ahmed Rusho

unread,
Feb 21, 2021, 3:34:30 AM2/21/21
to netlogo-users
Hi, I am new to Netlogo and have pretty basic programming skills. In developing my model I am stuck at the following part:

I have assigned the patches a variable called nearby-turtles which stores the turtles nearby as list

ex: 
patches-own [nearby-turtles]

ask patches [set nearby-turtles []]

to setup

create-turtles 10 [
     ask patches at-points nearby ;;;where nearby are set of certain co-ordinates
         [
             set nearby-turtles fput myself nearby-turtles
        ]
end
;;; this gives me a list of agents which are near to the particular patch, ex: [turtle 0 turtle 4 turtle 6]

;;;now I want to assign another variable to the patch which will create a list of distance of  each of these nearby turtles from the patch. For example if the nearby-turtles are [turtle 0 turtle 4 turtle 6] then the new variable for the patch should be like [3.44 2.67 2.99] where 3.44 is the distance of turtle 0 from the patch etc. Please help.


 


Klaus G. Troitzsch

unread,
Feb 21, 2021, 5:42:10 AM2/21/21
to netlog...@googlegroups.com, klaus.g....@bluewin.ch

.. perhaps it would be better to define nearby-turtles as an agentset instead of as a list, then the distances can be calculated as

set nearby-turtles-distances [ distance myself ] nearby-turtles

Good luck

Klaus

Prof. (i.R.) Dr. Klaus G. Troitzsch
Schillerstraße 26
79713 Bad Säckingen
oder
Aeussere Dorfstrasse 39
3718 Kandersteg, Schweiz
Telefon +49 7761 9982074/5 bzw. +41 33 6750166
klaus.g....@bluewin.ch
https://www.uni-koblenz-landau.de/en/campus-koblenz/fb4/iwvi/former-rg/rgtroitzsch/klaus-troitzsch
https://klausgtroitzsch.academia.edu/
--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/506ddc5a-12fc-48aa-b1f1-56c264260e82n%40googlegroups.com.

wade.s...@gmail.com

unread,
Feb 21, 2021, 6:43:21 AM2/21/21
to netlogo-users
Turns out  I posted a solution to this problem and managing the twin lists in the modeling commons

Here's a snippet of that code:
 ;; get a list of my neighbors
    let nearbylist [self] of neighbors

 ;; create a list of indices
    let listplace n-values (  length nearbylist) [ i -> i]

    ;; create a list of distance of each neighbor from the forest centroid
    let dlist [];
    foreach nearbylist [ x -> ask (patch xc yc) [ set dlist lput distance x dlist]  ]
       

Wade
Reply all
Reply to author
Forward
0 new messages