move inside shape - netlogo - netlogo

I need to implement the motion of small polygon shapes inside the world
The patches are colored this way:
1) big oval shape having blue color (appropriate patches are blue)
2) inside it 2 circular shapes having green color (appropriate patches are green)
Each circular shape "has" several tunnels turtles on its border
And I have several turtles having polygon shape, initially placed inside green circles(polygonInside)
I need the polygons motion inside circles until they hit one of tunnels. After that they go out and move inside oval only (not return to circle). I create appropriate polygonOutside instead of polygonInside
I tried:
ask polygonInside [
let step 0.7
ifelse (green = [pcolor] of patch-ahead 0.7)
[
rt random 90
lt random 90
]
[
ifelse any? turtles with [ shape = "tunnel" ] in-radius 1.3
[
hatch-polygonOutside 1
[
set shape "polygon"
move-to min-one-of neighbors with [pcolor = blue] [distance myself]
]
die
]
[
face min-one-of neighbors with [pcolor = green] [distance myself]
]
]
fd step
]
ask polygonOutside [
ifelse ((blue = [pcolor] of patch-ahead 1))
[
rt random 90
lt random 90
]
[
; !!!!they are stucked
; move-to min-one-of neighbors with [pcolor = blue] [distance myself]
; !!!!sometimes runtime error
face min-one-of neighbors with [pcolor = blue] [distance myself]
]
fd 0.7
]
It almost works ok but there are 2 issues:
1) The polygons when they outside go very close to the green circles (almost intersect)
2)sometimes I get runtime error from
face min-one-of neighbors with [pcolor = blue] [distance myself]
Any advises how to solve them?

Related

NetLogo Trouble detecting turtles in radius

I'm trying to have a car visit 50 different cities in the shortest route possible, and every time he visits a place he changes the colour of the city form blue to yellow and moves on, trouble is I'm finding errors trying to find a way to implement this. I'm getting many errors in the last line of code, where it says CAR expected 1 input, a number. Any help would be appreciated.
breed [cities city]
breed [cars car]
cars-own [history travelled-distance]
to setup
clear-all
reset-ticks
setup-patches
setup-turtles
end
to setup-turtles
ask n-of 50 patches with [pcolor = 55 and not any? other turtles-here][sprout-cities 1 [set color blue set size 2 set shape "square"]]
create-cars 1[
setxy -90 -90
set color red
set size 5
]
end
to setup-patches
ask patches [set pcolor green]
ask n-of 100 patches [set pcolor brown ask neighbors [set pcolor brown]]
end
to go
ask cars [
pendown
if history <= 50
[ ;set heading towards city in-radius 10]]
move-to min-one-of cities in-radius 360 [distance myself]
]
if car in-radius 5 = true [set color = yellow]]
end
set heading towards one-of cities in-radius 10

How to force turtles to move only in a half of the world?

I created a world divided in two parts with the command ask patches with [ pxcor < 0] [set pcolor blue] ask patches with [pxcor > 0] [set pcolor green] .
In one of this there're 100 turtles, who 5 are infected and the same in the other part.
My problem is to force the turtles to move only in their part of the world. So I want that turtles with pcolor = blue move randomly in the second and third quadrant (pxcor <0) and turtles with pcolor = green in the first and fourth quadrant (pxcor> 0). how do I do?
This is the code:
turtles-own
[
sick?
sick-time]
to setup
ca
ask patches with [ pxcor < 0 ] [set pcolor blue] ; we want divide the world in two parts: the blue one in the north of Italy
ask patches with [pxcor > 0 ] [set pcolor green]; the white one is the south of Italy
ask patches with [pxcor = 0 ] [set pcolor white ] ; represent the border
create-turtles 200 ; we create a population made up for 200 people
[ set size 1
set shape "person"
set sick-time 0
get-healthy]
ask n-of 100 turtles ; 100 of this one live in north of Italy
[setxy 12 random-ycor ]
ask n-of 100 turtles ; another 100 in the south
[setxy -12 random-ycor
]
ask n-of 5 turtles with [pcolor = blue] ; we want infect 5 people for each world
[get-sick ]
ask n-of 5 turtles with [pcolor = green]
[get-sick ]
reset-ticks
end
to get-healthy
set sick? false
set color white
end
to get-sick
set sick? true
set color yellow
set shape "circle"
set sick-time sick-time + 1
end
to go
ask turtles
[
move ]
tick
end
to move
rt random-float 360
fd 1
end
Your movement procedure looks like:
to move
right random-float 360
forward 1
end
If you want them to just stay where they are if moving would take them into the wrong half, then you can use patch-ahead to test the patch they'd be moving to. I think what you want is that they don't go to a different coloured patch. One way is:
to move
right random-float 360
if [pcolor] of patch-ahead 1 = pcolor [forward 1]
end
[pcolor] of patch-ahead 1 returns the colour of the patch that is one distance unit ahead, so where the turtle is trying to move to. pcolor is the colour of the patch that the turtle is currently standing on.

Spatial Autocorrelation in NetLogo

