Reputation: 15
I am new to netlogo and developing a model that incorporates floor plans in which agents essentially evacuate the building avoiding obstacles etc. I have set up my model so that a node sprouts on every patch within the building, and by modifying an example i found on here by Luke C i have programmed the agents to select a path towards the exit.
The problem i am experiencing however, is that only one agent moves per tick. Is there any way i can change this? so for example, an agent will move forward 1 patch per tick, cycling through agents this way? I understand that more than one agent cannot move per tick. Thank's in advance!
Here is the code
extensions [ nw ]
breed [nodes node]
breed [evacuees evacuee]
breed [leaders leader]
breed [cells cell]
evacuees-own [panic calm speed fear direction enterthenetwork]
leaders-own [calm speed ]
to setup
ca
clear-all
set-default-shape turtles "person";
import-pcolors "foreal2.png"
set-default-shape nodes "circle"
ask patches with [ pcolor = white ] [
sprout-nodes 1 [
set size 0.5
set shape "circle"
set color green
]
]
ask nodes [
create-links-with turtles-on neighbors4 [
set color green
]
]
ask n-of evacnum nodes [
hatch 1 [
set size 10
set color green
set breed evacuees
set shape "person"
]
]
ask n-of 2 evacuees [
set color blue
]
ask patch 146 199
[
sprout-cells 1 [
set size 1.5
set shape "box"
set color yellow
]
]
reset-ticks
end
to avoid-walls
let front-patches patches in-cone 2 75
if [pcolor] of one-of front-patches = black [set heading heading - -120]
end
to go
let ready-evacuees evacuees with [ color = green ]
let evac-proxies turtle-set map [ i -> [nodes-on patch-here] of i ] sort
ready-evacuees
ask one-of cells [
let node-proxy one-of nodes-on neighbors4
ask node-proxy [
let my-evac-proxy min-one-of evac-proxies [length ( nw:turtles-on-path-
to myself) ]
ask my-evac-proxy [
let path-to-follow nw:turtles-on-path-to myself
ask turtle-set path-to-follow [
set color orange
]
let ready-evacuee one-of evacuees-here with [ color = green ]
ask ready-evacuee[
set color yellow
]
ask ready-evacuee [
foreach path-to-follow [
n ->
face n
move-to n
wait 0.1
]
]
]
]
]
end
Upvotes: 1
Views: 309
Reputation: 17678
Here is a complete model that will give you a starting point. It includes movement toward an evacuation point and using min-n-of
(like min-one-of
) to find somewhere to move towards. You will need to use the speed slider (top middle) to slow this down to see the behaviour.
To build your model, try making smaller changes and getting them to work before adding the next element. For example, you should not consider walls until you have the movement sorted out. And it's unclear what all the different breeds are for.
breed [nodes node]
breed [evacuees evacuee]
evacuees-own
[ target
]
to setup
clear-all
create-evacuees 100
[ setxy random-xcor random-ycor
set shape "person"
set color blue
]
create-nodes 20
[ setxy random-xcor random-ycor
set shape "circle"
set color red
]
ask evacuees
[ set target one-of min-n-of 5 nodes [distance myself]
face target
]
reset-ticks
end
to go
move
end
to move
ask evacuees
[ forward 0.25
if distance target < 0.2
[ set target one-of min-n-of 5 nodes [distance myself]
]
face target
]
end
Upvotes: 1
Reputation: 17678
Unfortunately, this is not an easy fix of simply changing some of your code to make it work. You appear to have a fundamental conceptual issue. At a code level, you are using wait 0.1
to stop everything happening immediately, and you don't have any command tick
to advance time.
Conceptually, you need to separate the things that are there when you start and the things that happen through time. You have done this, breaking your model into the setup
and go
procedures as normal. But within the time progression, you need to imagine a tick
as representing some specific amount of time (let's say 10 seconds). What happens within a 10s slice of time - all your evacuees move to the next node, or at least towards it or whatever.
As a first approximation:
ask one-of
type constructions with ask
(that will instruct them all to do it).wait
instructiontick
as the last command in the go procedure (to advance the clock)Then your go button will move through time every time you press it. You can edit the go button to repeatedly run the go procedure by checking the 'forever' box.
Upvotes: 3