London Underground Escalators System

London Underground Escalators System preview image

This model is seeking new collaborators — would you please help?

1 collaborator

Pp Muhammad Hijazy (Author)

Tags

commuter 

Tagged by Muhammad Hijazy 3 months ago

crowd dynamics 

Tagged by Muhammad Hijazy 3 months ago

escalator 

Tagged by Muhammad Hijazy 3 months ago

london 

Tagged by Muhammad Hijazy 3 months ago

subway 

Tagged by Muhammad Hijazy 3 months ago

train 

Tagged by Muhammad Hijazy 3 months ago

underground 

Tagged by Muhammad Hijazy 3 months ago

Visible to everyone | Changeable by the author
Model was written in NetLogo 6.0.2 • Viewed 206 times • Downloaded 4 times • Run 0 times
Download the 'London Underground Escalators System' modelDownload this modelEmbed this model

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


# London Underground Escalators System

## WHAT IS IT? / Model Scope

The model simulates how commuters ride London underground (subway) escalators. Commuters using London underground follow a traditional rule stating that people should stand on the right side and walk on the left side of the escalator. Transport for London tried in 2015 to change this rule by asking commuters to stand on both sides of the escalator in order to ‘ease crowds’. However, despite proven effectiveness of reducing the amount of overcrowding, this suggestion of standing-only escalators was scrapped after it faced severe criticism from the public and was described as ‘going against everything about being British’. See the videos in the links below for more information about this issue:

https://www.youtube.com/watch?v=cX11cxeW6hA

https://www.youtube.com/watch?v=tplFfiDj0S0

The model studies whether this problem can be solved by keeping that traditional rule, while adding a financial incentive for people who would like to walk on the left side of the escalator. The idea is that Oyster card system, which is already implemented in London underground, could be used to give discounts to the commuters who choose to walk on the escalator. Oyster is a ‘smartcard which can hold pay as you go credit’. Card holders need to tap (touch) in with their Oyster cards on the yellow card reader at the start and out at the end of their journey to pay the right fare (it is important to note here that not all commuters use Oyster card as a method to pay their train fare). The idea here is that card readers could be installed at the left side of the escalators. Thus, people can be encouraged to walk on the escalators by offering discounts to those who walk on the left side and tap their cards during the overcrowding times. People are notified about the discount times by green lights flashing at the times of overcrowding.

