Work Conservation Comparison of BP, CABP and PWBP_without incident
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
This model shows you how the Position-weighted Backpressure (PWBP) differs from the original Backpressue (BP), and the Capacity-Aware Backpressure (CABP) in terms of work conservation.
It has two intersections: the left intersection with two signal lights is the one that uses the BP-series controllers; the right intersection with only one signal light uses fixed timing controller.
The car-following model used in this model is a collision free car-following model for connected and automated vehicles from the literature.
HOW TO USE IT
Click on the Reset button to set up the network and vehicles.
Click on BP, CABP, or PWBP to start the simulation under different controllers. Note that when you switch between different controllers, you need to first click the previous controller to pause the simulation, and then click the new controller to continue the simulation.
You can move the model speed bar to adjust the simulation speed.
THINGS TO NOTICE
We can find that eventually the BP controller always gives green to the east-bound approach, even when the east approach is fully occupied and hence no vehicles can actually pass the intersection during green. However, if the green is given to the north-bound traffic, vehicles will be able to pass the intersection. We call this phenomenon "loss of work conservation". The reason behind this is that BP only considers the vehicle number difference between incoming and outgoing approaches, and assumes that saturation flow is always guaranteed, which is reasonable in communication network, but obviously not the case in traffic network.
CABP somehow solves this spillback problem by adjusting the movement weight calculation method, but it keeps the assumption about saturation flow rate. Therefore CABP is useful in limited certain cases, and cannot handle incident/accident scenarios, which is shown in other simulation models.
PWBP manages to resolve the basic issue: the way to calculate movement flow, along with movement weight. Hence work conservation is always guranteed in PWBP, no matter there is incident/accident or not.
HOW TO CITE
If you mention this model or the NetLogo software in a publication, we ask that you include the citations below.
For the PWBP model:
- Li, Li, and Saif Eddin Jabari. "Position weighted backpressure intersection control for urban networks." Transportation Research Part B: Methodological 128 (2019): 435-461.
For the BP model:
- Wongpiromsarn, Tichakorn, et al. "Distributed traffic signal control for maximum network throughput." 15th international IEEE conference on intelligent transportation systems. IEEE, 2012.
For the CABP model:
- Gregoire, Jean, et al. "Capacity-aware backpressure traffic signal control." IEEE Transactions on Control of Network Systems 2.2 (2014): 164-173.
For the car following model:
- Li, Li, and Wanjing Ma. "A collision-free car-following model for connected automated vehicles." Proc. 96th Transportation Research Board Annual Meeting. 2017.
Please cite the NetLogo software as:
- Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.
This work was funded in part by the C2SMART Center, a Tier 1 USDOT University Transportation Center, and in part by the New York University Abu Dhabi Research Enhancement Fund.
Comments and Questions
globals [comfortable-acceleration max-deceleration Tdeta Tdc Tde Vp Pp Vf Pf Lp
         A1obj_lower A1obj_upper A2obj_lower A2obj_upper A3obj_lower A3obj_upper Aobj_lower Aobj_upper
         cor-unit tick-unit W-volume S-volume vehicle-size-in-Netlogo d L Source-Queue-W Source-Queue-S W-weight S-weight W-phase S-phase min-Green Wmu Wx-in Wx-out Smu Sx-in Sx-out
         Wspillbacks Sspillbacks Wsubjectcar Ssubjectcar W-almost-spillback S-almost-spillback W-flow S-flow WCars-out-approach SCars-out-approach
         W1-in W1-out S1-in S1-out W2-in W2-out max-xcor max-ycor W1-light-xcor W2-light-xcor S1-light-ycor Mid-light-xcor PhaseList]
