Turtles do not stop when condition is set in Netlogo - netlogo

I have been trying to make a turtle (user) stop when they find a other turtle (bin). For this, the user own waste production that is equal to 0.9. Once they find the bin (bin own bin_holding_capacity) they lose the 0.9.
I want one of them to stop once they find the first bin around them.
The part of the code that I have written is as it follows:
to throw-waste
ask one-of users [
if any? bins with [distance myself <= 1] [ set wasteproduction ( - 0.9)]
]
ask one-of users [
if wasteproduction = ( - 0.9) [ ask users [wait 60] ] ;[stop]
]
end
to receive-waste
ask bins [
if any? users with [distance myself <= 1] [set bins_holding_capacity bins_holding_capacity + 0.9 ]
if bins_holding_capacity >= 38 [stop]
if any? collectors with [distance myself <= 1] [set bins_holding_capacity bins_holding_capacity - 25 ]
]
end
If someone could help me with this, I would appreciate it.
Thank you!

Related

NetLogo let target min-one-of neighbors math operation produced a non-number

I am new to NetLogo and I am trying to reproduce https://github.com/YangZhouCSS/Pedestrian_Model_Krasnow. When I open, it says that it was produced in NetLogo 5.2 and I am running NetLogo 6.3 so I may need to update code. When I try to run I get a math operation produced a non-number on the following line in the to go section:
let target min-one-of neighbors [ elevation + ( count turtles-here * 9999999) ]
This is the complete to go section:
to go
if count turtles > 0 [set move-speed count turtles with [moved? = true] / count turtles]
if count turtles = 0 [stop]
ask patches with [exit = 1] [ask turtles-here[die]]
ask turtles [
set moved? false
let target min-one-of neighbors [ elevation + ( count turtles-here * 9999999) ]
if [elevation + (count turtles-here * 9999999)] of target < [elevation] of patch-here
[ face target
move-to target
set moved? true
ask target [set path path + 1]]
]
if Show_path? [ask patches with [elevation < 9999999][let thecolor (9.9 - (path * 0.15)) if thecolor < 0.001 [set thecolor 0.001] set pcolor thecolor]]
tick
end
And the complete code is here: https://github.com/YangZhouCSS/Pedestrian_Model_Krasnow/blob/master/pedestrian_floor-2exits.nlogo
Thank you in advance for any guidance
Many of the patches have invalid (NaN) values for their elevation, which then causes the error you are getting when you try to use them in an arithmetic operation. I'm not conversant in the gis extension, so I can't tell you why it seems to be assigning invalid elevations to these patches, but if you run setup and then enter in the command center
ask patches [show elevation]
you will see which ones are invalid and may then be able to trace how they came to be that way. Perhaps the gis extension has changed the way it works with the data files since NetLogo v5?
Charles
Not exactly sure why it worked but I replaced
let target min-one-of neighbors [ elevation + ( count turtles-here * 9999999) ]
With
let target min-one-of neighbors [ elevation ]
And the simulation ran

Minimum distance and interference between turtles

I am doing boarding processes model with anti-Covid measures. I would like to know if any of you could help me.
I would like to enforce that the minimum distance between turtles will be 4 patches.
I would like to identify if there is an interference, that is, that a previous turtle occupies a seat that prevents a new agent from passing through.
I don't know how to insert this in my code:
to go
; stop when all the pessengers have found a seat
if not any? turtles with [seated? = false]
[stop]
set counter counter + 1
(foreach (sort turtles with [seated? = false] ) [a ->
ask a [
; check if we have reached the correct row of seats
ifelse [seat-row] of patch-at 1 -1 = assigned-seat-row
[
; only seat the passenger if he/she has stored the luggage OR if we don't take luggages into account
ifelse luggage-store-ticks = 0 or storing-luggage-takes-time = false
[
let seat patch-at 1 -1
set xcor [pxcor] of seat
set ycor assigned-seat-number
set seated? true
]
[
set luggage-store-ticks luggage-store-ticks - 1
]
]
[
let passenger-ahead one-of turtles-on patch-ahead 1
ifelse passenger-ahead != nobody
[
set speed [speed] of passenger-ahead
if xcor != airplane-door-x-cor
[fd speed]
]
[
set speed default-speed
fd speed
]
]
]
])
end
You could extend your existing patch-ahead 1 to also look at the patches 2, 3 and 4 ahead. But I think it would be easiest to use in-cone 5 10 or similar. That will look ahead in a cone shape, 10 degrees on either side of the heading and a distance of 5. So you could do something like:
let potential-blockers turtles in-cone 5 10
let blocker min-one-of potential-blockers [distance myself]
That should (not tested) find the closest turtle approximately in front and name it "blocker" so that you can do things like check if it's far enough away, match speed (see the basic traffic model in the NetLogo models library)

