Router
The router class is where all the magic happens. Once you have a RouterDb setup, you can create a router. The router class functions as a façade for most if not all routing requests.
An overview of available features:
- Resolving: Snapping locations to the network.
- Routing: Calculating one, multiple routes or a matrix of routes.
- Weight Matrices: Calculating weight matrices between a collection of locations.
- Connectivity checks: Check if a RouterPoint is connected to the rest of the network.
The router is setup with the following priorities in mind:
- Correctness: A route has to be correct as requested.
- Performance: Performance is the next primary choice.
Result object
Each method has two counterparts, one that returns the result in a Result<T> object and one that doesn't:
- Calculate: As expected just returns the route or routes that have been calculated.
- TryCalculate: Also returns the route or routes that have been calculated but in a Result<T> object. When, for whatever reason, calculation fails, route is not found or resolving fails, the result object just contains the error message.
We do this because exceptions are bad for performance, if you are in a high-performance environment, consider using the TryCalculation methods and checking the result object.
Resolving
One of the most important functions of the router is the option to resolve points. Read more about this in the RouterPoint section.
RouterPoint Resolve(Profile profile, float latitude, float longitude)
- profile: The Profile, defines the vehicle to resolve for.
- latitude,longitude: Defines the location to resolve.
There are several more overloads and functions to resolve multiple locations at the same time. Check the API documentation for the Router object and the extension methods in RouterBaseExtensions.
Routing
The most basic function of the router is to calculate routes:
Route Calculate(Profile profile, float sourceLatitude, float sourceLongitude, float targetLatitude, float targetLongitude)
- profile: The Profile, defines the vehicle's behavour to calculate a route for.
- latitude,longitude: Defines the source and target location of this route.
There are several more overloads, to calculate multiple routes at the same time or to calculate matrices of routes. Check the API documentation for the Router object and the extension methods in RouterBaseExtensions.
Weight Matrices
The most basic function of the router is to calculate routes:
float[][] CalculateWeight(IProfileInstance profile, RouterPoint[] locations, ISet<int> invalids)
- profile: The Profile, defines the vehicle's behavour to calculate a route for.
- locations: The locations to calculate the matrix for.
- invalids: The set of invalid locations, some may not be routable.
There are several more overloads. Check the API documentation for the Router object and the extension methods in RouterBaseExtensions.
Check Connectivity
Checks connectivity of the given router point:
bool CheckConnectivity(IProfileInstance profile, RouterPoint point, float radiusInMeters)
- profile: The Profile, defines the vehicle's behavour to calculate a route for.
- point: The point to check for.
- radiusInMeters: The radius in meter to check.
There are several more overloads. Check the API documentation for the Router object and the extension methods in RouterBaseExtensions.
What to read next?
If you followed the what to read next sections you pretty much covered all the most important concepts. Interesting could be the information about the Route concept.