AnyLogic
Expand
Font size

Defining routes on GIS map

AnyLogic provides ready-to-use routes for you to use with GIS maps. In your model if you want an agent to travel only along the existing roads of a GIS map, defining its route is simple: you only have to specify the route’s start and end points. AnyLogic will then download an existing route (i.e., roads) from an online map service. Because such existing routes are requested from an online service, you must stay online while developing your model. But, to make it easier to develop and run your model, and to improve its performance, its routes will be cached (i.e., saved) in the model’s folder. To obtain the necessary routes from an online map service and then cache them as GIS Routes, follow the instructions below.

If a transportation network you want to model is not available for download from an online map service, you can use GIS space markup elements to explicitly define its individual routes. You can also join individual routes together with GIS points to create a route network.

Alternatively, you can upload a file to create routes for the model, or use straight-line routes for movement between map locations.

To use existing routes

  1. Select the GIS map in the graphical editor and navigate to its Properties view.
  2. Expand the Routing properties section. There you will find the Routes are: requested from OSM server parameter and the routing options for these routes.
  3. AnyLogic supports three online routing servers: AnyLogic (recommended), YOURS and BRouter. You can choose one of them under the Routing server option. All of them are based on the OSM data.
  4. For the YOURS server, you can choose if you want the routes to be the shortest or the fastest.
  5. Then, you can select a road type that fits your needs with each of the servers. By default, the car type is suggested. The bike and foot road types are also available.
  6. Now you only need to define locations on the map with GIS points or regions. If you send an agent from one location to another, it will be moving along the routes that it will receive from the route provider.

To save and edit a GIS route

  1. Double-click the map to enter its edit mode, then pan and zoom it to display the area where you need the route to start or end.
  2. Right-click the map and select  Route from here or  Route to here from the context menu. Then, move to another location and select the other option.

  3. Special marks will appear in these locations on the map.

  4. You will see the GIS Route  element appear on the map.

  5. The route’s appearance and type depend are defined in the Routing section of the GIS Map shape’s properties. If you use an online routing service or create routes from an OSM file, a route of the specified road type between two indicated points will be provided for you. If AnyLogic cannot find an appropriate route through an online service or a routing graph, it will create the route as a straight line or show the error message. (AnyLogic will also create the route as a straight line if you indicate the Straight lines mode in the Routing section.)
  6. After the route is created, you can edit it as you would edit any other manually-drawn GIS route. You can also fix its points on the map using the Lock the position route property.
  7. If you connect two or more routes with GIS points, altogether they form a network.

Alternatively, you can manually draw a route using the  GIS Route markup element.

Creating a route programmatically

There are multiple ways to create a route programmatically:

  • By using one of the getRoute() functions available for the GIS map.
  • By using one of the getRoute() functions available for the IGISRouteProvider interface. This interface is specifically designed for creating routes in the GIS space.
  • By creating a new GISRoute object using one of the available constructors.

All methods that create new routes allow creating one-way routes and bidirectional routes.

For details, see the API documentation for the corresponding objects.

To select the routing method

AnyLogic supports different routing options which define the routes that you request from the routing servers.

  1. Select the GIS map in the graphical editor and go to its Properties view.
  2. Expand the Routing properties section and find the Routing method option. This option is available for routes that are requested from the YOURS routing server, and routes that are obtained from a routing graph.
  3. Here you can choose if the routes should be the shortest or fastest.
  4. When you choose to build the shortest routes, then only the length of routes is considered.
  5. When you use the fastest routes option, the speed limitations on different segments of the route are taken into account.

To select the road type

  1. Select the GIS map in the graphical editor and go to its Properties view.
  2. Expand the Routing properties section. You can choose between the following road types for your routes: for car, bike, or foot.
  3. If the routes in your model are requested from OSM server, you can define Road type for the routes right in this properties section.
  4. When you load the routes from PBF file, you can choose the Road type in the wizard for creating a routing graph. First click the Specify routing graph button, then choose Create new.

