List Info

Thread: FW: filter list (again)




FW: filter list (again)
country flaguser name
United Kingdom
2008-03-11 05:37:00

 

I am replying to this because nick (my student) is away now amnd I wanted to correct some misunderstandings. The list that the example uses called allscents is a list of scent values that are exactly equivalent to the kind of data you need for hillclimbing, its just that there are say 5 of them, like [0.45  5.6 7.8 34.2 7.]

 

They are the values that result from diffusion from 5 different locations on the world. Each turtle has an id (corresponding to her hatch location) and should hillclimb using the id217;th entry in the list

 OOPS! Just sent this before I’d finished, sorry I meant to add the workaround we used to solve the problem copying the help file’;s code (turtle proc) we copy the turtles-own id to a local, then it seems ok

 

 to  do-uphill

;; this is the code in the help for uphill

; it didn’;t like 'identity' cos its a turtles own variable but it is ok if i set id locally it seems

 

  let id (identity - 1) ;identity is a turtle variable

 

  move-to patch-here  ;; go to patch center

    let p max-one-of neighbors [item id allscents] 

    if [item id allscents] of p > item id allscents 

    [

        face p

        move-to p

        fd 1

        ]   

 

end

 

so the question is why wont it let us say

 

uphill item id of allscents

 

????

 

 

 

Paul S Coates AA Dip
Programme leader for MSc Architecture:Computing & Design
School of Architecture and the Visual Arts
University of East London
Docklands Campus
4-6 University Way
London E16 2RD
tel +44 208 223 3220

-----Original Message-----
From: netlogo-usersyahoogroups.com [mailto:netlogo-usersyahoogroups.com] On Behalf Of James Steiner
Sent:
10 March 2008 02:09
To: netlogo-usersyahoogroups.com
Subject: Re: [netlogo-users] filter list

 

In this case, "anything" literally means anything. NetLogo's uphill expects the name of a variable, and you gave it something else. It doesn't want anything else.

So, one source of trouble here is that what you are doing is not hillclimbing, so using uphill is not really appropriate.

Hillclimbing is when there is a gradient of values, and the agent moves from an area of lower value to an area of higher value (uphill) or vice-versa (downhill).

In this case, if I understand your example, the patches contain not graduated values, but markers. The turtles are following the trail of markers. So, if the list contains the number 3, then turtle with ID 3 will step into that patch.

Now, maybe I'm misunderstanding your example.

If what you had was a list of values and turtle with id 3 was interested in the value of the 3rd value in the list, and hillclimbed on that, well, now we have hillclimbing.

However, even in this case, you'd have trouble using uphill, because it expects a single patch variable, not an expression, so using "item 3 allscents" isn't going to work.

=====

So, to follow markers, you just need to tell if the patch's list contains the marker for that turtle.

e.g. a patch can have a list, like [ 1 5 7 9 ]. Only turtles with ID numbers 1, 5, 7 and 9 will step into this patch. So, a turtle would filter the neighboring patches something like this:

let next-step one-of neighbors with [ member? ( [ ID ] of myself) allscents ]
if is-patch? next-step [ move-to next-step ]

Note that this is dead-stupid, and doesn't prevent the turtle from backtracking. Some additional stuff is needed to assure the turtle moves forward.

==========

To uphill on a value that's stored in a list, you can't use uphill directly. You can do one of two things.

You could copy the values of interest into a patch variable, then use uphill on them. That seems unwieldy.

You could roll your own uphill routine.

======

You may actually intend a combination of this... there is a "global" scent (rather, a patches-own'd variable) that all turtles follow uphill, but turtles may only move through patches marked with the turtle's ID number.

In that case you still need to roll your own uphill routine, to a routine that filters the set of neighboring patches to only include patches the turtle is allowed to step into, and then select the patch with the greatest value.

I hope this helps,
~~James

On Sat, Mar 8, 2008 at 4:34 PM, timirelandesq < timirelandesqyahoo.co.uk">timirelandesqyahoo.co.uk> wrote:

Hi there,

I'm trying to make a turtle follow a particular value in a list - so
that it hillclimbs this particular value.

in my model turtles have identities which are equal to a particular
value in the list.

So, each patch has a list of values; say [1 2 3 4]

A turtle of identity 3 would follow the value '3'.

We have written;
set heading heading uphill (item id allscents)
, which means it should follow the value in the list relative to
its 'id' in the ascending direction - but it doesn't. It reports
that "uphill expected a variable but got anything instead&quot;.

I think i should probably use 'filter' but have got stuck.

Can anyone help please?

Also, what is meant by "anything",can't find reference to this in
guides.

Thanks, tim

 

__._,_.___
.

__,_._,___
Re: FW: filter list (again)
country flaguser name
United States
2008-03-11 10:25:19

Thanks for the  clarification!

On Tue, Mar 11, 2008 at 6:37 AM, Paul S. Coates < P.S.Coatesuel.ac.uk">P.S.Coatesuel.ac.uk> wrote:

 

uphill item id of allscents


The reason is that uphill is programmed specifically to accept ONLY a patches-own'd variable. Think of it this way: you are not giving uphill a value to use, but rather the name of a variable (that must be a patch variable) to use. It would probably be nice if the syntax for uphill was "uphil [ expression ]", so that uphill could evaluate the patches based on any expression you like--just like one can do if one writes one's own uphill-like procedure.

~~James

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )