Alonso Ogueda Oliva
Alonso Ogueda Oliva

Reputation: 301

How to make agents follow a multi-line shape?

I have been working on a evacuation agent-based model with NetLogo and I would like to make some agents follow multi-lines shapes.

As a context, I have a urban network (basically a graph) with its nodes and edges, I pre-compute the shortest paths from nodes to an exit node (a shelter in my project) but so far it works with straight lines (single line).

Basically what I do right now is, for each agent, I set its next node, heads towards it and then I move it a certain distance, something like this:

set next_node (something something)
set heading towards next_node
fd distance

What I would like to do now, is to set the next node, but the agent moving from node A to node B following the non-straight (multi-line) edge.

Is it there any way to do this?

an urban network example where an edge is not straight

PS: As more context, each agent has its own speed that is updated every tick, it even depends on the agents in front.

Upvotes: 1

Views: 61

Answers (1)

Bart de Bruin
Bart de Bruin

Reputation: 61

It depends a bit on how you integrated your non-straight (multi-line) edges in Netlogo. I recommend you to look at Mouse Recording Example (See Netlogo Model Library) where they save coordinates between nodes in path list using pen-down. Then the turtles move to the next coordinate in the list. In this way you make sure that although the path moves in the opposite direction of the end location, you will continue following the route.

Alternatively you could use something similar by uploading your graph as a picture where the paths have a different pcolor than the non-path patches. Than use something like:

turtles-own [
  target 
  reached-target? 
  visited-patches]

to setup
create-turtles 1 [
  set visited-patches (list patch-here)
  set reached-target true
  ] 
end 

to go
 set-speed
 move 
end 

to set-new-target
end

to move
  ask turtles [ 
    repeat my-speed [
      if reached-target? [
       set-new-target 
       set reached-target? false
      ] 
    ;; Select next location of next step the patch with road color that you haven't stepped on before (visited-patches) and that is closed to target location

      let location-next-step min-one-of patches with [pcolor = red and member? self [visited-patches] of myself = false] [distance [target] of myself]  
      face location-next-step
      set visited-patches visited-patches lput patch-here visited-patches
      if length visited-patches > 2 [set visited-patches but-first visited-patches] 
      ;; clean up recently visited patches. 
      move-to location-next-step
      if target = patch-here? [
       set reached-target? true 
       set visited-patches (list patch-here)
      ]
    ]  
 ]

Upvotes: 3

Related Questions