;;cars in different approaches
breed [Wcars Wcar]
breed [Scars Scar]
breed [Wlight1s Wlight1]
breed [Wlight2s Wlight2]
breed [Slight1s Slight1]
breed [Midlights Midlight]
turtles-own [acceleration pre-speed speed next-speed next-dis next-dis-in-netlogo min-speed max-speed pre-position PV distance-of-PV PL spillback-same-direction spillback-other-direction block]
;; PWBP how to correctly evaluate the real discharging rate based on downstream density? Current algorithm tend to switch very frequently.
to setup
  clear-all
  set max-xcor 350
  set max-ycor 140
  ask patches [setup-road]
  set Tdeta 0.1 ;;communication interval
  set Tdc 0.1 ;;communication delay = 0.1 s
  set Tde 0.1  ;;execution delay = 0.1 s
  set vehicle-size-in-Netlogo 5 ;; a vehicle occupies 5 patches in Netlogo is
  set cor-unit 5 ;;suppose 1 cor = 5 m
  set L vehicle-size-in-Netlogo * cor-unit ;;vehicle length in real world
  set d 3 ;; the safety stop distance
  set Lp L + d ;; vehicle space headway when stop
  set tick-unit 0.1 ;;suppose 1 tick = 0.1 s
  ;;hence 1 cor/tick = 5 m/ 0.1 s = 50 m/s, 0.1 cor/tick = 5 m/s, and 0.01 cor/tick2 = 5 m/s2
  set comfortable-acceleration 2 ;;comfortable acceleration is 2 m/s2
  set max-deceleration -6 ;;max-deceleration is -6 m/s2
  set W-volume 3600 ;;volume of west approach
  set S-volume 600 ;;volume of south approach
  set min-Green 10 ;;minimum green is 10 s
  set Source-Queue-W 0 ;;initialize the source queue at west approach
  set Source-Queue-S 0 ;;initialize the source queue at south approach
  set W-weight 0  ;;initialize the weight of west approach
  set S-weight 0  ;;initialize the weight of south approach
  set W-phase 0  ;;initialize the state of west phase
  set S-phase 0  ;;initialize the state of south phase
  set-default-shape turtles "new-car"
  set PhaseList []
  setup-lights
  reset-ticks
end 
to setup-road ;; patch procedure
  set W1-in 190
  set W1-out 195
  set S1-in 70
  set S1-out 75
  set W2-in 270
  set W2-out 275
  if (pycor > S1-out) or (pycor < S1-in) [set pcolor gray]
  if (pycor <= S1-out) and (pycor >= S1-in) [set pcolor white]
  if (pxcor <= W1-out) and (pxcor >= W1-in) [set pcolor white]
  if (pxcor <= W2-out) and (pxcor >= W2-in) [set pcolor white]
end 
to setup-lights
  create-Wlight1s 1[
    set shape "cylinder"
    set color red
    set W1-light-xcor (W1-in - 3)
    set xcor W1-light-xcor
    set ycor (S1-in + S1-out) / 2
    set heading 90
    set size 5]
  create-Wlight2s 1[
    set shape "cylinder"
    set color red
    set W2-light-xcor (W2-in - 3)
    set xcor W2-light-xcor
    set ycor (S1-in + S1-out) / 2
    set heading 90
    set size 5]
  create-Slight1s 1[
    set shape "cylinder"
    set color green
    set xcor (W1-in + W1-out) / 2
    set S1-light-ycor (S1-in - 3)
    set ycor S1-light-ycor
    set heading 0
    set size 5]
end 
to go-PWBP
  operate-lights-PWBP
  generate-vehicles
  car-run-CFFM
  tick
end 
to go-BP
  operate-lights-BP
  generate-vehicles
  car-run-CFFM
  tick
end 
to go-CABP
  operate-lights-CABP
  generate-vehicles
  car-run-CFFM
  tick