Netlogo Creating a Link with a turtle when they both hit the same patch

Maybe i worded the question wrong but what i want to do in the code is when another turtle meets another turtle they create links with each other
I know its
to go
tick
make-circle
move
if ticks >= timer1 [stop]
end
to move
ask turtles
[
create-links-with other turtles ;here is where i want to put the code
set heading random 360 fd 1]
create-network
end
to create-network
ask links [
set thickness 0.01 * counter
if [patch-here] of end1 = [patch-here] of end2
[set counter (counter + 1)]
]
end
but im not sure how to word it correctly to link when they meet how do i do that
Establish a breed variable for your counts. Then create a link between all turtles that are on the same patch with other turtles-here. Then increment that count variable for when the others turtles have met the original calling turtle. I'll note that I increment the count variable by .5 because each turtle in the link will increment it (there's 2 turtles, so .5 * 2 = 1).
links-own [meets]
to setup
clear-all
crt 100 [setxy random-xcor random-ycor ]
end
to go
ask turtles [fd 1]
ask turtles [rt random 90]
ask turtles [ create-links-with other turtles-here]
ask turtles [ ask other turtles-here [ask link-with myself [ set meets meets + .5]]]
end

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 : Keep turtles moving continuously till the end

Readers,
I'm a beginner in NetLogo. Please help me in solving few issues with my code that is below:
I'm getting an error "You can't use tick in a turtle context, because tick is observer-only.
I need to get tick value updated after each turtle go all three of "arrive-reception, arrive-triage, go-drroom".
the rest of people is not moving around the arrive reception, arrive triage is running.
to setup-people
set-default-shape turtles "person"
set destination ( patch-set patch -2 34 patch 8 34 )
create-turtles uninfected
[ set color blue
allocate-turtles
]
create-turtles infected
[ set color red
allocate-turtles
]
end
to allocate-turtles
if (pcolor = 9.9 and any? turtles-here)
[
set size 1.5
set heading 0
setxy int random-xcor int random-ycor
]
end
to go
move-people
arrive-reception
arrive-triage
go-drroom
tick
end
to move-people
ask turtles [
rt 360
forward 1
]
end
to arrive-reception
ask n-of (random count turtles) turtles
[
if windows = 1
[
move-to patch -2 34
ifelse not any? turtles-here
[ wait wait-time ]
[ wait-in-queue ]
]
]
end
to wait-in-queue
set arrival-time ticks
bk 1
if any? other turtles-here
[ wait-in-queue ]
wait wait-time
if ticks - arrival-time > wait-time
[ set arrival-time 0
fd 1 ]
end
to arrive-triage
if triage = "Open"
[
move-to patch 26 11
if any? other turtles-here
[ wait-in-queue]
wait wait-time
move-to one-of patches with [pcolor = 109 and not any? other turtles-here ]
wait wait-time
]
end
to go-drroom
move-to one-of patches with [pcolor = 128]
if ( min-one-of other turtles in-radius 5 [distance myself] != nobody)
[
move-to one-of patches with [pcolor = 129]
if ( min-one-of other turtles in-radius 5 [distance myself] != nobody)
[
move-to one-of patches with [pcolor = 5]
if any? seats with [turtles = nobody]
[
move-to one-of max-n-of 6 neighbors [seats]
]
]
]
wait wait-time
die
end
Thanks.
First, some basic programming tricks - don't write so much before trying to debug. If you make a small change and check it, then it's easy to work out where the error is. The first draft of a procedure can be as simple as:
to go-drroom
end
and then fill in the details of what happens in the procedure later.
Typically this error is because you forgot to close a bracket somewhere. That is, one of the procedures starts with ask turtles [ ... and there is no ] so NetLogo is still thinking that the code applies to turtles. However, I can't see an obvious missing ].
But you do have a conceptual problem. The term context is used in NetLogo to refer to who is asking the code to be done and to whom. So ask turtles [ forward 1] is the observer asking the turtles to move and is an observer context procedure. You are not thinking about what context you are in when writing the procedures, and this is probably what is setting off your error.
In the go procedure, you first call move-people. This does ask turtles [ ] so is (appropriately) from the observer context. Then you call arrive-reception and it is also okay.
But then you call arrive-triage and go-drroom still from the observer context and have commands like move-to. Who is being asked to move? You don't have ask turtles .... On the other hand, the procedure wait-in-queue has commands like move-to, but it is fine because it is only called from within an ask turtles ... in the arrive-reception procedure.