Road Traffic Library Webinar

Road Traffic Library Webinar


Skip to 3:20 Let’s start by creating the road network. First, we need to add a new model. We give it a
name and keep the default model time unit which
is “seconds”. Next step is to add a satellite image by bringing it
from the “presentation” pallet I check the “lock” checkbox to make the image
unselectable by left click. We also have to scale the model. According to
the image scale, ruler length should correspond
to 120 feet. Let’s disable the grid to draw the roads freely. I start drawing the roads by double clicking on the
road markup element. This part of the road network has 4 forward, and
4 backward lanes with a 10-meter-wide median
strip. I change the median strip color to grass texture. Next, I start drawing this part of the network and
connecting it to the median of the previous road. To draw the other part, I should put the road start
point close enough to see its color change to
cyan. Both of these sections are one way and have 4
lanes. We can adjust the location by mouse or
keyboard arrows. We can hide the space markup elements to see
the image underneath. This will help us to adjust
our markup elements. Now I draw and adjust the other segments of the
road network which are similar to the last step. By clicking twice on any segment of the network
you can select the entire network. I change the road color of the entire network to
tarmac texture. As you can see AnyLogic draws some lane
connectors by default. I want to disable some of
them to customize the traffic directions. To do so I have to select the intersection first. The
selected intersection will highlight the lane
handles. As you can see, I can disable or enable its lane
connectors by clicking on them. I do the same for the second intersection. Let’s add the traffic flows logic. This part of flowchart relates to the cars that
start from the upper left segment of the network
and will go to the upper right segment. I start by adding a “CarSource” block, then a
“carMoveTo”, and finally a “carDispose”. This part of flowchart relates to the cars that
start from the bottom right segment of the
network. These cars have three options: continuing
straight, turning right, or turning left. Road traffic library is interoperable with process
modeling library and other standard libraries of
AnyLogic. As you can see I used “selectOutput5” from
process modeling library. This part of flowchart relates to the cars that
start from the bottom segment of middle road. These cars have two options: continuing straight
to upper part of the middle road, or turning left. The last part of flowchart relates to the cars that
start from the top segment of middle road and go
to the bottom segment of it. Let’s make some minor adjustments and then
move to associating the flowchart blocks with space markups representing different
segments of the road network. First, this “carSource” should be associated with
the left segment of the upper road. This “carMoveTo” should be associated with the
right segment of the upper road. The cars that start in the right segment of the
bottom road have three options: turning right,
turning left, or continuing straight ahead. But first, let’s adjust the probabilities of each car
choosing any of these three options. Now I associate the flowchart blocks with the
space markups. The cars that are turning right, will go to upper
segment of middle road but in the backward lane. Therefore, I have to check the “end of backward
lane” checkmark. These cars that start from the bottom segment of
middle road will start in a backward lane. They have two options: continuing straight which
means going to the end of backward lane, or
turning left. Finally, the cars that start from the top segment of
middle road will go to the bottom segment of it. Let’s save the model and run it. As you can see, I received the “car failed to
change lane” error message. This is due the fact that this car started from a
lane on the right side of this road and did not have enough space and time to reach
the left lane. We can increase the length of this road segment
or put these cars on a specific lane from the
beginning. However, I’m going to use the “outWayNotFound”
port. Basically I’m telling the cars that want to turn left
but are not able to reach the left lane on time to
continue straight ahead. Lets’ run the model and see the result of this
modification. Ok let’s change the portion of the cars that should
turn left in the lower intersection to 30 percent. I also want to let the cars that start on the bottom
right segment of network to continue straight
ahead in case they cannot change lane on time to turn. Let’s take a look at bottom intersection during the
runtime. As you can see, cars that are turning left
do not stop for the incoming traffic. To add a yield sign, I select the stop line and
check the “Yield” checkbox. Now if I run the model again, we can see that the
cars that are coming from the bottom segment will let the others to proceed if they reach the
intersection at the same time. OK! Let’s setup the traffic lights. I will drag and drop a “Traffic Light” block to the
model. The mode of this traffic light is “Intersection’s stop
lines”. I select the upper intersection. Let’s add two yellow phases and change their
duration to 5. I also change the other two phases duration to 30
seconds. After selecting a traffic light phase, I can change
the color of each stop line by clicking on it. Now I’m adding the second traffic light. Its mode
is “intersection’s lane connectors”. By clicking on each lane connector, we can set
its color during each phase. Now that everything is set I can run the model to
see how the traffic lights will affect the traffic. In this intersection, you can observe the effect of
the yield sign on the cars who want to turn left. OK! It looks like that the cars behave as expected.
Let’s optimize the traffic lights. First, we need to add a custom car type that
knows the time it entered the model. We can add a custom car type from the “Road
Traffic Library” pallet or from the “create a
custom type” link in the “carSource” properties. We create the agent type from scratch with the
default animation. I add a parameter and rename it to “startTime”. Its
default value will be time() function which will be
evaluated at the time this agent is being created. Basically “startTime” works as a time stamp that
records the arrival time of each car into the
model. Now I will create an initially empty population of
agents that are from the car type that we’ve just
created. I click on each “carSource” and under the
advance section, I will assign the added cars to the custom population that we’ve created in the
last step. Just remember to change the new car type in all
the car sources to “Car”. To assign the added cars to the custom
population you can either use the element
chooser or the drop down menu. Next is to add a “Histogram Data” from “Analysis”
pallet. Double click on the “cars” population to add a
piece of code to its “On destroy” field. We point to the histogram in the main and add the
difference between current time and the time this
car arrived at the model. Basically we record the duration of time this car
will spend in the model. Let’s add a histogram and assign the
“timeInModel” histogram to it. I want this graph to
show the mean as well. I want this graph to show the mean as well. Ok, if I run the model and let it run for a
reasonable time, we will be able to see the mean
duration time that the cars spent in this model. This average value is a good performance
measure indicator of traffic signal controls. Before we start building the optimization
experiment, let’s change the model stop time. I want this model to run for 10 minutes which is
enough to go through several cycles. As you can see the average time in model is
around 55 seconds with the current setup of
traffic lights. Let’s see if we can reduce this number by
optimizing the traffic lights’ phases. I want to parametrize duration of each phase,
therefore I need four parameters with a default
value of 30 seconds. Now I go back to each traffic light, and change
the duration of each phase with the parameters. To create a new optimization experiment, I need
to right click on the model, new experiment and
select the optimization experiment. As you see, all the parameters in the main are
now in this optimization experiment. Our objective is to minimize the mean value of the
time all cars spend in the model. Root here points to main. “timeInModel” is the
histogram object inside main. I will change the type of all four parameters to
discrete. Their values could be between 10 to 35
seconds with steps of 5. Now I create a default UI and then run the
optimization experiment. Here you can see that AnyLogic automatically
detects the number of available cores and runs several
iterations in parallel on different processor cores. The chart visually illustrates the optimization
process. The X-axis represents simulations, and
the Y-axis represents Current Objective, Best Feasible Objective and Best Infeasible
Objective found for each simulation. Ok, now I can copy the best feasible values and paste them to the original simulation
experiment. We can see that the mean value is decreased to
46 seconds after optimizing the traffic lights. At this step, I want to add a parking lot to the
model. “Parking lot” is a space markup element in road
traffic library. I change the number of parking
spaces to 10. Now I need to add a “selectOutput”, a
“carMoveTo”, and a “delay” block to this part of
the flowchart. Some of the cars that are starting at left segment
of the upper road will go to this parking lot. Their duration of stay in the parking lot is coming
from a triangular distribution. You can choose from a large set of probability
distributions by clicking on the “choose probability
distribution” icon. The delay also has a maximum capacity. As you can see 50% of cars will try to park in the
parking lot. Let run the model and observe the parking lot. I received the “Car failed to reserve a parking
space in parking lot” error. Similar to what we did before I will use the
“outWayNotFound” port to tell the cars that
cannot park to go straight. Let’s run the model again and observe the parking
lot. It looks like everything is working as expected. OK! Let’s add a bus route. I’m adding three bus
stops to the network. Here I want to create the flowchart associated
with the buses starting with a “carSource”. Next is to build a custom agent type for buses.I
choose this icon. I am adding a parameter and name it
“stopCounter”. This parameter is of type integer and counts the
number of bus stops each bus has passed by. I want to build a custom object for bus routes. I bring an agent from the agent pallet. I select “a
single agent”. Choose “I want to create a new agent type”.
Agent type name is “BusRoute” and click finish. I add a picture from “pictures” pallet for the icon
representing this custom object. We need two ports that we can bring from
“agent” pallet. Click on the shape and check the “icon” checkbox
to make it an icon. Now I can build the flowchart that each bus will
pass through whenever they enter this custom
object. We need a “carMoveTo”, a “delay”, and a
“selectOutput”. I connect the two ports we’ve added to the
associated ports in the flowchart. Make sure all
the connectors are connected correctly. OK, let’s go back to the main and complete the
flowchart. Whenever a bus is injected to the
model, it goes to the “busRoute” custom object. Buses will be injected into the model with a rate
of 1 per minute. They start at the right segment of the bottom
road. Length of the buses is 8 meters. Their initial and
preferred speed are 40 kilometers per hour. If needed, you can change the unit of length or
speed from the drop down menus on the right. I also uncheck the random lane checkbox and ask
the bus to start at the lane with index of zero
which is the furthest right lane. After going through all the bus stops each bus
will go to the right segment of the upper road and
eventually leaves the model. OK, now I want my custom object to be capable
of selecting the bus stops. To do so, I need to add
a parameter to “BusRoute”. The parameter is an array of bus stops. I change its label to Bus Stops and its control type
should be one-dimensional array. Now if I go back and click on the “busRoute”
object, it lets me pick the bus stops and put them
in the array. I choose the bus stops in the correct order. OK, let’s go back to the custom object and set the
properties of each block. The agents that are passing through this custom
object are of type Bus and they are moving to
bus stops. Each bus will pick its next stop from the
“busStops” array, starting from index zero. Then the bus increments its “stopCounter” to
know the index of the next bus stop. This “selectOutput” should work similar to a while
loop. As long as the bus has not passed by all the bus
stops, it will be sent back to the “carMoveTo”
block. We need a condition here. This condition says that if the bus’s “stopCounter”
is equal to the total number of bus stops in the
“busStops” array, then the bus has passed by all the stops and it
should exit the “busRoute” object. Finally, I adjust the values of triangular distribution
in the delay. Delay has maximum capacity. Now it’s time to run the model but first I want to
set the stop time of the model to “never” so that I
can run it as long as I want. You can see that buses are moving in the
furthers right lane and stop at each bus stop as
we expected. Let’s add a “Road Network Descriptor”. You can
use it to get access to all the vehicles located in
one road network. I want to enable Traffic density map which is a
semi-transparent coloring of roads depending on
the average speed of a car on each section of the road. I set the “road section length” to 20 meters. These
sections are used in density maps and average
speed reporting. Let’s run the model and see the density map!
Traffic density map is shown in both 2D and 3D
animation. Now it’s time to add some pedestrian to the mix! First I draw a wall around the pedestrian
movement area. The “wall” space markup is on
top of “Pedestrian library” pallet. I draw two target lines and a “rectangular area”
to define the pedestrian movement. We need a “pedAreaDescriptor”. This block
allows to define rules on pedestrians being inside
the rectangular area. Check the “Enable access control” check box. We need a stop line here. I’m going to add a Traffic Light block and assign it
to this stop line. The traffic light will specify the
traffic behavior at this stop line. I’m modifying the phases of this traffic light. Let’s modify the flowchart and add the
pedestrians. I start with a “split” block that lets us create
several pedestrian for each incoming car. We need a “pedEnter” after the split to assign
location to pedestrians and inject them into the
model. I am adding three “pedGoTo” blocks here and a
“pedSink” at the end. Before setting the attributes of these blocks, we
need to add a custom pedestrian type. I keep the default animation, and add two
parameters to record the pedestrians’ initial
location. Now on the split block, the “new agent” type
should be the custom Pedestrian. Number of copies or the passengers of the cars
is coming from a discrete uniform distribution. “On exit copy” field, we assign the location of
cars to the pedestrians. “agent” is the pedestrian and “original” is the car. We get the X and Y of the car and assign it to the
pedestrian. For the Y axis of the pedestrian, I add a 5 pixel
offset. Pedestrians that are injected by “pedEnter”
should appear at a point. X and Y values of that point is equal to the values
of x and y parameters inside each pedestrian. Now I’m setting the movement of pedestrians by
these three “pedGoTo” blocks. First they go to the bottom target line, then the
rectangular area and finally the target line on top. OK, now we are ready to run the model and see
the pedestrian movement. I turn off the density
map first. You can see that the cars are parking and
passengers getting out of the cars. Then they move toward the target line. The problem is passengers don’t pay attention to
the traffic light and cross the road whenever
they reach the target line even when the light is green for the cars. Ok, we can fix this by going to the traffic lights
and “on phase change” field I only open the
“pedAreaDescriptor” during the red light. “currentPhaseIndex” equals 2 means when the
traffic light is in red phase. Whenever the phase index is not equal to 2 the
expression will be false and therefore
“pedAreaDescriptor” will be closed which will prevent pedestrians from crossing the
road. As you can see the pedestrians only start
crossing the road when the traffic light is red. However, if pedestrians are in the middle of road
and traffic light turns green, cars will ignore the
pedestrians and pass through them. To fix this, we can add a second stop line and put
it after the stop line assigned to the traffic light. Now I go to the “on Enter” field of
“pedAreaDiscriptor” and set the signal of the stop
line to red. This means that whenever a pedestrian moves
into the rectangular area, the stop line will be red
stopping cars from passing. We also need to change the light to green
whenever the rectangular area is empty. I do this
by adding this code in the “On Exit” field. Ok let’s run the model and see the results! At this moment, the traffic light is red and
pedestrians start crossing the road. Now, the traffic light is green but cars are not
moving because some pedestrian are in the
rectangular area and therefore the second stop line is red. Ok, looks like everything works fine.

Only registered users can comment.

  1. Greetings. I'm working on a project. I need your assistance on a project that I'm working on right now. Could you please provide me with your mail address?

Leave a Reply

Your email address will not be published. Required fields are marked *