end 
to generate-vehicles
  ;; sprout new cars in western approach
  if  ticks mod int((3600 / W-volume) / tick-unit) = 0   ;;volume is the traffic demand for each lane
  [set Source-Queue-W (Source-Queue-W + 1)]
  let near-origin-Wcars turtles with [xcor < 8]
  if Source-Queue-W > 0 and (count near-origin-Wcars) = 0
  [set Source-Queue-W (Source-Queue-W - 1)
   ask patch 0 round((S1-in + S1-out) / 2) [sprout-Wcars 1 [
      set color blue
      set size vehicle-size-in-Netlogo
      set ycor (S1-in + S1-out) / 2
      set heading 90
      set speed 5
      set pre-speed speed
      set pre-position xcor * cor-unit
      set max-speed 20
      set min-speed 0]]]
   ;; sprout new cars in southern approach
  if  ticks mod int((3600 / S-volume) / tick-unit) = 0
  [set Source-Queue-S (Source-Queue-S + 1)]
  let near-origin-Scars turtles with [ycor < 8]
  if Source-Queue-S > 0 and (count near-origin-Scars) = 0
  [set Source-Queue-S (Source-Queue-S - 1)
   ask patch round((W1-in + W1-out) / 2) 0 [sprout-Scars 1 [
      set color blue
      set size vehicle-size-in-Netlogo
      set xcor (W1-in + W1-out) / 2
      set heading 0
      set speed 5
      set pre-speed speed
      set pre-position ycor * cor-unit
      set max-speed 20
      set min-speed 0]]]
end 
to car-run-CFFM
  ask Wcars [
    ifelse xcor >= world-width - 1
    [die]
    [ifelse any-PV?
     [follow-PV-CFFM]
     [speed-up-CFFM]]]
  ask Wcars [
    set pre-speed speed
    set pre-position xcor * cor-unit
    fd next-dis-in-netlogo
    set speed next-speed]
  ask Scars [
    ifelse ycor >= world-height - 1
    [die]
    [ifelse any-PV?
     [follow-PV-CFFM]
     [speed-up-CFFM]]]
  ask Scars [
    set pre-speed speed
    set pre-position ycor * cor-unit
    fd next-dis-in-netlogo
    set speed next-speed]
end 
to-report any-PV?
  let myhd heading
  let front-cars turtles with [(((distance myself) > 0 and color = blue) or ((distance myself) > 5 and color = red) or ((distance myself) > 5 and color = green and (spillback-same-direction = 1 or spillback-other-direction = 1))) and (towards myself) != myhd and heading = myhd]
  let front-lights turtles with [(((distance myself) > 5 and color = red) or((distance myself) > 5 and color = green and (spillback-same-direction = 1 or spillback-other-direction = 1))) and (distance myself) <= 15 and (towards myself) != myhd and heading = myhd]
  set PV (min-one-of front-cars [distance myself])
  set PL (min-one-of front-lights [distance myself])
  ifelse PV != nobody
  [set distance-of-PV  distance PV
    ifelse distance-of-PV <= 15
    [if PL != nobody
      [if PL != PV
        [set PV PL ]]
      report true]
    [report false]]
  [report false]
