[pgrouting-users] pgrouting Dijksta Travelling Salesman Problem (TSP) with OpenStreetmap
Carsten Hogertz
carsten.hogertz at gmail.com
Tue Feb 25 12:32:05 PST 2014
Thanks Steve,
my version is
PostgreSQL 9.1.11 on i686-pc-linux-gnu, compiled by gcc (Ubuntu/Linaro
4.6.3-1ubuntu5) 4.6.3, 32-bit
I'am running it on a OSGeoLive 7.0
I'll wait till later or if someone else who wants to try to solve this one
I'll be happy.
Until later
--
Carsten
2014-02-25 21:23 GMT+01:00 Stephen Woodbridge <woodbri at swoodbridge.com>:
> I'm busy for the next few days so I will not have time to look at it until
> later this week.
>
> What version of postgresql are you running?
>
> select * from version();
>
> I would google "postgresql array functions" and read up on these.There is
> a function that will tell you the dimensions of an array and maybe you need
> to print out some more notices to figure out what it is expecting.
>
> Maybe someone else on the list wants to take a crack at this.
>
> Thanks,
> -Steve
>
> On 2/25/2014 3:14 PM, Carsten Hogertz wrote:
>
>> Hi Steve,
>> have been busy the last days so I only check your Thursday's solution
>> right now. Still not working.
>> My function looks like this:
>>
>> 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>||'), 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> loop
>> matrixl := array_append(matrixl, dmatrix[i][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;
>> --ids := ids || r2.id1;
>> ids := array_cat(ids, array[r2.id1]);
>> 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>
>> 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>=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;
>>
>>
>>
>> AND the error I am getting:
>> 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: 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
>>
>> ********** 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 26 at assignment
>> PL/pgSQL function "pgr_tspdijkstra" line 8 at RETURN QUERY
>> PL/pgSQL function "pgr_tspdijkstralen" line 3 at RETURN QUERY
>>
>>
>> HOW comes? I really don't know what to do.
>> May you be so kind and try to help again?
>> Thanks
>> Carsten
>>
>>
>> 2014-02-21 9:36 GMT+01:00 Carsten Hogertz <carsten.hogertz at gmail.com
>> <mailto:carsten.hogertz at gmail.com>>:
>>
>>
>>
>>
>> 2014-02-20 23:25 GMT+01:00 Stephen Woodbridge
>> <woodbri at swoodbridge.com <mailto: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>
>> <mailto: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>>
>> <mailto:woodbri at swoodbridge.
>> <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>>
>> <tel:3602868897 <tel:3602868897> <tel:3602868897
>> <tel:3602868897>>>,4.6782573327 <tel:6782573327>
>> <tel:6782573327 <tel:6782573327>>
>> <tel:6782573327 <tel:6782573327>
>> <tel:6782573327 <tel:6782573327>>>,5.6026971537 <tel:
>> 6026971537>
>> <tel:6026971537 <tel:6026971537>> <tel:6026971537
>> <tel:6026971537> <tel:6026971537
>> <tel:6026971537>>>,5.2062747797 <tel:2062747797>
>> <tel:2062747797 <tel:2062747797>>
>> <tel:2062747797 <tel:2062747797>
>>
>> <tel:2062747797
>> <tel:2062747797>>>,5.__0497181017,5.3147719797
>> <tel:3147719797> <tel:3147719797 <tel:3147719797>>
>> <tel:3147719797 <tel:3147719797>
>> <tel:3147719797
>> <tel:3147719797>>>,5.__0700916462,4.____3220066797,4.__
>> 8593618137
>> <tel:8593618137>
>> <tel:8593618137 <tel:8593618137>>
>> <tel:8593618137 <tel:8593618137>
>> <tel:8593618137
>> <tel:8593618137>>>,4.0002255227,6.______055760592,12.
>> 5155379824
>> <tel:5155379824>
>> <tel:5155379824 <tel:5155379824>>
>> <tel: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>>
>> <tel:7037465591 <tel:7037465591>
>>
>> <tel:7037465591
>> <tel:7037465591>>>,2.__7282842677,8.4758437557
>> <tel:4758437557> <tel:4758437557 <tel:4758437557>>
>> <tel: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>>
>> <tel:8106133327 <tel:8106133327>
>> <tel:8106133327
>> <tel:8106133327>>>,5.__9579132527,5.____9888473034,6.__
>> 5618433959
>> <tel:5618433959>
>> <tel:5618433959 <tel:5618433959>>
>> <tel:5618433959 <tel:5618433959>
>> <tel:5618433959 <tel:5618433959>>>,4.5013708887 <tel:
>> 5013708887>
>> <tel:5013708887 <tel:5013708887>>
>> <tel:5013708887 <tel:5013708887>
>> <tel:5013708887
>> <tel:5013708887>>>,1.__9218516244,5.____7559805232,5.__
>> 2267081177
>> <tel:2267081177>
>> <tel:2267081177 <tel:2267081177>>
>> <tel:2267081177 <tel:2267081177>
>> <tel:2267081177
>> <tel:2267081177>>>,5.0968196707,4.______8949133597,5.
>> 9137964962
>> <tel:9137964962>
>> <tel:9137964962 <tel:9137964962>>
>> <tel:9137964962 <tel:9137964962>
>> <tel:9137964962
>> <tel:9137964962>>>,4.__2936059427,4.____6948533593,3.__
>> 4377318427
>> <tel:4377318427>
>> <tel:4377318427 <tel:4377318427>>
>> <tel:4377318427 <tel:4377318427>
>> <tel:4377318427
>> <tel:4377318427>>>,3.7991617067,4.______
>> 1242444467,3.8858731777,3.______9596393887,4.9192685996
>> <tel:9192685996>
>> <tel:9192685996 <tel:9192685996>>
>> <tel: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>
>> <tel:9296475385
>> <tel:9296475385>>,7.__0136847108,7.____
>> 1371500908,7.__2719520708,6.__6787720528
>> <tel:6787720528>
>> <tel:6787720528
>> <tel:6787720528>>,7.__3530295908,6.__8599596928 <tel:
>> 8599596928>
>> <tel:8599596928
>> <tel:8599596928>>,7.__2216891568,7.____4951304208,7.__
>> 4404728868
>> <tel:4404728868>
>> <tel:4404728868
>> <tel:4404728868>>,8.__1332243958,6.____
>> 2736028029,6.__963685048,6.____0483763169,5.__8653351624
>> <tel:8653351624>
>> <tel:8653351624 <tel:8653351624>>,5.__6164044005
>> <tel:6164044005>
>> <tel:6164044005
>> <tel:6164044005>>,6.__54979166,5.__8783224469 <tel:8783224469
>> >
>> <tel:8783224469
>> <tel:8783224469>>,6.__533468297,5.__8553434082 <tel:
>> 8553434082>
>> <tel: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>
>> <tel:5.859442385
>> <tel:5.859442385>>,6.____080574272,5.__
>> 3767159992,6.____170852717,5.__3001119472,5.____687201287,5.
>> __3573110752,3.____586385579,5.__566591422,5.____5104826925
>> <tel:5104826925>,5.__916268775,5.____4418422465,5.__
>> 4037394705
>> <tel:4037394705>,5.____640889612,5.__
>> 1407657702,4.____5523677017,5.__3873769863,3.____601570449,
>> 2.__978252449,4.____8725960282
>> <tel: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
>> <tel:8472818275>,4.__6043306952
>> <tel:6043306952>,3.____3542942377,4.__7660145915,6.____
>> 6679095357
>> <tel:6679095357>,5.__51150886,2.____7404344677
>> <tel:7404344677>,5.__9332075344,6.____2019594857
>> <tel:2019594857>,5.__266709364,5.____
>> 4924174224,5.__180577724,3.____0277711677,6.__2913260157,4._
>> ___2862670877,5.__5461328154,5.____5809644644
>> <tel:5809644644>,5.__1132029296,5.____1904326724,4.__
>> 8352505633
>> <tel: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
>> <tel:7124246547>,5.2
>>
>> 186371577,2.9723417287 <tel:9723417287>
>> <tel:9723417287 <tel:9723417287>> <tel:9723417287
>> <tel:9723417287>
>>
>> <tel:9723417287
>> <tel:9723417287>>>,2.3171875277,2.8159853427
>> <tel:8159853427> <tel:8159853427 <tel:8159853427>>
>> <tel:8159853427 <tel:8159853427>
>>
>> <tel:8159853427
>> <tel:8159853427>>>,__4.7913513947,4.7863347867
>> <tel:7863347867> <tel:7863347867 <tel:7863347867>>
>> <tel:7863347867 <tel:7863347867>
>> <tel:7863347867
>> <tel:7863347867>>>,3.4531342837,__3.____
>> 8161332287,5.8431115757,4.______4873126817,5.6577494097
>> <tel:6577494097>,5.______5867970832
>> <tel:5867970832>,9.4583860946
>> <tel:4583860946>,2.______7784615917
>> <tel:7784615917>,5.4279953797,1.______9376872717
>> <tel:9376872717>,5.0813930177,5.______
>> 8860618114,6.2411339874,6.______4536904614,6.0972641874,5.__
>> ____7247963284
>> <tel:7247963284>,5.9823452114,5.______8316140784
>> <tel:8316140784>,5.2398164977
>> <tel: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>
>> <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>,5.____0700916462,4.3220066797,4.__8593618137<tel:
>> 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> <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: {}
>>
>> 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>
>> <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> <http://r.id> loop
>>
>>
>> matrixl := array_append(matrixl,
>> dmatrix[i][r.id <http://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 <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.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
>> <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: 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> <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>
>> <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>>>
>> <mailto:woodbri at swoodbridge
>> <mailto:woodbri at swoodbridge>.
>> <mailto:woodbri at swoodbridge
>> <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>>>
>>
>>
>>
>>
>>
>> <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>>>
>>
>>
>>
>>
>> <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"
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/pgrouting-users/attachments/20140225/6476a635/attachment-0001.html>
More information about the Pgrouting-users
mailing list