Re: [netlogo-users] Evacuation Model

21 views
Skip to first unread message
Message has been deleted

Aaron Andre Brandes

unread,
Apr 4, 2023, 9:20:19 AM4/4/23
to Ato Kwame Nsiah, netlogo-users

Hi,

You have an interesting model which must need some improvement in its logic.

This is a great opportunity to learn and use some debugging skills.

 

I ran your model and have some suggestions to help you debug your model. I think the turtles wind up with the condition  ; If no valid headings, the turtle is trapped and stops moving

Usually a “go” procedure represents one “step” of the action. You can add a “stop condition” inside if you want it to eventually stop.

 

So in your go I would remove the line   while [count turtles > 0] [. And its matching closing bracket ] and add  the line

 

    if count turtles = 1 or ticks = 50 [ stop ]

before the end.  (If your go is a forever button, otherwise just click go until the turtles are stuck.)

The ticks part of the condition is just to get the model to stop so you can do some debugging. Your turtles are trapped by then.

Now you can investigate.

 

You can simplify the situation by reducing to one turtle.

In the command center type

ask n-of (count turtles - 1) [die]

 

Now you can go back to your go procedure and add print statements so you can find the value of nearest-exit,  valid-headings, best-heading and other variables.

Check whether they make sense. Look at where the nearest exit is. Look for unexpected results. For example if the turtle appears to have a heading that works,  and valid-headings is an empty list figure out why.  You might want to increase the choice of headings. The primitive range will let you easily create a list of as many evenly spaced headings as you want.

 

Have fun,

Aaron

-- 

Aaron Brandes, Software Developer

Center for Connected Learning and Computer-Based Modeling

 

 

From: netlog...@googlegroups.com <netlog...@googlegroups.com> on behalf of Ato Kwame Nsiah <aton...@gmail.com>
Date: Monday, April 3, 2023 at 8:50 PM
To: netlogo-users <netlog...@googlegroups.com>
Subject: [netlogo-users] Evacuation Model

Hello, i am trying to create an evacuation model but some of the agents in my model just stick to a wall and stay put. The model features two big rooms with mutiple utility rooms attached to them. I also my the tick counter to stop once the agents have exited the building.This is my code below:

globals [ wall door move-speed ]

patches-own [ exit elevation path ]

turtles-own [ moved? ]

to setup
  clear-all
  setup-patches
  create-agents
  reset-ticks
end

to setup-patches
  resize-world -15 15 -15 15
  draw-wall
  draw-exit
  draw-utility-rooms
  draw-stairs
  ask patches [
    set elevation 0
    set path 0
    if pcolor = gray or pcolor = red or pcolor = yellow or pcolor = orange [set elevation 9999999]
  ]
  ask patch 0 0 [
    set plabel-color white
  ]
end

to draw-wall
  ask patches with [pxcor <= max-pxcor and pxcor >= min-pxcor and (pycor = min-pycor or pycor = max-pycor)]
    [set pcolor gray]
  ask patches with [pycor <= max-pycor and pycor >= min-pycor and (pxcor = min-pxcor or pxcor = max-pxcor)]
    [set pcolor gray]
  ask patches with [pycor = 0 and pxcor < max-pxcor and pxcor > min-pxcor] [set pcolor gray]
  ask patches with [pxcor = max-pxcor - 5 and pycor < max-pycor and pycor > 0] [set pcolor gray]
  ask patches with [pxcor = max-pxcor - 5 and pycor > min-pycor and pycor < 0] [set pcolor gray]
end

to draw-exit
  ask patches with [pxcor = min-pxcor and pycor = max-pycor]
    [set pcolor green]
  ask patches with [pxcor = min-pxcor and pycor = min-pycor]
    [set pcolor green]
  ask patches with [pxcor = max-pxcor - 5 and pycor = max-pycor]
    [set pcolor green]
  ask patches with [pxcor = max-pxcor - 5 and pycor = min-pycor]
    [set pcolor green]
  ; Add doors for the vertically aligned utility rooms
  ask patches with [pxcor = max-pxcor - 5 and pycor = 4] [set pcolor green]
  ask patches with [pxcor = max-pxcor - 5 and pycor = -4] [set pcolor green]
end