end 
to follow-PV-CFFM
  set Vp [pre-speed] of PV
  set Pp [pre-position] of PV
  ;;calculate the distance travelled in this cycle
  ifelse speed + acceleration * Tdeta < min-speed
  [let t-deceleration (min-speed - speed) / acceleration
   set next-dis speed * t-deceleration + 0.5 * acceleration * t-deceleration * t-deceleration + min-speed * (Tdeta - t-deceleration)]
  [ifelse speed + acceleration * Tdeta > max-speed
    [let t-acceleration (max-speed - speed) / acceleration
     set next-dis speed * t-acceleration + 0.5 * acceleration * t-acceleration * t-acceleration + max-speed * (Tdeta - t-acceleration)]
    [set next-dis speed * Tdeta + 0.5 * acceleration * Tdeta * Tdeta]]
  set next-dis-in-netlogo next-dis / cor-unit
  ;;update the speed at the beginning of next cycle
  ifelse speed + acceleration * Tdeta < min-speed          ;; to avoid speed < min-speed
  [set next-speed min-speed]
  [ifelse speed + acceleration * Tdeta > max-speed       ;; to avoid speed > max-speed
    [set next-speed max-speed]
    [set next-speed speed + acceleration * Tdeta]]
  set Vf next-speed
  ifelse heading = 90
  [set Pf xcor * cor-unit + next-dis]
  [set Pf ycor * cor-unit + next-dis]
  ;;calculate the acceleration during next cycle
  let Vfmax max-speed
  let apmax- max-deceleration
  let afmax- max-deceleration
  let afmax+ comfortable-acceleration
  let A1 Vf * Vf / -2
  let B1 Pp + Vp * Vp / (2 * apmax-) - Pf - Lp
  let A2 Tdeta * Tdeta / (-2 * afmax-)
  let B2 Tdeta * Tdeta / 2 - Vf * Tdeta / afmax-
  let C2 Pf + Lp + Vf * Tdeta - Pp + Vp * Vp / (2 * apmax-) - Vf * Vf / (2 * afmax-)
  let A3 (Vfmax - Vf) * (Vfmax - Vf) / -2
  let B3 Vfmax * Vfmax / (2 * afmax-) - Vp * Vp / (2 * apmax-) - Vfmax * Tdeta + Pp - Pf - Lp
  ifelse -1 * (Vf / Tdeta) > afmax-      ;;calculate the solution of segment 1
  [ifelse B1 > 0
    [ifelse A1 / B1 >= -1 * (Vf / Tdeta)
      [set A1obj_lower afmax- set A1obj_upper -1 * (Vf / Tdeta)]
      [ifelse A1 / B1 >= afmax-
        [set A1obj_lower afmax- set A1obj_upper A1 / B1]
        [set A1obj_lower 10 set A1obj_upper -10]]]
    [ifelse B1 < 0
      [set A1obj_lower 10 set A1obj_upper -10]
      [ifelse Vf = 0
        [set A1obj_lower afmax- set A1obj_upper -1 * (Vf / Tdeta)]
        [set A1obj_lower 10 set A1obj_upper -10]]]]
  [set A1obj_lower 10 set A1obj_upper -10]
  ifelse B2 * B2 - 4 * A2 * C2 >= 0       ;;calculate the solution of segment 2
  [ifelse (B2 + sqrt (B2 * B2 - 4 * A2 * C2)) / (-2 * A2) >= (Vfmax - Vf) / Tdeta or (sqrt (B2 * B2 - 4 * A2 * C2) - B2) / (2 * A2) < (-1 * Vf) / Tdeta
    [set A2obj_lower 10 set A2obj_upper -10]
    [ifelse max (list ((B2 + sqrt (B2 * B2 - 4 * A2 * C2)) / (-2 * A2)) ((-1 * Vf) / Tdeta) (afmax-)) <= min (list ((sqrt (B2 * B2 - 4 * A2 * C2) - B2) / (2 * A2)) ((Vfmax - Vf) / Tdeta) (afmax+))
      [set A2obj_lower max (list ((B2 + sqrt (B2 * B2 - 4 * A2 * C2)) / (-2 * A2)) ((-1 * Vf) / Tdeta) (afmax-)) set A2obj_upper min (list ((sqrt (B2 * B2 - 4 * A2 * C2) - B2) / (2 * A2)) ((Vfmax - Vf) / Tdeta) (afmax+))]
      [set A2obj_lower 10 set A2obj_upper -10]]]
  [set A2obj_lower 10 set A2obj_upper -10]
  ifelse (Vfmax - Vf) / Tdeta < afmax+      ;;calculate the solution of segment 3
  [ifelse B3 < 0
    [ifelse A3 / B3 > (Vfmax - Vf) / Tdeta
      [set A3obj_lower (Vfmax - Vf) / Tdeta set A3obj_upper min (list (A3 / B3) (afmax+))]
      [set A3obj_lower 10 set A3obj_upper -10]]
    [set A3obj_lower (Vfmax - Vf) / Tdeta set A3obj_upper afmax+]]
  [set A3obj_lower 10 set A3obj_upper -10]
  ifelse A3obj_lower <= A3obj_upper      ;; obtain Aobj
  [set Aobj_upper A3obj_upper
    ifelse A2obj_lower <= A2obj_upper
    [ifelse A1obj_lower <= A1obj_upper
      [set Aobj_lower A1obj_lower]
      [set Aobj_lower A2obj_lower]]
    [set Aobj_lower A3obj_lower]]
  [ifelse A2obj_lower <= A2obj_upper
    [set Aobj_upper A2obj_upper
      ifelse A1obj_lower <= A1obj_upper
      [set Aobj_lower A1obj_lower]
      [set Aobj_lower A2obj_lower]]
    [ifelse A1obj_lower <= A1obj_upper
      [set Aobj_lower A1obj_lower set Aobj_upper A1obj_upper]
      [set Aobj_lower 10 set Aobj_upper -10]]]
  ifelse Aobj_lower <= Aobj_upper
  [set acceleration min (list (afmax+) (Aobj_upper))]
  [set acceleration afmax-]
