This problem occurred to me. The passengers move, but do not go towards the exit in a smart way and remain in the centre moving around. They also move out of the edge of the room. How can I solve it?
I need to do this thing:
If a cell is a PP (possible position) of an exit, it may be occupied by the occupant at the next time step.
Each exit may have more than one PP. On the other hand, each occupant can only stay in one cell within a time step. In the proposed CA model, the probability of an exit’s PP to be occupied within the next time step is assumed to be equal. The cell to be selected is termed the Lucky PP (LPP). Assuming the number of PP of an exit is M, the probability of each PP to be a LPP is Pu= 1/M
This error appear when pressing the Setup button:
WITH expected input to be an agentset but got the patch (patch 35 -7) instead.
error while passenger 22 running WITH
called by procedure CHOOSE-EXIT
called by procedure INITIALIZE-PASSENGERS
called by procedure SETUP
called by Button 'setup'
breed [ passengers passenger]
breed [ fire-spots a-fire-spot]
breed [ smoke-spots a-smoke-spot]
globals [ exit1 ;; pID
exit2 ;; pID
exits-list ;; [ pID ... ]
passenger_count ;; integer
exit-probabilities ;; [probability ...]
]
passengers-own [ in-seat? ;; boolean
safe? ;; boolean
dead? ;; boolean
panic? ;; boolean
current-heading ;; turtleHDG
target-exit ;; pID
my-exits-list ;; [ pID ... ]
item? ;; boolean
]
patches-own [ accessible? ;; boolean
fire? ;; boolean
]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; FUNZIONI SETUP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to setup
__clear-all-and-reset-ticks
;;;;;; DEBUG
type "----------------------------[SETUP]\n"
;;;;;; DEBUG
initialize-globals
initialize-train
initialize-exits
initialize-passengers
; initialize-fire
reset-ticks
end
to initialize-globals
set exit1 patch 64 -13
set exit2 patch 13 -54
set exits-list ( list exit1 exit2 )
set exit-probabilities (list 0.5 0.5)
end
to initialize-train
import-pcolors "images/ambiente.png"
ask patches [
if pcolor = 86.6 [set pcolor cyan]
if pcolor = 0 [set pcolor black]
if pcolor = 64.3 [set pcolor green]
if pcolor = 9.9 [set pcolor white]
set fire? false
set accessible? false ; Imposta tutte le patch come inaccessibili di default
]
ask patches with [pcolor = white] [
set accessible? true ; Contrassegna le patch verdi come accessibili
]
end
to initialize-exits
set exit1 patch 64 -13
set exit2 patch 13 -54
set exits-list (list exit1 exit2)
end
to initialize-passengers
create-passengers passenger-count [
set shape "person business"
set size 2
set color yellow
set in-seat? false ; Cambia da true a false
set safe? false
set dead? false
set panic? true
set current-heading 0
set my-exits-list [] ; SET here, it must assign a []-list to this property BEFORE next call to choose-exit
set target-exit nobody ; SET this as the initial target-exit
; Aggiungi il seguente blocco di codice per posizionare casualmente i passeggeri in patch accessibili
let target one-of patches with [accessible?]
move-to target
set target-exit choose-exit patch-here ; Aggiorna il target-exit dopo esserti spostato sulla patch iniziale
update-exit-probabilities self
]
end
to-report choose-exit [current-position]
let possible-exits []
let shortest-distance 10000
let nearest-exit nobody
foreach exits-list [ exitUnderTest ->
let exit-coords (list [pxcor] of exitUnderTest [pycor] of exitUnderTest) ;; Get exit coordinates as a list
let exit-distance distance exitUnderTest
if exit-distance < shortest-distance [
set shortest-distance exit-distance
set nearest-exit exitUnderTest
set possible-exits []
]
if exit-distance = shortest-distance [
set possible-exits lput exit-coords possible-exits ;; Use exit coordinates instead of the patch object
]
]
if length possible-exits = 0 [
print "No exits found."
report nobody
]
; Use the updated exit probabilities to choose the exit
let lucky-exit-coords one-of weighted-n-of 1 possible-exits exit-probabilities
let lucky-exit patch-at (item 0 lucky-exit-coords) (item 1 lucky-exit-coords) ;; Get the object using the coordinates
set target-exit lucky-exit
; Calculate the possible positions (PP) around the lucky exit
let pp-list (patch-set [neighbors4] of lucky-exit with [accessible?])
; Calculate the probability of each PP to be a LPP
let M count pp-list
let P 1 / M
; Select a LPP for the passenger
let lpp one-of pp-list
face lpp
set my-exits-list lput lucky-exit my-exits-list
report lpp
end
to update-exit-probabilities [passenger1]
let kie 1.5
let initial-exit [target-exit] of passenger
let initial-exit-index position initial-exit exits-list
let initial-exit-probability item initial-exit-index exit-probabilities
let pie kie * initial-exit-probability
if pie > 1 [ set pie 1 ]
let delta-pi pie - initial-exit-probability
let updated-exit-probabilities []
foreach exit-probabilities [p ->
let index position p exit-probabilities
if index = initial-exit-index [
set updated-exit-probabilities lput pie updated-exit-probabilities
] [
let pje p - (p / (1 - initial-exit-probability)) * delta-pi
set updated-exit-probabilities lput pje updated-exit-probabilities
]
]
set exit-probabilities updated-exit-probabilities
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; FUNZIONI GO ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to go
;;;;;; DEBUG
type "----------------------------[GO.tick]\n"
;;;;;; DEBUG
ask passengers [
if panic? [
let target-to-exit choose-exit patch-here
face target-to-exit
]
move
]
tick
end
;;;go()
to move
if panic? [
let next-patch patch-ahead 1
if [accessible?] of next-patch and not any? other passengers-here [
move-to next-patch
if member? patch-here exits-list [
set safe? true
set in-seat? false
]
]
]
end
The ABM-simulation code as-was, after MCVE-reproducibility-GAPs fixed, experiences many further conceptual gaps (even without further creeping of the posted code-updates and ideas, do not creep post-content. This is not considered correct here). As the as-was code is being heavily (if not exclusively) Agents'-properties data-driven,
but not properly equipped with detecting the Agents' in-scene locality context and some Simulation-goal consistent and relevant self-adaptive behaviour re-evaluation, the execution keeps headbanging and will keep doing so into many further collisions, until properly refactored.
Best start with revision & re-design all data-driving assignments, where proper fusing for
!DIV0and/or emptylist-instances, voidagentSet-s orNOBODYobjects result and must result in crashing the syntax-expectations of the simulation-language ( NetLogo ).You have been provided both tools, bonuses and other insights to improve your re-factored design, to develop the global simulation strategy further on.
(for previous release of the NetLogo code -- see post-revisions)
The original post went through review (naturally not reflecting the last minute changes, announced right now) and after obvious repairs of reproducibility GAPs, the code is reproducing some other kind of data-driven errors.
Feel free to use the tools offered and continue debugging further on, also perhaps resolving some bonus-inlined remarks that indicate future problems your ABM-simulation will sooner or later experience.