Font size

Alternative route providers for cars and trains

 Route Provider element enables you to define an alternative road network in GIS model in addition to the default one defined by the GIS map.

In GIS models agents move along the existing roads. However, different types of agents use different types of roads: trains move along railways, cars follow automobile routes, and so on. That is why AnyLogic enables users to obtain data on roads of different types and make agents use this or that specific road network.

AnyLogic supports four types of road networks: Car (for all types of vehicles), Rail, Bike, and Foot.

If all moving agents in your GIS model belong to one category (e.g., vehicles), you just specify the required Road type: Car in the Routing section of the GIS map properties.

But if you have several types of agents that use different types of roads, you need to add Route provider element in your model to enable some agents to use not the default road network of the GIS map, but some alternative road network.

The model below demonstrates how to do this. It contains two types of transport: trains and cars. On clicking a button in the model, you start movement of an agent (either a car, or a train) from Paris to Nice. If you send both of them, you will see that cars and trains use different routes to reach the same destination. Cars use the default road network provided by the GIS map (Road type: Car), while trains use the custom route provider with the Road type: Rail.

Demo model: Route Provider Open the model page in AnyLogic Cloud. There you can run the model or download it (by clicking Model source files).

To define an additional route provider in a GIS model

  1. Select your GIS map. Open the Routing section of the map properties. In the Road type list, select the road network type for the default route provider in the model. Choose the road type that is mostly used in the model, e.g. Car.
  2. Now define the alternative route provider. Drag the Route Provider element from the GIS section of the Space Markup palette into the graphical editor.
  3. In the Road type list of the route provider properties, select the road network type for this alternative route provider: Rail.
  4. Now it is time to set up agents living in the model to use this or that route provider. Say, we have two agent populations on Main: vehicles and trains. Leave vehicles to use the default route network. Select trains and in the Initial location properties section, choose the name of the earlier created custom route provider from the Routing drop-down list.
    Now if you run the model you will see that agents use different road networks to get to the destination: cars use automobile routes, while trains use railway network.



Name — The name of the route provider. The name is used to refer to the provider from agent population properties, etc.

Ignore — If selected, the route provider is excluded from the model.

Visible on upper agent — If selected, the route provider icon is also visible on the upper agent where this agent lives.

Visible — Here you specify whether the route provider icon is visible on animation at model runtime, or not. Using the control, choose yes or no.

Routes are — Here you can choose how this route provider obtains the data on the route network. You can choose the routes to be Requested from OSM server (then you can choose the routing server), or use the option Loaded from PBF file to create a routing graph from a file on your hard drive. If you select the Straight lines option, the routes will be just drawn as straight lines on the GIS map.

Routing server — [Available if the Routes are: requested from OSM server] There are three routing servers available: AnyLogic (recommended) YOURS and BRouter.

Routing method — [N/A if the Routes are: Straight lines] Choose here, if you want agents to take Shortest or Fastest routes in the network.

Road type — [N/A if the Routes are: Straight lines] Choose here the road network type: Road, Rail, Bike, or Foot.

Pathfinding algorithm — [Available if Routes are: loaded from PBF file] Choose the pathfinding algorithm: A*, bidirectional A*, Dijkstra, Dijkstra bidirectional, Dijkstra native bidirectional.

Specify routing graph — [Available if Routes are: loaded from PBF file] Click this button to open the routing graph wizard where you can create a new graph or select to use an existing one. The supported file types are PBF and OSM.

If route not found — [Not available if the Routes are: Straight lines] Here you indicate what you want AnyLogic to do if a route cannot be created (typically because the route does not exist). If you want AnyLogic to approximate a route with a straight line and continue running the model, select the option Create straight route. If you want AnyLogic to notify you about such a problem and stop, choose Show error dialog.


Show name — If selected, the name of the route provider will be shown in the graphical editor close to the element icon.

Use custom route provider — If you want to use a custom on-line route service, select this option and an edit box labeled Custom route provider will appear. In this box, you will find sample code with comments.

How can we improve this article?