end 
to speed-up-CFFM
  ifelse speed + acceleration * Tdeta < min-speed
  [let t-deceleration (min-speed - speed) / acceleration
   set next-dis speed * t-deceleration + 0.5 * acceleration * t-deceleration * t-deceleration + min-speed * (Tdeta - t-deceleration)]
  [ifelse speed + acceleration * Tdeta > max-speed
    [let t-acceleration (max-speed - speed) / acceleration
     set next-dis speed * t-acceleration + 0.5 * acceleration * t-acceleration * t-acceleration + max-speed * (Tdeta - t-acceleration)]
    [set next-dis speed * Tdeta + 0.5 * acceleration * Tdeta * Tdeta]]
  set next-dis-in-netlogo next-dis / 5
  ;;update the speed at the beginning of next cycle
  ifelse speed + acceleration * Tdeta < min-speed          ;; to avoid speed < min-speed
  [set next-speed min-speed]
  [ifelse speed + acceleration * Tdeta > max-speed       ;; to avoid speed > max-speed
    [set next-speed max-speed]
    [set next-speed speed + acceleration * Tdeta]]
  set acceleration comfortable-acceleration
end 
to operate-lights-PWBP
  operate-other-lights
  capture-spillback-other-direction
  capture-spillback-same-direction
  if ticks mod (min-Green / tick-unit) = 0
  [calculate-weight-PWBP
   operate-main-lights]
end 
to operate-lights-BP
  operate-other-lights
  capture-spillback-other-direction
  capture-spillback-same-direction
  if ticks mod (min-Green / tick-unit) = 0
  [calculate-weight-BP
   operate-main-lights]
end 
to operate-lights-CABP
  operate-other-lights
  capture-spillback-other-direction
  capture-spillback-same-direction
  if ticks mod (min-Green / tick-unit) = 0
  [calculate-weight-CABP
   operate-main-lights]
end 
to operate-other-lights
  ifelse ticks mod (90 / tick-unit) <= (30 / tick-unit) ;; the cycle for this light is 90, with 30 green
  [ask Wlight2s[set color green]]
  [ask Wlight2s[set color red]]
end 
to operate-main-lights
  ifelse W-phase = 1
  [ask Wlight1s[set color green]]
  [ask Wlight1s[set color red]]
  ifelse S-phase = 1
  [ask Slight1s[set color green]]
  [ask Slight1s[set color red]]
  ifelse W-phase = 1
  [set PhaseList lput 1 PhaseList]
  [set PhaseList lput 0 PhaseList]
end 
to capture-spillback-other-direction
  set Wspillbacks Wcars with [xcor >= W1-light-xcor and xcor <= (W1-out + 2)]
  ifelse any? Wspillbacks
  [ask Slight1s[set spillback-other-direction 1]]
  [ask Slight1s[set spillback-other-direction 0]]
  set Sspillbacks Scars with [ycor >= S1-light-ycor and ycor <= (S1-out + 2)]
  ifelse any? Sspillbacks
  [ask Wlight1s[set spillback-other-direction 1]]
  [ask Wlight1s[set spillback-other-direction 0]]
