Crossroad simulation


 * Project name: Crossroad simulation
 * Class:4IT496 Simulation of Systems (WS 2014/2015)
 * Author: Bc. Jan Hudeček
 * Model type: Agent-based simulation
 * Software used: NetLogo 5.3.0

= Problem definition = The simulated crossroad is meeting point of heavily used streets Sokolovska, Jecna and Legerova. We can see the situation on following map. The roads are crossed by a tram rail and there is also a subway and tram station near the crossroad. So we can expect high numbers of cars and pedestrians.



On the picture we can see 3 more little streets that will be simulated. On the crossroad, there are several traffic lights which are controlling the traffic. We are not taking into account that pedestrians can walk into stores or buildings and that cars can stop in parking spots. This should not affect the reality so much.

= Goal =

The main goal will be to find the ideal intervals to lower the waiting times to minimum. Of course we need to keep in mind that the traffic should be safe and fluent. Safety of the crossroad is assured by the timing of the lights and by the code. To measure the goal, the simulation is using average time, in which the agent will leave the crossroad (average time to leave = AVG-TTL). This value is then printed into the graph separately for each kind of agent. Also they are visible in numbers above the graph. Lower is better.
 * Pedestrians take precedence on crossings
 * Cars or trams cannot crush into each other
 * Lights should be set in the way, that cars and pedestrians won't meet on the street (of course, in some cases it is possible, e.g. turning right)

= Method = NetLogo 5.2.1

This software is used because of each of the objects can make its own decisions.

= Detailed description of the method =

In the net logo, I created following model of the real crossroads.




 * Black = Roads
 * Blue = sidewalks
 * Brown = tram rail
 * Yellow = places where cars can turn
 * Red = places where cars can change lane
 * Black numbers = pedestrian spawn points
 * Black letters = places, where pedestrians are making change of direction
 * White letters A-F = pedestrian crossings with lights
 * White numbers = traffic lights for cars
 * White letters y,z = rail crossings

= Agents =

Pedestrians
Pedestrians are using sidewalks (blue). They are randomly spawned on one of the number-marked points and their destination is also selected as random number. Then they are moving forward until they hit one of the letter-marked patch or their destination. On the letter-marked patches (decision points) they will decide, which direction they will go next. If they reach destination, they will die. If there is a crosswalk in front of them with red traffic light, they will wait for the green light. They will ignore red light, if they are already crossing the road. On the crosswalks without lights, they won’t stop (they take precedence).


 * speed – the distance that will agent travel in one tick. It’s also used as checking distance for lights
 * destination – random number (1-14) marking the destination of the agent. Used for making decisions
 * spawn-time – time (ticks) when agent was spawned

Trams
Trams (Triangle shape) are spawned on one of the spawn points on one of the ends of the tram rail (brown). Then they will go towards the other end of the tram rail. If the traffic light for trams in front of the tram is red, it will wait for the green light. Also the tram will stop, if any other tram is in front of it.


 * speed – the distance that will agent travel in one tick. It’s also used as checking distance for lights
 * spawn-time - time (ticks) when agent was spawned

Cars
Cars are using roads (black). They are randomly spawned on one of the spawning points. Also their destination is selected randomly as one of the leaving end of the road. Depending on their destination cars can change lines (red marked areas) or turn (yellow marked points in the crossroads). If the traffic light for cars in front of the car is red, it will wait for the green light. Also the car will stop, if any other car or pedestrians are in front of it.


 * speed – the distance that will agent travel in one tick. It’s also used as checking distance for lights
 * destination – random number (1-3) marking the destination of the agent. Used for making decisions.
 * waiting? – Boolean, if the car is waiting on the green light
 * changing-line? – how long will the car currently be changing lines
 * spawn-time - time (ticks) when agent was spawned

Lights
The traffic lights are spawned in the simulation with the draw procedure. There are actually three kinds of agents – lights for cars, trams and for pedestrians.For their function is used build-in variable color. Color is changed in regular intervals derived from the ticks counter and global setting.

= Simulation controll =
 * setup (S) – will draw the map and reset ticks counter
 * go (G) – will start/pause the simulation
 * sim-speed – speed of the simulation, will change the wait times between the ticks
 * Psize - size of the patches
 * Xprob – probability for spawning certain agent in next tick (P – pedestrian, C – car, T – Tram (the tram probability is in promile, because there are very low numbers of them compared to the cars or pedestrians))
 * change1, change2, global-time – settings of the timing of traffic lights

There are 3 phases of the traffic lights. First is ending in the time of change1, second in the time of change2 and the third in global-time.

= Results =

The results of the simulation are visible in the following table. The AVG-TTL times are in seconds (5 ticks = 1 second). These times was marked after around 40 000 ticks. Used probability of agents (more or less corresponding with the real situation) The light intervals are changed by the change1 and change2 inputs. The global-time should stay the same, as the crossroad should reset every minute. Please note, that not every simulated intervals are included in this table (There is of course unlimited number of combinations). This is table of just some of the more interesting (and the best ones) intervals. Every change of the lights timing changes all of the variables. We can see some trend in this table
 * Pedestrians 30%
 * Cars 33%
 * Trams 0.8%
 * AVG-TTL of trams is lowering when we extend 1st phase
 * AVG-TTL of cars is lowering when we extend 3rd phase
 * Pedestrians are not so much affected by the intervals
 * The changes of trams AVG-TTL are so big, because there are so low number of them, so every change will affect the average a lot.

= Conclusion = Its hard to make any conclusion in this project. Every change in the intervals will make some of the objects to wait longer, some shorter. So the question is which objects will we prefer. The best AVG-TTLs are marked blue in the table above. To find the optimal one, I used the sum of weighted arithmetic means of the 3 numbers weighted by the probability of each agent. Thus we can see, which interval had the lowest combined average time to leave of all agents. We can see the result on following table.

This is of course contestable as the tram can be carrying several passengers, thus it can be preferred. In real project, the customer will have the final word about the results.

= Model source code =

Following link is containing the code of the simulation [[Media:Simulation_Xhudj17.nlogo]] Following link is containing the simulation itself [[Media:Simulation_Xhudj17rar.rar]]