[pgrouting-dev] Having problems under standing the distance matrix of TSP in respect to route network pgroute version 2, possible solution

Stephen Woodbridge woodbri at swoodbridge.com
Sat Jun 15 12:45:27 PDT 2013


On 6/15/2013 2:34 PM, Dave Potts wrote:
> On 15/06/13 14:28, Stephen Woodbridge wrote:
>
> Nice Idea, but one of the problems I have is that I am VERY lazy!
>
> When I create a source/target/cost table I only tend to populate it with
> existing routes, so if I have path at cost of 42 betweens nodes 2 and 3
>
> I will create an entry  like
>
>      2 3 42
>
> I have no desire to create an entry for journey between nodes 5 6 that
> does not exist or having to provide  a value for journey between myself
> and myself eg a journey from node 2 to node 2,  I think the suggested
> solution would require me to create entries like
>
>     2 2 0
>     5 6 0  etc
>
> So I had a crack at writing a function based on Steves original
> screenplay.  I think it needs a lot more work,  when I create the
> temporary tables,  I get a diagnostic from psql saying that its created
> a table.  There must be a better way of doing it
>
> Its invoked as
> select mktsparray(' select source,target ,cost  from edge_table2');
>
>
> -- Make a distance matrix for the traveling salesman  problem
> --
> -- Input is an sql string that provides source, target and the cost
> -- of getting between them
> --

Dave,

You have to do the work somewhere ;) Either in the table entries or when 
you initial the array. And the TSP code will not work if it is not a 
symmetric matrix with all values filled in. My note about checking the 
matrix was a hint check for these issues. Symmetric means the 2-3 has to 
be equal to 3-2 and the diagonal is all zeros.

-Steve


More information about the pgrouting-dev mailing list