This is quite a simple problem but I don't know why I can't solve it, nor do my searches on the Net are suitable to my code. I've been stuck for weeks because of this simple problem ・゜・(ノД`)
.
Here is the problem,
I have an agentset called myteamset where in this agentset, it include myself and 2 other turtles, what I need now is to remove myself from this set and name this new agentset as myteamset1
I have tried
set myteamset1 myteamset [not member? self myself] - got error;
set myteamset1 myteamset with [self != myself] - didn't get error but the agentset is empty
Code:
ask turtles [
if myteamset = nobody [
let possible-teammates other turtles with [ myteamset = nobody ]
ifelse count possible-teammates > 1 [
set myteamset (turtle-set self n-of 2 possible-teammates )
; set myteamset1 myteamset [not member? self myself] here is problem
Please help me, I don't know why I can't do this simple code, it's like my brain stuck and I feel so desperate now, Thanks in advance.
Try set myteamset1 other myteamset. The primitive other means everyone in the agentset except me.
Here is a full example
turtles-own [myteamset myteamset1]
to testme
clear-all
create-turtles 20
ask turtles
[ set myteamset (turtle-set self n-of 2 turtles)
set myteamset1 other myteamset
]
end
Related
I would like to drop links between one turtle and another one with different breed if a condition is satisfied.
I am using the following code to do this:
ask one-of turtle1 [
if any? my-out-links with [breed = turtle2]
[ask one-of out-link-neighbors with [breed = turtle2 and value < 0.7] ;; value should refer to a neighbour's characteristics and it represents my condition
[die]
]
]
But the links seems to be kept. No link has been deleted.
Could you please tell me what it is wrong in my code and how to fix it accordingly?
I'm assuming that turtle1 and turtle2 are two breeds of turtles. If so,
if any? my-out-links with [breed = turtle2]
will never find any such out-links as you are checking to see if any of my-out-links are of breed turtle2, and of course no links are of that breed. What you want is to know if the turtle at the other end of the link is of breed turtle2. Since these are directed links, the turtle you want to check is at end2.
if any? my-out-links with [[breed] of end2 = turtle2]
will let you know if the any of the turtles at the other end of my-out-links are of breed turtle2.
The line
ask one-of out-link-neighbors with [breed = turtle2 and value < 0.7] [die]
may do more than you intend. It asks a link-neighbor turtle of breed turtle2 and with value < 0.7 to die. That will indeed kill the link as well (since it has lost its end2), but if you want to kill the link and not the turtle at the other end you could do all this in a single line
ask one-of turtle1 [
ask one-of my-out-links with [[breed = turtle2 and value < 0.7] of end2] [die]
]
If there are no such out-links, then you will be asking nobody and the ask will do nothing.
I have breed [walkers walker] which walk roads in a road map represented by links in Netlogo.
The links-own [ guiri-ids ] which I intend to be an turtle-set of walkers that have already walked for the link.
I would like to use this guiri-ids to select, from the set of possible next links, which I call nextlinks, the links that the walker has not been walked before (the new ones).
If all possible links have been walked before then choose one of them.
How could obtain the set of next links which guiri-ids set does not contain myself (the walker) ?.
I am trying this line
let new-nextlinks nextlinks with [ guiri-ids != myself ]
but the keeps taking old paths.
Thank your very much for your help
breed [walkers walker]
links-own [ guiri-ids ]
to test
ca
crt 25 [setxy random-xcor random-ycor]
ask turtles [
create-link-with one-of other turtles
]
create-walkers 10
ask links [set guiri-ids n-of 3 walkers]
ask walkers [walk]
end
to walk
let _next one-of links with [not member? myself guiri-ids]
ifelse (_next != nobody) [
ask _next [set guiri-ids (turtle-set myself guiri-ids)]
] [
;do whatever you wish in this case
]
end
I've been trying to link turtles from BREED1 (still) to turtles from breed2 (mobile) who are on neighbors of BREED1. I want to do so in order to change a variable according the link-length between BREED1 and breed2.
(you can say that BREED1 represent houses and breed2 represents people, I would like to change the fact that the people are "protected" or not, according to the distance that separates them from their house (BREED1 that they are linked to))
I don't know if this is the best way to do it, but here's my code, I know it's not working because the "protected" variable is always false by default.
to protect
ask n-of total-number-BREED1 BREED1
[ if any? breed2-on neighbors
[ create-link-with [who] of breed2-on neighbors]
ask link-neighbors
[ set protected true]
]
I would also like to add a part concerning the link's length
ask link-neighbors
[ ifelse link-length < 2
[set protected true]
[set protected false]]
Thank you for your help !
Try this to create links with the breed2-on the neighboring patches:
ask BREED1
[
if any? breed2-on neighbors [ create-links-with breed2-on neighbors]
ask link-neighbors [ set protected true]
]
and this, which gets the link-length between the breed1 and it's neighbors
ask BREED1
[
ask link-neighbors
[
if [link-length] of link-with myself < 2 [ do something]
]
]
Note: link-length is called from a link's perspective, so you need to get the link that's connecting two things.
I been looking for the way to place each turtle in a parcel, but I do not want to have two turtles in the same parcel. Does anybody know how to do it?. (Without using sprout).
Assuming you have more patches than turtles, all you need is:
ask turtles [
move-to one-of patches with [ not any? turtles-here ]
]
Interesting side note:
People are often tempted to stick other in there, as in:
; bad code:
ask turtles [
move-to one-of patches with [ not any? other turtles-here ]
]
but this calls other within the patch context, so it doesn't actually do anything. To achieve the desired effect of not excluding the patch that the turtle is already on, you could write:
ask turtles [
let me self
move-to one-of patches with [ not any? turtles-here with [ self != me ] ]
]
Whether or not it is worth the trouble depends on your particular circumstances.
Finally, note that:
; bad code:
ask turtles [
move-to one-of patches with [ not any? [ other turtles-here ] of myself ]
]
would not work either because turtles-here would then be called in the turtle's context instead of being called in the patch context.
I have individuals (turtles) and I have households (turtles with fixed xy)
I have a variable address stored at households. I have a number of a family attached to individuals. The households has the same number.
How can I ATTACH or MOVE the individuals to their corresponding household?
I tried something like:
ask individuals
[ if family = [family-place] of household
[
move-to [address] of household
]
]
Since it is a slow monday morning, here is how I would do it.
I assume familiy-number to be the name of the common number in both moving and sessile turtles. I would use let to create a local variable that only works within the procedure. (See the procedure go-home for this)
breed [walkers walker]
breed [houses house]
houses-own [family-number]
walkers-own [family-number]
to setup
clear-all
set-default-shape houses "house"
create-houses 10 [
setxy random-xcor random-ycor
set family-number random 10000
]
reset-ticks
end
to leave-home
ask houses [
hatch-walkers 1 [
set family-number [family-number] of myself
set color [color] of myself
set heading random 360
fd 1
]
]
end
to go
ask walkers [
rt random 120
lt random 120
fd 1
]
tick
end
to go-home
ask walkers [
let family-place one-of houses with [family-number = [family-number] of myself]
move-to family-place
fd 1 ;; walker will step away one step so we can see him.
]
end
Just copy it into NetLogo, make a button for each procedure and play. Works best if in the order
setup
leave-home
go
go-home
Hope this helps!
move-to household should do it.
I'm having trouble understanding your question, so I've having to guess at what you want, but with the help of your comment on Bryan's answer, maybe I've guessed right?
ask individuals [
move-to one-of households with [address = [family-place] of myself]
]
if this seems confusing because of the myself, you could also write it as:
ask individuals [
let f family-place
move-to one-of households with [address = f]
]