|
| 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; |
0 commit comments