Skip to content

Commit 1d2a605

Browse files
committed
adding the wrapper for pgr_vrpOneDepot
1 parent d0721d0 commit 1d2a605

3 files changed

Lines changed: 159 additions & 1 deletion

File tree

sql/vrp_basic/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
SET(LOCAL_FILES
3-
routing_vrp.sql
3+
#routing_vrp.sql
4+
_pgr_vrpOneDepot.sql
5+
pgr_vrpOneDepot.sql
46
)
57

68
foreach (f ${LOCAL_FILES})

sql/vrp_basic/_pgr_vrpOneDepot.sql

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*PGR-GNU*****************************************************************
2+
File: _pgr_vrpOneDepot.sql
3+
4+
Generated with Template by:
5+
Copyright (c) 2017 pgRouting developers
6+
Mail: project@pgrouting.org
7+
8+
Function's developer:
9+
Copyright (c) 2017 Celia Virginia Vergara Castillo
10+
Mail:
11+
12+
------
13+
14+
This program is free software; you can redistribute it and/or modify
15+
it under the terms of the GNU General Public License as published by
16+
the Free Software Foundation; either version 2 of the License, or
17+
(at your option) any later version.
18+
19+
This program is distributed in the hope that it will be useful,
20+
but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
GNU General Public License for more details.
23+
24+
You should have received a copy of the GNU General Public License
25+
along with this program; if not, write to the Free Software
26+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27+
28+
********************************************************************PGR-GNU*/
29+
30+
31+
CREATE OR REPLACE FUNCTION _pgr_vrpOneDepot(
32+
customers_sql TEXT,
33+
vehicles_sql TEXT,
34+
TEXT, -- matrix_sql
35+
depot_id INTEGER,
36+
37+
OUT seq INTEGER,
38+
OUT vehicle_seq INTEGER,
39+
OUT vehicle_id BIGINT,
40+
OUT stop_seq INTEGER,
41+
OUT stop_type INTEGER,
42+
OUT stop_id BIGINT,
43+
OUT order_id BIGINT,
44+
OUT cargo FLOAT,
45+
OUT travel_time FLOAT,
46+
OUT arrival_time FLOAT,
47+
OUT wait_time FLOAT,
48+
OUT service_time FLOAT,
49+
OUT departure_time FLOAT
50+
)
51+
RETURNS SETOF RECORD AS
52+
$BODY$
53+
DECLARE
54+
orders_sql TEXT;
55+
trucks_sql TEXT;
56+
matrix_sql TEXT;
57+
final_sql TEXT;
58+
BEGIN
59+
60+
orders_sql = $$WITH
61+
vrp_orders AS ($$ || customers_sql || $$ ),
62+
pickups AS (
63+
SELECT id, x AS p_x, y AS p_y, open_time AS p_open, close_time AS p_close, service_time AS p_service
64+
FROM vrp_orders
65+
WHERE id = $$ || depot_id || $$
66+
)
67+
SELECT vrp_orders.id AS id, order_unit AS demand, pickups.id AS p_node_id, p_x, p_y, p_open, p_close, p_service,
68+
vrp_orders.id AS d_node_id, x AS d_x, y AS d_y, open_time AS d_open, close_time AS d_close, service_time AS d_service
69+
FROM vrp_orders, pickups
70+
WHERE vrp_orders.id != $$ || depot_id;
71+
72+
73+
trucks_sql = $$ WITH
74+
vrp_orders AS ($$ || customers_sql || $$ ),
75+
vrp_vehicles AS ($$ || vehicles_sql || $$ ),
76+
starts AS (
77+
SELECT id AS start_node_id, x AS start_x, y AS start_y, open_time AS start_open, close_time AS start_close, service_time AS start_service
78+
FROM vrp_orders
79+
WHERE id = $$ || depot_id || $$
80+
)
81+
SELECT vehicle_id AS id, capacity, starts.* FROM vrp_vehicles, starts;
82+
$$;
83+
84+
final_sql = '
85+
SELECT * FROM pgr_pickDeliver(
86+
$$' || orders_sql || '$$,
87+
$$' || trucks_sql || '$$,
88+
$$' || $3 || '$$,
89+
max_cycles := 2,
90+
initial_sol := 4 ); ';
91+
92+
RAISE DEBUG '%', orders_sql;
93+
RAISE DEBUG '%', trucks_sql;
94+
RAISE DEBUG '%', $3;
95+
RAISE DEBUG '%', final_sql;
96+
97+
RETURN QUERY EXECUTE final_sql;
98+
END;
99+
$BODY$
100+
LANGUAGE plpgsql VOLATILE STRICT;

sql/vrp_basic/pgr_vrpOneDepot.sql

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*PGR-GNU*****************************************************************
2+
3+
Copyright (c) 2015 pgRouting developers
4+
Mail: project@pgrouting.org
5+
6+
------
7+
8+
This program is free software; you can redistribute it and/or modify
9+
it under the terms of the GNU General Public License as published by
10+
the Free Software Foundation; either version 2 of the License, or
11+
(at your option) any later version.
12+
13+
This program is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Public License for more details.
17+
18+
You should have received a copy of the GNU General Public License
19+
along with this program; if not, write to the Free Software
20+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21+
22+
********************************************************************PGR-GNU*/
23+
-----------------------------------------------------------------------
24+
-- Core function for vrp with sigle depot computation
25+
-- See README for description
26+
-----------------------------------------------------------------------
27+
--
28+
--
29+
30+
create or replace function pgr_vrpOneDepot(
31+
order_sql text,
32+
vehicle_sql text,
33+
cost_sql text,
34+
depot_id integer,
35+
36+
OUT oid integer,
37+
OUT opos integer,
38+
OUT vid integer,
39+
OUT tarrival integer,
40+
OUT tdepart integer)
41+
RETURNS SETOF RECORD AS
42+
$BODY$
43+
BEGIN
44+
RETURN query SELECT order_id::INTEGER, stop_seq::INTEGER, vehicle_id::INTEGER, arrival_time::INTEGER, departure_time::INTEGER
45+
FROM _pgr_vrpOneDepot($1, $2,
46+
'
47+
SELECT src_id AS start_vid, dest_id AS end_vid, traveltime AS agg_cost FROM ('||$3||') AS a
48+
',
49+
$4
50+
) a;
51+
END
52+
$BODY$
53+
LANGUAGE plpgsql VOLATILE
54+
COST 100
55+
ROWS 1000;
56+

0 commit comments

Comments
 (0)