NetLogo code to move agents towards a goal using extension GIS and NW

38 Views Asked by At

My code is already running correctly to move the agents from node to node. However I want them to move towards "safe_area" when I press the "Evacuate Button". I am dealing with this problem for a couple of days, with no sucess what so ever. Here is my code:

extensions [ gis nw ]
globals [ shape-file-primary-road build-shape final_dest]
breed [ nodes node ]
breed [ walkers walker ]
breed [safe_areas safe_area ]
walkers-own [ mynode destination last-stop initial_position target-nodes path]

patches-own [
  entrance
]

nodes-own [

  myneighbors
  test
  dist

]

to setup

  clear-all
  reset-ticks

  resize-world 0 120 0 120
  set-patch-size 5.5
  set shape-file-primary-road gis:load-dataset "C:/***/Roads_Final.shp"
  gis:set-world-envelope (gis:envelope-of shape-file-primary-road)
  gis:set-drawing-color blue
  gis:draw shape-file-primary-road 1

  make-road-network
  build_to_evacuate
end


to make-road-network

  clear-links
  let first-node nobody
  let previous-node nobody
  foreach gis:feature-list-of shape-file-primary-road [ polyline -> ; each polyline
    foreach gis:vertex-lists-of polyline [ segment -> ; each polyline segment / coordinate pair
      foreach segment[ coordinate ->; each coordinate
        let location gis:location-of coordinate
        if not empty? location [ ; some coordinates are empty []
          create-nodes 1 [
            set myneighbors n-of 0 turtles
            set color green
            set xcor item 0 location
            set ycor item 1 location
            set hidden? true
            if first-node = nobody [
              set first-node self
            ]
            if previous-node != nobody [
              create-link-with previous-node
            ]
            set previous-node self
          ]
        ]
      ]
      set previous-node nobody
    ]
  ]
  
  delete-duplicates
  ask nodes [ set myneighbors link-neighbors ]
  delete-not-connected
  ask nodes [ set myneighbors link-neighbors ]

  create-walkers Agent_Number [
    set shape "person"
    set size 2
    set color red
    set destination nobody
    set last-stop nobody
    set target-nodes nobody
    set mynode one-of nodes move-to mynode
    set destination one-of nodes

  ]

end


to clear_all
  clear-all
end

to delete-duplicates
  ask nodes [
    if count nodes-here > 1 [
      ask other nodes-here [
        ask myself [
          create-links-with other [link-neighbors ] of myself
        ]
        die
      ]
    ]
  ]

end

to delete-not-connected
  ask nodes [set test 0]
  ask one-of nodes [set test 1]
  repeat 500 [
    ask nodes with [test = 1] [
      ask myneighbors [
        set test 1
      ]
    ]
  ]
  ask nodes with [test = 0] [
    die
  ]

end


to go

  ask links [ set thickness 0 ]
  ask walkers [
    let new-destination one-of [link-neighbors] of destination
    ask [link-with new-destination] of destination [set thickness 0.5]
    face new-destination
    move-to new-destination
    set destination new-destination
  ]

  tick

end


to build_to_evacuate

  let num_safe_zones 1
  let breakout-condition? false
  let cnt 0
  set final_dest nobody

  foreach gis:feature-list-of shape-file-primary-road [ vector-feature ->
    let coord-tuple gis:location-of (first (first (gis:vertex-lists-of vector-feature)))
    let long-coord item 0 coord-tuple
    let lat-coord item 1 coord-tuple

      create-safe_areas 1 [
        set shape "circle"
        set color green
        set size 1
        set xcor long-coord
        set ycor lat-coord
        set final_dest self
      ]

      set cnt cnt + 1

      if cnt >= num_safe_zones [
        set breakout-condition? true
      ]if breakout-condition? [
        stop
      ]
  ]

end

to evacuate

 


end

I am new to NetLogo and I am trying to understand the nw and gis extensions

0

There are 0 best solutions below