## Re: [netlogo-users] How do I integrate data from neighboring patches in turtles-own function?

Expand Messages
• Hi. Well, the first thing to check is: make sure that every patch has time to set the four attributes before ANY turtles try and use that data. It may be that
Message 1 of 13 , Oct 1, 2011
• 0 Attachment
Hi.

Well, the first thing to check is: make sure that every patch has time to set the four attributes before ANY turtles try and use that data.  It may be that the error message is due to a turtle trying to access data from a patch-neighbor that hasn't yet set a, b, c, and d.

-Ted

On Fri, Sep 30, 2011 at 6:35 PM, gaklemm wrote:

Hi,

I think this is an easy problem, but I am fairly new to NetLogo, and programming in general.

I want my turtles to be able to retrieve data from neighboring (Moore) patches, then use this data in a turtle-specific function and be able to attribute the outcome of the function to the respective patch that supplied the data.

For instance, if patches have the attributes

set a random-float 1
set b random-float 1
set c random 100
set d random 100

(a, b, c, d are patches-own)

and the turtle uses these data to calculate set Z [x * (a * c) + y * (b * d)], then how do I achieve that the turtle can separately identify the Z value that comes from the data of each neighboring patch and match it with that patch?

(Z is turtles-own)

It is absolutely no problem if they turtle uses the data from the patch it stands on, but when trying to use the data from neighbors, I always get an error message whatever I try. Is there a way around this without moving attributes to globals []?

To complicate things more, there is another function set [r = c / w] where r and w is also turtles-own. ... And, finally set Q [Z * r] with Q also turtles-own will yield the number that the turtles needs and match it to each neighbor, where the patch with the data that yields Q max will be chosen by the turtle.

Any attempts to help appreciated. Thanks.

--
Ted Carmichael, Ph.D.
Complex Systems Institute
Department of Software and Information Systems
College of Computing and Informatics
310-A Woodward Hall
UNC Charlotte
Charlotte, NC 28223

• Exactly how we do this entirely depends on how you need to relate the value back to the patch... it could be done on the fly using ASK or WITH, or we could
Message 2 of 13 , Oct 1, 2011
• 0 Attachment
Exactly how we do this entirely depends on how you need to "relate"
the value back to the patch... it could be done on the fly using ASK
or WITH, or we could make a list containing the patches and the
results. That's what I'm doing here.

Assuming that you have a procedure, like CALC-Z that a patch runs to
return the value of Z, like so:

to-report CALC-Z report (pxcor * (a * c) + pycor * (b * d)) end

We can use OF NEIGBORS...

let Z [LIST SELF calc-z] OF NEIGHBORS

A key concept, above and beyond all the magic of OF, is that a patch
or other agent can be "stored" in a variable... it's really a
reference to the agent, but that's exactly what we want here.

Now, you can use the Z values, search them, whatever, and as long as
you know the list index of the value you are interested in, you can
use that index to get back to the patch.

Again, depending on what you do next, this could be much simpler,
LIke, finding the patch with the max Z:

let big-z max-one-of neighbors [ CALC-Z ]

~~James

On 9/30/11, gaklemm <gaklemm@...> wrote:
> Hi,
>
> I think this is an easy problem, but I am fairly new to NetLogo, and
> programming in general.
>
> I want my turtles to be able to retrieve data from neighboring (Moore)
> patches, then use this data in a turtle-specific function and be able to
> attribute the outcome of the function to the respective patch that supplied
> the data.
>
> For instance, if patches have the attributes
>
> set a random-float 1
> set b random-float 1
> set c random 100
> set d random 100
>
> (a, b, c, d are patches-own)
>
> and the turtle uses these data to calculate set Z [x * (a * c) + y * (b *
> d)], then how do I achieve that the turtle can separately identify the Z
> value that comes from the data of each neighboring patch and match it with
> that patch?
>
> (Z is turtles-own)
>
> It is absolutely no problem if they turtle uses the data from the patch it
> stands on, but when trying to use the data from neighbors, I always get an
> error message whatever I try. Is there a way around this without moving
> attributes to globals []?
>
> To complicate things more, there is another function set [r = c / w] where r
> and w is also turtles-own. ... And, finally set Q [Z * r] with Q also
> turtles-own will yield the number that the turtles needs and match it to
> each neighbor, where the patch with the data that yields Q max will be
> chosen by the turtle.
>
> Any attempts to help appreciated. Thanks.
>
>
>
> ------------------------------------
>
>
>
>
>
• ... You want to use the of primitive. See the Variables section of the Programming Guide and of in the Dictionary. The primitive neighbors is an agentset
Message 3 of 13 , Oct 1, 2011
• 0 Attachment
On Sep 30, 2011, at 6:35 PM, gaklemm wrote:

