Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

For more than two days I'm trying to make the TSP algorithm work in PostgreSQL/PostGIS. My problem seems to occur when I'm trying to take into account the road network for TSP algorithm. I know that the algorithm it will calculate the distance in Euclidean space as a default setting.

As a example:

SELECT vertex_id
FROM tsp('SELECT id as source_id, lon AS x, lat AS y 
          FROM point_layer','23,221,63,432,335,',63);

where the point_layer is the table which holds the points information (as PlaceMarks), numbers like: 23,221,63,432,335 stands for place (cities) and 63 as a starting point.

If you have experience with this approach please advise. Thank you. Ionut

share|improve this question
    
Did you manage to make it work? It may have to do with how your point_layer is organised –  Vladtn Feb 17 '12 at 15:11
add comment

1 Answer 1

According to the examples and the documentation, you should only be loading the five nodes you are interested in in the select query, so I added a where clause to your select query. You also had a trailing comma, following the list of ids in parameter two that I removed.

So give this a try and see if it works better:

SELECT vertex_id
FROM tsp('SELECT id as source_id, lon AS x, lat AS y 
          FROM point_layer where id in (23,221,63,432,335)','23,221,63,432,335',63);

Here is a link to the doc: http://pgrouting.org/docs/1.x/tsp.html

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.