Volunteer coordination system for modelling natural disaster emergencies [closed] - netlogo

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
This model is a system model of centralized coordination of volunteers for the Response Phase of a volcanic eruption. Agent (Volunteers) were placed randomly will try to reach the point of barracks (red colored patches). Each agent (volunteers) has energy capacity will be channelled to the point barracks if a volunteer has been able to achieve. Point barracks have demand could be reduced by the capacity of volunteers if the volunteer is able to reach the point of the refugee camps.
Problems on the program I created is a volunteer movement was not run in accordance with a predetermined color patch and move back and forth. Volunteers can’t choose to turn left or turn right if the color patch in front of it instead of the specified color. Is there a solution for the movement of agents (volunteers) about this model?
Besides how volunteers can measure the shortest distance to the agent could reach the point quickly barracks?
Furthermore, is there any way that volunteers can perform a search where the evacuation point that must be reached in advance if the demand of each point varies barracks or upon priorities?
This is my code:
to go
if ticks = 180 [ stop]
ask Volunteers
[ifelse capacity = 0 [ fd 0 frozen][ move search ]]
;search
;update-demand
tick
display-labels
do-plots
end
to move
ask Volunteers
[
move-to one-of patches in-radius 2 with [pcolor = 0]
ifelse [pcolor] of patches in-radius 2 = 0 [move-to one-of patches in-radius 2 with [pcolor = 0]]
[
ifelse [pcolor] of patch-ahead 1 = 105 [set heading -180 move-to one-of patches in-radius 2 with [pcolor = 0] ]
[
ifelse [pcolor] of patch-ahead 1 = 8 [set heading -180 move-to one-of patches in-radius 2 with [pcolor = 0]]
[
if [pcolor] of patch-ahead 1 = red [move-to one-of patches in-radius 2 with [pcolor = red] fd 0 ]
]
]
]
]
end
to search
if any? turtles-on patches with [ pcolor = red ]
[
ifelse capacity < demand
[
set demand (( 1 + Rate-of-Demand) * (demand - (capacity * (1 + Rate-of-Capacity))))
set capacity 0
]
[set capacity (( 1 + Rate-of-Capacity) * (capacity - demand ))
set demand 0 ]
]
end
to frozen
if capacity = 0
[ fd 0
set waiting-time waiting-time + 1
if waiting-time > 5 [set capacity 1000 / Jumlah-Relawan set waiting-time 0]
]
end

I've just recently finish, not the exact same but mostly the same, this kind of model.
The model I made is about evacuation of the people. and just like you, I am a student in UGM too.
The solution I used to solve the agent's movements is implementing a shortest-path algorithm in the netlogo code.
You could look up, Djikstra Algorithm or other. In my case, I use a*(aStar) algorithm. There are some example of a* implementation in netlogo as well. you could look it up.
I could only help this far, just like Seth Tisue Said, any details answer would take hours to write.
Hope it helps.

Related

Color a radius of patches Netlogo