I want my turtles to be able to retrieve data from neighboring (Moore) patches, then use this data in a turtle-specific function and be able to attribute the outcome of the function to the respective patch that supplied the data.

For instance, if patches have the attributes

set a random-float 1
set b random-float 1
set c random 100
set d random 100

(a, b, c, d are patches-own)

and the turtle uses these data to calculate set Z [x * (a * c) + y * (b * d)], then how do I achieve that the turtle can separately identify the Z value that comes from the data of each neighboring patch and match it with that patch? ...

You want to use the 'of' primitive. See the Variables section of the Programming Guide and 'of' in the Dictionary. The primitive 'neighbors' is an agentset of the eight patches in the Moore neighborhood of a turtle (and the patch it is on). So [a] of neighbors would be a list of the a values of those patches in no particular order.

To get at the patches individually you would want to use the 'patch-at' primitive. For example (if by x and y you mean the patch's coordinates):

; calculate Z for the patch north of this one
set Z [pxcor * a * c + pycor * b * d] of patch-at 0 1

Does this help? Check back if you want to know more.

Jim

• Hi ... For example: ask turtles [ let current-position (list xcor ycor) foreach sort neighbors [move-to ? ;turtle moves onto all neighbors in order ;insert
Message 4 of 13 , Oct 1, 2011
• 0 Attachment
Hi

> It is absolutely no problem if they turtle uses the data from the patch it stands on, but when trying to use the data from neighbors, I always get an error message whatever I try.

For example:

let current-position (list xcor ycor)
foreach sort neighbors
[move-to ?
;turtle moves onto all neighbors in order
]
setxy (item 0 current-position) (last current-position)
]

Extra stuff that i think might be useful:

to a
ca
crt 1 [set color 12 + random-float 5]
[

show neighbors
show one-of neighbors
show sort neighbors
foreach sort neighbors4
[show ?]
print ".."
[set pcolor 2 + random-float 5
show self
show myself
show [color] of myself
show [color] of myself + pcolor
show [myself] of myself
show [color + [pcolor] of myself] of myself
]
print "..."
ask neighbors with [pcolor = 0]
[set plabel random 10 set pcolor 84]
repeat 3[show [plabel] of neighbors]
show sort [plabel] of neighbors
show neighbors with [pcolor = 0]

]
end
• ... Hi Jim, thanks for your reply. I should clarify that I just chose x and y randomly; it s not related to patch coordinates. In fact, they stand for certain
Message 5 of 13 , Oct 1, 2011
• 0 Attachment
--- In netlogo-users@yahoogroups.com, Jim Lyons <jimlyons@...> wrote:
>
> On Sep 30, 2011, at 6:35 PM, gaklemm wrote:
>
> > I want my turtles to be able to retrieve data from neighboring (Moore) patches, then use this data in a turtle-specific function and be able to attribute the outcome of the function to the respective patch that supplied the data.
> >
> > For instance, if patches have the attributes
> >
> > set a random-float 1
> > set b random-float 1
> > set c random 100
> > set d random 100
> >
> > (a, b, c, d are patches-own)
> >
> > and the turtle uses these data to calculate set Z [x * (a * c) + y * (b * d)], then how do I achieve that the turtle can separately identify the Z value that comes from the data of each neighboring patch and match it with that patch? ...
>
> You want to use the 'of' primitive. See the Variables section of the Programming Guide and 'of' in the Dictionary. The primitive 'neighbors' is an agentset of the eight patches in the Moore neighborhood of a turtle (and the patch it is on). So [a] of neighbors would be a list of the a values of those patches in no particular order.
>
> To get at the patches individually you would want to use the 'patch-at' primitive. For example (if by x and y you mean the patch's coordinates):
>
> ; calculate Z for the patch north of this one
> set Z [pxcor * a * c + pycor * b * d] of patch-at 0 1
>
> Does this help? Check back if you want to know more.
>
> Jim
>

Hi Jim,

thanks for your reply. I should clarify that I just chose x and y randomly; it's not related to patch coordinates. In fact, they stand for certain coefficients that the turtles use to compute the respective Z for each neighbor. So let's call them alpha and beta.

Using the 'of' primitive was my first intuition, and that's were I would get an error saying that (in your example) 'patch-at 0 1 cannot access [ alpha * a * c + beta * b * d] because alpha is turtle-only.'

I realized it can't work because I made x and y to be turtle variables, when in fact there are going to be 8 different values for x and y for each turtle at each step of the simulation. Now before I add alpha-for-x0-y1, alpha-for-x1-y1, ... beta-for-x0-y1, etc. as turtle-variables, maybe you have another (cleaner) idea? I hope this is not too confusing to you. Again, thanks so much for your help!
• Hi James, thanks for your help. I have already witnessed the magic of OF, and I d like to use it here too. I must clarify that x and y do not refer to
Message 6 of 13 , Oct 1, 2011
• 0 Attachment
Hi James, thanks for your help. I have already witnessed the magic of OF, and I'd like to use it here too.

I must clarify that x and y do not refer to coordinates, but stand for coefficients that are part of a function that the agent runs, so they are constant. I realized that was not a wise choice for the example. Let's just say Z is rendered by multiplying the patch variables with 5.

I also need the turtles to run CALC-Z because the function contains unique turtle variables, so I'm using ASK TURTLES followed by

set Z1 [5 * a] of neighbors
set Z2 [5 * b] of neighbors

which yields 8 output values for Z1 as well as for Z2.

However, Z1 and Z2 are just variables of another function run by turtles, so while I could, for instance, easily get ZCUM [5 * a + 5 * b] OF NEIGHBORS, I cannot substitute and SET ZCUM (Z1 + Z2) because arithmetic operators 'expect a number and not a list' - which makes sense, but I don't know how to get around this.

I hope this is not too confusing. I am very grateful for your help.

Alexander

P.S.

I need to substitute because Z is again used variable in another function which again must yield 8 output values, one for each neighbor. And that function will contain another turtle variable too. All this is probably going to be happening within the same procedure.
Sorting and finding the max value will be part of a different procedure, though.

--- In netlogo-users@yahoogroups.com, James Steiner <gregortroll@...> wrote:
>
> Exactly how we do this entirely depends on how you need to "relate"
> the value back to the patch... it could be done on the fly using ASK
> or WITH, or we could make a list containing the patches and the
> results. That's what I'm doing here.
>
> Assuming that you have a procedure, like CALC-Z that a patch runs to
> return the value of Z, like so:
>
> to-report CALC-Z report (pxcor * (a * c) + pycor * (b * d)) end
>
> We can use OF NEIGBORS...
>
> let Z [LIST SELF calc-z] OF NEIGHBORS
>
> A key concept, above and beyond all the magic of OF, is that a patch
> or other agent can be "stored" in a variable... it's really a
> reference to the agent, but that's exactly what we want here.
>
> Now, you can use the Z values, search them, whatever, and as long as
> you know the list index of the value you are interested in, you can
> use that index to get back to the patch.
>
> Again, depending on what you do next, this could be much simpler,
> LIke, finding the patch with the max Z:
>
> let big-z max-one-of neighbors [ CALC-Z ]
>
> ~~James
>
>
>
> On 9/30/11, gaklemm <gaklemm@...> wrote:
> > Hi,
> >
> > I think this is an easy problem, but I am fairly new to NetLogo, and
> > programming in general.
> >
> > I want my turtles to be able to retrieve data from neighboring (Moore)
> > patches, then use this data in a turtle-specific function and be able to
> > attribute the outcome of the function to the respective patch that supplied
> > the data.
> >
> > For instance, if patches have the attributes
> >
> > set a random-float 1
> > set b random-float 1
> > set c random 100
> > set d random 100
> >
> > (a, b, c, d are patches-own)
> >
> > and the turtle uses these data to calculate set Z [x * (a * c) + y * (b *
> > d)], then how do I achieve that the turtle can separately identify the Z
> > value that comes from the data of each neighboring patch and match it with
> > that patch?
> >
> > (Z is turtles-own)
> >
> > It is absolutely no problem if they turtle uses the data from the patch it
> > stands on, but when trying to use the data from neighbors, I always get an
> > error message whatever I try. Is there a way around this without moving
> > attributes to globals []?
> >
> > To complicate things more, there is another function set [r = c / w] where r
> > and w is also turtles-own. ... And, finally set Q [Z * r] with Q also
> > turtles-own will yield the number that the turtles needs and match it to
> > each neighbor, where the patch with the data that yields Q max will be
> > chosen by the turtle.
> >
> > Any attempts to help appreciated. Thanks.
> >
> >
> >
> > ------------------------------------
> >
> >
> >
> >
> >
>
• ... OK, in that case, to illustrate with this example, you would write: ; turtle code set Z [[alpha] of myself * a * c + [beta] of myself * b * d] of patch-at
Message 7 of 13 , Oct 3, 2011
• 0 Attachment
On Oct 1, 2011, at 7:12 PM, gaklemm wrote:

thanks for your reply. I should clarify that I just chose x and y randomly; it's not related to patch coordinates. In fact, they stand for certain coefficients that the turtles use to compute the respective Z for each neighbor. So let's call them alpha and beta.

Using the 'of' primitive was my first intuition, and that's were I would get an error saying that (in your example) 'patch-at 0 1 cannot access [ alpha * a * c + beta * b * d] because alpha is turtle-only.'

OK, in that case, to illustrate with this example, you would write:

; turtle code
set Z [[alpha] of myself * a * c + [beta] of myself * b * d] of patch-at 0 1

The outer brackets are the patch's context, the inner brackets refer back to the turtle's context using 'myself'

I realized it can't work because I made x and y to be turtle variables, when in fact there are going to be 8 different values for x and y for each turtle at each step of the simulation. Now before I add alpha-for-x0-y1, alpha-for-x1-y1, ... beta-for-x0-y1, etc. as turtle-variables, maybe you have another (cleaner) idea?

Using lists would probably work. If you could precompute these numbers and make two 8-element lists, and if ticks correspond to your steps, something like:

; turtle code, alpha-list and beta-list are turtles-own
let alpha item ticks alpha-list  ; these are now local vars,
let beta item ticks beta-list    ; so no need to change context
set Z [alpha * a * c + beta * b * d] of patch-at 0 1

Again, alpha and beta in this block are local variables, so the same in any context in the block. (This will give error if ticks becomes greater than the length of the lists.)

Jim

• You can nest one OF inside another. You can refer back to the calling agent using MYSELF. So, you can write something like this: ;; turtle runs this Set z [
Message 8 of 13 , Oct 3, 2011
• 0 Attachment

You can nest one OF inside another. You can refer back to the calling agent using MYSELF.

So, you can write something like this:

;; turtle runs this
Set z  [  5 * [ a ] of myself]  of neighbors
....that gives a list. But you can use sum or whatever on it after Ward.
Also look at MAP.

~~JAMES

On Oct 3, 2011 9:18 AM, "gaklemm" <gaklemm@...> wrote:
>
>
> Hi James, thanks for your help. I have already witnessed the magic of OF, and I'd like to use it here too.
>
> I must clarify that x and y do not refer to coordinates, but stand for coefficients that are part of a function that the agent runs, so they are constant. I realized that was not a wise choice for the example. Let's just say Z is rendered by multiplying the patch variables with 5.
>
> I also need the turtles to run CALC-Z because the function contains unique turtle variables, so I'm using ASK TURTLES followed by
>
> set Z1 [5 * a] of neighbors
> set Z2 [5 * b] of neighbors
>
> which yields 8 output values for Z1 as well as for Z2.
>
> However, Z1 and Z2 are just variables of another function run by turtles, so while I could, for instance, easily get ZCUM [5 * a + 5 * b] OF NEIGHBORS, I cannot substitute and SET ZCUM (Z1 + Z2) because arithmetic operators 'expect a number and not a list' - which makes sense, but I don't know how to get around this.
>
> I hope this is not too confusing. I am very grateful for your help.
>
> Alexander
>
>
> P.S.
>
> I need to substitute because Z is again used variable in another function which again must yield 8 output values, one for each neighbor. And that function will contain another turtle variable too. All this is probably going to be happening within the same procedure.
> Sorting and finding the max value will be part of a different procedure, though.
>
>
> --- In netlogo-users@yahoogroups.com, James Steiner <gregortroll@...> wrote:
>>
>> Exactly how we do this entirely depends on how you need to "relate"
>> the value back to the patch... it could be done on the fly using ASK
>> or WITH, or we could make a list containing the patches and the
>> results. That's what I'm doing here.
>>
>> Assuming that you have a procedure, like CALC-Z that a patch runs to
>> return the value of Z, like so:
>>
>> to-report CALC-Z report (pxcor * (a * c) + pycor * (b * d)) end
>>
>> We can use OF NEIGBORS...
>>
>> let Z [LIST SELF calc-z] OF NEIGHBORS
>>
>> A key concept, above and beyond all the magic of OF, is that a patch
>> or other agent can be "stored" in a variable... it's really a
>> reference to the agent, but that's exactly what we want here.
>>
>> Now, you can use the Z values, search them, whatever, and as long as
>> you know the list index of the value you are interested in, you can
>> use that index to get back to the patch.
>>
>> Again, depending on what you do next, this could be much simpler,
>> LIke, finding the patch with the max Z:
>>
>> let big-z max-one-of neighbors [ CALC-Z ]
>>
>> ~~James
>>
>>
>>
>> On 9/30/11, gaklemm <gaklemm@...> wrote:
>> > Hi,
>> >
>> > I think this is an easy problem, but I am fairly new to NetLogo, and
>> > programming in general.
>> >
>> > I want my turtles to be able to retrieve data from neighboring (Moore)
>> > patches, then use this data in a turtle-specific function and be able to
>> > attribute the outcome of the function to the respective patch that supplied
>> > the data.
>> >
>> > For instance, if patches have the attributes
>> >
>> > set a random-float 1
>> > set b random-float 1
>> > set c random 100
>> > set d random 100
>> >
>> > (a, b, c, d are patches-own)
>> >
>> > and the turtle uses these data to calculate set Z [x * (a * c) + y * (b *
>> > d)], then how do I achieve that the turtle can separately identify the Z
>> > value that comes from the data of each neighboring patch and match it with
>> > that patch?
>> >
>> > (Z is turtles-own)
>> >
>> > It is absolutely no problem if they turtle uses the data from the patch it
>> > stands on, but when trying to use the data from neighbors, I always get an
>> > error message whatever I try. Is there a way around this without moving
>> > attributes to globals []?
>> >
>> > To complicate things more, there is another function set [r = c / w] where r
>> > and w is also turtles-own. ... And, finally set Q [Z * r] with Q also
>> > turtles-own will yield the number that the turtles needs and match it to
>> > each neighbor, where the patch with the data that yields Q max will be
>> > chosen by the turtle.
>> >
>> > Any attempts to help appreciated. Thanks.
>> >
>> >
>> >
>> > ------------------------------------
>> >
>> >
>> >
>> >
>> >
>>
>
>
>
>
> ------------------------------------
>
>
> <*> To visit your group on the web, go to:
> http://groups.yahoo.com/group/netlogo-users/
>
>
> <*> To change settings online go to:
> http://groups.yahoo.com/group/netlogo-users/join
> (Yahoo! ID required)
>
> <*> To change settings via email:
> netlogo-users-digest@yahoogroups.com
> netlogo-users-fullfeatured@yahoogroups.com
>
> <*> To unsubscribe from this group, send an email to:
> netlogo-users-unsubscribe@yahoogroups.com
>
> <*> Your use of Yahoo! Groups is subject to:
> http://docs.yahoo.com/info/terms/
>
• Hi Ted, thanks for the input. I managed to solve this problem, but another one popped up: ask patches [ set a random 10 set b random 10 ] ask turtles [ set
Message 9 of 13 , Oct 11, 2011
• 0 Attachment
Hi Ted, thanks for the input. I managed to solve this problem, but another one popped up:

set a random 10
set b random 10
]

set alpha random-float 1
]

[
set Q ( (a + b) * alpha)
]
set turtle-Q Q
show turtle-Q
]
]

SHOW TURTLE-Q gives me 8 different values for Q, one for each neighbor, sorted
from top left to bottom right. It looks like this:
turtle 0: 0.35
turtle 0: 0.76
turtle 0: -0.32
... etc.

But I want to make a LIST (purely a turtle-variable) that contains all Q in one, so that I can sort by size. Do you know how to do that? Thank you.

-Alexander

--- In netlogo-users@yahoogroups.com, Ted Carmichael <tedsaid@...> wrote:
>
> Hi.
>
> Well, the first thing to check is: make sure that every patch has time to
> set the four attributes before ANY turtles try and use that data. It may be
> that the error message is due to a turtle trying to access data from a
> patch-neighbor that hasn't yet set a, b, c, and d.
>
> -Ted
>
> On Fri, Sep 30, 2011 at 6:35 PM, gaklemm <gaklemm@...> wrote:
>
> > **
> >
> >
> > Hi,
> >
> > I think this is an easy problem, but I am fairly new to NetLogo, and
> > programming in general.
> >
> > I want my turtles to be able to retrieve data from neighboring (Moore)
> > patches, then use this data in a turtle-specific function and be able to
> > attribute the outcome of the function to the respective patch that supplied
> > the data.
> >
> > For instance, if patches have the attributes
> >
> > set a random-float 1
> > set b random-float 1
> > set c random 100
> > set d random 100
> >
> > (a, b, c, d are patches-own)
> >
> > and the turtle uses these data to calculate set Z [x * (a * c) + y * (b *
> > d)], then how do I achieve that the turtle can separately identify the Z
> > value that comes from the data of each neighboring patch and match it with
> > that patch?
> >
> > (Z is turtles-own)
> >
> > It is absolutely no problem if they turtle uses the data from the patch it
> > stands on, but when trying to use the data from neighbors, I always get an
> > error message whatever I try. Is there a way around this without moving
> > attributes to globals []?
> >
> > To complicate things more, there is another function set [r = c / w] where
> > r and w is also turtles-own. ... And, finally set Q [Z * r] with Q also
> > turtles-own will yield the number that the turtles needs and match it to
> > each neighbor, where the patch with the data that yields Q max will be
> > chosen by the turtle.
> >
> > Any attempts to help appreciated. Thanks.
> >
> >
> >
>
>
>
> --
> Ted Carmichael, Ph.D.
> Complex Systems Institute
> Department of Software and Information Systems
> College of Computing and Informatics
> 310-A Woodward Hall
> UNC Charlotte
> Charlotte, NC 28223
>
• Thanks for the input. FOREACH did the trick! However, another problem came up: ask patches [ set a random 10 set b random 10 ] ask turtles [ set alpha
Message 10 of 13 , Oct 11, 2011
• 0 Attachment
Thanks for the input. FOREACH did the trick! However, another problem came up:

set a random 10
set b random 10
]

set alpha random-float 1
]

