NetLogo中的疏散建模

时间:2018-08-23 23:26:53

标签: netlogo

我正在根据一个简单的计划建模疏散模型,该计划有4个房间和一个走廊。我在从房间到走廊以及从走廊到主要出口的位置导航代理商时遇到问题。你能指导我吗?enter image description here

我写的代码在那里:

  globals [
  wall
  window
  door
  goal-x goal-y
  n
]

patches-own [path?]
turtles-own [direction
  fast?

  other-nearby]

to setup
  clear-all

    setup-patches

   set-default-shape turtles "person" ;makes them look like people
   ask n-of number-room1 patches with [pxcor < 71 and pycor < 79 and pxcor > 0 and pycor > 50 and pcolor = black]  ; makes turtles sprout on black patches = room1
  [
  sprout 1 [

      set size 5              ;; setting turtle size
      facexy 124 79 ; initial direction faceing
      set direction 1
      set color yellow     ;initial color

    ]
    ]

  ask n-of number-room2 patches with [pxcor < 112 and pycor < 79 and pxcor > 71 and pycor > 50 and pcolor = black]  ; makes turtles sprout on black patches= room2
  [
  sprout 1 [

      set size 5              ;; setting turtle size
      facexy 124 79 ; initial direction faceing
      set direction 1
      set color yellow     ;initial color

    ]
  ]



  ask n-of number-room3 patches with [pxcor < 82 and pycor < 36 and pxcor > 0 and pycor > 0 and pcolor = black]  ; makes turtles sprout on black patches= room3
  [
  sprout 1 [
      set size 5              ;; setting turtle size
      facexy 124 79 ; initial direction faceing
      set direction 1
      set color yellow     ;initial color
      ]
   ]



   ask n-of number-room4 patches with [pxcor < 132 and pycor < 36 and pxcor > 82 and pycor > 0 and pcolor = black]  ; makes turtles sprout on black patches= room4
 [
 sprout 1 [

      set size 5              ;; setting turtle size
      facexy 124 79 ; initial direction faceing
      set direction 1
      set color yellow     ;initial color

    ]
    ]


  reset-ticks
 end


to setup-patches

  draw-wall;wall, Windows and Doors
  draw-exit

    ;Labels
  ask patch 35 54[
    set plabel-color white
    set plabel "Room1"
  ]
  ask patch 90 54[
    set plabel-color white
    set plabel "Room2"
  ]
  ask patch 77 44[
    set plabel-color white
    set plabel "Corridor"
  ]
   ask patch 41 13[
    set plabel-color white
    set plabel "Room3"
  ]
   ask patch 105 13[
    set plabel-color white
    set plabel "Room4"
  ]

end

  to draw-wall
  ask patches with [pxcor <= 120.42 and pxcor >= 0 and pycor = 79]
    [set pcolor blue]
  ask patches with [pxcor <= 132 and pxcor >= 129.57 and pycor = 79]
    [set pcolor blue]
  ask patches with [pycor <= 79 and pycor >= 0 and pxcor = 132]
    [set pcolor blue]
  ask patches with [pycor <= 79 and pycor >= 0 and pxcor = 0]
    [set pcolor blue]

  ask patches with [pxcor <= 34.43 and pxcor >= 0 and pycor = 0]
    [set pcolor blue]
  ask patches with [pxcor <= 132 and pxcor >= 43.58 and pycor = 0]
    [set pcolor blue]
  ask patches with [pxcor <= 112 and pxcor >= 108.57 and pycor = 50]
    [set pcolor blue]
  ask patches with [pxcor <= 49.42 and pxcor >= 0 and pycor = 50]
    [set pcolor blue]
   ask patches with [pxcor <= 84.425 and pxcor >= 79.575 and pycor = 36]
    [set pcolor blue]
   ask patches with [pxcor <= 70.425 and pxcor >= 0 and pycor = 36]
    [set pcolor blue]
  ask patches with [pxcor <= 132 and pxcor >= 93.575 and pycor = 36]
    [set pcolor blue]

   ask patches with [pycor <= 79 and pycor >= 50 and pxcor = 71]
    [set pcolor blue]
  ask patches with [pycor <= 79 and pycor >= 50 and pxcor = 112]
    [set pcolor blue]
  ask patches with [pycor <= 36 and pycor >= 0 and pxcor = 82]
    [set pcolor blue]
   ask patches with [pxcor <= 99.42 and pxcor >= 58.57 and pycor = 50]
    [set pcolor blue]

  end

