The cars in our model are currently moving in a single direction, from the North-West to the South, along Tapiolavägen.
This phase is devoted to creating an intersection by drawing Menninkäisentie road that is connected to Tapiolavägen from the East. Then we will add new blocks to the flowchart in order to model traffic flow on both roads, in all directions.
Draw an intersection
In AnyLogic, intersections are drawn automatically for every road connection. You simply need to draw Menninkäisentie and connect it to Tapiolavägen.
- Click the
Road element in the Space Markup section of the Road Traffic Library palette.
-
Start drawing the road by clicking the median strip of the Menninkäisentie road at the right border of the layout image.
-
To get a T-shaped intersection, hover your mouse over the median of Tapiolavägen road and double-click the purple point that appears. This will set the end point of the road.
-
A T-shaped intersection will be created.
- Each direction of the drawn road has two lanes, while the actual Menninkäisentie road consists of one forward and one backward lane. To customize the road attributes, click the road and go to the Properties view. Set both Number of forward lanes and Number of backward lanes to 1. The number of lanes will decrease.
-
To make it easier to refer to this road from the flowchart blocks in the future, change the road’s Name to roadEast.
-
Once you make the previously described changes, the road network should look similar to the one in the figure below.
If you run the model now, you will notice that the cars move along Tapiolavägen only to reach the intersection and not the end of the road. The reason behind this is that connecting a new road to an existing one and creating a new intersection splits the first road into two separate ones.
Our flowchart contains a Car Source block that generates cars entering the forward lane of the
road and a
Car Move To block that directs cars to the end of the same road. This road currently ends at the intersection as the other half of it is a new road now, named
road2.
We shall rename our roads to make it easier to refer to them from the flowchart blocks.
Rename the roads
-
Select and rename the roads to: roadNorth, roadSouth, and roadEast correspondingly (see figure below).
Since the carSource and carMoveTo flowchart blocks still refer to old road names, we need to specify the correct names in their properties.
Adjust the properties of the flowchart blocks
- Select the carSource block. Change its Name to carSourceN as the block generates cars that appear from the North.
-
In the Road parameter of this block you will see the old name of the road. To change it to the new one, select
roadNorth from the drop-down list.
- Make similar changes to the carMoveTo block’s properties. Name it carMoveToS as it will model traffic directed to the end of the road going South, and select
roadSouth from the Road drop-down list.
On running the model now, you will see that the cars are moving from north to south along Tapiolavägen again.
However, we did not create the intersection to please ourselves with the cars moving along one road only. Our next step is to add flowchart blocks to make cars move on all roads in every possible direction.
Add new blocks to the flowchart
- First, we need to reposition the existing flowchart since it will grow and extend beyond the area shown at model runtime. Select the entire flowchart and drag it below the blue rectangular frame of the model window.
-
Now we will add blocks that model traffic on the backward lane of Tapiolavägen, from south to north. Add a
Car Source and a
Car Move To block. Connect them to the existing blocks in the following way:
As you can on see in the figure above, the blocks’ connectors are not necessarily straight lines. By default, connectors take the most efficient shape and bend automatically. You can also create connectors of a custom shape. To do so, click the first port and then add turning points by clicking the corresponding area. Finish drawing with a double-click on the second port. You can also add turning points after you have finished drawing by selecting an existing connector, setting a turning point with a double-click and dragging it to a desired location.
Adjust the properties of the added flowchart blocks
- Rename the carSource block to carSourceS: this block generates cars appearing from the South.
- In the Road property, choose
roadSouth. This is the road the cars will appear on.
- Choose backward lane in the Enters property since we need the cars to appear at the South end, which is where the backward lane starts.
-
In the Car section, select
Car as the New car. From now on, the carSourceS block will be generating cars of the specified
Car type. These cars will have the shape of the previously defined green car instead of the colored blocks offered by default.
-
Make the same changes to the carMoveTo block. Name it carMoveToN as it will model northbound traffic. Select
roadNorth in the Road property and set end of backward lane as Destination.
If you run the model now, you will see cars moving along Tapiolavägen in both directions.
The following step will be devoted to modeling traffic flow from the East, along Menninkäisentie. A certain number of cars, approximately half of them, will be heading South after the intersection, while the remaining cars will be heading north.
Add new blocks to the flowchart
- Add another carSource block. It will generate cars at the beginning of the Menninkäisentie.
- Name it carSourceE and choose
roadEast as the Road. Open the Car properties section and choose
Car in the New car property.
- Switch to the
Process Modeling Library palette and add a
Select Output block to the flowchart, placing it close to the just created carSourceE block.
- Name it selectNS.
-
Connect the two output ports of the selectSN block to the input ports of the carMoveToS and carMoveToN blocks. The flowchart should look like this:
TheSelect Output block redirects the incoming agents (cars in our case) to one of its output ports either according to the predefined probabilities, or depending on the execution of a specified condition. By default, the block is operating according to the specified probability, directing approximately 50% of agents to the upper output port. We will keep these settings for selectNS.
Road traffic model flowcharts are most frequently constructed with the Road Traffic Library blocks Car Source,
Car Move To, and
Car Dispose, as well as with the help of the Process Modeling Library blocks
Select Output or
Select Output 5 (reroutes cars in various directions) and
Delay (models the time cars spend in parking lots or at bus stops). We will cover these cases further in this tutorial.
If you run the model now, you will see that cars are moving along Tapiolavägen in both directions, and they are also coming from the East moving along Menninkäisentie, heading either south or north afterwards. The only thing that is left to model is the cars turning from Tapiolavägen to Menninkäisentie.
Let’s add a few more blocks to the flowchart to model this traffic scenario.
Modify the flowchart
- Add a
Select Output block from the Process Modeling Library. Place it between the carSourceN and carMoveToS blocks in such a way that it is connected to both blocks as shown in the figure below. We need this block to distribute the traffic flow between the East and the North. Name the block selectSE.
- Open the block’s properties to set the traffic rerouting. We will assume that the majority of cars moving along the main road (approximately 70%) will continue to move along the same road. In this case, we need to adjust the quantity of cars to be redirected to each output port of the selectSE block. Enter 0.7 as the block’s Probability value. As a result, 70% of the traffic will proceed straight to the port on the right, while the remaining 30% will be redirected to the port below (we will connect the lower port to a corresponding block later).
-
Add another
selectOutput block and name it selectNE. Place it between the carSourceS and carMoveToN blocks (see figure below). We need this block to define the direction for cars coming from the North. Once again, set the percentage of cars which will continue moving along the same road to 70% by entering 0.7 as the Probability value.
- Switch back to the Road Traffic Library palette and add another
Car Move To block. Name it carMoveToE as it will model eastbound traffic on Menninkäisentie. Connect the incoming port to the lower ports of both (!) selectSE and selectNE blocks. Then connect the output port to the carDispose block as shown in the figure below.
- Click the carMoveToE block to open its properties. Select
roadEast as the Road and set Destination to end of backward lane.
We have finally completed the flowchart logic defining the traffic flow on the intersection. Run the model and watch cars move along all the roads.
Demo model: Road Traffic Tutorial — Phase 3 Open the model page in AnyLogic Cloud. There you can run the model or download it (by clicking Model source files). Demo model: Road Traffic Tutorial — Phase 3Open the model in your AnyLogic desktop installation.-
How can we improve this article?
-