end 
to capture-spillback-same-direction
  set Wsubjectcar min-one-of (Wcars with [xcor >= (W1-light-xcor - 15) and xcor <= W1-light-xcor]) [xcor]
  if Wsubjectcar != nobody
  [let xtemp [xcor] of Wsubjectcar
   set W-almost-spillback Wcars with [xcor > xtemp and xcor < W2-light-xcor]
   ifelse count W-almost-spillback >= (round((W2-light-xcor - W1-out) / 5.6) - 1) ;;(W2-light-xcor - W1-out) / 5.6 calculates the jam vehicle number on the approach, floor is for conservation
   [ask Wlight1s[set spillback-same-direction 1]]
   [ask Wlight1s[set spillback-same-direction 0]]]
  set Ssubjectcar min-one-of (Scars with [ycor >= (S1-light-ycor - 15) and ycor <= S1-light-ycor]) [ycor]
  if Ssubjectcar != nobody
  [let ytemp [ycor] of Ssubjectcar
   set S-almost-spillback Scars with [ycor > ytemp and ycor < max-ycor]
   ifelse count S-almost-spillback >= (round((max-ycor - S1-out) / 5.6) - 1)
   [ask Slight1s[set spillback-same-direction 1]]
   [ask Slight1s[set spillback-same-direction 0]]]
end 
to calculate-weight-PWBP
  let W-weight-in (sum [xcor] of Wcars with [xcor >= 0 and xcor <= W1-in]) / (W1-in - 0)
  let W-weight-out (W2-in * (count Wcars with [xcor >= W1-out and xcor <= W2-in]) - (sum [xcor] of Wcars with [xcor >= W1-out and xcor <= W2-in])) / (W2-in - W1-out)
  set W-weight (W-weight-in - W-weight-out)
  let S-weight-in (sum [ycor] of Scars with [ycor >= 0 and ycor <= S1-in]) / (S1-in - 0)
  let S-weight-out (max-ycor * (count Scars with [ycor >= S1-out and ycor <= max-ycor]) - (sum [ycor] of Scars with [ycor >= S1-out and ycor <= max-ycor])) / (max-ycor - S1-out)
  set S-weight (S-weight-in - S-weight-out)
  ifelse W-phase = 1
  [set Wmu floor(min-Green / 1.7)]  ;;according to observation, the start-up lost time is 4.5s, and the saturated headway is 1.7s.
  [set Wmu 1 + floor((min-Green - 4.5) / 1.7)]
  set Wx-in count Wcars with [xcor <= W1-in and xcor >= (W1-in - Wmu * 6.6 - 10)] ;;6.6 = 5.6 + 1, a vehicle takes up 5.6 cor when saturated, 1 cor is considered as a buffer in case some vehicles could catch up, 10 is the distance from the first vehicle to the stop line
  set WCars-out-approach (Wcars with [xcor >= W1-out and xcor <= (W1-out + 5.6 * (min list Wmu Wx-in))])
  ifelse any? WCars-out-approach
  [let Wmean-speed mean [speed] of WCars-out-approach
   let Wmean-density (count WCars-out-approach) / (5.6 * (min list Wmu Wx-in) * cor-unit)
   set Wx-out Wmean-speed * Wmean-density * min-Green]
  [set Wx-out min list Wmu Wx-in]
  set W-flow min (list Wmu Wx-in Wx-out)
  ifelse S-phase = 1
  [set Smu floor(min-Green / 1.7)]
  [set Smu 1 + floor((min-Green - 4.5) / 1.7)]
  set Sx-in count Scars with [ycor <= S1-in and ycor >= (S1-in - Smu * 6.6 - 10)]
  set SCars-out-approach (Scars with [ycor >= S1-out and ycor <= (S1-out + 5.6 * (min list Smu Sx-in))])
  ifelse any? SCars-out-approach
  [let Smean-speed mean [speed] of SCars-out-approach
   let Smean-density (count SCars-out-approach) / (5.6 * (min list Smu Sx-in) * cor-unit)
   set Sx-out Smean-speed * Smean-density * min-Green]
  [set Sx-out min list Smu Sx-in]
  set S-flow min (list Smu Sx-in Sx-out)
  ifelse W-weight * W-flow > S-weight * S-flow
  [set W-phase 1 set S-phase 0]
  [ifelse W-weight * W-flow < S-weight * S-flow
    [set W-phase 0 set S-phase 1]
    [let x random 2
     ifelse x = 0  ;;breaking ties arbitrarily
      [set W-phase 1 set S-phase 0]
      [set W-phase 0 set S-phase 1]]]
