# Work Conservation Comparison of BP, CABP and PWBP_Case (a)

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)

## WHAT IS IT?

This model models the movement of cars on a highway. Each car follows a simple set of rules: it slows down (decelerates) if it sees a car close ahead, and speeds up (accelerates) if it doesn't see a car ahead.

The model demonstrates how traffic jams can form even without any accidents, broken bridges, or overturned trucks. No "centralized cause" is needed for a traffic jam to form.

## HOW TO USE IT

Click on the SETUP button to set up the cars.

Set the NUMBER-OF-CARS slider to change the number of cars on the road.

Click on GO to start the cars moving. Note that they wrap around the world as they move, so the road is like a continuous loop.

The ACCELERATION slider controls the rate at which cars accelerate (speed up) when there are no cars ahead.

When a car sees another car right in front, it matches that car's speed and then slows down a bit more. How much slower it goes than the car in front of it is controlled by the DECELERATION slider.

## THINGS TO NOTICE

Traffic jams can start from small "seeds." These cars start with random positions and random speeds. If some cars are clustered together, they will move slowly, causing cars behind them to slow down, and a traffic jam forms.

Even though all of the cars are moving forward, the traffic jams tend to move backwards. This behavior is common in wave phenomena: the behavior of the group is often very different from the behavior of the individuals that make up the group.

The plot shows three values as the model runs:

- the fastest speed of any car (this doesn't exceed the speed limit!)
- the slowest speed of any car
- the speed of a single car (turtle 0), painted red so it can be watched.

Notice not only the maximum and minimum, but also the variability -- the "jerkiness" of one vehicle.

Notice that the default settings have cars decelerating much faster than they accelerate. This is typical of traffic flow models.

Even though both ACCELERATION and DECELERATION are very small, the cars can achieve high speeds as these values are added or subtracted at each tick.

## THINGS TO TRY

In this model there are three variables that can affect the tendency to create traffic jams: the initial NUMBER of cars, ACCELERATION, and DECELERATION. Look for patterns in how the three settings affect the traffic flow. Which variable has the greatest effect? Do the patterns make sense? Do they seem to be consistent with your driving experiences?

Set DECELERATION to zero. What happens to the flow? Gradually increase DECELERATION while the model runs. At what point does the flow "break down"?

## EXTENDING THE MODEL

Try other rules for speeding up and slowing down. Is the rule presented here realistic? Are there other rules that are more accurate or represent better driving strategies?

In reality, different vehicles may follow different rules. Try giving different rules or ACCELERATION/DECELERATION values to some of the cars. Can one bad driver mess things up?

The asymmetry between acceleration and deceleration is a simplified representation of different driving habits and response times. Can you explicitly encode these into the model?

What could you change to minimize the chances of traffic jams forming?

What could you change to make traffic jams move forward rather than backward?

Make a model of two-lane traffic.

## NETLOGO FEATURES

The plot shows both global values and the value for a single turtle, which helps one watch overall patterns and individual behavior at the same time.

The `watch`

command is used to make it easier to focus on the red car.

The `speed-limit`

and `speed-min`

variables are set to constant values. Since they are the same for every car, these variables could have been defined as globals rather than turtle variables. We have specified them as turtle variables since modifications or extensions to this model might well have every car with its own speed-limit values.

## RELATED MODELS

"Traffic Grid" adds a street grid with stoplights at the intersections.

"Gridlock" (a HubNet model) is a participatory simulation version of Traffic Grid

## 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 model itself:

- Wilensky, U. (1997). NetLogo Traffic Basic model. http://ccl.northwestern.edu/netlogo/models/TrafficBasic. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.

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.

## COPYRIGHT AND LICENSE

Copyright 1997 Uri Wilensky.

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit https://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at uri@northwestern.edu.

This model was created as part of the project: CONNECTED MATHEMATICS: MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL MODELS (OBPML). The project gratefully acknowledges the support of the National Science Foundation (Applications of Advanced Technologies Program) -- grant numbers RED #9552950 and REC #9632612.

This model was developed at the MIT Media Lab using CM StarLogo. See Resnick, M. (1994) "Turtles, Termites and Traffic Jams: Explorations in Massively Parallel Microworlds." Cambridge, MA: MIT Press. Adapted to StarLogoT, 1997, as part of the Connected Mathematics Project.

This model was converted to NetLogo as part of the projects: PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS and/or INTEGRATED SIMULATION AND MODELING ENVIRONMENT. The project gratefully acknowledges the support of the National Science Foundation (REPP & ROLE programs) -- grant numbers REC #9814682 and REC-0126227. Converted from StarLogoT to NetLogo, 2001.

## 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 3 months ago by Li Li.

This model does not have any ancestors.

This model does not have any descendants.