|
List Info
Thread: filter list
|
|
| filter list |
  United States |
2008-03-08 14:34:25 |
|
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".
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: filter list |
  United States |
2008-03-09 21:09:23 |
|
In this case, "anything" literally means anything. NetLogo9;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, timireland esq < timirelandesq yahoo.co.uk">timirelandesq yahoo.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 'id9; in the ascending direction - but it doesn't. It reports
that "uphill expected a variable but got anything instead".
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: filter list |
  United States |
2008-03-09 17:18:53 |
|
Tim,
That is a funny error message, in a somewhat existential way. In my experience, NetLogo seems to use "anything" to refer to an expression which might conceivably return any type of value. Perhaps the error message would have been clearer (but possibly still not entirely illuminating) if it had said: "Uphill expected a variable, but got something else instead." That's basically what happened: you gave uphill an expression, instead of a variable. There are a few primitives like that, where a simple variable, rather than an expression, is required. For set (the first parameter), diffuse,
and diffuse4, for example, the reason for this is pretty clear: we're actually supplying a reference to a variable whose value will be modified by the primitive. In the case of uphill and uphill4, it's not quite as clear why only a single variable is allowed; I suspect it's because it could otherwise be pretty difficult for NetLogo to determine and apply the appropriate evaluation context(s), when it evaluates an arbitrarily complex expression across the current and neighboring patches. (As an alternative, I guess NetLogo could take the expression as is, and try to evaluate it identica
lly in the context of each of the patches; but that could result in hard-to-debug errors, in my opinion.)
If you look at the documentation for uphill and uphill4, you'll see that an equivalent fragment of code is given. That fragment is fairly easy to modify for your purposes, and use in place of uphill. So, in your case, where turtles have an id variable and patches have an allscents variable, you could use a procedure like this
:
to uphill-scent
move-to patch-here let value-here (item id allscents)
let best-neighbor (max-one-of neighbors [item ([id] of myself) allscents])
if ((item id ([allscents] of best-neighbor)) > value-here) [
face best-neighbor
move-to best-neighbor
]
end
Note that this procedure uses three different forms of the item id allscents expression, for the different evaluation contexts: one for evaluating in the current patch, one for evaluating over a patch agentset, and one for evaluating in a single patch other than the current patch. With some work, these expressions could be coerced into a single f0rm (especially if you wrote a reporter that would be evaluated by patches, with an id value as a parameter). However, either approach is arguably best left up to the programmer, rather than trying to have NetLogo do it automatically.
I hope this helps.
Regards,
Nick
--- In netlogo-users yahoogroups.com, "timirelandesq" <timirelandesq ...> 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". > > I think i should probably use 'filter' but have got stuck. > > Can anyone help please? > > Also, what is meant by "anythin
g",can't find reference to this in > guides. > > Thanks, tim >
__._,_.___
.
__,_._,___
|
[1-3]
|
|