Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Finding the shortest route between two paths

Hi Guys,

I have a table that is having the train information like train no , train name, source station name, destination station name, distance

the table looks like this:

Train No    Train Name       Source Station Name      Destination Name    Distance

-------------------------------------------------------------------------------------------------------------- 

     1               ABC                           A                                   B                         10

     2               CDE                           B                                   E                         30

     3              EFG                            E                                   D                         40

     4               HIJ                             E                                   F                         20

     5               KLM                           B                                   D                         10

what I need is if I select Source Station : A and Destination : D then it should give the me list of all the train numbers, I need to connect to reach to the destination using shortest distance .

For example: from  A To D : A->B->D = 20 then the train no will be 1,5

                     2:    A->B->E->D= 80 then the train numbers will be 1,2,3

This is what I need , it would be great if anyone can help me finding the solution

Thanks,

Vivek

19 Replies
swuehl
MVP
MVP

The HIERARCHY LOAD prefix might be limited to routes without possible loops, which I think is hard to ensure.

I've tried to create a similar approach without using the HIERARCHY LOAD prefix, but using a loop that iteratively joins all source stations to the previous destination stations.

2016-06-07 18_05_10-QlikView x64 - [C__Users_Stefan_Downloads_comm219620_2.qvw_].png

=Aggr(If(Left(Path,1) = SourceSelect and Right(Path,1) = DestinationSelect, Path),Path) TotalDistance Path
A/B/D20A/B/D
A/B/E/D80A/B/E/D

edit:

Also attaching a slightly modified version where the selection of source and destination station is linked to the path.

2016-06-07 18_28_54-QlikView x64 - [C__Users_Stefan_Downloads_comm219620_2b.qvw].png

Anonymous
Not applicable
Author

Hi Swuehl,

When I am connecting it with my data it is taking too much of time and get stuck in the middle, I don't have any clue can you help me out

Thank You,

Vivek

swuehl
MVP
MVP

How many stations / connections do you have in your data?

Can you estimate the max number of stations on any given route?

Anonymous
Not applicable
Author

Hi Swuehl,

I am having total 69K records out of which I am just loading 296 records , still it is loading

What should I do now?, No I can't estimate maximum number of stations for any given route.

Thank you,

Vivek

Anonymous
Not applicable
Author

Hi Swuehl,

I am having 356 source and 356 destinations , in that case they are connected in the one or the other way I feel

what should I do now?

Thanks,

Vivek

Anonymous
Not applicable
Author

Hi Swuehl,

I have attached an image in this if I select B as source and E as destination then it give me two train nos :1,2  but ideally it should be 2 I feel , then how can I remove it?.

Sorry for troubling you.Capture.PNG

Thanks,

Vivek

swuehl
MVP
MVP

Start with limiting the number of hops to evaluate:

Instead of

For i = 1 to FieldValueCount('Destination Name')-1

use a low upper limit, like

For i = 1 to 2


then investigate in the SourceSelect and DestinationSelect, if all possible combinations are possible.


This might not find the optimal path, though.


If you get a feeling for the number of possible routes created, slowly increase the upper limit of the for loop.

It will depend on the properties of your network how much iterations you will need to find all connections and a at least near-optimal route.

Note that this approach is a brute force one, if you need to handle thousands of stations with a lot of possible destinations, this brute force approach will not work (well).

There are specialized tools for route optimization and you might want to have a look into some other external tools as well.

swuehl
MVP
MVP

It doesn't look like you are using my latest version?

I don't support version 0.9 anymore

Anonymous
Not applicable
Author

Hi Swuehl,

I am Using Version 11 , Is it because of that ??

Thank you,

Vivek

swuehl
MVP
MVP

No, sorry, I am referring to my latest uploaded QVW sample file.

This should not show the two train numbers when you are expecting only one.

The field is called TrainSeq