Using routing profiles to avoid French autoroute tolls

route with and without autoroute

If you want to avoid a certain type of road, but not prohibit it entirely, you can give it a large negative bonus in the routing profile. For example, to avoid motorways, but not prohibit them entirely, in case there is no other reasonable route, you can create a profile like this:

// Add an extra routing profile for routes avoiding motorways; make them no more preferable than tertiary roads.
 Router::TProfile profile;
 profile.iBonus[Router::KArcMotorway] = profile.iSpeed[Router::KArcTertiaryRoad] - profile.iSpeed[Router::KArcMotorway];
 profile.iBonus[Router::KArcMotorwayLink] = profile.iSpeed[Router::KArcTertiaryRoad] - profile.iSpeed[Router::KArcMotorwayLink];

In this code we give motorways and motorway links a negative bonus to make them no more attractive than tertiary roads. Routes are calculated using the speed + bonus for every segment, giving a notional speed which is used as a weight. A weight of zero or less causes a segment not to be used.

By calling CFramework::AddProfile we add a new profile to the existing standard profile. The framework calculates routes for all the current profiles.

In the image, the orange route allows the use of motorways and the blue route avoids them.