netlogo

Creating a bottleneck obstacle for agents


I am trying to create a patch that will be a bottleneck structure in the middle of a path where the turtles have to go through.

I have created the parabolas but I would like to add a slider so that the size of the bottleneck can be changed but I don't know how to create a code that will move it.

Here is the code (I am very bad with the maths of the parabola so I had help with the top one and I just manually created the down one)

to setup-road
  ;; patch procedure
  ;; colour patches to paint a horizontal road

  let bound (max-pycor / 3)
  ifelse (pycor < (max-pycor  - bound)) and (pycor > (min-pycor + bound))
  [ set pcolor red - 3 ]
  [ set pcolor green ]

  set upper-road-bound (max-pycor  - bound - 2 )
  set lower-road-bound (min-pycor  + bound + 2 )
  setup-top-parabola-on-road
  setup-down-parabola-on-road
end
;; I want to be able to expand the parabolas so that the opening between them will be wider as well as narrow according a slider.
to setup-top-parabola-on-road
  ask patches with
  [pxcor > -25 and pxcor < 25] [
     if pycor > ((pxcor ^ 2) / 20 + 10)
    [ set pcolor green  ]
    ]
end

to setup-down-parabola-on-road

  ask patches with [pxcor >= -4 and pxcor <= 4 and pycor = -11][set pcolor green]
  ask patches with [pxcor >= -5 and pxcor <= 5 and pycor = -12][set pcolor green]
  ask patches with [pxcor >= -6 and pxcor <= 6 and pycor = -13][set pcolor green]
  ask patches with [pxcor >= -7 and pxcor <= 7 and pycor = -14][set pcolor green]
  ask patches with [pxcor >= -8 and pxcor <= 8 and pycor = -15][set pcolor green]
  ask patches with [pxcor >= -9 and pxcor <= 9 and pycor = -16][set pcolor green]
  ask patches with [pxcor >= -10 and pxcor <= 10 and pycor = -17][set pcolor green]
  ask patches with [pxcor >= -11 and pxcor <= 11 and pycor = -18][set pcolor green]
  ask patches with [pxcor >= -12 and pxcor <= 12 and pycor = -19][set pcolor green]
  ask patches with [pxcor >= -13 and pxcor <= 13 and pycor = -20][set pcolor green]
  ask patches with [pxcor >= -14 and pxcor <= 14 and pycor = -21][set pcolor green]
  ask patches with [pxcor >= -15 and pxcor <= 15 and pycor = -22][set pcolor green]
  ask patches with [pxcor >= -16 and pxcor <= 16 and pycor = -23][set pcolor green]
  ask patches with [pxcor >= -17 and pxcor <= 17 and pycor = -24][set pcolor green]
  ask patches with [pxcor >= -18 and pxcor <= 18 and pycor = -25][set pcolor green]
end

Can anyone help?


Solution

  • Here you go. This assumes you have a button called setup and a slider for variable "width" that ranges from 0 to 11.

    I added an "ask patches [ ]" in near the top where you are setting red and green.

    
    to setup
      clear-all
      setup-road
      reset-ticks
    end
    
    
    to setup-road
      ;; patch procedure
      ;; colour patches to paint a horizontal road
    
      let bound (max-pycor / 3)
      
      ask patches [
           ifelse (pycor < (max-pycor  - bound)) and (pycor > (min-pycor + bound))
           [ set pcolor red - 3 ]
           [ set pcolor green ]
      ]
      
      let upper-road-bound (max-pycor  - bound - 2 )
      let lower-road-bound (min-pycor  + bound + 2 )
      
      
      setup-top-parabola-on-road
      setup-down-parabola-on-road
    end
    ;; I want to be able to expand the parabolas so that the opening between them will be wider as well as narrow according a slider.
    to setup-top-parabola-on-road
      ask patches with
      [pxcor > -25 and pxcor < 25] [
         if pycor > ((pxcor ^ 2) / 20 + width)
        [ set pcolor blue  ]
        ]
    end
    
    to setup-down-parabola-on-road
     ask patches with
      [pxcor > -25 and pxcor < 25] [
         if pycor <   (-1 * (pxcor ^ 2) / 20) - width + 1   
        [ set pcolor yellow  ]
        ]
    
       
    end