Attributing patches with direction to target patch.

29 views
Skip to first unread message

cycadmedia

unread,
Oct 5, 2019, 9:15:19 PM10/5/19
to netlogo-users
I am trying to assign all patches a direction value relative to one single patch. I have tried sprouting turtles or moving turtles across all patches and facing the turtle towards a set target patch with the heading value then given to each patch as it moves. This works but is very slow especially for larger grids. As a patch can not 'face towards' I can not think of a patch only way to do this. Any suggestions?

Dale Frakes

unread,
Oct 5, 2019, 10:01:28 PM10/5/19
to cycadmedia, netlogo-users
You might try looking at "gradient" (see Ants in Model Library), or maybe add a special breed that's invisible and sits one per patch and can do a head-towards.




On October 5, 2019 6:15:19 PM PDT, cycadmedia <cycad...@gmail.com> wrote:
I am trying to assign all patches a direction value relative to one single patch. I have tried sprouting turtles or moving turtles across all patches and facing the turtle towards a set target patch with the heading value then given to each patch as it moves. This works but is very slow especially for larger grids. As a patch can not 'face towards' I can not think of a patch only way to do this. Any suggestions?

--
Dale Frakes
E-mail: dfr...@gmail.com ** Web: http://www.dalefrakes.com

"that white light is made of colors, that color measures light waves,
that transparent air reflects light...? It does no harm to the romance
of a sunset to know a little about it." -Carl Sagan

Pradeesh Kumar K V

unread,
Oct 5, 2019, 10:24:58 PM10/5/19
to cycadmedia, netlogo-users
Maybe you could make the desired patch as a proxy origin and assign proxy x and proxy y values for all other patches relative to the desired patch x and y values. For example, if the desired patch is at (Xo,Yo) = (2,3), then the patch can be assigned proxy-x 0 and proxy-y 0. The patch next to it will then have proxy-x and proxy-y = (X - Xo, Y - Yo) = (3 - 2, 3 - 3) = (1, 0)

In this way all patches will be positioned relative to the desired patch.

On Sun, Oct 6, 2019 at 6:45 AM cycadmedia <cycad...@gmail.com> wrote:
I am trying to assign all patches a direction value relative to one single patch. I have tried sprouting turtles or moving turtles across all patches and facing the turtle towards a set target patch with the heading value then given to each patch as it moves. This works but is very slow especially for larger grids. As a patch can not 'face towards' I can not think of a patch only way to do this. Any suggestions?

--
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/bf8bb02a-8538-4a18-b4c2-18bd35c56db2%40googlegroups.com.

Dale Frakes

unread,
Oct 6, 2019, 3:00:19 AM10/6/19
to netlog...@googlegroups.com
Here's a solution that seems to work like you expect... you can't "face" a patch, but since a patch is just a special kind of agent, you can still use "towards" between it and another patch or turtle. (Adapted from "Ants")

patches-own [
 
  nest?                ;; true on nest patches, false elsewhere
  nest-direction           ;; number that is heading to "nest" patch
]

;;;;;;;;;;;;;;;;;;;;;;;;
;;; Setup procedures ;;;
;;;;;;;;;;;;;;;;;;;;;;;;

to setup
  clear-all

  ask patches [
    set nest? false
  ]

  let #nest-patch one-of patches
  ask #nest-patch [
    set nest? true
    set pcolor white
  ]
 
  ask patches with [nest? = false] [
    set nest-direction towards #nest-patch
    set plabel precision nest-direction 1
  ]

  reset-ticks
end

It comes out looking like this:
of a sunset to know a little about it." -Carl Sagan --
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/AC170F4F-7C23-4EB5-8EC2-D950C0FDD9A4%40gmail.com.

-- 
Dale Frakes
Adjunct Instructor, PhD Candidate
PSU Systems Science
dfr...@pdx.edu - http://web.pdx.edu/~dfrakes/
Patch_Heading_to_One_Patch.nlogo

rohan fisher

unread,
Oct 6, 2019, 7:10:03 PM10/6/19
to Dale Frakes, netlog...@googlegroups.com
Brilliant, thank you!


Minor query - why the # in front of the #nest-patch?

jdopbgfbcaaeoiha.png

Dale Frakes

unread,
Oct 6, 2019, 9:15:28 PM10/6/19
to rohan fisher, netlog...@googlegroups.com
Hi Rohan,

the # in front of the variable is just a convention I use for
variables that are local to a procedure/reporter - it makes it obvious
to me that they're not a turtle, patch, or global variable.

I don't remember where I picked this up, but it works well for me.

Dale
>> On 10/5/19 7:01 PM, Dale Frakes wrote:
>>
>> You might try looking at "gradient" (see Ants in Model Library), or maybe
>> add a special breed that's invisible and sits one per patch and can do a
>> head-towards.
>>
>>
>>
>> On October 5, 2019 6:15:19 PM PDT, cycadmedia <cycad...@gmail.com>
>> <cycad...@gmail.com> wrote:
>>>
>>> I am trying to assign all patches a direction value relative to one
>>> single patch. I have tried sprouting turtles or moving turtles across all
>>> patches and facing the turtle towards a set target patch with the heading
>>> value then given to each patch as it moves. This works but is very slow
>>> especially for larger grids. As a patch can not 'face towards' I can not
>>> think of a patch only way to do this. Any suggestions?
>>>
>>>
>> --
>> Dale Frakes
>> E-mail: dfr...@gmail.com ** Web: http://www.dalefrakes.com
>>
>> "that white light is made of colors, that color measures light waves,
>> that transparent air reflects light...? It does no harm to the romance
>> of a sunset to know a little about it." -Carl Sagan --
>> 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/AC170F4F-7C23-4EB5-8EC2-D950C0FDD9A4%40gmail.com
>> <https://groups.google.com/d/msgid/netlogo-users/AC170F4F-7C23-4EB5-8EC2-D950C0FDD9A4%40gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>>
>> --
>> Dale Frakes
>> Adjunct Instructor, PhD Candidate
>> PSU Systems Science...@pdx.edu - http://web.pdx.edu/~dfrakes/
>>
>> --
>> 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/853d1a1b-9477-269a-ec07-db871475601b%40pdx.edu
>> <https://groups.google.com/d/msgid/netlogo-users/853d1a1b-9477-269a-ec07-db871475601b%40pdx.edu?utm_medium=email&utm_source=footer>
>> .
>>
>


--
Dale Frakes
Adjunct Instructor, PhD Student
Reply all
Reply to author
Forward
0 new messages