to draw-utility-rooms
  ; Define the utility rooms for the top big room
  ask patches with [pxcor >= max-pxcor - 4 and pycor >= max-pycor - 4 and pycor < max-pycor] [set pcolor red ]  ;First Utility Room
  ask patches with [pxcor >= max-pxcor - 4 and pycor >= 4 and pycor <= 10] [set pcolor yellow]  ;Second Utility Room
  ask patches with [pxcor >= max-pxcor - 4 and pycor >= 1 and pycor <= 3] [set pcolor green]  ;Third Utility Room


  ; Merge the third utility room of the top big room and the first utility room of the bottom big room
  ask patches with [pxcor >= max-pxcor - 4 and pycor = 0] [set pcolor green]
  ask patches with [pxcor >= max-pxcor - 4 and pycor <= -1 and pycor >= -4] [set pcolor green]

   ; Define the utility rooms for the bottom big room
  ask patches with [pxcor >= max-pxcor - 4 and pycor <= -5 and pycor >= -7] [set pcolor red] ;First Utility Room
  ask patches with [pxcor >= max-pxcor - 4 and pycor <= -8 and pycor >= -13] [set pcolor yellow] ;Second Utility Room
  ask patches with [pxcor >= max-pxcor - 4 and pycor <= min-pycor + 4 and pycor > min-pycor] [set pcolor green] ;Third and bottom utility
end




to draw-stairs
  ask patches with [pxcor = min-pxcor + 1 and pycor = max-pycor]
    [set pcolor orange]
  ask patches with [pxcor = min-pxcor + 1 and pycor = min-pycor]
    [set pcolor orange]
end

to create-agents
  set-default-shape turtles "person"
  ask n-of num-agents patches with [pxcor < max-pxcor and pycor < max-pycor and pxcor > min-pxcor and pycor > min-pycor and pcolor = black]
  [
    sprout 1 [
      set size 1.5
      set color green
    ]
  ]
end


to go
  while [count turtles > 0] [
    if count turtles = 0 [print "the time taken:" print ticks reset-ticks stop]
    ask patches with [pcolor = green] [ask turtles-here[die]]

    ask turtles [
      let nearest-exit min-one-of patches with [pcolor = green] [distance myself]
      face nearest-exit

      let possible-headings [0 45 90 135 180 225 270 315]
      let wall-following [90 -45]

      ; Filter out the headings that would lead the turtle into a wall
      let valid-headings []
      foreach possible-headings [
        h -> if [pcolor] of patch-ahead 1 != gray [
          set valid-headings lput h valid-headings
        ]
      ]

      ; Choose a random valid heading and move forward
      ifelse not empty? valid-headings [
        let current-distance distance nearest-exit
        let best-heading heading
        let best-distance current-distance
        foreach valid-headings [
          h ->
          set heading (heading + h) mod 360
          let new-distance distance nearest-exit
          if new-distance < best-distance [
            set best-distance new-distance
            set best-heading heading
          ]
          set heading (heading - h) mod 360
        ]
        set heading best-heading
        forward 1
      ] [
        ; If no valid headings, the turtle is trapped and stops moving
        stop
      ]


    ]

    tick
    wait 0.1  ; Adjust the delay value as needed (0.1 represents a 100ms delay)
  ]
end

--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/44e02226-6aa3-4979-9f61-84c880d46020n%40googlegroups.com.

Pradeesh Kumar K V

unread,
Apr 4, 2023, 10:19:13 AM4/4/23
to netlogo-users
You could also consider unchecking 'World wraps horizontally' and 'World wraps vertically'. When I ran the model with the world wrapped both horizontally and vertically, I observed that an agent walks into a wall on the opposite side of an exit whenever the agent is nearer to the wall than the exit. 

In a world wrapped horizontally, the surface on which the agent moves is cylindrical with no boundaries / edges. Even if we think that the agent is at a great distance from the door (i.e. in the perceived flat world), it is infact near to the door in the actual cylindrical world implemented in the model. Therefore, the agent moves towards the door. But it encounters the wall before it reaches the door and therefore it stops moving.

Aaron Andre Brandes

unread,
Apr 4, 2023, 6:42:07 PM4/4/23
to Ato Kwame Nsiah, netlogo-users

