breed-here equivalent for agentsets? - netlogo

I want to make an agentset of patches that have turtles only of a specific agentset. This is easy with breeds but is not working for me with an agentset.
All my turtles are the same breed.
let moveAgents n-of (count turtles * 0.1) turtles
let availablePlots patches with [any? moveAgents-here] ;does not work

Just invert the search:
let availablePlots patch-set [patch-here] of moveAgents

Related

netlogo realistic predator behaviour

I am working with Netlogo to create a realistic predator prey-model and am stumped at the distance command.
ifelse any? sheep in-radius senserange [
let prey min-one-of sheep in-radius senserange [distance myself]
**ifelse [distance prey] < speedrange**
[move-to prey
let addenergy [energy] of prey
ask prey [die]
set energy energy + (addenergy * energy-gain-from-sheep)
rt 180
fd speedrange
]
[set heading towards prey
fd speedrange
]
]
[wiggle
fd 1]
The code in bold is the problem: I want the wolves not to immediately go to the prey but move towards it in an increment of its speedrange, unless of course it is within that range, then run to it and grab it ;).
I get ERROR: "Expected an agent or number or string here, rather than a list or block"
I think it is with the distance command, I've also tried something like this
ifelse prey in-radius speedrange [distance myself]
Thsi version results in ERROR: "IFELSE expected this input to be a T/F but got a turtle agentset or patch agentset instead
try ifelse distance prey < speedrange instead of ifelse [distance prey] < speedrange - you don't need the reporter/command brackets here

netlogo: have patches calculate influence value using reporter

I'm modeling a cityscape for looking at movement, where patches equate to buildings and have different influence values. I need to use a reporter function that calculates the value of each patch with something like:
(its own influence) plus (the influence of neighbors) divided by the
distance to a specific turtle (max-one-of distance myself)
The turtle will then move towards the patch with the highest influence value, but along a defined street.
I'm new to using netlogo and have gotten completely stuck.
I've included a portion of what I have so far, but I can't figure out how to write the reporter function that will compute each patches influence value (in-cone) so that the turtles can then move towards the best option.
to setup-influence-field
ask patches with [pcolor = green] [set influence commercial-influence]
ask patches with [pcolor = orange] [set influence production-influence]
ask patches with [pcolor = yellow] [set influence domestic-influence]
ask patches with [pcolor = pink] [set influence religious-influence]
ask patches with [pcolor = blue] [set influence public-influence]
end
to go
move-serapis
end
to move-serapis
ask serapis [set-procession-heading]
repeat 2 [ ask serapis [ fd .25 ] display ]
tick
end
;;;;; the reporter values are need for this part of the code so that the turtles (serapis) can move towards the patches with the highest influence value;;;;
to set-procession-heading
let direction patches in-cone 4 40 with [influence-field > 0]
if any? influence-field
[face max-one-of influence-field] ;;;; face towards the highest computed influence value
ifelse any? patches with [pcolor = black] in-cone 1 25
[process]
end
Any help would be greatly appreciated!
I don't think this is completely correct and I can't test it, but it should start you off and maybe someone here can fix it if you let us know the errors.
to set-procession-heading
let direction-targets patches in-cone 4 40 with [influence-field > 0]
if any? direction-targets
[ face max-one-of direction-targets [ influence-amount self ] ]
end
to-report influence-amount [ target-node ]
report ( [ influence-field ] + sum [ influence-field] of neighbors ) / distance target-node
end
What I have done is set up a separate procedure to report the results of your calculation. That procedure takes an argument (named target-node) because you need to be able to pass the identity of the turtle being influenced. Once you have that procedure, then you can simply pass the agent-set of potential directions to the calculation procedure and pick the one with the largest value.

Having turtles verify if they own a link / have a neighbor turtle

Is there a way for turtles to verify if they have links or neighbors?
I need a way for turtles to check if they have a link. If the turtle does, then I need it change the variable SocialST to 1. If the turtle does not, then it should skip. Here is what I have devised so far...
to SocialStructure
ask turtles with [link-neighbors]
[if (abs([SN] of self - [SN] of one-of link-neighbors) >= Soctol ) [Set SocialST 1]]
end
Making minimal changes to your code:
to updateSocialStructure
ask turtles with [any? link-neighbors] [
if (abs([SN - [SN] of one-of link-neighbors) >= Soctol )) [Set SocialST 1]
]
end
But do you really want one-of?

NetLogo: select a patch with neighbors having certain qualities?

I want to let my turtle move to certain patch and make a "splotch". The central patch = my turtle location, can be selected randomly, however satisfy two conditions:
has to be in a certain distance from turtle's actual position
has to surrounded (neighbors in certain radius) by patches with specific quality
The reason is to create kind of "buffers" around my turtle's position, with aim to obstruct the close proximity of my clumps.
Please, how can I satisfy these two conditions?
As far, I have:
to go
ask turtles [
; select one of patches in specific distance, and
; surrounded by patches with no magenta color
let aaa one-of patches with [distance myself > 3 and
all? neighbors with [pcolor != magenta]]
; how to write this condition above ??
; and how replace "neighbors" by "in-radius"??
move-to aaa
ask neighbors [ ; create clump of magenta patches
set pcolor magenta ]
ask patch-here [ ; set central patch to magenta
set pcolor magenta ]
]
You're almost there; you just need to reread the documentation for all? and any?.
let _candidates patches with [distance myself > 3]
set _candidates _candidates with [
not any? (patches in-radius 3 with [pcolor = magenta])
]
let aaa one-of _candidates
If it is possible that there will be no candidates, you should guard against that.

How to avoid turtles revisiting the patch on which they were last time?

Turtles stay on patches for 60 ticks, and then move to another target patch. How to avoid turtles revisiting the patch on which they were last time? Thanks
Hi Seth and Frank,
Thank you very much for your reply. I am sorry I did not describe the questions in detail.
Turtles will not visit the patch that they were on the last tick, and will move to another nearest patch instead in next tick. The following codes mean they find the nearest patch, and move on to it.
What I would want to do is the turtle will find the nearest patch again in the next tick. They will move to other alternative that is nearest to themselves, if the nearest patch is still the same one that they were on the last tick. Thanks
let closest-leaf min-one-of (patches in-radius 1 with [pcolor = lime]) [distance myself]
face closest-leaf
fd distance closest-leaf
A good way is to have a turtles-own variable of patches visited that can be maintained (remember to initialize it to the empty list when you create the turtle).
turtles-own [ patches-visited ]
to setup
...
ask turtles [ set patches-visited [] ]
...
end
to move
let potential-targets filter [ not member? ? patches-visited ] target-patches
let target-patch one-of potential-targets
if target-patch != NOBODY [
set patches-visited fput target-patch patches-visited
; move to target patch
]
end
Add a get-target reporter.
to-report get-target ;;turtle proc
let %close patches in-radius 1 with [pcolor = lime and self != [patch-here] of myself]
ifelse (any? %close) [
report min-one-of %close [distance myself]
] [
report nobody
]
end
Now you can easily change your mind about how to pick a target. You can then move to the target (if one exists).
to move ;; turtle proc
let %target get-target
ifelse (%target = nobody) [
;handle this case
] [
face %target move-to %target
]
end