Is there any straight-forward way to adjust spatial autocorrelation for three different patch colors? I am trying to control both the number of red patches and how spatially autocorrelated (how close same colored patches are to each other). I can control the proportion of red patches, but don't know how to setup the autocorrelation.
Here is my code so far:
to setup-patches
resize-world 0 15 0 15
set-patch-size 30
ask patches [
set pcolor one-of [ green brown ]
]
ask patches [
let close-patches patches with [pcolor != red]
ask n-of ((proportion-red-plants * count patches) - count patches with [pcolor = red]) close-patches
[set pcolor red]
]
end
proportion-red-plants is a slider in the interface
If you know that AC of 0 means pick a patch that has no red neighbours, and that AC of 1 means pick a neighbour of any red patch, then all that is required is to choose AC=1 method with the given probability and the AC=0 method otherwise. This is what I meant by a design issue, you need to work out the steps required before trying to code those steps.
Here is an almost solution. I haven't bothered to do things like make sure the patches being turned red aren't already red so the counts will be incorrect.
to setup
clear-all
let prop-red 0.1
let AC 0
ask one-of patches [set pcolor red]
ask n-of (prop-red * count patches) patches
[ ifelse random-float 1 < AC
[ ask one-of patches with [ pcolor = red ]
[ ask one-of neighbors [ set pcolor red ]
]
]
[ let candidates patches with [not any? neighbors with [pcolor = red] ]
if any? candidates
[ ask one-of candidates [ set pcolor red ]
]
]
]
end
Thank you JenB again for helping. This is the code I ended up using which proved to get the job done (while keeping counts of red patches correct)
to setup-patches
resize-world 0 15 0 15
set-patch-size 30
ask patches [set pcolor one-of [green brown]]
let first-patch one-of patches
ask first-patch [set pcolor red]
repeat (proportion-red-plants * count patches - 1) [ask one-of patches [assign]]
end
to assign
ifelse random-float 1 < AC
[let candds patches with [any? (neighbors with [pcolor = red])]
ask one-of candds [set pcolor red]]
[ask one-of patches [set pcolor red]]
end

How can i make my model count ticks faster vs the actions they are doing using NetLogo?

I'm modeling a critical situation that's happening in my city (ViƱa del Mar, Chile), where the "metro" (subway)can have serious problems if a tsunami occurs because the evacuation exits are not well prepared nor well managed.
This example is a simple model of the real one, but i was having really big problems trying to make the turtles move from the subway (blue patches), using the door (lime patch) and then jumping into the railways (gray patches). When i finally made them do those actions i found 2 problems: (1) the ticks aren't working the way i need them to work. I need it to run like it was a clock, counting seconds. (2) i create 3 actions called "check-vecinos-azul/lime/gray" where they need to check if there's any turtle arround them (neighbors). If there's an empty space arround a turtle it moves to that empty spot, otherwise it stands until it finds an empty one.
I'd be so glad if anyone of you could give me a help/tip with my model.
Thank you guys,
Kind regards,
Felipe.
breed [pasajeros pasajero]
turtles-own [
distancia
speed
speed-limit
speed-min
evacuacion
]
patches-own
[
pvacio
]
to setup
ca
setup-patches
setup-pasajeros
reset-ticks
end
to setup-patches
ask patches with [pycor <= 0]
[set pcolor blue - 1]
ask patches with [pycor > 0]
[set pcolor gray + 2]
ask patch 0 0 [set pcolor lime]
end
to setup-pasajeros
ask n-of num-pasajeros (patches with [pcolor = blue - 1])
[
sprout-pasajeros 1
[set size 1
set color orange
set speed 0.1 + random-float 0.9
set speed-limit 1
set speed-min 0
set evacuacion 0
]
]
end
to go
ask pasajeros [
ifelse evacuar?
[
go-puerta
salir-puerta
move-chancado
]
[
stop
]
]
tick
end
to go-puerta
ask turtles with [pcolor = blue - 1]
[
set evacuacion 1
if evacuacion = 1
[
check-vecinos-azul
face min-one-of patches with [pcolor = lime][distance myself]
fd speed ;;
]
]
end
to salir-puerta
ask turtles with [pcolor = lime]
[
set evacuacion 1
if evacuacion = 1
[
check-vecinos-lime
face min-one-of patches with [pcolor = gray + 2][distance myself]
fd speed
]
]
end
to move-chancado
ask turtles with [pcolor = gray + 2]
[
set evacuacion 1
check-vecinos-gray
]
end
to check-vecinos-azul
ifelse not any? turtles-on one-of neighbors
[
wait 0
move-to min-one-of patches with [pcolor = blue - 1][distance myself]
fd speed
]
[
wait 0.5
]
end
to check-vecinos-lime
ifelse not any? turtles-on one-of neighbors
[
wait 0
face one-of patches with [pcolor = gray + 2]
fd speed
]
[
wait 0.5
]
end
to check-vecinos-gray
ifelse not any? turtles-on one-of neighbors
[
wait 0
face min-one-of patches with [pcolor = gray + 2][distance myself]
fd speed
]
[
wait 0.5
]
end

How to make turtles move in one color in Netlogo

I start developping with Netlogo and I face the problem that I want to make all Turtles moving in one way which has the Black Color. How can I do that ? I tried with patch-ahead but I didn't success.
Anyone have a solution ? I will be grateful.
to setup
clear-all
import-drawing "patch.png"
create-turtles 10 [set xcor -10 set ycor -13]
ask turtles [set color white]
ask turtles [set shape "bug"]
reset-ticks
end
to bouge
ask turtles[
fd 1
]
end
to go
bouge
ask turtles [if [pcolor] of patch-ahead 6 != black [set heading heading - 100] ]
end
enter image description here
You should use something like these:
set black-patches patches with [pcolor = black]
ask turtles [
face one-of black-patches
]
Bests, Ervin