im trying to show a cultivation process. At setup im creating the farmers and giving them a random farm size (with the splotch) then, at go, im telling them that if they have enought money all patches near them that are the splotch turn into green, representing cultivation. But its just changing one pixel and not all round it. It most be someting small but i cant see it. Thanks in advance for the help
.
breed [cercas cerca]
breed [medios medio]
breed [lejos lejo]
patches-own[calidad
cercanialago
cultivado
]
turtles-own [ingresos
gastos]
create-cercas 10 + random 10
[ set size 1 ;; easier to see
set color 135
setxy random xcor random ycor
move-to one-of patches with [not any? other turtles in-radius 3 and pcolor = 57]
set heading random 45 + 45
set ingresos 1000000 + random 6000000
]
ask turtles
[ ask patches in-radius (1 + random 3)
[ set pcolor 35 ] ]
to go
ask cercas [
ifelse ingresos > 2000000 [if any? patches in-radius 4 with [pcolor = 35] [if ticks mod 3 = 0 [set pcolor 62] ]]
[]
] ```
Your cercas are a breed of turtles.
A useful feature of NetLogo is that any turtle can directly read and modify the variables of the patch it is on (i.e. without the need to invoke such patch).
So when you ask a turtle to set pcolor 62, it will automatically refer to pcolor of the patch it is on.
If we eliminate all of the conditions from your last block of commands, we have:
ask cercas [set pcolor 62]. This is what you are asking cercas to do: simply changing the pcolor of the patch they are on.
The fact that you use patches in-radius 4 in the condition for the first if statement does not influence the ask cercas [set pcolor 62] part. The condition is one thing, the command to be executed if the condition holds true is a separate thing.
Therefore you should make cercas ask patches in-radius 4 to change their pcolors.

Netlogo ask turtles to go to the second destination after reaching the first destination

I am trying to write some code in Netlogo to ask my turtles to go to the second destination after reaching the first destination. Here's my code and hope it will help explain my question.
SETUP:
First, the patch will generate turtles, and I will give each turtle a variable called my-patch:
ask n-of 40 patches with [ pxcor > -23 and pxcor < -5 and pycor < 21 and pycor > -6]
[
set quad-patch 1
sprout 1 [
set origin-turtle 1
set color yellow
set my-patches patch-here
set goal one-of patches with [pxcor = 0 and pycor = 12]
set speed 0.1 + random-float 0.9
set size 0.5
set shape "person"]
]
Secondly I will ask these turtles to move to the road which is outside the building:
set road patches with [
(pxcor > 45 and pycor <= 8 and pycor >= -18)
]
ask turtles [
move-to one-of road with [not any? other turtles]
]
GO:
This is the tricky part. Now I have set up a path to ask my turtles walk along that path and go into the building. So first I set a goal which is like a rest point in the building. All the turtles will head off to that rest point first and then they will start to find their origins (which I saved as a variable as mentioned before called my-patches).
to go
ask turtles with [should-stay = false] [
move
]
tick
end
to move
face best-way-to goal
avoid-walls
ifelse patch-here != goal
[fd 1]
[find-origin]
end
to avoid-walls
if [wall] of patch-ahead 1 = 1
[set heading heading - 180]
end
to find-origin
face my-patches
fd 1
end
to-report best-way-to [ destination ]
; of all the visible route patches, select the ones
; that would take me closer to my destination
let visible-routes patches with [ path = 1 ]
set routes-that-take-me-closer visible-routes with [
distance destination < [ distance destination - 1 ] of myself
]
ifelse any? routes-that-take-me-closer [
; from those route patches, choose the one that is the closest to me
report min-one-of routes-that-take-me-closer [ distance myself ]
] [
; if there are no nearby routes to my destination
report destination
]
end
So my problem is after turtles move along the walking path that I have set, they seem to stop at the rest point instead of moving on to find their origins (my-patch). I know this is because the code I set here:
ifelse patch-here != goal
[fd 1]
[find-origin]
But I am not sure how to ask these turtles go to find their origins next after they already reached at this rest point? Any help is really appreciated. Thanks!

You can't use Migrate in a turtle context, because migrate is observer-only

I managed to build my small model, but i do get an error, but don't know why?
Ps: i'm a bloody beginner
The Error code is:
You can't use migrate in a turtle context, because migarte ia observer-only.
So what can I do?
Thank you for your answers.
breed [fish a-fish]
breed [boats boat]
boats-own [profit]
to setup
clear-all
ask patches [set pcolor blue]
set-default-shape fish "fish"
create-fish initial-number-fish
[
set color grey
set size 1.0
setxy random-xcor random-ycor
]
set-default-shape boats "boat"
create-boats initial-number-boats
[
set color black
set size 1.5
set profit random (1 * profit-per-fish)
setxy random-xcor random-ycor
]
reset-ticks
end
to go
if not any? turtles [stop]
ask fish
[
move
fish-reproduce
]
ask boats
[
move-boats
catch-fish
death
reproduce-boats
migrate
]
tick
end
to move
rt random 50
lt random 50
fd 1
end
to fish-reproduce
if random-float 100 < fish-growth
[hatch 1 [rt random-float 360 fd 1]]
end
to move-boats
rt random 50
lt random 50
fd 1
set profit profit - 0.1
end
to catch-fish
let prey one-of fish-here
if prey != nobody
[ask prey [die]
set profit profit + profit-per-fish]
end
to death
if profit < 0 [die]
end
to reproduce-boats
if profit > 1
[
set profit (profit / 2)
hatch 1 [rt random-float 360 fd 1]]
end
to migrate
if random-float 100 < random-spawn-rate
[create-turtles 2 [rt random-float 360 fd 1]]
end
There are 3 different primitives for creating new turtles in NetLogo:
create (observer), hatch (turtle) and sprout (patch).
Each one works only in a specific context.
This means you have to be aware of the context in which you are calling your procedure.
In your example, you are calling the create-turtles primitive inside of an ask turtles (specifically ask boats) context. Which means you are in a turtle context and not in an observer context and therefore create-turtles is not allowed to use.
To solve your problem, you just have to replace create-turtles by hatch (or hatch-<breed>, like hatch-fish if you want to spawn new agents in a specific breed).

NetLogo: creation of lattice/grid resources world without using turtles?

I would like to create a "gridded" world of resources, in specific distance from the central patch and keep distances equal between these patches. Due to calculation demand, I prefer not to use turtles to create this patchy world. I expect to create something like this:
Equally, I would like to define distance between patches as a slider tool. I was wandering to use turtle lattice walk and then turn patches to different color, but is there any way how to do that without turtles ? Thanks for any suggestions !
My not totally working exemple:
to setup
clear-all
ask patches [set pcolor green]
foreach [5 10 15] [
repeat 9 [
make-red-patch ?
]
]
reset-ticks
end
to make-red-patch [dist]
crt 1 [
fd dist
rt 90
while [pcolor = red] [
bk dist
rt 90
fd 2 * dist
]
set pcolor red
die
]
end
I am not exactly sure what you need, first you mentioned you don't want to use turtles and in your own answer you have problem with the patch without a turtle.
There might be another way to approach this question:
to setup
clear-all
ask patches with [pxcor mod Grid = 0 and pycor mod Grid = 0] [set pcolor red]
end
And these are examples with different Grid size:
After more detailed search I found my answer here: http://netlogo-users.18673.x6.nabble.com/Setting-up-agents-in-a-grid-formation-td4864083.html
They consider to distribute turtles, not patches and then attribute patches turtles' qualities.
Here is the code:
to setup
clear-all
create-turtles 1
[ let $n 0 ; actual number of turtles on this patch
let $s 0 ; current number of turtles on a side of square pattern - 1
set heading 0
ask patch-here [set pcolor red]
repeat 16 ; number of needed turtles
[ hatch 1 jump Grid ; make one turtle and move
set $n $n + 1 ; increment count of curent side
ask patch-here [set pcolor red]
if $n > $s ; if side finished...
[
right 90 set $n 0 ; turn and reset count
ask patch-here [set pcolor red]
; if headed up or down, increment side count
if heading mod 180 = 0 [ set $s $s + 1
]
]
]
die
]
end
which produce:
I still don't know how to deal with 1 patch without turtle (bottom right corner), but this exemple helped me a lot ! :)

Define home area-turtles?

I am very new to netlogo. I have searched every question here before I posted this.
I have the following code which sprouts a given number of horses:
ask n-of Number-horses patches with [grass? = "Yes"]
[sprout-horses 1 [set color 25 ]]
The person can change the number of horses using the slider but I would like each horse to have its own area/range/radius.
They can only move within this radius/area and they cannot meet each other.
From what I've read it's got something to do with the distance function?
You can find a similar problem here which has examples too :
Spacing agents in NetLogo based on territory size
There are several ways that you can assign a territory zone to each horse, but all methods that I know have two steps, first step is in order to make sure initial home area of horses are separated from each other , So we need to create horses only in patches which has a certain distance from another patch which has a horse on it,I did not follow your method that asked patches to sprout horses and instead I created them without asking patches.
I was not sure how you defined grass? Variable for each patch but I have assigned a number of patches with grass? = true and others false.
Second step is to set home-area property of each horse. If initially you moved them far away from each other they will have separate territories.
I have included a few examples here :
First to use in-radius for both steps:
Breed [Horses horse]
Horses-own [home-area]
patches-own [grass?]
globals [Zone-Radius]
to setup
clear-all
reset-ticks
set Zone-Radius 2
ask patches
[
ifelse pxcor mod 5 = 3
[ set Grass? true ]
[ set Grass? false ]
]
create-horses Number-horses
[ Move-to one-of patches with [Grass? and not any? other horses in-radius (Zone-Radius + 1)]
set home-area patches in-radius Zone-Radius
set color 25
]
end
to go
ask horses [
ifelse member? patch-ahead 1 home-area
[rt random 10 fd 1 ] ; move if next patch is in their zone
[rt random 180]
]
tick
end
In this example horses only move in the patches in their radius 2. But you can change that base on your model requirements.
In the second method you can use distance for the first step (finding empty patches with enough distance to current patch) and radius for second one (assigning home-area to each horse).
Move-to one-of patches with [Grass? and not any? other horses with [distance myself < (Zone-Radius + 1)]]
set home-area patches in-radius Zone-Radius
If you use higher distance for finding empty patches you will have completely seprated zones. Finally , you can use distance for both steps:
Move-to one-of patches with [Grass? and not any? other horses with [distance myself < (Zone-Radius + 1)]]
set home-area patches with [distance myself < Zone-Radius]
I just did it another way:
Breed [Horses horse]
Horses-own [home-area]
patches-own [ concession? forest? parks?]
globals [Zone-Radius]
to setup
clear-all
reset-ticks
set Zone-Radius 2
ask n-of 500 patches [ set concession? "No" ]
ask n-of 500 patches[ set forest? "Yes" ]
ask n-of 500 patches[ set parks? "Yes"]
let i 0
while [i < Number-horses]
[
ask one-of patches with [(concession? = "No" or forest? = "YES" or parks? = "YES" ) and (not any? horses in-radius (Zone-Radius + 2) )]
[
sprout-horses 1 [
set home-area patches with [distance myself < Zone-Radius]
let w who
ask home-area [set pcolor red]
set color 25 ]
]
set i (i + 1)
]
end
to go
ask horses [
ifelse member? patch-ahead 1 home-area [rt random 10 fd 1 ] [rt random 180]
]
tick
end
As you can see I used while and a condition to ask patches one by one, I might be mistaken but when I ask all the n-of Number-of-horses patches with [YourCondition][...] I get the wrong results and distance between horses is not effective, maybe they are created all at the same time and therefore upon creating a horse there was no horse nearby!? I am new to these concepts and might be wrong.
This is the code and view for the one which asks patches to create horses at once here :
Breed [Horses horse]
Horses-own [home-area]
patches-own [ concession? forest? parks?]
globals [Zone-Radius]
to setup
clear-all
reset-ticks
set Zone-Radius 2
ask n-of 500 patches [ set concession? "No" ]
ask n-of 500 patches[ set forest? "Yes" ]
ask n-of 500 patches[ set parks? "Yes"]
ask n-of number-horses patches with [(concession? = "No" or forest? = "YES" or parks? = "YES" ) and (not any? horses in-radius (Zone-Radius + 2) )]
[
sprout-horses 1 [
set home-area patches with [distance myself < Zone-Radius]
let w who
ask home-area [set pcolor red]
set color 25 ]
]
end
to go
ask horses [
ifelse member? patch-ahead 1 home-area [rt random 10 fd 1 ] [rt random 180]
]
tick
end