![NetLogo](https://metrouk2.files.wordpress.com/2011/01/article-1295298977829-0085d8ea1000044c-370982_636x300.jpg)

The model aims to examine whether the implementation of the discount system can reduce the overcrowding level in the escalators area. It also aims to find the optimal combination of inputs which leads to the most cost- and time-effective solution to the problem of overcrowding in the given London underground escalators area. In other words, the model should be used to find a solution that minimise the number of discounts given to commuters, but at the same time, significantly reduce the overcrowding in the two waiting areas^.

^ There are two waiting areas: the first one (the blue area) is between the train platforms and escalators, and the second one (the green area) is between the escalators and gates.

## HOW IT WORKS

### Agent Selection

There are three types of agents in the model:

1. **_Commuters_** who travel from the start line (train platforms) to the gate line (exits).

2. **_Discount Lights_** which turn on/off based on the crowding level of the two waiting areas; the discount lights flash (turned on) only in the case when the blue area is overcrowded and the green area is not overcrowded.

3. **_Unloading Control_** which disable/enable the unloading process and turn on/off red lights based on the crowding level of the blue area.

### Agent Properties

#### Commuters

* Whether the commuter is an Oyster card holder `oyster-card-holder?`.

* Whether the commuter already decided to walk on the escalator (due to habit or personal circumstances) regardless of the discount lights `walk-escalator-regardless?`.

* Whether the commuter can be motivated by the discount to walk on the escalator `motivated-by-discount?`.

* Whether the commuter has earned a discount `discount-earned?`.

* The number of ticks taken by the commuter to move from the start line (train platforms) to the gate line (exits) `number-of-ticks-taken`.

* Whether the commuter has exited the escalator from the walking line or from the standing line `exiting-escalator-while-walking?`.

#### Discount Lights

* True when they are flashing and false when they are not flashing `discount-on?`.

#### Unloading Control

* Disable/enable the unloading process and turn on/off the red lights based on the overcrowding level in the blue area.

### Agent Actions

#### Commuters

* Move to the nearest escalator/gate.

* Avoid stampede (only walk on non-preoccupied patches).

* Stand on the right side or walk on the left side of the escalator (either as a reaction to discount lights or due to other personal preferences).

#### Discount Lights

* Turn on or off based on the crowding level monitored by CCTVs (the crowding level is calculated by counting the number of turtles in a specific patch area and divide it by the overall capacity of that area).

#### Unloading Control

* Turn on the red lights and disable the unloading process when the blue area is overcrowded.

### Environment

It is a spatial environment in which a patch should only be occupied by one turtle (commuter), and the goal of turtles is to move from the start line (train platforms) to the gate line (exits). To simplify the model (i) only the escalators which are going up to the gate line are included in the model; the arrival section is included/the departure section is not included (ii) the number of escalators and gates, and the escalators’ speed and length cannot be changed (iii) the sizes of the two waiting areas (the blue and green) cannot be changed.

### Order of Events

#### Commuters

* Get off the train to the platform (spawned at the start line).

* Go to the nearest escalator using non-preoccupied patches.

* Decide whether to stand or walk on the escalator.

* Tap the Oyster card (if have one) on the card reader in the case of walking on the escalator and the discount lights are flashing (earn discount).

* Go to the nearest gate using non-preoccupied patches.

* Exit the gate (die).

#### Discount Lights

* Check the crowding level of the two waiting areas (the blue and green).

* Based on the crowding level of the two waiting areas, decide whether to turn on green lights.

#### Unloading Control

* Check the crowding level of the blue area.

* Based on the crowding level of the blue area, decide whether to disable the unloading process and to turn on the red lights.

## HOW TO USE IT

### Inputs

The following inputs are described in the same order as they are seen (from top downward) in the Interface tab:

* **_Slider:_** the number of commuters who arrive to the start line (are unloaded from trains to platforms) in every tick.

* **_Chooser:_** choose between two different arrival patterns: a _continues-unloading_ which allows a number of commuters (stated in the first slider) to be unloaded every tick nonstop, and a _discrete-unloading_ which organises the unloading of commuters in frequent but separated time circles.

* **_Slider:_** (only applicable to the _discrete-unloading_ pattern) the number of commuters to be unloaded from trains in every separate unloading circle.

* **_Slider:_** (only applicable to the _discrete-unloading_ pattern) the number of ticks taken for each unloading circle to be completed _OR_ how long each unloading circle lasts.

* **_Switch:_** ON for enabling trains to unload commuters, and OFF for disabling trains from unloading commuters (immediately in the case of the _continues-unloading_ pattern, and beginning from the next unloading circle in the case of the _discrete-unloading_ pattern).

* **_Switch:_** ON for enabling the implementation of the discount system, and OFF for disabling the implementation of the discount system.

* **_Slider:_** the occupancy percentage (out of the overall capacity of the BLUE area) which is considered as overcrowding.

* **_Slider:_** the occupancy percentage (out of the overall capacity of the GREEN area) which is considered as overcrowding.

* **_Slider:_** the overcrowding level (occupancy percentage in the BLUE area) in which trains stop unloading commuters.

* **_Slider:_** the percentage of Oyster card holders in the population of commuters _OR_ the likelihood of a commuter to be an Oyster card holder.

* **_Slider:_** the percentage of commuters who would be motivated by the discount offered to walk on the escalator _OR_ the likelihood that a commuter would be motivated by the discount offered to walk on the escalator.

* **_Slider:_** the percentage of commuters who already decided to walk on the escalator (due to habit or personal circumstances) regardless of the discount lights _OR_ the likelihood that a commuter already decided to walk on the escalator (due to habit or personal circumstances) regardless of the discount lights.

### Outputs

The outputs of this model are presented by monitors and plots:

#### Monitors

All the following monitors are located on the bottom-right side of the Interface tab:

* **_Commuters Arrived:_** the overall number of commuters who have arrived to the start line (train platforms) and gone to the escalators area during the current run.

* **_Commuters Exited:_** the overall number of commuters who have exited from the gate line (exits) during the current run.

* **_Overall Discount Given:_** the overall number of discounts given to commuters so far.

* **_Ineffective Discount Given:_** the number of discounts given so far to the commuters who decided to walk on escalators regardless of the discount offered, but tapped their cards anyway.

* **_Crowding Level - Blue Area %:_** the current occupancy percentage (out of the overall capacity) of the blue area.

* **_Crowding Level - Green Area %:_** the current occupancy percentage (out of the overall capacity) of the green area.

* **_% Discount Time out Overall Time:_** the percentage calculated so far of the discount time out of the overall time.

* **_Average Commuters Exited from Escalators; Discount On:_** the average number, in a single tick, calculated so far of the commuters who exited from escalators during the discount time.

* **_Average Escalators Loads; Discount On:_** the average number, in a single tick, calculated so far of the commuters who were on the two escalators during the discount time.

* **_Average Commuters Exited from Escalators; Discount Off:_** the average number, in a single tick, calculated so far of the commuters who exited from escalators during the time when the discount system was not implemented.

* **_Average Escalators Loads; Discount Off:_** the average number, in a single tick, calculated so far of the commuters who were on the two escalators during the time when the discount system was not implemented.

#### Plots

* **_Commuters on Escalators (Magnified View)_** this plot shows the overall number of commuters riding escalators (orang line), as well as the number of commuters who are in the walking line (black lines) and standing line (brown lines) of each escalator. Green bars indicate the periods in which the discount system is implemented (the values in the green bars are only used for display purposes). Red bars with negative values indicate the periods in which trains are not allowed to unload commuters to the start line/train platforms (the negative values in the red bars are only for display purposes; they are only used to make the bars located under the X axis). The plot only shows the data generated within a specific time period (for more information, please see the NETLOGO FEATURES heading).

* **_Crowding in Blue and Green Areas (Magnified View)_** this plot shows the overall number of commuters in the blue area (blue line) and green area (green line). Green bars indicate the periods in which the discount system is implemented (the values in the green bars are only used for display purposes). Magenta/purple bars with negative values indicate the periods in which trains unload commuters to the start line/train platforms (the negative values in the magenta/purple bars are only for display purposes; they are only used to make the bars located under the X axis). The plot only shows the data generated within a specific time period (for more information, please see the NETLOGO FEATURES heading).

* **_Crowding in the Blue and Green Areas_** this plot is the same as the previous one; however, unlike the previous plot, it shows all the data generated from the current run and it does not include the green and magenta/purple bars.

* **_Number of Commuters who could not be Unloaded from Trains_** this plot shows the number of commuters (in black bars) who could not be unloaded from trains to the start line (train platforms), due to overcrowding of the blue area.

* **_Number of Ticks Taken by each Commuter_** this plot shows (in black points) the number of ticks taken by each commuter to move from the start line (train platforms) to the gate line (exits).

### Setting Up the Model

This model follows the NetLogo style which states that any sliders, choosers or switches which need to be set before setup the model should be placed before the _Setup_ and _Go_ buttons; while the sliders, choosers or switches which can be changed after/while the model is running should be placed below the _Setup_ and _Go_ buttons. However, in theory, the sliders above the _Setup_ and _Go_ buttons of this model can be changed while the model is running, but playing with the _arrival-pattern_ chooser while the model is running **_can sometimes lead to an error message_**.

## THINGS TO NOTICE

During the discount time, a message saying **_Discount On_** should be shown in the world as well as green squares near the left side of escalators, which indicates that commuters who are walking on escalators are able to tap their Oyster cards in the card readers resembled by the green squares.

When trains are ordered to stop unloading commuters to the start line (train platforms), red squares should be shown in the world to inform the user that the unloading activities have been stopped due to overcrowding in the blue area. However, in the _discrete-unloading_ pattern, it could happen sometimes that red squares are shown, but the number of commuters spawned in the start line has not been cut and the **_Number of Commuters who could not be Unloaded from Trains_** plot has not shown any increase in the number of commuters who could not be unloaded. That is because the **_Unloading Control_** prevents a whole train’s load from being released only when the red squares are shown at the start of a new unloading time circle (assuming that the time circle starts when a train arrives to the station). This also explains that, in the _discrete-unloading_ pattern, the crowding level of the blue area often resembles a periodic trend in which a sudden drop in the crowding level indicates that a whole train has been prevented from unloading its load of commuters. Similarly, in the _discrete-unloading_ pattern, if the _unloading?_ switch turns off in the middle of an unloading circle, the unloading process will continue until all the load of the current circle is released, then, the next circle will be prevented from unloading any further commuters.

The colour of commuters is usually red; however, commuters become black when they walk on escalators, while they turn brown when they stand on escalators.

When the occupancy percentage in one of the two waiting areas (blue or green) reaches the overcrowding level already set by the user (using a slider), a message saying **_CROWDED_** should be shown in the middle of the waiting area.

## THINGS TO TRY

After an initial testing of the model, I came to a conclusion that although the escalators’ loads are less when implementing the discount system (the number in the **_Average Escalators Loads; Discount On_** monitor is often less than the number in the **_Average Escalators Loads; Discount Off_** monitor), the average number of commuters exiting escalators every tick is higher when implementing the discount system. That is because, in the case of implementing the discount system, there are more commuters walking on escalators, and accordingly, there is even a significantly large number of commuters exiting escalators from the walking lines because commuters moving faster on those lines than on the standing lines. I also concluded that the discount system has a positive influence in easing crowds, however, this influence sometimes is not strong enough to eliminate overcrowding in the blue area. Having said that, more comprehensive tests of the model are needed, which might include trying combinations of different arrival modes, different crowding levels, and different values/percentages of parameters related to commuters.

To better understand the phenomenon and suggested solution which the model simulates, you need to run the model for at least 10000 ticks.

> I appreciate any feedback about the model. I am particularly interested in any interesting observation or any optimal combination that you might achieve while you are testing the model. To provide your feedbacks, please either include them under the **_Discuss Tab_** (Comments and Questions) or email them to me on muhammad_hijazy@hotmail.com.

## EXTENDING THE MODEL

There are some parameters which can be added to the model to make it more accurate in representing the phenomenon under study. For example, we can include the **_preferable personal space of commuters_**, which reflects the likelihood that commuters would leave empty steps between themselves and other people riding the same escalator. Another factor could be the **_length of escalators_**, as it was suggested that the longer the escalator is, the fewer commuters would be willing to walk their way up rather than standing on the escalators. There is also the issue of manipulating the discount system by some commuters who would, for example, tap their cards when entering the escalator from the walking line to get the discount and then quickly move over to the standing line.

There are some limitations in the model which can be cured by developing the model further. For instance, due to the dynamic flow of commuters in escalators, the code does not check if every patch within the escalators is occupied by only a single turtle (commuter). Another limitation is that turtles (commuters) use only one rule to pick the escalator/gate which they are moving toward, which can be summarised as _move to the nearest escalator/gate regardless of the amount of crowds surrounding that escalator/gate and its neighbours_.

## NETLOGO FEATURES

A **_Magnified View_** of some plots was achieved by writing codes in the **_plot update commands_** section. The _magnified view_ feature allows some plots to only show the data generated within a specific time period which can be set by the **_magnifying-period_** slider. The value of the _magnifying-period_ slider determines the number of recent ticks whose data are shown in the plot. This feature can also be disabled by using the **_Magnify?_** switch.

Bars with negative values were also used in plots for display purposes; the negative values are used to locate the bars under the X axis in order to make the plots easier to navigate by avoiding any distractive overlapping between the lines and bars drawn.

## RELATED MODELS

The following models seem similar to mine, although I have not had a chance to check them out thoroughly or use them for guidance when designing my model:

[Traffic Flow on Escalators and Moving Walkways: Quantifying and Modeling Pedestrian Behavior in a Continuously Moving System]( https://theses.lib.vt.edu/theses/available/etd-02162011-170912/unrestricted/Kauffmann_PD_T_2011.pdf)

[Optimalizace nastavení eskalátorů v metru (NetLogo) (download Xrojr01-eskalatory-final.nlogo)]( http://www.simulace.info/index.php/File:Xrojr01-eskalatory-final.nlogo)

[Crowded Station]( http://modelingcommons.org/browse/one_model/4622#model_tabs_browse_info)

## CREDITS AND REFERENCES

####The agents of the model and their properties were suggested based on my personal observations using London underground.

#### The following articles were used in documenting the model:

[London Underground to pilot new escalator arrangement at Holborn Tube station](https://tfl.gov.uk/info-for/media/press-releases/2016/march/london-underground-planspilot-of-new-escalator-arrangement-at-holborn-tube-station)

[The simulation that proves standing only escalators work on the Tube](http://www.telegraph.co.uk/news/2016/03/22/the-simulation-that-proves-standing-only-escalators-work-on-the/)

[The Results Are In: The Holborn Escalator Trial Proves That It Is Better To Stand On the Escalator (Well, Sometimes)](http://www.gizmodo.co.uk/2017/03/the-results-are-in-the-holborn-escalator-trial-proves-that-it-is-better-to-stand-on-the-escalator-well-sometimes/)

[Standing-only escalators to be scrapped on London Underground](http://metro.co.uk/2017/03/08/standing-only-escalators-to-be-scrapped-on-london-underground-6495821/)

[What is Oyster?](https://tfl.gov.uk/fares-and-payments/oyster/what-is-oyster)

[Touching in and out](https://tfl.gov.uk/fares-and-payments/oyster/using-oyster/touching-in-and-out)

#### The photo used in the _WHAT IS IT? / Model Scope_ heading above was taken from the following article:

[MasterCard plans tap-and-go payment for the Tube](http://metro.co.uk/2011/01/17/mastercard-plans-tap-and-go-payment-for-the-tube-629161/)

The model was build by using NetLogo 6.0.2

Muhammad Hijazy 2017 ©

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

globals [
  blue-area   ;;the area between the start line (train platforms) and escalators.
  green-area   ;;the area between the escalators and gate line (exits).
  crowding-in-blue-area   ;;the number of turtles (commuters) in the blue area.
  crowding-in-green-area   ;;the number of turtles (commuters) in the green area.
  right-standing-line   ;;the number of turtles (commuters) standing in the right escalator.
  left-standing-line   ;;the number of turtles (commuters) standing in the left escalator.
  right-walking-line   ;;the number of turtles (commuters) walking in the right escalator.
  left-walking-line   ;;the number of turtles (commuters) walking in the left escalator.
  commuters-exited-escalators-while-walking--discount-on   ;;the number of turtles (commuters) who exited escalators from the walking line during the discount time.
  commuters-exited-escalators-while-standing--discount-on   ;;the number of turtles (commuters) who exited escalators from the standing line during the discount time.
  commuters-exited-escalators-while-walking--discount-off   ;;the number of turtles (commuters) who exited escalators from the walking line when the discount system is not implemented.
  commuters-exited-escalators-while-standing--discount-off   ;;the number of turtles (commuters) who exited escalators from the standing line when the discount system is not implemented.
  average-commuters-exited-escalators--one-discount-on-tick   ;;the average number (in a single tick) of turtles (commuters) who exited escalators during the discount time.
  average-commuters-exited-escalators--one-discount-off-tick   ;;the average number (in a single tick) of turtles (commuters) who exited escalators when the discount system is not implemented.
  number-in   ;;the number of turtles (commuters) who arrived in the start line (train platforms).
  number-out   ;;the number of turtles (commuters) who exited from the the gate line (exits).
  discount-on?   ;;true if the discount offered, and false if not.
  frequent-tick-counter   ;;a variable counting the unloading time in the mode of 'discrete unloading'.
  number-of-commuters-to-be-unload   ;;the number of turtles (commuters) who are still to be unloaded from trains in the current unloading time (cycle).
  number-of-ticks-taken--global   ;;a variable used to move values from the turtles-own [ number-of-ticks-taken ] in order to present them in a plot.
  commuters-could-not-be-unloaded   ;;the number of turtles (commuters) who could not be unloaded from trains to the start line (train platforms) due to overcrowding in the blue area.
  overall-discount-given   ;;the overall amount of discount which has been given to turtles (commuters) so far.
  ineffective-discount-given   ;;the overall amount of discount which has been given to the turtles (commuters) who decided to walk on the escalator regardless the discount offer, but tapped their Oyster cards anyway.
  overall-commuters-on-escalators-while-discount-on   ;;the overall number of turtles (commuters) who are on escalators during the discount time.
  overall-commuters-on-escalators-while-discount-off   ;;the overall number of turtles (commuters) who are on escalators when the discount system is not implemented.
  average-commuters-on-escalators-while-discount-on--one-tick   ;;the average number (in a single tick) of turtles (commuters) who are on escalators during the discount time.
  average-commuters-on-escalators-while-discount-off--one-tick   ;;the average number (in a single tick) of turtles (commuters) who are on escalators when the discount system is not implemented.
  discount-on-counter   ;;the number of ticks taken during the discount time.
  discount-plot   ;;a variable used in plots.
  stop-unloading-plot   ;;a variable used in plots.
  unloading-time-plot   ;;a variable used in plots.
  ticks-plot1   ;;a variable (counter) used in plots.
  ticks-plot2   ;;a variable (counter) used in plots.
]

turtles-own [
  oyster-card-holder?   ;;true if the turtle (commuter) is an Oyster card holder, and false if not.
  walk-escalator-regardless?   ;;true if the turtle (commuter) already decided to walk on the escalator (due to habit or personal circumstances) regardless of the discount offered, and false if not.
  motivated-by-discount?   ;;true if the turtle (commuter) can be motivated by discount to walk on the escalator, and false if not.
  discount-earned?   ;;true if the turtle (commuter) has earned discount, and false if not.
  number-of-ticks-taken   ;;the number of ticks that the turtle (commuter) took to move from the start line (train platforms) to the gate line (exits).
  exiting-escalator-while-walking?   ;;true if the turtle (commuter) exited the escalator from the walking line and false if it was from the standing line; the value 0 is used to mark the turtle (commuter) who has been counted in the green area.
]



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   SETUP procedure   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to setup
  clear-all
  ask patches [
    set pcolor white
    set plabel-color black
  ]
  set blue-area patches with [ pycor < -12 ]
  ask blue-area [ set pcolor blue ]
  set green-area patches with [ pycor > 12 ]
  ask green-area [ set pcolor green ]
  ask patches with [ (abs pxcor >= 8) and (abs pxcor <= 9) and (abs pycor <= 12) ] [ set pcolor gray + 2 ] ;;two escalators.
  ask patches with [ (abs pxcor = 10) or (abs pxcor = 7) and (abs pycor <= 12) ] [ set pcolor yellow ] ;;escalators' handles.
  ask (patch-set patch 6.66 20 patch 13.33 20 patch 0 20 patch -6.66 20 patch -13.33 20) [ set pcolor white ] ;;five gates (exits).
  set-default-shape turtles "person"
  set discount-on? false
  reset-ticks
end 



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   GO procedure   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go
  tick
  calculate-crowding ;;go to calculate-crowding procedure.
  let crowding-level-in-blue-area (crowding-in-blue-area / count blue-area * 100)
  let number-of-commuters-arriving-every-tick--exchange number-of-commuters-arriving-every-tick ;;create a local variable indicating the number of commuters arriving every tick, which can have any value between the number-of-commuters-arriving-every-tick and the number-of-commuters-to-be-unload.
  if arrival-pattern = "discrete-unloading" [
    if frequent-tick-counter <= 0 [ ;;the case in which a new unloading period has not started yet
      set frequent-tick-counter frequency-in-which-trains-unload-commuters ;;reset frequent-tick-counter in the new unloading circle by the value of frequency-in-which-trains-unload-commuters slider.
      ifelse crowding-level-in-blue-area < overcrowding-level-in-which-trains-stop-unloading-commuters and unloading? [
        set number-of-commuters-to-be-unload number-of-commuters-to-be-unload + number-of-commuters-in-each-unload ;;reset number-of-commuters-to-be-unload in the new unloading circle by the value of number-of-commuters-in-each-unload slider.
      ]
      [
        set commuters-could-not-be-unloaded commuters-could-not-be-unloaded + number-of-commuters-in-each-unload ;;record the number of turtles (commuters) that could not be unloaded.
      ]
    ]
    if number-of-commuters-to-be-unload <= number-of-commuters-arriving-every-tick--exchange [ set number-of-commuters-arriving-every-tick--exchange number-of-commuters-to-be-unload ] ;;unload the remaining turtles (commuters).
    set frequent-tick-counter frequent-tick-counter - 1 ;;one tick has passed from the current unloading circle.
  ]
  ifelse crowding-level-in-blue-area >= overcrowding-level-in-which-trains-stop-unloading-commuters or not unloading? [
    ask (patch-set patch 13 -11 patch 16 -11 patch 19 -11 patch -13 -11 patch -16 -11 patch -19 -11) [ set pcolor red - 1 ] ;;indicate (by the red lights) that the unloading process has stopped.
    if arrival-pattern = "continues-unloading" [ set commuters-could-not-be-unloaded commuters-could-not-be-unloaded + number-of-commuters-arriving-every-tick ] ;;record the number of turtles (commuters) that could not be unloaded.
    set stop-unloading-plot -5
  ]
  [
    ask (patch-set patch 13 -11 patch 16 -11 patch 19 -11 patch -13 -11 patch -16 -11 patch -19 -11) [ set pcolor white ] ;;indicate that the unloading process is not stopped.
    set stop-unloading-plot 0
  ]

  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; unloading procedure ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ifelse (arrival-pattern = "continues-unloading" and unloading? and crowding-level-in-blue-area < overcrowding-level-in-which-trains-stop-unloading-commuters) or (arrival-pattern = "discrete-unloading" and number-of-commuters-to-be-unload >= 1) [
    set unloading-time-plot -30
    ask n-of number-of-commuters-arriving-every-tick--exchange patches with [ pycor = -20 ] [ ;;turtles (commuters) are spawned in the start line (train platforms).
      sprout 1 [
        set color red
        set size 2
        ifelse random 100 <= likelihood-of-owning-oyster-card [ set oyster-card-holder? true ] [ set oyster-card-holder? false ]
        ifelse random 100 <= likelihood-that-commuters-walk-on-escalators-regardless-of-discount [ set walk-escalator-regardless? true ] [ set walk-escalator-regardless? false ]
        ifelse random 100 <= likelihood-that-commuters-are-motivated-by-discount-to-walk-on-escalators [ set motivated-by-discount? true ] [ set motivated-by-discount? false ]
        set exiting-escalator-while-walking? false
        set discount-earned? false
        setxy xcor + (random-float 1) - 0.5 ycor + (random-float 1) - 0.5
        set number-in number-in + 1
        if arrival-pattern = "discrete-unloading" [ set number-of-commuters-to-be-unload number-of-commuters-to-be-unload - 1 ]
      ]
    ]
  ]
  [
    set unloading-time-plot 0
  ]

  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; implementing the discount system ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ask patch 5 -16.5 [
    ifelse crowding-level-in-blue-area >= overcrowding-level-in-blue-area [ set plabel "CROWDED" ] [ set plabel "" ] ;;indicate whether the blue area is crowded.
  ]
  ask patch 5 16 [
    ifelse (crowding-in-green-area / count green-area * 100) >= overcrowding-level-in-green-area [ set plabel "CROWDED" ] [ set plabel "" ] ;;indicate whether the green area is crowded.
  ]
  ifelse ([ plabel ] of patch 5 -16.5 = "CROWDED") and ([ plabel ] of patch 5 16 = "") and implement-discount-system? [ ;;decide whether the discount system is implemented.
    set discount-on? true
    ask (patch-set patch 6 3 patch 6 9 patch 6 -3 patch 6 -9 patch-set patch -11 3 patch -11 9 patch -11 -3 patch -11 -9) [ set pcolor lime + 2 ] ;;indicate (by the green lights) that the discount system has been implemented.
    ask patch 5 1 [ set plabel "DISCOUNT" ] ;;indicate (by the 'DISCOUNT ON' message) that the iscount system has been implemented.
    ask patch 1 -2 [ set plabel "ON" ] ;;indicate (by the 'DISCOUNT ON' message) that the iscount system has been implemented.
  ]
  [
    set discount-on? false
    ask (patch-set patch 6 3 patch 6 9 patch 6 -3 patch 6 -9 patch-set patch -11 3 patch -11 9 patch -11 -3 patch -11 -9) [ set pcolor white ]
    ask (patch-set patch 5 1 patch 1 -2) [ set plabel "" ]
  ]

  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; movement of turtles (commuters) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ask turtles [
    set number-of-ticks-taken number-of-ticks-taken + 1
    ifelse patch-here = patch 6.66 20 or patch-here = patch 13.33 20 or patch-here = patch 0 20 or patch-here = patch -6.66 20 or patch-here = patch -13.33 20 [ ;;green area.
      set number-out number-out + 1
      if discount-earned? [
        set overall-discount-given overall-discount-given + 1
        if walk-escalator-regardless? [ set ineffective-discount-given ineffective-discount-given + 1 ]
      ]
      set number-of-ticks-taken--global number-of-ticks-taken
      die
    ]
    [
      ifelse pycor > 12 [ go-to-exits ]
      [
        ifelse abs pycor <= 12 [ riding-escalators ] ;;escalators area.
          [
            if pycor >= -13 and (pxcor = 8 or pxcor = 9) [ enter-right-escalator ]
            if pycor >= -13 and (pxcor = -8 or pxcor = -9) [ enter-left-escalator ]
          ]
            ifelse DISTANCE patch 8 -13 < DISTANCE patch -8 -13 [ go-to-right-escalator ] [ go-to-left-escalator ] ;;blue area.
        ]
      ]
    ]
end 



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   when turtles (commuters) decide to go to the left escalator   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go-to-left-escalator ;;if the turtle (commuter) wants to walk on the escalator, go to the beginning (patch -9 -13) of the walking line; otherwise, go to the beginning (patch -8 -13) of the standing line.
  let targets neighbors with [ not any? turtles-here and pycor < -12 ]
  ifelse walk-escalator-regardless? or (oyster-card-holder? and motivated-by-discount? and discount-on?) [
    let target min-one-of targets [ distance patch -9 -13 ]
    if target != nobody [
      face target
      move-to target
    ]
  ]
  [
    let target min-one-of targets [ distance patch -8 -13 ]
    if target != nobody [
      face target
      move-to target
    ]
  ]
end 



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   when turtles (commuters) decide to go to the right escalator   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go-to-right-escalator ;;if the turtle (commuter) wants to walk on the escalator, go to the beginning (patch 8 -13) of the walking line; otherwise, go to the beginning (patch 9 -13) of the standing line.
  let targets neighbors with [ not any? turtles-here and pycor < -12 ]
  ifelse walk-escalator-regardless? or (oyster-card-holder? and motivated-by-discount? and discount-on?) [
    let target min-one-of targets [ distance patch 8 -13 ]
    if target != nobody [
      face target
      move-to target
    ]
  ]
  [
    let target min-one-of targets [ distance patch 9 -13 ]
    if target != nobody [
      face target
      move-to target
    ]
  ]
end 



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   turtles (commuters) entering the left escalator   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to enter-left-escalator
  let targets neighbors with [ not any? turtles-here and pycor = -12 and (pxcor = -8 or pxcor = -9) ]
  let target min-one-of targets [ distance myself ]
  ifelse walk-escalator-regardless? or (oyster-card-holder? and motivated-by-discount? and discount-on?) [
    ifelse target = patch -9 -12 [ ;;if the turtle (commuter) wants to walk on the escalator and patch -9 -12 is empty, then move to patch -9 -12.
      face target
      entering-escalator2
    ]
    [
      if target = patch -8 -12 [ ;;however, if patch -9 -12 is not empty but patch -8 -12 is empty, then move to patch -8 -12 and try to go to the walking line later.
        face target
        entering-escalator2
      ]
    ]
  ]
  [
    ifelse target = patch -8 -12 [ ;;if the turtle (commuter) wants to stand on the escalator and patch -8 -12 is empty, then move to patch -8 -12.
      face target
      entering-escalator2
    ]
    [
      if target = patch -9 -12 [ ;;however, if patch -8 -12 is not empty but patch -9 -12 is empty, then move to patch -9 -12 and try to go to the standing line later.
        face target
        entering-escalator2
      ]
    ]
  ]
end 



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   turtles (commuters) entering the right escalator   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to enter-right-escalator
  let targets neighbors with [ not any? turtles-here and pycor = -12 and (pxcor = 8 or pxcor = 9) ]
  let target min-one-of targets [ distance myself ]
  ifelse walk-escalator-regardless? or (oyster-card-holder? and motivated-by-discount? and discount-on?) [
    ifelse target = patch 8 -12 [ ;;if the turtle (commuter) wants to walk on the escalator and patch 8 -12 is empty, then move to patch 8 -12.
      face target
      entering-escalator2
    ]
    [
      if target = patch 9 -12 [ ;;however, if patch 8 -12 is not empty but patch 9 -12 is empty, then move to patch 9 -12 and try to go to the walking line later.
        face target
        entering-escalator2
      ]
    ]
  ]
  [
    ifelse target = patch 9 -12 [ ;;if the turtle (commuter) wants to stand on the escalator and patch 9 -12 is empty, then move to patch 9 -12.
      face target
      entering-escalator2
    ]
    [
      if target = patch 8 -12 [ ;;however, if patch 9 -12 is not empty but patch -8 -12 is empty, then move to patch -8 -12 and try to go to the standing line later.
        face target
        entering-escalator2
      ]
    ]
  ]
end 



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   a complement procedure to enter-left-escalator AND enter-right-escalator   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to entering-escalator2
  forward 1.5 ;;jump into the escalator.
  set heading 0
  if pxcor = 9 or pxcor = -8 [ set color brown - 2 ] ;;change color to indicate that the turtle (commuter)  is in the standing line.
  if pxcor = -9 or pxcor = 8 [ set color black ] ;;change color to indicate that the turtle (commuter)  is in the walkining line.
end 



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   when turtles (commuters) are actually inside escalators   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to riding-escalators
  set heading 0
  forward 1
  ifelse walk-escalator-regardless? or (oyster-card-holder? and motivated-by-discount? and discount-on?) [
    if (pxcor = 9 or pxcor = -8) and not any? turtles-on patch-left-and-ahead 90 1 [ ;;if the turtle (commuter) wants to walk on the escalator and finds the place next to the left on the walking line is empty, then move to the walking line.
      move-to patch-left-and-ahead 90 1
      riding-escalators2
      stop ;; turtles are only allowed to do one move per tick
    ]
  ]
  [
    if (pxcor = -9 or pxcor = 8) and not any? turtles-on patch-right-and-ahead 90 1 [ ;;if the turtle (commuter) wants to stand on the escalator and finds the place next to the right on the standing line is empty, then move to the standing line.
      move-to patch-right-and-ahead 90 1
      riding-escalators2
      stop ;; turtles are only allowed to do one move per tick
    ]
  ]
  if (pxcor = -9 or pxcor = 8) and not any? turtles-on patch-ahead 1 [ move-to patch-ahead 1 ] ;;move on the walking line if the patch ahead is empty.
  riding-escalators2
end 



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   a complement procedure to riding-escalators   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to riding-escalators2
  if pxcor = 9 or pxcor = -8 [ set color brown - 2 ] ;;change color to indicate that the turtle (commuter)  is in the standing line.
  if pxcor = -9 or pxcor = 8 [ set color black ] ;;change color to indicate that the turtle (commuter)  is in the walkining line.
  if discount-on? and oyster-card-holder? and (pxcor = -9 or pxcor = 8) [ set discount-earned? true ] ;;if the turtle (commuter) is an Oyster card holder and walking on the escalator during the discount time, then give discount to the turtle.
  if (pxcor = -9 or pxcor = 8) and pycor <= 12 and pycor > 6 [ set exiting-escalator-while-walking? true ] ;;set the variable exiting-escalator-while-walking? true if the turtle (commuter) is on the top quarter of the escalator's walking line.
end 



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   when turtles (commuters) are in the green area and going to the nearest exit   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go-to-exits ;;when reaching the green area, go to the nearest exit.
  set color red

  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;calculate the number of turtles (commuters) who have exited escalators from the walking lines and from the standing lines;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  if exiting-escalator-while-walking? != 0 [ ;;if the turtle (commuter) has not been marked (counted) yet, then do the following procedure.
    if exiting-escalator-while-walking? = true [
      ifelse discount-on? [
        set commuters-exited-escalators-while-walking--discount-on commuters-exited-escalators-while-walking--discount-on + 1
      ]
      [
        set commuters-exited-escalators-while-walking--discount-off commuters-exited-escalators-while-walking--discount-off + 1
      ]
    ]
    if exiting-escalator-while-walking? = false [
      ifelse discount-on? [
        set commuters-exited-escalators-while-standing--discount-on commuters-exited-escalators-while-standing--discount-on + 1
      ]
      [
        set commuters-exited-escalators-while-standing--discount-off commuters-exited-escalators-while-standing--discount-off + 1
      ]
    ]
    set exiting-escalator-while-walking? 0  ;;mark the turtle (commuter) as counted.
  ]

  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;make the turtle (commuter) go to the nearest one of the five gate;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  let list-counter 0
  while [ list-counter < 5 ] [
    if min (list DISTANCE patch -13.33 20 DISTANCE patch -6.66 20 DISTANCE patch 0 20 DISTANCE patch 6.66 20 DISTANCE patch 13.33 20) = item list-counter (list DISTANCE patch -13.33 20 DISTANCE patch -6.66 20 DISTANCE patch 0 20 DISTANCE patch 6.66 20 DISTANCE patch 13.33 20) [
      let targets neighbors with [ not any? turtles-here and pycor > 12 ]
      let target min-one-of targets [ DISTANCE patch item list-counter (list -13.33 -6.66 0 6.66 13.33) 20 ]
      if target != nobody [
        face target
        move-to target
        stop
      ]
    ]
    set list-counter list-counter + 1
  ]
end 



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   calculate some statistics   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to calculate-crowding ;;make some calculations about the crowding in the blue and green areas, and the load in the two escalators.
  set crowding-in-blue-area count turtles-on blue-area
  set crowding-in-green-area count turtles-on green-area
  set right-standing-line count turtles-on patches with [ pycor >= -12 and pycor <= 12 and pxcor = 9 ]
  set left-standing-line count turtles-on patches with [ pycor >= -12 and pycor <= 12 and pxcor = -8 ]
  set right-walking-line count turtles-on patches with [ pycor >= -12 and pycor <= 12 and pxcor = 8 ]
  set left-walking-line count turtles-on patches with [ pycor >= -12 and pycor <= 12 and pxcor = -9 ]
  ifelse discount-on? [
    set discount-plot 40
    set overall-commuters-on-escalators-while-discount-on overall-commuters-on-escalators-while-discount-on + (left-walking-line + left-standing-line + right-walking-line + right-standing-line)
    set discount-on-counter discount-on-counter + 1
    set average-commuters-on-escalators-while-discount-on--one-tick overall-commuters-on-escalators-while-discount-on / discount-on-counter
    set average-commuters-exited-escalators--one-discount-on-tick (commuters-exited-escalators-while-walking--discount-on + commuters-exited-escalators-while-standing--discount-on) / discount-on-counter
  ]
  [
    set discount-plot 0
    set overall-commuters-on-escalators-while-discount-off overall-commuters-on-escalators-while-discount-off + (left-walking-line + left-standing-line + right-walking-line + right-standing-line)
    set average-commuters-on-escalators-while-discount-off--one-tick overall-commuters-on-escalators-while-discount-off / (ticks - discount-on-counter)
    set  average-commuters-exited-escalators--one-discount-off-tick (commuters-exited-escalators-while-walking--discount-off + commuters-exited-escalators-while-standing--discount-off) / (ticks - discount-on-counter)
  ]
end 



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   clear all plots   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to clear-plots
  clear-all-plots
  set ticks-plot1 0 ;;reset the plot ticks.
  set ticks-plot2 0 ;;reset the plot ticks.
end 

There are 2 versions of this model.

Uploaded by When Description Download
Muhammad Hijazy 3 months ago made the code more compact Download this version
Muhammad Hijazy 3 months ago Initial upload Download this version

Attached files

File Type Description Last updated
London Underground Escalators System.png preview Preview for 'London Underground Escalators System' 3 months ago, by Muhammad Hijazy Download
MHijazy_London_Underground_Escalators_System2.png png interface 3 months ago, by Muhammad Hijazy Download

This model does not have any ancestors.

This model does not have any descendants.