[
set Q ( (a + b) * alpha)
]
set turtle-Q Q
show turtle-Q
]
]

SHOW TURTLE-Q gives me 8 different values for Q, one for each neighbor, sorted
from top left to bottom right. It looks like this:
turtle 0: 0.35
turtle 0: 0.76
turtle 0: -0.32
... etc.

That's great, but now I want to make a LIST (purely a turtle-variable) that contains all Q in one, so that I can sort by size. Do you know how to do that? Thanks!

-Alexander

--- In netlogo-users@yahoogroups.com, "turtlemaniac5000" <turtlemaniac5000@...> wrote:
>
>
>
> Hi
>
> > It is absolutely no problem if they turtle uses the data from the patch it stands on, but when trying to use the data from neighbors, I always get an error message whatever I try.
>
>
> For example:
>
> let current-position (list xcor ycor)
> foreach sort neighbors
> [move-to ?
> ;turtle moves onto all neighbors in order
> ]
> setxy (item 0 current-position) (last current-position)
> ]
>
>
> Extra stuff that i think might be useful:
>
> to a
> ca
> crt 1 [set color 12 + random-float 5]
> [
>
> show neighbors
> show one-of neighbors
> show sort neighbors
> foreach sort neighbors4
> [show ?]
> print ".."
> [set pcolor 2 + random-float 5
> show self
> show myself
> show [color] of myself
> show [color] of myself + pcolor
> show [myself] of myself
> show [color + [pcolor] of myself] of myself
> ]
> print "..."
> ask neighbors with [pcolor = 0]
> [set plabel random 10 set pcolor 84]
> repeat 3[show [plabel] of neighbors]
> show sort [plabel] of neighbors
> show neighbors with [pcolor = 0]
>
> ]
> end
>
• ... Alexander, Maybe something like this will get what you want: patches-own [ a b ] turtles-own [ alpha Q-list ] to test clear-all ask patches [ set a random
Message 11 of 13 , Oct 11, 2011
• 0 Attachment
On Oct 11, 2011, at 11:33 AM, gaklemm wrote:

[
set Q ( (a + b) * alpha)
]
set turtle-Q Q
show turtle-Q
]
]

