[pgrouting-users] pgrouting Dijksta Travelling Salesman Problem (TSP) with OpenStreetmap

Carsten Hogertz carsten.hogertz at gmail.com
Fri Feb 21 00:36:33 PST 2014


2014-02-20 23:25 GMT+01:00 Stephen Woodbridge <woodbri at swoodbridge.com>:

> On 2/20/2014 4:59 PM, Carsten Hogertz wrote:
>
>>
>>
>>
>> 2014-02-20 22:47 GMT+01:00 Stephen Woodbridge <woodbri at swoodbridge.com
>> <mailto:woodbri at swoodbridge.com>>:
>>
>>
>>     On 2/20/2014 4:39 PM, Carsten Hogertz wrote:
>>
>>
>>
>>
>>         2014-02-20 22:20 GMT+01:00 Stephen Woodbridge
>>         <woodbri at swoodbridge.com <mailto:woodbri at swoodbridge.com>
>>         <mailto:woodbri at swoodbridge.__com
>>         <mailto:woodbri at swoodbridge.com>>>:
>>
>>
>>              On 2/20/2014 3:54 PM, Carsten Hogertz wrote:
>>
>>                  Thanks Steve,
>>
>>                  coming home and adding your lines it returns with an
>> error:
>>
>>                  NOTICE:  r2:
>>                  (34304,"{0,5.3602868897 <tel:3602868897>
>>         <tel:3602868897 <tel:3602868897>>,4.6782573327 <tel:6782573327>
>>                  <tel:6782573327 <tel:6782573327>>,5.6026971537
>>         <tel:6026971537> <tel:6026971537 <tel:6026971537>>,5.2062747797
>>         <tel:2062747797>
>>                  <tel:2062747797
>>
>>         <tel:2062747797>>,5.__0497181017,5.3147719797 <tel:3147719797>
>>                  <tel:3147719797
>>         <tel:3147719797>>,5.__0700916462,4.__3220066797,4.__8593618137
>>         <tel:8593618137>
>>                  <tel:8593618137
>>         <tel:8593618137>>,4.0002255227,6.____055760592,12.5155379824
>>         <tel:5155379824>
>>                  <tel:5155379824
>>         <tel:5155379824>>,9.__3170226155,8.__
>> 72783427270001,5.__9460446587,__3.0868131677,5.__1839796057,
>> 5.__2301666167,2.__1211198847,5.__7037465591
>>         <tel:7037465591>
>>                  <tel:7037465591
>>
>>         <tel:7037465591>>,2.__7282842677,8.4758437557 <tel:4758437557>
>>                  <tel:4758437557
>>         <tel:4758437557>>,11.__1027935904,7.__
>> 9434273599,7.__8361619299,7.__7610621969,7.__4929139614,5.__8106133327
>>         <tel:8106133327>
>>                  <tel:8106133327
>>         <tel:8106133327>>,5.__9579132527,5.__9888473034,6.__5618433959
>>         <tel:5618433959>
>>                  <tel:5618433959 <tel:5618433959>>,4.5013708887
>>         <tel:5013708887>
>>                  <tel:5013708887
>>         <tel:5013708887>>,1.__9218516244,5.__7559805232,5.__2267081177
>>         <tel:2267081177>
>>                  <tel:2267081177
>>         <tel:2267081177>>,5.0968196707,4.____8949133597,5.9137964962
>>         <tel:9137964962>
>>                  <tel:9137964962
>>         <tel:9137964962>>,4.__2936059427,4.__6948533593,3.__4377318427
>>         <tel:4377318427>
>>                  <tel:4377318427
>>         <tel:4377318427>>,3.7991617067,4.____
>> 1242444467,3.8858731777,3.____9596393887,4.9192685996
>>         <tel:9192685996>
>>                  <tel:9192685996
>>         <tel:9192685996>>,4.__6734033563,4.__
>> 7511846457,4.__4544981945,4.__2748693367,3.__411559417,6.__
>> 6851381985,6.__6744741285,6.__9296475385
>>         <tel:9296475385>,7.__0136847108,7.__
>> 1371500908,7.__2719520708,6.__6787720528
>>         <tel:6787720528>,7.__3530295908,6.__8599596928
>>         <tel:8599596928>,7.__2216891568,7.__4951304208,7.__4404728868
>>         <tel:4404728868>,8.__1332243958,6.__2736028029,6.__963685048,6.__
>> 0483763169,5.__8653351624
>>         <tel:8653351624>,5.__6164044005
>>         <tel:6164044005>,6.__54979166,5.__8783224469
>>         <tel:8783224469>,6.__533468297,5.__8553434082
>>         <tel:8553434082>,5.__7676662122,6.__267915357,5.__22607939
>>
>>
>>         03,3.745459072,6.352470342,5.____4392033722,5.5562602522,5._
>> ___3996670482,6.171297855,5.____648779598,5.5653279855,5.___
>> _671668653,5.3243595462,5.____879320328,5.859442385
>>         <tel:5.859442385>,6.____080574272,5.3767159992,6.____170852717,5.
>> 3001119472,5.____687201287,5.3573110752,3.____586385579,5.
>> 566591422,5.____5104826925,5.916268775,5.____4418422465,5.4037394705
>> ,5.____640889612,5.1407657702,4.____5523677017,5.
>> 3873769863,3.____601570449,2.978252449,4.____8725960282,4.
>> 9817842222,5.____2355359365,5.1227105795,5.____177856607,5.
>> 098596533,5.____1891181988,4.9327118245,4.____4632330777,7.
>> 4879538737,4.____8591269625,3.1339054377,5.____8472818275,4.6043306952
>> ,3.____3542942377,4.7660145915,6.____6679095357,5.51150886,2.____
>> 7404344677,5.9332075344,6.____2019594857,5.266709364,5.____4924174224,5.
>> 180577724,3.____0277711677,6.2913260157,4.____2862670877,5.
>> 5461328154,5.____5809644644,5.1132029296,5.____1904326724,4.
>> 8352505633,4.____9641930171,5.1366240426,7.____0699378037,3.
>> 1274712477,5.____1487646306,5.2717034197,5.____0200090866,3.
>> 0911490977,5.____8984613527,5.1973381747,4.__
>>
>>     2427530627,6.7293864957,4.____7943011637,5.1130266607,5.____
>> 3948779287,4.7124246547,5.2
>>
>>              186371577,2.9723417287 <tel:9723417287> <tel:9723417287
>>
>>         <tel:9723417287>>,2.3171875277,2.8159853427 <tel:8159853427>
>>              <tel:8159853427
>>
>>         <tel:8159853427>>,__4.7913513947,4.7863347867 <tel:7863347867>
>>              <tel:7863347867
>>         <tel:7863347867>>,3.4531342837,__3.__
>> 8161332287,5.8431115757,4.____4873126817,5.6577494097,5.____
>> 5867970832,9.4583860946,2.____7784615917,5.4279953797,1.____
>> 9376872717,5.0813930177,5.____8860618114,6.2411339874,6.____
>> 4536904614,6.0972641874,5.____7247963284,5.9823452114,5.____
>> 8316140784,5.2398164977,6.____2963392357,5.5864457124,6.____
>> 1599995178,5.2609646384,6.____1012355027,6.4129483756,6.____
>> 0056487896,5.0106569884,5.____4239402364,6.1148656496,2.____
>> 673828844,4.3332873457,3.____2943586634,4.5834393467,7.____
>> 278601561,3.5870893269,3.____3299191554,4.1049776549,5.____
>> 9256568037,6.2719334873,6.____2594329923,5.5752581689,5.____
>> 6058592867,6.1311384893,6.____4726413519,5.8973941434,6.____
>> 2572672069,5.9667442136,5.____3965422637,7.2837623985,6.____
>> 9586195092,7.1137641952,6.____3682104908,7.8495628418,7.____
>> 2245886958,6.2983788278,7.____3509762248,6.9925366658,6.____
>> 5600944468,6.936328733,6.____616665943,6.738732443}")
>>
>>
>>
>>                  CONTEXT:  PL/pgSQL function "pgr_tspdijkstra" line 8 at
>>         RETURN QUERY
>>                  PL/pgSQL function "pgr_tspdijkstralen" line 3 at RETURN
>>         QUERY
>>                  NOTICE:  r2.id1: 34304
>>                  CONTEXT:  PL/pgSQL function "pgr_tspdijkstra" line 8 at
>>         RETURN QUERY
>>                  PL/pgSQL function "pgr_tspdijkstralen" line 3 at RETURN
>>         QUERY
>>                  NOTICE:  ids: <NULL>
>>                  CONTEXT:  PL/pgSQL function "pgr_tspdijkstra" line 8 at
>>         RETURN QUERY
>>                  PL/pgSQL function "pgr_tspdijkstralen" line 3 at RETURN
>>         QUERY
>>                  ERROR:  cannot concatenate incompatible arrays
>>                  DETAIL:  Arrays with differing element dimensions are not
>>                  compatible for
>>                  concatenation.
>>                  CONTEXT:  PL/pgSQL function "pgr_makedijkstramatrix"
>>         line 25 at
>>                  assignment
>>                  PL/pgSQL function "pgr_tspdijkstra" line 8 at RETURN
>> QUERY
>>                  PL/pgSQL function "pgr_tspdijkstralen" line 3 at RETURN
>>         QUERY
>>
>>                  I tried to write to Dose but he didn't reply yet.
>>                  Does anyone have a clue?
>>
>>
>>              Try adding the follow line after the "begin" line:
>>
>>                  ids := '{}'::integer[];
>>
>>              This should make sure the ids is initialized as an empty
>>         array of
>>              integers.
>>
>>              -Steve
>>
>>
>>
>>         Again:
>>         NOTICE:  r2:
>>         (34304,"{0,5.3602868897 <tel:3602868897>,4.6782573327
>>         <tel:6782573327>,5.6026971537 <tel:6026971537>,5.2062747797
>>         <tel:2062747797>,5.__0497181017,5.3147719797,5.__
>> 0700916462,4.3220066797,4.__8593618137,4.0002255227,6.__055760592,12.
>> 5155379824,9.__3170226155,8.72783427270001,5.__9460446587,
>> 3.0868131677,5.__1839796057,5.2301666167,2.__1211198847,5.
>> 7037465591,2.__7282842677,8.4758437557,11.__1027935904,7.
>> 9434273599,7.__8361619299,7.7610621969,7.__4929139614,5.
>> 8106133327,5.__9579132527,5.9888473034,6.__5618433959,4.
>> 5013708887,1.__9218516244,5.7559805232,5.__2267081177,5.
>> 0968196707,4.__8949133597,5.9137964962,4.__2936059427,4.
>> 6948533593,3.__4377318427,3.7991617067,4.__1242444467,3.
>> 8858731777,3.__9596393887,4.9192685996,4.__6734033563,4.
>> 7511846457,4.__4544981945,4.2748693367,3.__411559417,6.
>> 6851381985,6.__6744741285,6.9296475385,7.__0136847108,7.
>> 1371500908,7.__2719520708,6.6787720528,7.__3530295908,6.
>> 8599596928,7.__2216891568,7.4951304208,7.__4404728868,8.
>> 1332243958,6.__2736028029,6.963685048,6.__0483763169,5.
>> 8653351624,5.__6164044005,6.54979166,5.__8783224469,6.
>> 533468297,5.__8553434082,5.7
>>
> 676662122,6.__267915357,5.22607939
>
>>
>>     03,3.745459072,6.352470342,5.__4392033722,5.5562602522,5.__
>> 3996670482,6.171297855,5.__648779598,5.5653279855,5.__
>> 671668653,5.3243595462,5.__879320328,5.859442385,6.__
>> 080574272,5.3767159992,6.__170852717,5.3001119472,5.__
>> 687201287,5.3573110752,3.__586385579,5.566591422,5.__
>> 5104826925,5.916268775,5.__4418422465,5.4037394705,5.__
>> 640889612,5.1407657702,4.__5523677017,5.3873769863,3.__
>> 601570449,2.978252449,4.__8725960282,4.9817842222,5.__
>> 2355359365,5.1227105795,5.__177856607,5.098596533,5.__
>> 1891181988,4.9327118245,4.__4632330777,7.4879538737,4.__
>> 8591269625,3.1339054377,5.__8472818275,4.6043306952,3.__
>> 3542942377,4.7660145915,6.__6679095357,5.51150886,2.__
>> 7404344677,5.9332075344,6.__2019594857,5.266709364,5.__
>> 4924174224,5.180577724,3.__0277711677,6.2913260157,4.__
>> 2862670877,5.5461328154,5.__5809644644,5.1132029296,5.__
>> 1904326724,4.8352505633,4.__9641930171,5.1366240426,7.__
>> 0699378037,3.1274712477,5.__1487646306,5.2717034197,5.__
>> 0200090866,3.0911490977,5.__8984613527,5.1973381747,4.__
>>
> 2427530627,6.7293864957,4.__7943011637,5.1130266607,5.__
> 3948779287,4.7124246547,5.2
>
>>     186371577,2.9723417287 <tel:9723417287>,2.3171875277,2.8159853427
>>     <tel:8159853427>,__4.7913513947,4.7863347867
>>     <tel:7863347867>,3.4531342837,__3.8161332287,5.8431115757,4.__
>> 4873126817,5.6577494097,5.__5867970832,9.4583860946,2.__
>> 7784615917,5.4279953797,1.__9376872717,5.0813930177,5.__
>> 8860618114,6.2411339874,6.__4536904614,6.0972641874,5.__
>> 7247963284,5.9823452114,5.__8316140784,5.2398164977,6.__
>> 2963392357,5.5864457124,6.__1599995178,5.2609646384,6.__
>> 1012355027,6.4129483756,6.__0056487896,5.0106569884,5.__
>> 4239402364,6.1148656496,2.__673828844,4.3332873457,3.__
>> 2943586634,4.5834393467,7.__278601561,3.5870893269,3.__
>> 3299191554,4.1049776549,5.__9256568037,6.2719334873,6.__
>> 2594329923,5.5752581689,5.__6058592867,6.1311384893,6.__
>> 4726413519,5.8973941434,6.__2572672069,5.9667442136,5.__
>> 3965422637,7.2837623985,6.__9586195092,7.1137641952,6.__
>> 3682104908,7.8495628418,7.__2245886958,6.2983788278,7.__
>> 3509762248,6.9925366658,6.__5600944468,6.936328733,6.__
>> 616665943,6.738732443}")
>>
>>         CONTEXT:  PL/pgSQL function "pgr_tspdijkstra" line 8 at RETURN
>> QUERY
>>         PL/pgSQL function "pgr_tspdijkstralen" line 3 at RETURN QUERY
>>         NOTICE:  r2.id1: 34304
>>         CONTEXT:  PL/pgSQL function "pgr_tspdijkstra" line 8 at RETURN
>> QUERY
>>         PL/pgSQL function "pgr_tspdijkstralen" line 3 at RETURN QUERY
>>         NOTICE:  ids: {}
>>
>>         CONTEXT:  PL/pgSQL function "pgr_tspdijkstra" line 8 at RETURN
>> QUERY
>>         PL/pgSQL function "pgr_tspdijkstralen" line 3 at RETURN QUERY
>>         ERROR:  cannot concatenate incompatible arrays
>>         DETAIL:  Arrays with differing element dimensions are not
>>         compatible for
>>         concatenation.
>>         CONTEXT:  PL/pgSQL function "pgr_makedijkstramatrix" line 26 at
>>         assignment
>>         PL/pgSQL function "pgr_tspdijkstra" line 8 at RETURN QUERY
>>         PL/pgSQL function "pgr_tspdijkstralen" line 3 at RETURN QUERY
>>
>>         Thanks for your help. Maybe you need some other facts about my
>>         table?
>>         The whole script I am excecuting is the following. I changed some
>>         things, like adding your code and changing the table name 'ways'
>> to
>>         'cgn_2po_4pgr':
>>
>>         create or replace function pgr_makeDijkstraMatrix(thetbl text,
>> sqlP
>>         text, OUT dmatrix double precision[], OUT ids integer[])
>>             as
>>         $body$
>>         declare
>>               sql text;
>>               sql2 text;
>>               r record;
>>               r2 record;
>>               i integer;
>>               j integer;
>>               matrixl double precision[];
>>         begin
>>
>>              ids := '{}'::integer[];
>>               sql:='select node, id-1 as id from '||thetbl;
>>               for r in execute sql loop
>>                       sql2:='select id1, array_agg(cost) as arow from (
>>                     SELECT id1, id2, cost
>>                     FROM pgr_kdijkstraCost('''||sqlP||'__'', '||r.node||
>>
>>                         ', (select array_agg(node) from '||thetbl||' where
>>         id>'||r.id <http://r.id> <http://r.id>||'), false, false)
>>
>>
>>                    ) as foo group by id1 order by id1';
>>                   for r2 in execute sql2 loop
>>                   matrixl := '{}';
>>                   for i in 1..r.id <http://r.id> <http://r.id> loop
>>
>>
>>                             matrixl := array_append(matrixl,
>>         dmatrix[i][r.id <http://r.id>
>>         <http://r.id>+1]);
>>
>>                           end loop;
>>                           matrixl := array_cat(matrixl, r2.arow);
>>                       dmatrix := array_cat(dmatrix, array[matrixl]);
>>                       raise notice 'r2: %', r2;
>>         raise notice 'r2.id1: %', r2.id1;
>>         raise notice 'ids: %', ids;
>>
>>
>>     Sorry, I don't have a running version of this so this is somewhat
>>     guess work.
>>
>>                   --  ids := ids || r2.id1;
>>                     ids := array_cat(ids, r2.id1);
>>
>
> try changing the line above to:
>
>                       ids := array_cat(ids, array[r2.id1]);
>

Hi Steve, thank you. Back in office now but I'll try that later at home.
I'll let you know and hopefully I get a good result :)
Thanks so much.
Carsten

>
>
>>     So comment out the old like and rewrite like this.
>>
>>     -Steve
>>
>>
>> Thanks for all your help Steve,
>> hope, we're getting closer! Look, not it returns this:
>> NOTICE:  r2:
>> (34304,"{0,5.3602868897,4.6782573327,5.6026971537,5.2062747797,5.
>> 0497181017,5.3147719797,5.0700916462,4.3220066797,4.
>> 8593618137,4.0002255227,6.055760592,12.5155379824,9.
>> 3170226155,8.72783427270001,5.9460446587,3.0868131677,5.
>> 1839796057,5.2301666167,2.1211198847,5.7037465591,2.
>> 7282842677,8.4758437557,11.1027935904,7.9434273599,7.
>> 8361619299,7.7610621969,7.4929139614,5.8106133327,5.
>> 9579132527,5.9888473034,6.5618433959,4.5013708887,1.
>> 9218516244,5.7559805232,5.2267081177,5.0968196707,4.
>> 8949133597,5.9137964962,4.2936059427,4.6948533593,3.
>> 4377318427,3.7991617067,4.1242444467,3.8858731777,3.
>> 9596393887,4.9192685996,4.6734033563,4.7511846457,4.
>> 4544981945,4.2748693367,3.411559417,6.6851381985,6.
>> 6744741285,6.9296475385,7.0136847108,7.1371500908,7.
>> 2719520708,6.6787720528,7.3530295908,6.8599596928,7.
>> 2216891568,7.4951304208,7.4404728868,8.1332243958,6.
>> 2736028029,6.963685048,6.0483763169,5.8653351624,5.
>> 6164044005,6.54979166,5.8783224469,6.533468297,5.
>> 8553434082,5.7676662122,6.267915357,5.22607939
>>
> 03,3.745459072,6.352470342,5.4392033722,5.5562602522,5.
> 3996670482,6.171297855,5.648779598,5.5653279855,5.
> 671668653,5.3243595462,5.879320328,5.859442385,6.080574272,5.3767159992,6.
> 170852717,5.3001119472,5.687201287,5.3573110752,3.586385579,5.566591422,5.
> 5104826925,5.916268775,5.4418422465,5.4037394705,5.
> 640889612,5.1407657702,4.5523677017,5.3873769863,3.
> 601570449,2.978252449,4.8725960282,4.9817842222,5.
> 2355359365,5.1227105795,5.177856607,5.098596533,5.
> 1891181988,4.9327118245,4.4632330777,7.4879538737,4.
> 8591269625,3.1339054377,5.8472818275,4.6043306952,3.
> 3542942377,4.7660145915,6.6679095357,5.51150886,2.
> 7404344677,5.9332075344,6.2019594857,5.266709364,5.
> 4924174224,5.180577724,3.0277711677,6.2913260157,4.
> 2862670877,5.5461328154,5.5809644644,5.1132029296,5.
> 1904326724,4.8352505633,4.9641930171,5.1366240426,7.
> 0699378037,3.1274712477,5.1487646306,5.2717034197,5.
> 0200090866,3.0911490977,5.8984613527,5.1973381747,4.
> 2427530627,6.7293864957,4.7943011637,5.1130266607,5.
> 3948779287,4.7124246547,5.2
> 186371577,2.9723417287,2.3171875277,2.8159853427,4.7913513947,4.7863347867
> ,3.4531342837,3.8161332287,5.8431115757,4.4873126817,5.6577494097,5.
> 5867970832,9.4583860946,2.7784615917,5.4279953797,1.
> 9376872717,5.0813930177,5.8860618114,6.2411339874,6.
> 4536904614,6.0972641874,5.7247963284,5.9823452114,5.
> 8316140784,5.2398164977,6.2963392357,5.5864457124,6.
> 1599995178,5.2609646384,6.1012355027,6.4129483756,6.
> 0056487896,5.0106569884,5.4239402364,6.1148656496,2.
> 673828844,4.3332873457,3.2943586634,4.5834393467,7.
> 278601561,3.5870893269,3.3299191554,4.1049776549,5.
> 9256568037,6.2719334873,6.2594329923,5.5752581689,5.
> 6058592867,6.1311384893,6.4726413519,5.8973941434,6.
> 2572672069,5.9667442136,5.3965422637,7.2837623985,6.
> 9586195092,7.1137641952,6.3682104908,7.8495628418,7.
> 2245886958,6.2983788278,7.3509762248,6.9925366658,6.
> 5600944468,6.936328733,6.616665943,6.738732443}")
>
>> CONTEXT:  PL/pgSQL function "pgr_tspdijkstra" line 8 at RETURN QUERY
>> PL/pgSQL function "pgr_tspdijkstralen" line 3 at RETURN QUERY
>> NOTICE:  r2.id1: 34304
>> CONTEXT:  PL/pgSQL function "pgr_tspdijkstra" line 8 at RETURN QUERY
>> PL/pgSQL function "pgr_tspdijkstralen" line 3 at RETURN QUERY
>> NOTICE:  ids: {}
>> CONTEXT:  PL/pgSQL function "pgr_tspdijkstra" line 8 at RETURN QUERY
>> PL/pgSQL function "pgr_tspdijkstralen" line 3 at RETURN QUERY
>>
>>
>> ERROR:  function array_cat(integer[], integer) does not exist
>>
>> LINE 1: SELECT array_cat(ids, r2.id1)
>>                 ^
>> HINT:  No function matches the given name and argument types. You might
>> need to add explicit type casts.
>> QUERY:  SELECT array_cat(ids, r2.id1)
>> CONTEXT:  PL/pgSQL function "pgr_makedijkstramatrix" line 31 at assignment
>> PL/pgSQL function "pgr_tspdijkstra" line 8 at RETURN QUERY
>> PL/pgSQL function "pgr_tspdijkstralen" line 3 at RETURN QUERY
>>
>> ********** Fehler **********
>>
>> ERROR: function array_cat(integer[], integer) does not exist
>> SQL Status:42883
>> Hinweis:No function matches the given name and argument types. You might
>> need to add explicit type casts.
>> Kontext:PL/pgSQL function "pgr_makedijkstramatrix" line 31 at assignment
>> PL/pgSQL function "pgr_tspdijkstra" line 8 at RETURN QUERY
>> PL/pgSQL function "pgr_tspdijkstralen" line 3 at RETURN QUERY
>>
>>
>> Function does not exist? Still have an idea?
>> Thanks
>> Carsten
>>
>>
>>                   end loop;
>>               end loop;
>>         end;
>>         $body$
>>         language plpgsql stable cost 10;
>>
>>
>>         create or replace function pgr_tspDijkstra(thetbl text, sql text,
>>         start_id integer, end_id integer default (-1))
>>               returns setof pgr_costResult as
>>         $body$
>>         declare
>>               sid integer;
>>               eid integer;
>>
>>         begin
>>
>>               return query with dm  as (
>>                   select * from pgr_makeDijkstraMatrix( thetbl, sql )
>>               ),
>>               ids as (
>>                   select (row_number() over (order by id asc))-1 as rnum,
>> id
>>                     from (
>>                           select unnest(ids) as id
>>                             from dm
>>                           ) foo
>>               ),
>>               t as (
>>                   select a.seq, b.rnum, b.id <http://b.id> <http://b.id>
>>
>>
>>                     from pgr_tsp(
>>                              (select dmatrix from dm),
>>                              (select rnum from ids where id=start_id limit
>>         1)::integer,
>>                              (case when end_id = -1 then -1 else (select
>>         rnum
>>         from ids where id=end_id limit 1) end)::integer
>>                          ) a,
>>                          ids b
>>                    where a.id <http://a.id> <http://a.id>=b.rnum
>>
>>
>>               ),
>>               r as (
>>                   select array_agg(t.rnum) as rnum from t
>>               )
>>               select t.seq::integer,
>>                      t.rnum::integer as id1,
>>                      t.id::integer as id2,
>>
>>         dm.dmatrix[r.rnum[t.seq+1]+1][__r.rnum[(t.seq+1)%array_
>> length(__r.rnum,
>>
>>         1)+1]+1]::float8 as cost
>>                 from t, dm, r;
>>         end;
>>         $body$
>>         language plpgsql volatile cost 50 rows 50;
>>
>>
>>         create or replace function pgr_tspDijkstraLen(thetbl text,
>> start_id
>>         integer, end_id integer default (-1))
>>               returns setof pgr_costResult as
>>         $body$
>>         begin
>>                return query SELECT * FROM pgr_tspDijkstra(thetbl,
>>                     'SELECT  id, source::integer, target::integer,
>>         length::double
>>         precision AS cost FROM cgn_2po_4pgr',
>>                      start_id, end_id);
>>         end;
>>         $body$
>>         language plpgsql stable;
>>
>>
>>         Maybe you've got another idea?
>>         Thank you
>>         Carsten
>>
>>
>>                  Thanks for you help
>>                  Carsten
>>
>>
>>                  2014-02-20 16:24 GMT+01:00 Stephen Woodbridge
>>                  <woodbri at swoodbridge.com
>>         <mailto:woodbri at swoodbridge.com>
>>         <mailto:woodbri at swoodbridge.__com <mailto:woodbri at swoodbridge.com
>> >>
>>                  <mailto:woodbri at swoodbridge.
>>         <mailto:woodbri at swoodbridge.>____com
>>
>>
>>                  <mailto:woodbri at swoodbridge.__com
>>         <mailto:woodbri at swoodbridge.com>>>>:
>>
>>
>>                       On 2/20/2014 9:41 AM, Stephen Woodbridge wrote:
>>
>>                           Hi Carsten,
>>
>>                           The functions at
>>         http://dose.0wnz.at/scripts/______sql/pgroute_tspDijkstra.sql
>>         <http://dose.0wnz.at/scripts/____sql/pgroute_tspDijkstra.sql>
>>
>>
>>         <http://dose.0wnz.at/scripts/____sql/pgroute_tspDijkstra.sql
>>         <http://dose.0wnz.at/scripts/__sql/pgroute_tspDijkstra.sql>>
>>
>>
>>
>>
>>         <http://dose.0wnz.at/scripts/____sql/pgroute_tspDijkstra.sql
>>         <http://dose.0wnz.at/scripts/__sql/pgroute_tspDijkstra.sql>
>>
>>         <http://dose.0wnz.at/scripts/__sql/pgroute_tspDijkstra.sql
>>         <http://dose.0wnz.at/scripts/sql/pgroute_tspDijkstra.sql>>>
>>                           are not part of pgRouting.
>>
>>                           You need to ask this question to Ivan the
>>         author of the
>>                  original
>>                           article.
>>
>>
>>                       Sorry, Dose was the original author.
>>
>>
>>
>>                           You probably need to add some debug statements
>>         to get a
>>                  better
>>                           understanding of what the code is doing. For
>>         example in
>>                           pgr_makeDijkstraMatrix before the statement:
>>
>>                           ids := ids || array[r2.id1];
>>
>>
>>                       You could try changing this line to:
>>
>>                       ids := ids || r2.id1;
>>
>>                       and see if that fixes the problem.
>>
>>                       -Steve
>>
>>
>>                           Add:
>>
>>                           raise notice 'r2: %', r2;
>>                           raise notice 'r2.id1: %', r2.id1;
>>                           raise notice 'ids: %', ids;
>>
>>                           This should show you the progression of how
>>         the array
>>                  ids is getting
>>                           built as it appears to be compaining about
>>         that in the
>>                  error
>>                           message.
>>
>>                           Hope this helps,
>>                               -Steve
>>
>>                           On 2/20/2014 9:21 AM, Carsten Hogertz wrote:
>>
>>                               Hi everybody, I am new to this list and new
>> to
>>                  pgrouting.
>>
>>                               I found the following TSP example
>>         http://hardwarefetish.com/513-______pgrouting-dijksta-____
>> travelling-__salesman-problem-____tsp-with-__openstreetmap
>>         <http://hardwarefetish.com/513-____pgrouting-dijksta-__
>> travelling-__salesman-problem-__tsp-with-__openstreetmap>
>>
>>         <http://hardwarefetish.com/__513-__pgrouting-dijksta-__
>> travelling-__salesman-problem-__tsp-with-__openstreetmap
>>         <http://hardwarefetish.com/513-__pgrouting-dijksta-
>> travelling-__salesman-problem-tsp-with-__openstreetmap>>
>>
>>
>>
>>         <http://hardwarefetish.com/____513-pgrouting-dijksta-____
>> travelling-salesman-problem-____tsp-with-openstreetmap
>>         <http://hardwarefetish.com/__513-pgrouting-dijksta-__
>> travelling-salesman-problem-__tsp-with-openstreetmap>
>>
>>
>>
>>         <http://hardwarefetish.com/__513-pgrouting-dijksta-__
>> travelling-salesman-problem-__tsp-with-openstreetmap
>>         <http://hardwarefetish.com/513-pgrouting-dijksta-
>> travelling-salesman-problem-tsp-with-openstreetmap>>>
>>
>>                               and tried to reproduce the solution.
>>
>>                               Unfortunately I always get an error message.
>>                               My DB is complaining about one of your
>>         functions.
>>
>>                               I got my routing table from osm2po. The
>>         table has
>>                  the following
>>                               structure:
>>
>>                               1;”id”;”integer”
>>                               2;”osm_id”;”bigint”
>>                               3;”osm_name”;”character varying”
>>                               4;”osm_meta”;”character varying”
>>                               5;”osm_source_id”;”bigint”
>>                               6;”osm_target_id”;”bigint”;
>>                               7;”clazz”;”integer”
>>                               8;”flags”;”integer”
>>                               9;”source”;”integer”
>>                               10;”target”;”integer”
>>                               11;”length”;”double precision”
>>                               12;”kmh”;”integer”
>>                               13;”cost”;”double precision”
>>                               14;”reverse_cost”;”double precision”
>>                               15;”x1″;”double precision”
>>                               16;”y1″;”double precision”
>>                               17;”x2″;”double precision”
>>                               18;”y2″;”double precision”
>>
>>           19;”geom_way”;”geometry(______LineString,4326)”
>>
>>
>>
>>
>>                               - I installed the functions as mentioned
>>         via SQL
>>                  window in
>>                               pgAdmin3
>>                               (copy&paste then excecute)
>>                               - I create and populate the my_route table
>>                               - When it comes to step 5 and I try
>>
>>                               select id,lon,lat from
>>                  pgr_tspDijkstraLen(’my_route’, 1260
>>                               ) dj, my_route rt where dj.id2=rt.node;
>>
>>                               my DB warns
>>
>>                               ERROR: cannot concatenate incompatible
>> arrays
>>                               DETAIL: Arrays with differing element
>>         dimensions
>>                  are not
>>                               compatible for
>>                               concatenation.
>>                               CONTEXT: PL/pgSQL function
>>         “pgr_makedijkstramatrix”
>>                  line 25 at
>>                               assignment PL/pgSQL function
>>         “pgr_tspdijkstra” line
>>                  8 at
>>                               RETURN QUERY
>>                               PL/pgSQL function “pgr_tspdijkstralen”
>>         line 3 at
>>                  RETURN QUERY
>>
>>                               ********** Fehler **********
>>
>>                               ERROR: cannot concatenate incompatible
>>         arrays SQL
>>                  Status:2202E
>>                               Detail:Arrays with differing element
>>         dimensions are not
>>                               compatible for
>>                               concatenation.
>>                               Kontext:PL/pgSQL function
>>         “pgr_makedijkstramatrix”
>>                  line 25
>>                               at assignment
>>                               PL/pgSQL function “pgr_tspdijkstra” line 8
>> at
>>                  RETURN QUERY
>>                               PL/pgSQL function “pgr_tspdijkstralen”
>>         line 3 at
>>                  RETURN QUERY
>>
>>                               Do you have any idea what went wrong? I
>> really
>>                  really need your
>>                               solutionget working. I would appreciate a
>> lot.
>>
>>                               Thanks for your help.
>>
>>                               PS: this text is a copy of what I wrote on
>>         on the
>>                  comment
>>                               site of the
>>                               blog where I found the solution.
>>
>>                               BR
>>                               Carsten
>>
>>
>>
>>           _____________________________________________________
>>                               Pgrouting-users mailing list
>>                               Pgrouting-users at lists.osgeo.______org
>>                               <mailto:Pgrouting-users at lists.
>>         <mailto:Pgrouting-users at lists.>____osgeo.org <http://osgeo.org>
>>                  <mailto:Pgrouting-users at lists.__osgeo.org
>>         <mailto:Pgrouting-users at lists.osgeo.org>>>
>>         http://lists.osgeo.org/______mailman/listinfo/pgrouting-___
>> ___users
>>         <http://lists.osgeo.org/____mailman/listinfo/pgrouting-____users>
>>
>>
>>         <http://lists.osgeo.org/____mailman/listinfo/pgrouting-____users
>>         <http://lists.osgeo.org/__mailman/listinfo/pgrouting-__users>>
>>
>>
>>         <http://lists.osgeo.org/____mailman/listinfo/pgrouting-____users
>>         <http://lists.osgeo.org/__mailman/listinfo/pgrouting-__users>
>>
>>         <http://lists.osgeo.org/__mailman/listinfo/pgrouting-__users
>>         <http://lists.osgeo.org/mailman/listinfo/pgrouting-users>>>
>>
>>
>>
>>           _____________________________________________________
>>                           Pgrouting-users mailing list
>>                           Pgrouting-users at lists.osgeo.______org
>>                           <mailto:Pgrouting-users at lists.
>>         <mailto:Pgrouting-users at lists.>____osgeo.org <http://osgeo.org>
>>                  <mailto:Pgrouting-users at lists.__osgeo.org
>>         <mailto:Pgrouting-users at lists.osgeo.org>>>
>>         http://lists.osgeo.org/______mailman/listinfo/pgrouting-___
>> ___users
>>         <http://lists.osgeo.org/____mailman/listinfo/pgrouting-____users>
>>
>>
>>         <http://lists.osgeo.org/____mailman/listinfo/pgrouting-____users
>>         <http://lists.osgeo.org/__mailman/listinfo/pgrouting-__users>>
>>
>>
>>         <http://lists.osgeo.org/____mailman/listinfo/pgrouting-____users
>>         <http://lists.osgeo.org/__mailman/listinfo/pgrouting-__users>
>>
>>         <http://lists.osgeo.org/__mailman/listinfo/pgrouting-__users
>>         <http://lists.osgeo.org/mailman/listinfo/pgrouting-users>>>
>>
>>
>>                       ______________________________
>> _______________________
>>                       Pgrouting-users mailing list
>>                       Pgrouting-users at lists.osgeo.______org
>>                       <mailto:Pgrouting-users at lists.
>>         <mailto:Pgrouting-users at lists.>____osgeo.org <http://osgeo.org>
>>                  <mailto:Pgrouting-users at lists.__osgeo.org
>>         <mailto:Pgrouting-users at lists.osgeo.org>>>
>>         http://lists.osgeo.org/______mailman/listinfo/pgrouting-___
>> ___users
>>         <http://lists.osgeo.org/____mailman/listinfo/pgrouting-____users>
>>
>>
>>         <http://lists.osgeo.org/____mailman/listinfo/pgrouting-____users
>>         <http://lists.osgeo.org/__mailman/listinfo/pgrouting-__users>>
>>
>>
>>
>>
>>         <http://lists.osgeo.org/____mailman/listinfo/pgrouting-____users
>>         <http://lists.osgeo.org/__mailman/listinfo/pgrouting-__users>
>>
>>         <http://lists.osgeo.org/__mailman/listinfo/pgrouting-__users
>>         <http://lists.osgeo.org/mailman/listinfo/pgrouting-users>>>
>>
>>
>>
>>
>>                  ___________________________________________________
>>                  Pgrouting-users mailing list
>>                  Pgrouting-users at lists.osgeo.____org
>>                  <mailto:Pgrouting-users at lists.__osgeo.org
>>         <mailto:Pgrouting-users at lists.osgeo.org>>
>>         http://lists.osgeo.org/____mailman/listinfo/pgrouting-____users
>>         <http://lists.osgeo.org/__mailman/listinfo/pgrouting-__users>
>>
>>         <http://lists.osgeo.org/__mailman/listinfo/pgrouting-__users
>>         <http://lists.osgeo.org/mailman/listinfo/pgrouting-users>>
>>
>>
>>              ___________________________________________________
>>              Pgrouting-users mailing list
>>              Pgrouting-users at lists.osgeo.____org
>>              <mailto:Pgrouting-users at lists.__osgeo.org
>>         <mailto:Pgrouting-users at lists.osgeo.org>>
>>         http://lists.osgeo.org/____mailman/listinfo/pgrouting-____users
>>         <http://lists.osgeo.org/__mailman/listinfo/pgrouting-__users>
>>
>>         <http://lists.osgeo.org/__mailman/listinfo/pgrouting-__users
>>         <http://lists.osgeo.org/mailman/listinfo/pgrouting-users>>
>>
>>
>>
>>
>>         _________________________________________________
>>         Pgrouting-users mailing list
>>         Pgrouting-users at lists.osgeo.__org
>>         <mailto:Pgrouting-users at lists.osgeo.org>
>>         http://lists.osgeo.org/__mailman/listinfo/pgrouting-__users
>>         <http://lists.osgeo.org/mailman/listinfo/pgrouting-users>
>>
>>
>>     _________________________________________________
>>     Pgrouting-users mailing list
>>     Pgrouting-users at lists.osgeo.__org
>>     <mailto:Pgrouting-users at lists.osgeo.org>
>>     http://lists.osgeo.org/__mailman/listinfo/pgrouting-__users
>>     <http://lists.osgeo.org/mailman/listinfo/pgrouting-users>
>>
>>
>>
>>
>> _______________________________________________
>> Pgrouting-users mailing list
>> Pgrouting-users at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/pgrouting-users
>>
>>
> _______________________________________________
> Pgrouting-users mailing list
> Pgrouting-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/pgrouting-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/pgrouting-users/attachments/20140221/8fc32c52/attachment-0001.html>


More information about the Pgrouting-users mailing list