[pgrouting-dev] TSP Euclidean distance function

Stephen Woodbridge woodbri at swoodbridge.com
Fri Jun 28 07:17:34 PDT 2013


Hi All,

I'm trying to understand how the old TSP code was supposed to work, as 
it is not making any sense to me. So the signature is:

select * from pgr_tsp(sql text, ids text, start_id integer, end_id integer);

sql - sql that selects some number of point that have id, x, and y, ie: 
'select id, x, y from table'
ids - is a comma separated list of ids, :ie: '3,27,44,6'
start_id - must be one of the ids in the ids list
end_id - [optional] will be the end of the path if passed in, otherwise 
assumes a loop. must be in ids

Currently 'sql' can select an arbitrary list of nodes greater than the 
list of ids. This does not make any sense to me and the code behaves 
badly in this case. For example if you select 100 points in the sql and 
only have 5 in the ids list what does this mean? Why is the ids list 
separate from the sql?

Currently the code only works cleanly if the the sql returns exactly the 
list of ids. ie:

select * from pgr_tsp(
   'select id, x, y from mytable where id in (3,27,44,6)',
  '3,27,44,6',
  3, -1);

This seems redundant and messy at best.
Can anyone clear up what was supposed to happen in the old version?

I'm temped to just through out the old code and rewrite this as a 
wrapper that computes a distance matrix and calls the matrix function, 
or something like that.

Thoughts, use cases?

-Steve


More information about the pgrouting-dev mailing list