SHOW TURTLE-Q gives me 8 different values for Q, one for each neighbor, sorted
from top left to bottom right. ....

But I want to make a LIST (purely a turtle-variable) that contains all Q in one, so that I can sort by size. Do you know how to do that? Thank you.

Alexander,
Maybe something like this will get what you want:

patches-own [ a b ]
turtles-own [ alpha Q-list ]

to test
clear-all
ask patches [ set a random 10  set b random 10 ]
[ sprout 1
[ set alpha random-float 1
set Q-list map [[(a + b)] of ? * alpha] sort neighbors
]
]
ask turtles [ show Q-list ]
end

HTH,
Jim
• Thanks Jim, that works great for my example. My actual code is a little more complex than that, though, and I have trouble applying the answer there. (See code
Message 12 of 13 , Oct 12, 2011
• 0 Attachment
Thanks Jim, that works great for my example. My actual code is a little more complex than that, though, and I have trouble applying the answer there. (See code below) ... Especially because relo1 and relo2 are using a patch variable as well as a turtle variable. When I use "ask patches" instead of "ask turtles [foreach sort neighbors...", they cannot access w.

globals [u]
patches-own [o1 o2 p1 p2 q1 q2 c]
turtles-own [w neighbor-u]

to calc-u
[
let wexp1 (p1 ^ 0.61) / ( ( (p1 ^ 0.61) + (q1 ^ 0.61 ) ) ^ (1 / 0.61)
let wexp2 (p2 ^ 0.61) / ( ( (p2 ^ 0.61) + (q2 ^ 0.61 ) ) ^ (1 / 0.61)

let tot-wexp (wexp1 + wexp2)

let relo1 (o1 / [w] of myself)
let relo2 (o2 / [w] of myself)
let relc (c / [w] of myself)

set u (-2.25 * (relc ^ 0.88) + (wexp1 * rel-o1 ^ 0.88) + (wexp2 * relo2 ^0.88))
]

set neighbor-u u
]
]

Which command would be helpful here? I don't mind rewriting the code above, as long as I get a turtle list with 8 values for u or neighbor-u. Many thanks.

- Alexander

--- In netlogo-users@yahoogroups.com, Jim Lyons <jimlyons@...> wrote:
>
> On Oct 11, 2011, at 11:33 AM, gaklemm wrote:
>
> > [
> > set Q ( (a + b) * alpha)
> > ]
> > set turtle-Q Q
> > show turtle-Q
> > ]
> > ]
> >
> > SHOW TURTLE-Q gives me 8 different values for Q, one for each neighbor, sorted
> > from top left to bottom right. ....
> >
> > But I want to make a LIST (purely a turtle-variable) that contains all Q in one, so that I can sort by size. Do you know how to do that? Thank you.
>
> Alexander,
> Maybe something like this will get what you want:
>
> patches-own [ a b ]
> turtles-own [ alpha Q-list ]
>
> to test
> clear-all
> ask patches [ set a random 10 set b random 10 ]