Alternative routes together on one map

This forum deals with any kind of routing computation whether it is simple A:B-routing, calculation of isochrones, simple matrix computation or nearest search.
Post Reply
VPlachy
Posts: 21
Joined: Fri Nov 27, 2015 10:44 am
Location: Czech Republic
Contact:

Alternative routes together on one map

Post by VPlachy »

Hello,
I need help with counting and displaying several alternative routes together on one map.
This feature is available?
What should I set to work properly?
It is a simple model of how to do it?

Thank you.
Vladimir Plachy
User avatar
Bernd Welter
Site Admin
Posts: 2695
Joined: Mon Apr 14, 2014 10:28 am
Contact:

Re: Alternative routes together on one map

Post by Bernd Welter »

Hello Vladimir,

basically the computation of alternative routes is based on the following principles:
  • in a first step a regular route is calculated, let's call it the VERSION_0.

    Code: Select all

    Route route = svcRoute.calculateRoute(arrWPD, arrRoutingOptions, null, resultListOptions, callerContext);
  • The output of the call is a route object including a so-called binaryPathDescription.
  • Based on the binaryPath you create an ExceptionPath together with a malus that suits your requirements, e.g. 500 if you want to avoid each VERSION_0 segment with a malus of 500%.
  • in a second call you use the same routing parametrization (profile/snippet encapsulated in the CallerCOntext, routing options as explicit parameters if necessary) but you add the ExceptionPath as an additional input information.
Maybe the following source in c# is a quick sample:

Code: Select all

Route route = svcRoute.calculateRoute(arrWPD, arrRoutingOption, null, rlo, cc);
ExceptionPath[] arrExPath = new ExceptionPath[] {
         new ExceptionPath() {
                   binaryPathDesc = route.binaryPathDesc,
            relMalus = 500
         }
};
Route alternativeRoute = svcRoute.calculateRoute(arrWPD, arrRoutingOption, arrExPath, rlo, cc);
So whenever you want to compute the alternative #N you have to compute the VERSION[0], VERSION[1], ... VERSION[N-1] and provide it in the call of VERSION[N].

There is also a shortcut available:
There is a special RoutingOption avalable for that scenario. So if you want to compute the VERSION[2] with just one single call you may use it:

Code: Select all

int malus = 500;
int indexALT = 2;
RoutingOption alt = new RoutingOption() {
  parameter = RoutingParameter.EXPERT_OPTIONS,
  value = "ALT|" + malus + "|" + indexALT
};
Be aware that the proper ExceptionPath mechanisms offers both an absolute malus and a relative malus..

Here are some example screenshots:
urban example
urban example
regional example
regional example
So quite often especially start and final part of a route do not change that much.

Best regards
Bernd

PS: my description is based on calcRoute but also works with calcExtendedRoute and the other, more complex variants.
VPlachy
Posts: 21
Joined: Fri Nov 27, 2015 10:44 am
Location: Czech Republic
Contact:

Re: Alternative routes together on one map

Post by VPlachy »

Hello Bernd,
Thank you for your help.

Vladimir
g.fiume
Posts: 30
Joined: Wed Jan 25, 2017 9:17 am

Re: Alternative routes together on one map

Post by g.fiume »

Bernd Welter wrote:Hello Vladimir,

basically the computation of alternative routes is based on the following principles:
  • in a first step a regular route is calculated, let's call it the VERSION_0.

    Code: Select all

    Route route = svcRoute.calculateRoute(arrWPD, arrRoutingOptions, null, resultListOptions, callerContext);
  • The output of the call is a route object including a so-called binaryPathDescription.
  • Based on the binaryPath you create an ExceptionPath together with a malus that suits your requirements, e.g. 500 if you want to avoid each VERSION_0 segment with a malus of 500%.
  • in a second call you use the same routing parametrization (profile/snippet encapsulated in the CallerCOntext, routing options as explicit parameters if necessary) but you add the ExceptionPath as an additional input information.
Hi, I've tryed to use a similar method, but I do not like the given results becouse if I assign a malus to a route the system creates a completely different alternative without taking into account that a better choice could be have a part of route in common.
As you can see in the image xroute gives me a route totally different from the first one.
cattura2_Ink_LI.jpg
Maybe I've to change the relMalus value but I'm not able to understand the meaning of the different values. Change the relMalus value from 2501 to 2000 doesn't make any difference.

Thank you
User avatar
Bernd Welter
Site Admin
Posts: 2695
Joined: Mon Apr 14, 2014 10:28 am
Contact:

Re: Alternative routes together on one map

Post by Bernd Welter »

Routing means (in rough terms):
determine the sequence of segments that successfully connects waypoint A(x0,y0) to waypoint B(x1,y1) and produces the minimum aggregated "cost".
The costs of a single segment are influenced by various factors, e.g.
  • length of a segment
  • driving time (derived by network class via speed values)
  • percentage malus due to road category (AVOID_TOLLROADS, AVOID_...)
  • other malus values (e.g. based on ExceptionPath)
Now setting the ALTERNATIVE ROUTE MALUS means that all the succeeding alternatives will "malify" the segments used in previous ALTERNATIVES. I attached some screenshots, maybe they can help you to understand the approaches,
MALUS = 25, small impact, some initial parts of the alternatives share segments
MALUS = 25, small impact, some initial parts of the alternatives share segments
MALUS = 2500, forces the (n+1) alternative to leave the (0),(1), ..(n) paths. so almost NO overlapping but possible (e.g. green + orange)
MALUS = 2500, forces the (n+1) alternative to leave the (0),(1), ..(n) paths. so almost NO overlapping but possible (e.g. green + orange)
MALUS = 2501, segments of a previous call are forbidden which could cause an error due to "no valid path found".
MALUS = 2501, segments of a previous call are forbidden which could cause an error due to "no valid path found".
If not let me know!

Regards Bernd
Bernd Welter
Technical Partner Manager Developer Components
PTV Logistics - Germany

Bernd at... The Forum,LinkedIn, Youtube, StackOverflow
I like the smell of PTV Developer in the morning... :twisted:
g.fiume
Posts: 30
Joined: Wed Jan 25, 2017 9:17 am

Re: Alternative routes together on one map

Post by g.fiume »

Bernd Welter wrote:Routing means (in rough terms):
determine the sequence of segments that successfully connects waypoint A(x0,y0) to waypoint B(x1,y1) and produces the minimum aggregated "cost".
The costs of a single segment are influenced by various factors, e.g.
  • length of a segment
  • driving time (derived by network class via speed values)
  • percentage malus due to road category (AVOID_TOLLROADS, AVOID_...)
  • other malus values (e.g. based on ExceptionPath)
Now setting the ALTERNATIVE ROUTE MALUS means that all the succeeding alternatives will "malify" the segments used in previous ALTERNATIVES. I attached some screenshots, maybe they can help you to understand the approaches,
alt25.PNG
alt2500.PNG
alt2501.PNG
If not let me know!

Regards Bernd
Thank you very much. With your help my routes are improving.
Post Reply