Create a new model
Click the New toolbar button. The New Model dialog box is displayed.
Specify the name of the model. In the Model name edit box, type Road Traffic Tutorial.
Specify the location where you want to store your model files. Browse for the existing folder using the Browse button, or type the name of the folder you want to create in the Location edit box.
Select seconds as the Model time units.
Click Finish to complete the process.
New model is created. It already has one agent type called Main and experiment called Simulation. Agents are the main building blocks of AnyLogic model. In our case Main agent will serve as the place where will define all the logic of the model: here we will draw road network and define the car traffic process using a flowchart.
center of the
workspace you will see the graphical editor. It shows the
of the Main
To the left of the graphical editor you can see the Projects view and the Palette view sharing the same area. The Projects view provides access to AnyLogic models currently opened in the workspace. The workspace tree provides easy navigation throughout the models. The Palette view contains all graphical elements, which you can add onto the graphical editor of your agent just by drag'n'drop. Model elements are grouped by categories in a number of palettes.
On the right side of the workspace you can see the Properties view. The Properties view is used to view and modify the properties of a currently selected model element(s). When you select something – e.g., in the Projects view or in the graphical editor – the Properties view displays the properties of the selection.
Now we can start developing the model.
The typical scenario is the following:
We will use the following layout:
Save the layout image to your computer
Add the layout on the canvas
First, open the Presentation palette of the Palette view. This palette contains shapes, which you can add on your presentation. To open a palette, just click on the corresponding icon in the vertical ribbon docked to the left part of the palette. While you are not accustomed to the palette icons, you may hover the mouse over the ribbon and wait for the popup window to appear. It will show you the names of all palettes.
Drag the Image element from the Presentation palette on the graphical diagram.
Choose the image file to be displayed by this shape. The file browser will open automatically. Browse to the folder where you just saved the layout image file, select it, and then click Open in the dialog box. You will see the drawing displayed in the graphical editor:
Now we will draw the road (Tapiolavagen), placing it exactly over a road on the layout. That is how you define road networks in AnyLogic: draw roads, intersections, and optionally add other space markup elements (bus stops, stop lines and parking lots).
Draw a road
As you can see, the road is drawn opaque. Let's make the road semi-transparent to double-check whether the resulting road perfectly matches the road on the map. The transparency setting (as well as traffic direction and lane width) is defined not in the road properties, but in the properties of the road network this road belongs to.
Now we will define the traffic process with a
composed from Road Traffic Library
Each block here defines some operation that will be performed with cars passing through this block.
In AnyLogic you create flowcharts by adding the blocks from the library palette onto the graphical diagram, connecting blocks together, and tuning the parameters of the blocks.
Create the model flowchart
Let's say a pair of words about these flowchart blocks.
CarSource block generates cars. It is usually used as a starting point of the car flowchart.
CarMoveTo simulates and controls car movement to the specified destination.
CarDispose indicates the end of the flowchart and discards incoming cars from the model.
You can refer to Road Traffic Library Reference Guide for the detailed information about all Road Traffic Library blocks.
Configure the flowchart blocks
Modify the properties of the carMoveTo. Leave the default setting Moves to: road and again select road in the Road drop-down list. This block will simulate how cars drive along the specified road, up to the end of the road's forward lane (it is set by the block's parameter Destination).
After the model is successfully built, you can start it. Running the simulation, you automatically bring the current model up to date.
Start the model
Click the Run toolbar button and choose the experiment you want to run from the drop-down list. Your simulation experiment is called Road Traffic Tutorial/Simulation.
In our case this model is the only one opened in the workspace at the moment, as a result you will be prompted to run this particular experiment. Later, on pressing this button you will start the previously launched experiment. To run any other experiment, right-click (Mac OS: Ctrl+click) the experiment in the Projects view and choose Run from the context menu.On starting the model, you will see the model window. It displays the presentation designed for your simulation experiment.
Click the Run button in the control panel displayed at the window bottom. Observe the process dynamics. You will see how cars move in 2D animation, over the layout image.
If needed, adjust the execution speed to your needs using slow down and speed up controls.
You will also see animated flowchart. Each model created with Road Traffic Library instantly acquires animated flowchart showing the number cars which passed through the block, and the number of cars that is currently inside this flowchart block.
Note that there are several reference models available representing the milestones of the editing. You can use them if you experience any difficulties creating a model and you would like to compare your model with the reference file. Below you can see the link opening the reference model corresponding to this phase.
Reference model: Road Traffic Tutorial - Phase 1
Road Traffic TutorialPhase 2, 3D animation