to draw-exit
  ;room1
  ask patches with [pxcor <= 58.57 and pxcor >= 49.42 and pycor = 50]
    [set pcolor green]
  ;room2
  ask patches with [pxcor <= 108.57 and pxcor >= 99.42 and pycor = 50]
    [set pcolor green]
  ;room3
  ask patches with [pxcor <= 79.575 and pxcor >= 70.425 and pycor = 36]
    [set pcolor green]
  ;room4
  ask patches with [pxcor <= 93.575 and pxcor >= 84.425 and pycor = 36]
    [set pcolor green]

  ;main exit
    ask patches with [pxcor <= 129.57 and pxcor >= 120.42 and pycor = 79]
    [set pcolor red]

  ;second exit
 ask patches with [pxcor <= 43.58 and pxcor >= 34.43 and pycor = 0]
    [set pcolor red]
 end


to go
  ask turtles [walk]
  tick
end

to walk
  let room1 patches with [pxcor < 71 and pycor < 79 and pxcor > 0 and pycor > 50]
  let room2 patches with [pxcor < 112 and pycor < 79 and pxcor > 71 and pycor > 50]
  let room3 patches with [pxcor < 82 and pycor < 36 and pxcor > 0 and pycor > 0]
  let room4 patches with [pxcor < 132 and pycor < 36 and pxcor > 82 and pycor > 0]
  let corridor patches with [pxcor < 132 and pycor < 50 and pxcor > 0 and pycor > 36]
  let exitpoint patches with [pxcor < 132 and pycor < 79 and pxcor > 112 and pycor > 50]

  ask turtles-on room1
  [face one-of patches with [pxcor <= 58.6 and pxcor >= 49.42 and pycor = 50]
    fd 0.5
  ]

  ask turtles-on room2
    [ face one-of patches with [pxcor <= 108.6 and pxcor >= 99.5 and pycor = 50]
    fd 0.5
  ]
  ask turtles-on room3
    [ face one-of patches with [pxcor <= 79 and pxcor >= 71 and pycor = 36]
    fd 0.5
  ]
  ask turtles-on room4
    [ face one-of patches with [pxcor <= 93.6 and pxcor >= 84.5 and pycor = 36]
    fd 0.5
  ]

  ask turtles-on corridor
  [ face one-of patches with [pxcor <= 132 and pxcor >= 112 and pycor = 50]
    fd 1
  ]
  ask turtles-on exitpoint
  [ face one-of patches with [pxcor <= 129 and pxcor >= 121 and pycor = 79]
    fd 1
  ]
   end

我可以将座席从每个房间导航到每个房间的门,但是我想在走廊中输入他们,然后从走廊到主出口。

1 个答案:

答案 0 :(得分:1)

我刚刚通过在“ walk”下方添加“ doors”变量来修改了您的代码。这告诉触碰绿色斑块的乌龟-您的门-向前走两步进入走廊。一旦他们进入走廊,他们就已经拥有向出口点移动的命令。

   to walk
      let room1 patches with [pxcor < 71 and pycor < 79 and pxcor > 0 and pycor > 50]
      let room2 patches with [pxcor < 112 and pycor < 79 and pxcor > 71 and pycor > 50]
      let room3 patches with [pxcor < 82 and pycor < 36 and pxcor > 0 and pycor > 0]
      let room4 patches with [pxcor < 132 and pycor < 36 and pxcor > 82 and pycor > 0]
      let corridor patches with [pxcor < 123 and pycor < 50 and pxcor > 0 and pycor > 36]
      let exitpoint patches with [pxcor < 130 and pycor < 80 and pxcor > 122 and pycor > 38]
      let doors patches with [pcolor = green]

      ask turtles-on room1
      [face one-of patches with [pxcor <= 58.6 and pxcor >= 49.42 and pycor = 50]
        fd 0.5
      ]

      ask turtles-on room2
        [ face one-of patches with [pxcor <= 108.6 and pxcor >= 99.5 and pycor = 50]
        fd 0.5
      ]
      ask turtles-on room3
        [ face one-of patches with [pxcor <= 79 and pxcor >= 71 and pycor = 36]
        fd 0.5
      ]
      ask turtles-on room4
        [ face one-of patches with [pxcor <= 93.6 and pxcor >= 84.5 and pycor = 36]
        fd 0.5

  ]

  ask turtles-on corridor
  [ face one-of patches with [pxcor <= 130 and pxcor >= 125 and pycor = 45]
    fd 1
  ]
  ask turtles-on exitpoint
  [ face one-of patches with [pxcor <= 129 and pxcor >= 121 and pycor = 79]
    fd 1
  ]


  ask turtles-on doors
  [ face one-of patches with [pxcor = 77 and pycor = 44 ]
    fd 2
 ]