The AnyLogic Road Traffic Library (RTL) is a bit of a genuine toolbox with respect to road traffic simulation, but it seems that developers had taken some assumptions into account which are correct in conventional and normal situations, but in some special cases, they might create conditions in model which are in non-conformance with real conditions. This first article explores how RTL behaves about Priority to the Right.
All of us know that in most countries with right hand traffic (and even some with left hand traffic such as Australia), the Priority to the Right system is used, and AnyLogic RTL considers this rule, too. But it is considered and implemented such a way that in some special cases of road network, it would create non rational behavior of cars. The example below represents how this would happen.
Imagine a simple road network containing 3 roads, namely "road", "road1" and "road2". The first one has two lanes, the second has three and the last one due to construction site has only one lane (Figure 1).
Figure 1: Simple network of three roads
Empty space, drag to resize
Simple blocks of road traffic library are also used. A carSource from "road", a carMoveTo to "road2" and finally a carDispose. Created cars are labeled with a code which is numbered according to the order of which cars injected into the model.
When running this simple model, a somehow irrational behavior is detected. While the one lane "road2" is located in front of lane 3 of "road1", cars in lane 3 of "road1" are giving way to cars in lane 1 and 2 in an immoderate manner (Figure 2 and video 1).
While 108th car is leaving "road1" because it has chosen lane 1, 18th car is still waiting for a way to leave "road1" because it has been placed in lane 3. It is especially irrational due to the fact that the narrow road is located in front of lane 3 of "road1".
I have seen and experienced in similar situations in real roads, usually the fastest lane is lane 3 (although not as fast as current result for lane 1), not lane 1 or 2, because cars in lane 1 and 2 need to change way.
Figure 2: Irrational situation while exiting "road1"
Video 1: Irrational situation while exiting "road1"
Empty space, drag to resize
Unfortunately it seems that there is no explicit way of managing such a behavior using built in AnyLogic tools, but like almost any other issue in AnyLogic, there exists an implicit way.
The approach I used is based on using three separate Stop Lines and setting their signals respectively to red and green.
I also have done this without using Traffic Light Block in order to frugal use of Blocks, especially useful for users of Evaluation version of AnyLogic which are restricted to utilize only 35 flowchart blocks in each agent including Main (Figure 3).
Figure 3: Stop lines, the event and variable used for manual traffic light
Empty space, drag to resize
In order to do this, I have used an Event component which is triggered every five seconds and based on the value of variable "timeCounter" (which its value is added by one each time the event is triggered) one of three defined stop lines; namely "stopLine2", "stopLine3" and "stopLine4", is set to be green and the others would be signaled red (Figure 4).
Figure 4: Event details and Action code
Empty space, drag to resize
Using this hand-made traffic light, the flow of cars seems much more natural and rational compared to similar situations in real roads. As it is apparent in Figure 5 (and video 2) the flow of cars exiting from "road1" is more realistic and cars exiting from the road are created in not so much different times as it was in previous version.
Figure 5: Flow of cars in case of using hand made traffic light