Hi,

 

I am forwarding your latest question to the whole netlogo-users group. This gives you opportunity to benefit from a larger group, and may be of some interest to group members.

 

I work on NetLogo development and generally can’t spend time on debugging that does not involve problems with NetLogo itself.

 

I am pleased that you have started the debugging process, and have a few suggestions.

 

I would add a button that executes go only once (not a forever button) which you can label “go once” This is often useful for debugging. Just watching what the turtles do each time can be informative.

Instead of the line

  if count turtles = 1 or ticks = 50 [ stop ]

near the top of go, I would remove it and add

  if count turtles = 0 [ stop ]

to right before the end of the procedure

The count of 1 was an error on my part, and you should be able to stop the forever button by clicking on it since the while is gone.

 

I left a word out of one of my suggestions. It should be

ask n-of (count turtles - 1) turtles [die]

 

It will be easier to debug with only one turtle.

 

I think you are missing an end of range in the line

    let wall-following (range 90 -45)

if you copy (range 90 -45)

to the command center you will see that it produces an empty list, so make a change and check that it does what you want.

Also note you need to be careful about making sure the last value you want is included in the range.

 

The user’s comment about making sure the world doesn’t  wrap is a good one.

 

One of your problems is that you are not making use of the heading in looking for valid headings,

if [pcolor] of patch-ahead 1

 

Please check out this documentation

patch-at-heading-and-distance heading distance

 

You can improve your current test with

 

    foreach possible-headings [

      h -> let the-patch  patch-at-heading-and-distance  1 h 

      if the-patch != nobody and [pcolor] of the-patch != gray [

        set valid-headings lput h valid-headings

      ]

    ]

 

When I did this the only turtles left had managed to get inside the wall.

 

You will probably need more print statements to figure things out.

 

-Aaron

-- 

Aaron Brandes, Software Developer

Center for Connected Learning and Computer-Based Modeling

 

 

From: Shaw Taylor <aton...@gmail.com>
Date: Tuesday, April 4, 2023 at 12:24 PM
To: Aaron Andre Brandes <aaron....@northwestern.edu>
Subject: Re: [netlogo-users] Evacuation Model

Hello sir, i implemented your suggestion and the movement of the agents is much better but a few agents still get stuck at a wall and cease all movement. I have made several changes to the possible headings range as well as the wall-following ranges:


to go


  if count turtles = 1 or ticks = 50 [ stop ]

  ask patches with [pcolor = green] [ask turtles-here[die]]

  ask turtles [
    let nearest-exit min-one-of patches with [pcolor = green] [distance myself]

    print (word "nearest-exit: " nearest-exit)
    face nearest-exit

    let possible-headings (range 0 360 10) 
    let wall-following (range 90 -45)



    ; Filter out the headings that would lead the turtle into a wall
    let valid-headings []
    foreach possible-headings [
      h -> if [pcolor] of patch-ahead 1 != gray [
        set valid-headings lput h valid-headings
      ]
    ]

    print (word "valid-headings: " valid-headings)



    ; Choose a random valid heading and move forward
    ifelse not empty? valid-headings [
      let current-distance distance nearest-exit
      let best-heading heading
      let best-distance current-distance
      foreach valid-headings [
        h ->
        set heading (heading + h) mod 360
        let new-distance distance nearest-exit
        if new-distance < best-distance [
          set best-distance new-distance
          set best-heading heading
        ]
        set heading (heading - h) mod 360
      ]
      set heading best-heading

      print (word "best-heading: " best-heading)
      forward 1
    ] [
      ; If no valid headings, the turtle is trapped but continues to move
      let wall-follow-valid-headings []
      foreach wall-following [


        h -> if [pcolor] of patch-ahead 1 != gray [

          set wall-follow-valid-headings lput h wall-follow-valid-headings
        ]
      ]

      if not empty? wall-follow-valid-headings [
        let chosen-wall-follow one-of wall-follow-valid-headings
        set heading (heading + chosen-wall-follow) mod 360
        forward 1
      ]
      ;[
      rt 180
       ;[ 
    ]
  ]
    
  tick
  display
end


Any further suggestions would be greatly appreciated. Thank you.


Reply all
Reply to author
Forward
Message has been deleted
0 new messages