To define a route that is not available

  1. Select the GIS map in the graphical editor and go to its Properties view.
  2. Expand the Routing section and find the If route not found parameter. Here you can indicate what you want AnyLogic to do if a route cannot be created (because, for instance, a route cannot be found in the online service’s database or in a file you selected as a routing graph file).
  3. Select one of the two options: Create straight route or Show error dialog.
  4. Select the Create straight route option if you want an unavailable route to be drawn as a straight line. Then at runtime if AnyLogic encounters a route that is unavailable, it will fill in a straight line and your model will run without interruption.
  5. Select the Show error dialog option if you want AnyLogic to notify you about the unavailable route and pause.

Importing routes from file

The default is to download routes using an online routing service. Instead, you can import routes from a routing file on your hard drive. For this purpose, you can download OSM (an XML format of open street map data) or PBF files (highly compressed, optimized binary format of OSM) from libraries on the Internet (for instance, from the GeoFabric.de or BBBike.org). You may find the PBF format files more convenient because their size is smaller, and they will be processed by AnyLogic more quickly.

GraphHopper is an efficient routing library based on OpenStreetMap data (see the GraphHopper website).

To create a new routing graph

  1. Select the GIS map in the graphical editor and go to its Properties view.
  2. Expand the Routing section, find the parameter Routes and select the option Loaded from PBF file.
  3. You can select here which routing method should be used: shortest or fastest, and also define the pathfinding algorithm before or after you create the routing graph.
  4. In the properties section, click the button Specify routing graph that opens the wizard for adding routing graphs. Choose the option Create new on the first page of the wizard.

  5. On the second page, specify the file name in the File field. You can click the Browse button to choose the file. The supported file types are PBF and OSM.
  6. Next, specify the Folder for storing routing graph. By default, this folder is called Routing graph. Click Browse to choose the folder where the files of created routes are stored. If you type the name of the folder in the edit field, this folder will be used if it exists in the model folder; otherwise, it will be created in the model folder with the specified name. If the specified folder already contains a routing graph, you will see a warning next to the folder name, you can still use the folder to create a graph in it, but the existing graph will be deleted.
  7. And last, select the road type (car, bike, or foot) and level of detail for your routes if the Road type is Car.

    • Low level of detail — motorways, trunk, primary, secondary roads, and link roads between them.
    • Medium — all of the low level, and also tertiary (and tertiary link roads), unclassified, and residential roads.
    • High — all of the above, and also living street, service roads, and tracks.
    The importance of a road type is defined with the help of the highway tag. Read more about it on the OSM wiki page.
  8. Click Finish to start creating routes. This process may take some time depending on the file size. You may click the Run in Background button in the Creating routing graph dialog window to hide it. You need to wait until the process of creating the routing graph is finished before you can use any routes it provides.
  9. After the routing graph is created, you can always choose a different file and rewrite the graph: click the Specify routing graph button in the map properties and repeat the process.

To use an existing routing graph

  1. Select the GIS map in the graphical editor and go to its Properties view.
  2. Go to the Routing section, find the Routes parameter and switch to the Loaded from PBF file option.
  3. In the properties section, click the Specify routing graph button that opens the wizard for adding routing graphs. Choose the Use existing option on the first page of the wizard.
  4. Choose a folder that contains routing graph files by clicking the Browse button or typing the name of the folder in the Folder for storing routing graph field and click Next.

  5. The routing graph folder should contain the following files:

  6. You will see a warning if the specified folder does not contain a routing graph.
  7. If necessary, you can go to the map properties to select which routing method should be used: shortest or fastest, and also define the pathfinding algorithm before or after you choose a routing graph in the wizard.

If none of the above options satisfies your needs, you can use a custom online routing service.

To use a custom online routing service

  1. Select the GIS map in the graphical editor and go to its Properties view.
  2. Open the Advanced section. Select the check box next to the Use custom route provider option.
  3. The Custom route provider edit box will appear with sample code you can use to specify a custom online routing service. You can find the API that you need to use to define a custom route provider in the AnyLogic API reference.
  4. When you select this advanced option, the supported providers are grayed out and unavailable.
Demo model: Product Delivery Open the model page in AnyLogic Cloud. There you can run the model or download it (by clicking Model source files).
How can we improve this article?