end 
to calculate-weight-BP
  let W-weight-in (count Wcars with [xcor >= 0 and xcor <= W1-in])
  let W-weight-out (count Wcars with [xcor >= W1-out and xcor <= W2-in])
  set W-weight max list (W-weight-in - W-weight-out) 0
  let S-weight-in (count Scars with [ycor >= 0 and ycor <= S1-in])
  let S-weight-out (count Scars with [ycor >= S1-out and ycor <= max-ycor])
  set S-weight max list (S-weight-in - S-weight-out) 0
  ifelse W-weight > S-weight
  [set W-phase 1 set S-phase 0]
  [ifelse W-weight < S-weight
    [set W-phase 0 set S-phase 1]
    [let x random 2
     ifelse x = 0  ;;breaking ties arbitrarily
      [set W-phase 1 set S-phase 0]
      [set W-phase 0 set S-phase 1]]]
end 
to calculate-weight-CABP
  let WCa round((W1-light-xcor - 0) / 5.6) ;; the maximum vehicles when in jam density
  let WCb round((W2-light-xcor - W1-out) / 5.6)
  let Cinf 500
  let m 4
  let WQa (count Wcars with [xcor <= W1-in])
  let W-weight-in min list 1 (WQa / Cinf + (2 - WCa / Cinf) * (WQa / WCa) ^ m) / (1 + (WQa / WCa) ^ (m - 1))
  let WQb (count Wcars with [xcor >= W1-out and xcor <= W2-in])
  let W-weight-out min list 1 (WQb / Cinf + (2 - WCb / Cinf) * (WQb / WCb) ^ m) / (1 + (WQb / WCb) ^ (m - 1))
  set W-weight max list (W-weight-in - W-weight-out) 0
  let SCa round((S1-light-ycor - 0) / 5.6)
  let SCb round((max-ycor - S1-out) / 5.6)
  let SQa (count Scars with [ycor >= 0 and ycor <= S1-in])
  let S-weight-in min list 1 (SQa / Cinf + (2 - SCa / Cinf) * (SQa / SCa) ^ m) / (1 + (SQa / SCa) ^ (m - 1))
  let SQb (count Scars with [ycor >= S1-out and ycor <= max-ycor])
  let S-weight-out min list 1 (SQb / Cinf + (2 - SCb / Cinf) * (SQb / SCb) ^ m) / (1 + (SQb / SCb) ^ (m - 1))
  set S-weight max list (S-weight-in - S-weight-out) 0
  ifelse W-weight > S-weight
  [set W-phase 1 set S-phase 0]
  [ifelse W-weight < S-weight
    [set W-phase 0 set S-phase 1]
    [let x random 2
     ifelse x = 0  ;;breaking ties arbitrarily
      [set W-phase 1 set S-phase 0]
      [set W-phase 0 set S-phase 1]]]
end 
There is only one version of this model, created about 6 years ago by Li Li.
This model does not have any ancestors.
This model does not have any descendants.
 
  Download this model
Download this model