diff --git a/doc/conf.py.in b/doc/conf.py.in index 46401c0e0..ecfa919cb 100644 --- a/doc/conf.py.in +++ b/doc/conf.py.in @@ -325,6 +325,12 @@ linkcheck_ignore = [ "https://vrp.pgrouting.org/latest/en/vrp_vroomJobs.html", "https://vrp.pgrouting.org/v0/en/vrp_vroomShipments.html", "https://vrp.pgrouting.org/latest/en/vrp_vroomShipments.html", + "https://vrp.pgrouting.org/v0/en/vrp_vroomPlain.html", + "https://vrp.pgrouting.org/latest/en/vrp_vroomPlain.html", + "https://vrp.pgrouting.org/v0/en/vrp_vroomJobsPlain.html", + "https://vrp.pgrouting.org/latest/en/vrp_vroomJobsPlain.html", + "https://vrp.pgrouting.org/v0/en/vrp_vroomShipmentsPlain.html", + "https://vrp.pgrouting.org/latest/en/vrp_vroomShipmentsPlain.html", # (see: https://github.com/sphinx-doc/sphinx/issues/7388) r"https://github.com/pgRouting/vrprouting/", # limit only vrprouting diff --git a/doc/general/sampledata.rst b/doc/general/sampledata.rst index 48e8bcb64..64eae77c2 100644 --- a/doc/general/sampledata.rst +++ b/doc/general/sampledata.rst @@ -126,6 +126,15 @@ Matrix :start-after: -- MATRIX TABLE start :end-before: -- MATRIX TABLE end +Modified VROOM Data +------------------------------------------------------------------------------- + +The tables created using the above VROOM Data are modified for the VROOM functions +with timestamps/interval, as: + +.. literalinclude:: ../../docqueries/vroom/doc-vrp_vroom.test.sql + :start-after: -- q0 + :end-before: -- q1 Images ------------------------------------------------------------------------------- diff --git a/doc/general/vroom-category.rst b/doc/general/vroom-category.rst index 1008291a3..247228327 100644 --- a/doc/general/vroom-category.rst +++ b/doc/general/vroom-category.rst @@ -33,6 +33,9 @@ VROOM - Category (Experimental) vrp_vroom vrp_vroomJobs vrp_vroomShipments + vrp_vroomPlain + vrp_vroomJobsPlain + vrp_vroomShipmentsPlain Synopsis diff --git a/doc/vroom/CMakeLists.txt b/doc/vroom/CMakeLists.txt index d537ef8af..c8d650c18 100644 --- a/doc/vroom/CMakeLists.txt +++ b/doc/vroom/CMakeLists.txt @@ -3,6 +3,9 @@ SET(LOCAL_FILES vrp_vroom.rst vrp_vroomJobs.rst vrp_vroomShipments.rst + vrp_vroomPlain.rst + vrp_vroomJobsPlain.rst + vrp_vroomShipmentsPlain.rst ) foreach (f ${LOCAL_FILES}) diff --git a/doc/vroom/vrp_vroom.rst b/doc/vroom/vrp_vroom.rst index 2987ee976..b02d6414b 100644 --- a/doc/vroom/vrp_vroom.rst +++ b/doc/vroom/vrp_vroom.rst @@ -49,7 +49,8 @@ Signature :start-after: signature start :end-before: signature end -**Example**: This example is based on the VROOM Data of the :doc:`sampledata` network: +**Example**: This example is based on the modified VROOM Data of the :doc:`sampledata` network. +The modification in the tables is mentioned at the end of the :doc:`sampledata`. .. literalinclude:: doc-vrp_vroom.queries :start-after: -- q1 diff --git a/doc/vroom/vrp_vroomJobs.rst b/doc/vroom/vrp_vroomJobs.rst index be67cf924..6c568a622 100644 --- a/doc/vroom/vrp_vroomJobs.rst +++ b/doc/vroom/vrp_vroomJobs.rst @@ -48,7 +48,8 @@ Signature :start-after: signature start :end-before: signature end -**Example**: This example is based on the VROOM Data of the :doc:`sampledata` network: +**Example**: This example is based on the modified VROOM Data of the :doc:`sampledata` network. +The modification in the tables is mentioned at the end of the :doc:`sampledata`. .. literalinclude:: doc-vrp_vroomJobs.queries :start-after: -- q1 diff --git a/doc/vroom/vrp_vroomJobsPlain.rst b/doc/vroom/vrp_vroomJobsPlain.rst new file mode 100644 index 000000000..db7a5c73f --- /dev/null +++ b/doc/vroom/vrp_vroomJobsPlain.rst @@ -0,0 +1,108 @@ +.. + **************************************************************************** + vrpRouting Manual + Copyright(c) vrpRouting Contributors + + This documentation is licensed under a Creative Commons Attribution-Share + Alike 3.0 License: https://creativecommons.org/licenses/by-sa/3.0/ + **************************************************************************** + +| + +* `Documentation `__ → `vrpRouting v0 `__ +* Supported Versions + `Latest `__ + (`v0 `__) + + +vrp_vroomJobsPlain - Experimental +=============================================================================== + +``vrp_vroomJobsPlain`` - Vehicle Routing Problem with VROOM, involving only jobs. + +.. include:: experimental.rst + :start-after: begin-warn-expr + :end-before: end-warn-expr + +.. rubric:: Availability + +Version 0.2.0 + +* New **experimental** function + + +Description +------------------------------------------------------------------------------- + +VROOM is an open-source optimization engine that aims at providing good solutions +to various real-life vehicle routing problems (VRP) within a small computing time. +This function can be used to get the solution to a problem involving only jobs. + +.. index:: + single: vrp_vroomJobsPlain -- Experimental on v0.2 + +Signature +------------------------------------------------------------------------------- + +.. include:: ../sql/vroom/vrp_vroomJobs.sql + :start-after: signature start + :end-before: signature end + +**Example**: This example is based on the VROOM Data of the :doc:`sampledata` network: + +.. literalinclude:: doc-vrp_vroomJobsPlain.queries + :start-after: -- q1 + :end-before: -- q2 + +Parameters +------------------------------------------------------------------------------- + +.. include:: ../sql/vroom/vrp_vroomJobs.sql + :start-after: parameters start + :end-before: parameters end + +Inner Queries +------------------------------------------------------------------------------- + +Jobs SQL +............................................................................... + +.. include:: ../../src/common/vroom/jobs_input.c + :start-after: vrp_vroom start + :end-before: vrp_vroom end + +.. include:: vroom-category.rst + :start-after: inner_queries_start + :end-before: inner_queries_end + +Result Columns +------------------------------------------------------------------------------- + +.. include:: vroom-category.rst + :start-after: result_columns_start + :end-before: result_columns_end + +Additional Example +------------------------------------------------------------------------------- + +Problem involving 2 jobs, using a single vehicle, corresponding to the VROOM Documentation +`Example 2 `__. + +.. literalinclude:: doc-vrp_vroomJobsPlain.queries + :start-after: -- q2 + :end-before: -- q3 + +See Also +------------------------------------------------------------------------------- + +* :doc:`vroom-category` +* The queries use the :doc:`sampledata` network. + +.. include:: vroom-category.rst + :start-after: see_also_start + :end-before: see_also_end + +.. rubric:: Indices and tables + +* :ref:`genindex` +* :ref:`search` diff --git a/doc/vroom/vrp_vroomPlain.rst b/doc/vroom/vrp_vroomPlain.rst new file mode 100644 index 000000000..79788d290 --- /dev/null +++ b/doc/vroom/vrp_vroomPlain.rst @@ -0,0 +1,116 @@ +.. + **************************************************************************** + vrpRouting Manual + Copyright(c) vrpRouting Contributors + + This documentation is licensed under a Creative Commons Attribution-Share + Alike 3.0 License: https://creativecommons.org/licenses/by-sa/3.0/ + **************************************************************************** + +| + +* `Documentation `__ → `vrpRouting v0 `__ +* Supported Versions + `Latest `__ + (`v0 `__) + + +vrp_vroomPlain - Experimental +=============================================================================== + +``vrp_vroomPlain`` - Vehicle Routing Problem with VROOM, involving both jobs and shipments. + +.. include:: experimental.rst + :start-after: begin-warn-expr + :end-before: end-warn-expr + +.. rubric:: Availability + +Version 0.2.0 + +* New **experimental** function + + +Description +------------------------------------------------------------------------------- + +VROOM is an open-source optimization engine that aims at providing good solutions +to various real-life vehicle routing problems (VRP) within a small computing time. +This function can be used to get the solution to a problem involving both jobs and +shipments. + +.. index:: + single: vrp_vroomPlain -- Experimental on v0.2 + +Signature +------------------------------------------------------------------------------- + +.. include:: ../sql/vroom/vrp_vroom.sql + :start-after: signature start + :end-before: signature end + +**Example**: This example is based on the VROOM Data of the :doc:`sampledata` network: + +.. literalinclude:: doc-vrp_vroomPlain.queries + :start-after: -- q1 + :end-before: -- q2 + +Parameters +------------------------------------------------------------------------------- + +.. include:: ../sql/vroom/vrp_vroom.sql + :start-after: parameters start + :end-before: parameters end + +Inner Queries +------------------------------------------------------------------------------- + +Jobs SQL +............................................................................... + +.. include:: ../../src/common/vroom/jobs_input.c + :start-after: vrp_vroom start + :end-before: vrp_vroom end + +Shipments SQL +............................................................................... + +.. include:: ../../src/common/vroom/shipments_input.c + :start-after: vrp_vroom start + :end-before: vrp_vroom end + +.. include:: vroom-category.rst + :start-after: inner_queries_start + :end-before: inner_queries_end + +Result Columns +------------------------------------------------------------------------------- + +.. include:: vroom-category.rst + :start-after: result_columns_start + :end-before: result_columns_end + +Additional Example +------------------------------------------------------------------------------- + +Problem involving 2 jobs and 1 shipment, using a single vehicle, similar to the VROOM Documentation +`Example 2 `__ with a shipment. + +.. literalinclude:: doc-vrp_vroomPlain.queries + :start-after: -- q2 + :end-before: -- q3 + +See Also +------------------------------------------------------------------------------- + +* :doc:`vroom-category` +* The queries use the :doc:`sampledata` network. + +.. include:: vroom-category.rst + :start-after: see_also_start + :end-before: see_also_end + +.. rubric:: Indices and tables + +* :ref:`genindex` +* :ref:`search` diff --git a/doc/vroom/vrp_vroomShipments.rst b/doc/vroom/vrp_vroomShipments.rst index 5a504eeed..5903a0b0b 100644 --- a/doc/vroom/vrp_vroomShipments.rst +++ b/doc/vroom/vrp_vroomShipments.rst @@ -48,7 +48,8 @@ Signature :start-after: signature start :end-before: signature end -**Example**: This example is based on the VROOM Data of the :doc:`sampledata` network: +**Example**: This example is based on the modified VROOM Data of the :doc:`sampledata` network. +The modification in the tables is mentioned at the end of the :doc:`sampledata`. .. literalinclude:: doc-vrp_vroomShipments.queries :start-after: -- q1 diff --git a/doc/vroom/vrp_vroomShipmentsPlain.rst b/doc/vroom/vrp_vroomShipmentsPlain.rst new file mode 100644 index 000000000..093f8582e --- /dev/null +++ b/doc/vroom/vrp_vroomShipmentsPlain.rst @@ -0,0 +1,109 @@ +.. + **************************************************************************** + vrpRouting Manual + Copyright(c) vrpRouting Contributors + + This documentation is licensed under a Creative Commons Attribution-Share + Alike 3.0 License: https://creativecommons.org/licenses/by-sa/3.0/ + **************************************************************************** + +| + +* `Documentation `__ → `vrpRouting v0 `__ +* Supported Versions + `Latest `__ + (`v0 `__) + + +vrp_vroomShipmentsPlain - Experimental +=============================================================================== + +``vrp_vroomShipmentsPlain`` - Vehicle Routing Problem with VROOM, involving only shipments. + +.. include:: experimental.rst + :start-after: begin-warn-expr + :end-before: end-warn-expr + +.. rubric:: Availability + +Version 0.2.0 + +* New **experimental** function + + +Description +------------------------------------------------------------------------------- + +VROOM is an open-source optimization engine that aims at providing good solutions +to various real-life vehicle routing problems (VRP) within a small computing time. +This function can be used to get the solution to a problem involving only shipments. + +.. index:: + single: vrp_vroomShipmentsPlain -- Experimental on v0.2 + +Signature +------------------------------------------------------------------------------- + +.. include:: ../sql/vroom/vrp_vroomShipments.sql + :start-after: signature start + :end-before: signature end + +**Example**: This example is based on the VROOM Data of the :doc:`sampledata` network: + +.. literalinclude:: doc-vrp_vroomShipmentsPlain.queries + :start-after: -- q1 + :end-before: -- q2 + +Parameters +------------------------------------------------------------------------------- + +.. include:: ../sql/vroom/vrp_vroomShipments.sql + :start-after: parameters start + :end-before: parameters end + +Inner Queries +------------------------------------------------------------------------------- + +Shipments SQL +............................................................................... + +.. include:: ../../src/common/vroom/shipments_input.c + :start-after: vrp_vroom start + :end-before: vrp_vroom end + +.. include:: vroom-category.rst + :start-after: inner_queries_start + :end-before: inner_queries_end + +Result Columns +------------------------------------------------------------------------------- + +.. include:: vroom-category.rst + :start-after: result_columns_start + :end-before: result_columns_end + +Additional Example +------------------------------------------------------------------------------- + +Problem involving 1 shipment, using a single vehicle, similar to the VROOM Documentation +`Example 2 `__ without jobs +and with a shipment. + +.. literalinclude:: doc-vrp_vroomShipmentsPlain.queries + :start-after: -- q2 + :end-before: -- q3 + +See Also +------------------------------------------------------------------------------- + +* :doc:`vroom-category` +* The queries use the :doc:`sampledata` network. + +.. include:: vroom-category.rst + :start-after: see_also_start + :end-before: see_also_end + +.. rubric:: Indices and tables + +* :ref:`genindex` +* :ref:`search` diff --git a/docqueries/pgr_pickDeliver/doc-pgr_pickDeliver.result b/docqueries/pgr_pickDeliver/doc-pgr_pickDeliver.result index 2aed993ed..2ae4bbc88 100644 --- a/docqueries/pgr_pickDeliver/doc-pgr_pickDeliver.result +++ b/docqueries/pgr_pickDeliver/doc-pgr_pickDeliver.result @@ -4,7 +4,7 @@ SET client_min_messages TO NOTICE; SET SET extra_float_digits=-3; SET ---q1 +/* --q1 */ SELECT * FROM vrp_pgr_pickDeliver( 'SELECT * FROM orders_1 ORDER BY id', 'SELECT * from vehicles_1', @@ -35,7 +35,7 @@ SELECT * FROM vrp_pgr_pickDeliver( 11 | -2 | 0 | 0 | -1 | -1 | -1 | -1 | 10 | -1 | 2 | 17 | 29 (11 rows) ---q2 +/* --q2 */ SELECT * FROM vrp_pgr_pickDeliver( $$ SELECT * FROM orders_1 ORDER BY id $$, $$ SELECT * FROM vehicles_1 ORDER BY id$$, @@ -63,6 +63,6 @@ SELECT * FROM vrp_pgr_pickDeliver( 11 | -2 | 0 | 0 | -1 | -1 | -1 | -1 | 16 | -1 | 1 | 17 | 34 (11 rows) ---q3 +/* --q3 */ ROLLBACK; ROLLBACK diff --git a/docqueries/pgr_pickDeliver/doc-pgr_pickDeliver.test.sql b/docqueries/pgr_pickDeliver/doc-pgr_pickDeliver.test.sql index 3d8e5b66d..3cdcf1fcb 100644 --- a/docqueries/pgr_pickDeliver/doc-pgr_pickDeliver.test.sql +++ b/docqueries/pgr_pickDeliver/doc-pgr_pickDeliver.test.sql @@ -1,5 +1,5 @@ SET extra_float_digits=-3; -\echo --q1 +/* --q1 */ SELECT * FROM vrp_pgr_pickDeliver( 'SELECT * FROM orders_1 ORDER BY id', 'SELECT * from vehicles_1', @@ -16,7 +16,7 @@ SELECT * FROM vrp_pgr_pickDeliver( FROM A, A AS B WHERE A.id != B.id' ); -\echo --q2 +/* --q2 */ SELECT * FROM vrp_pgr_pickDeliver( $$ SELECT * FROM orders_1 ORDER BY id $$, @@ -31,4 +31,4 @@ SELECT * FROM vrp_pgr_pickDeliver( $$ ); -\echo --q3 +/* --q3 */ diff --git a/docqueries/pgr_pickDeliver/doc-pgr_pickDeliverEuclidean.result b/docqueries/pgr_pickDeliver/doc-pgr_pickDeliverEuclidean.result index f5bcb5f1b..e173dc10d 100644 --- a/docqueries/pgr_pickDeliver/doc-pgr_pickDeliverEuclidean.result +++ b/docqueries/pgr_pickDeliver/doc-pgr_pickDeliverEuclidean.result @@ -4,7 +4,7 @@ SET client_min_messages TO NOTICE; SET SET extra_float_digits=-3; SET ---q1 +/* --q1 */ SELECT * FROM vrp_pgr_pickDeliverEuclidean( 'SELECT * FROM orders_1 ORDER BY id', 'SELECT * from vehicles_1' @@ -24,6 +24,6 @@ SELECT * FROM vrp_pgr_pickDeliverEuclidean( 11 | -2 | 0 | 0 | -1 | -1 | -1 | 11 | -1 | 1 | 17 | 29 (11 rows) ---q2 +/* --q2 */ ROLLBACK; ROLLBACK diff --git a/docqueries/pgr_pickDeliver/doc-pgr_pickDeliverEuclidean.test.sql b/docqueries/pgr_pickDeliver/doc-pgr_pickDeliverEuclidean.test.sql index 359a5d734..ad787385f 100644 --- a/docqueries/pgr_pickDeliver/doc-pgr_pickDeliverEuclidean.test.sql +++ b/docqueries/pgr_pickDeliver/doc-pgr_pickDeliverEuclidean.test.sql @@ -1,7 +1,7 @@ SET extra_float_digits=-3; -\echo --q1 +/* --q1 */ SELECT * FROM vrp_pgr_pickDeliverEuclidean( 'SELECT * FROM orders_1 ORDER BY id', 'SELECT * from vehicles_1' ); -\echo --q2 +/* --q2 */ diff --git a/docqueries/pgr_pickDeliver/pickDeliver.result b/docqueries/pgr_pickDeliver/pickDeliver.result index 66c36af68..4716bb189 100644 --- a/docqueries/pgr_pickDeliver/pickDeliver.result +++ b/docqueries/pgr_pickDeliver/pickDeliver.result @@ -1,4 +1,4 @@ ---q1 +/* --q1 */ 1|1|1|-1|0|0|0|0|0 2|1|2|5|15.1327459504216|15.1327459504216|0|90|105.132745950422 3|1|3|3|1|106.132745950422|0|90|196.132745950422 @@ -126,7 +126,7 @@ 125|10|11|99|5|782.402110959561|0|90|872.402110959561 126|10|12|-1|33.5410196624968|905.943130622058|0|0|905.943130622058 127|-2|0|-1|879.42275822512|-1|0|9000|9879.42275822512 ---q2 +/* --q2 */ 1|1|1|1|-1|1|0|0|0|0|0|0 2|1|1|2|5|2|10|15.1327459504216|15.1327459504216|0|90|105.132745950422 3|1|1|3|3|2|20|1|106.132745950422|0|90|196.132745950422 @@ -254,4 +254,4 @@ 125|10|1|11|100|3|0|5|782.402110959561|0|90|872.402110959561 126|10|1|12|-1|6|0|33.5410196624968|905.943130622058|0|0|905.943130622058 127|-2|0|0|-1|-1|-1|879.42275822512|-1|0|9000|9879.42275822512 ---q3 +/* --q3 */ diff --git a/docqueries/pgr_pickDeliver/pickDeliver.test.sql b/docqueries/pgr_pickDeliver/pickDeliver.test.sql index 9dc7ce239..bad99832f 100644 --- a/docqueries/pgr_pickDeliver/pickDeliver.test.sql +++ b/docqueries/pgr_pickDeliver/pickDeliver.test.sql @@ -1,10 +1,10 @@ -\echo --q1 +/* --q1 */ SELECT * FROM _pgr_pickDeliver( 'select * from customer order by id', 25, 200, 1, 30); -\echo --q2 +/* --q2 */ SELECT * FROM _pgr_pickDeliverEuclidean( 'SELECT * FROM orders ORDER BY id', 'SELECT * FROM vehicles', 30); -\echo --q3 +/* --q3 */ diff --git a/docqueries/version/doc-full_version.result b/docqueries/version/doc-full_version.result index be5593924..8e8df0161 100644 --- a/docqueries/version/doc-full_version.result +++ b/docqueries/version/doc-full_version.result @@ -2,13 +2,13 @@ BEGIN; BEGIN SET client_min_messages TO NOTICE; SET --- q1 +/* -- q1 */ SELECT version, library FROM vrp_full_version(); version | library -----------+------------------ 0.2.0-dev | vrprouting-0.2.0 (1 row) --- q2 +/* -- q2 */ ROLLBACK; ROLLBACK diff --git a/docqueries/version/doc-full_version.test.sql b/docqueries/version/doc-full_version.test.sql index f9f5afa1d..ba6422521 100644 --- a/docqueries/version/doc-full_version.test.sql +++ b/docqueries/version/doc-full_version.test.sql @@ -1,3 +1,3 @@ -\echo -- q1 +/* -- q1 */ SELECT version, library FROM vrp_full_version(); -\echo -- q2 +/* -- q2 */ diff --git a/docqueries/version/doc-version.result b/docqueries/version/doc-version.result index 8e56dbfb6..b498fff1c 100644 --- a/docqueries/version/doc-version.result +++ b/docqueries/version/doc-version.result @@ -2,13 +2,13 @@ BEGIN; BEGIN SET client_min_messages TO NOTICE; SET --- q1 +/* -- q1 */ SELECT vrp_version(); vrp_version ------------- 0.2.0-dev (1 row) --- q2 +/* -- q2 */ ROLLBACK; ROLLBACK diff --git a/docqueries/version/doc-version.test.sql b/docqueries/version/doc-version.test.sql index f0e09b5a5..717eaeab8 100644 --- a/docqueries/version/doc-version.test.sql +++ b/docqueries/version/doc-version.test.sql @@ -2,6 +2,6 @@ -------------------------------------------------------------------------------- -- vrp_version -------------------------------------------------------------------------------- -\echo -- q1 +/* -- q1 */ SELECT vrp_version(); -\echo -- q2 +/* -- q2 */ diff --git a/docqueries/vroom/CMakeLists.txt b/docqueries/vroom/CMakeLists.txt index ad8f8281f..a28beba0e 100644 --- a/docqueries/vroom/CMakeLists.txt +++ b/docqueries/vroom/CMakeLists.txt @@ -3,6 +3,9 @@ SET(LOCAL_FILES doc-vrp_vroom doc-vrp_vroomJobs doc-vrp_vroomShipments + doc-vrp_vroomPlain + doc-vrp_vroomJobsPlain + doc-vrp_vroomShipmentsPlain ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/vroom/doc-vrp_vroom.result b/docqueries/vroom/doc-vrp_vroom.result index 371ee2ad9..85468ee55 100644 --- a/docqueries/vroom/doc-vrp_vroom.result +++ b/docqueries/vroom/doc-vrp_vroom.result @@ -2,7 +2,32 @@ BEGIN; BEGIN SET client_min_messages TO NOTICE; SET --- q1 +/* -- q0 */ +ALTER TABLE vroom.jobs ALTER COLUMN service TYPE INTERVAL USING make_interval(secs => service); +ALTER TABLE +ALTER TABLE vroom.shipments ALTER COLUMN p_service TYPE INTERVAL USING make_interval(secs => p_service); +ALTER TABLE +ALTER TABLE vroom.shipments ALTER COLUMN d_service TYPE INTERVAL USING make_interval(secs => d_service); +ALTER TABLE +ALTER TABLE vroom.vehicles ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE +ALTER TABLE vroom.vehicles ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE +ALTER TABLE vroom.breaks ALTER COLUMN service TYPE INTERVAL USING make_interval(secs => service); +ALTER TABLE +ALTER TABLE vroom.jobs_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE +ALTER TABLE vroom.jobs_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE +ALTER TABLE vroom.shipments_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE +ALTER TABLE vroom.shipments_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE +ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE +ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE +/* -- q1 */ SELECT * FROM vrp_vroom( 'SELECT * FROM vroom.jobs', @@ -14,38 +39,38 @@ FROM vrp_vroom( 'SELECT * FROM vroom.breaks_time_windows', 'SELECT * FROM vroom.matrix' ); - seq | vehicle_seq | vehicle_id | step_seq | step_type | task_id | arrival | travel_time | service_time | waiting_time | load ------+-------------+------------+----------+-----------+---------+---------+-------------+--------------+--------------+------ - 1 | 1 | 1 | 1 | 1 | -1 | 300 | 0 | 0 | 0 | {30} - 2 | 1 | 1 | 2 | 5 | 1 | 300 | 0 | 0 | 0 | {30} - 3 | 1 | 1 | 3 | 2 | 2 | 350 | 50 | 250 | 900 | {30} - 4 | 1 | 1 | 4 | 3 | 5 | 1500 | 50 | 2250 | 11850 | {40} - 5 | 1 | 1 | 5 | 3 | 3 | 15650 | 100 | 2250 | 0 | {60} - 6 | 1 | 1 | 6 | 4 | 5 | 17950 | 150 | 2250 | 225 | {50} - 7 | 1 | 1 | 7 | 4 | 3 | 20425 | 150 | 2250 | 200 | {30} - 8 | 1 | 1 | 8 | 6 | -1 | 22925 | 200 | 0 | 0 | {30} - 9 | 2 | 2 | 1 | 1 | -1 | 275 | 0 | 0 | 0 | {70} - 10 | 2 | 2 | 2 | 5 | 2 | 275 | 0 | 10 | 0 | {70} - 11 | 2 | 2 | 3 | 2 | 5 | 360 | 75 | 250 | 665 | {70} - 12 | 2 | 2 | 4 | 2 | 3 | 1325 | 125 | 250 | 1400 | {70} - 13 | 2 | 2 | 5 | 2 | 4 | 2975 | 125 | 250 | 550 | {70} - 14 | 2 | 2 | 6 | 6 | -1 | 3775 | 125 | 0 | 0 | {70} - 15 | 3 | 3 | 1 | 1 | -1 | 0 | 0 | 0 | 0 | {20} - 16 | 3 | 3 | 2 | 5 | 3 | 0 | 0 | 0 | 0 | {20} - 17 | 3 | 3 | 3 | 2 | 1 | 0 | 0 | 250 | 3625 | {20} - 18 | 3 | 3 | 4 | 3 | 4 | 3875 | 0 | 2250 | 2500 | {40} - 19 | 3 | 3 | 5 | 4 | 4 | 8700 | 75 | 2250 | 225 | {20} - 20 | 3 | 3 | 6 | 6 | -1 | 11250 | 150 | 0 | 0 | {20} - 21 | 4 | 4 | 1 | 1 | -1 | 250 | 0 | 0 | 0 | {0} - 22 | 4 | 4 | 2 | 5 | 4 | 250 | 0 | 0 | 0 | {0} - 23 | 4 | 4 | 3 | 3 | 2 | 275 | 25 | 2250 | 100 | {10} - 24 | 4 | 4 | 4 | 3 | 1 | 2650 | 50 | 2250 | 0 | {20} - 25 | 4 | 4 | 5 | 4 | 2 | 4990 | 140 | 2250 | 0 | {10} - 26 | 4 | 4 | 6 | 4 | 1 | 7351 | 251 | 2250 | 17574 | {0} - 27 | 4 | 4 | 7 | 6 | -1 | 27200 | 276 | 0 | 0 | {0} + seq | vehicle_seq | vehicle_id | step_seq | step_type | task_id | arrival | travel_time | service_time | waiting_time | load +-----+-------------+------------+----------+-----------+---------+---------------------+-------------+--------------+--------------+------ + 1 | 1 | 1 | 1 | 1 | -1 | 2021-09-02 09:05:00 | 00:00:00 | 00:00:00 | 00:00:00 | {30} + 2 | 1 | 1 | 2 | 5 | 1 | 2021-09-02 09:05:00 | 00:00:00 | 00:00:00 | 00:00:00 | {30} + 3 | 1 | 1 | 3 | 2 | 2 | 2021-09-02 09:05:50 | 00:00:50 | 00:04:10 | 00:15:00 | {30} + 4 | 1 | 1 | 4 | 3 | 5 | 2021-09-02 09:25:00 | 00:00:50 | 00:37:30 | 03:17:30 | {40} + 5 | 1 | 1 | 5 | 3 | 3 | 2021-09-02 13:20:50 | 00:01:40 | 00:37:30 | 00:00:00 | {60} + 6 | 1 | 1 | 6 | 4 | 5 | 2021-09-02 13:59:10 | 00:02:30 | 00:37:30 | 00:03:45 | {50} + 7 | 1 | 1 | 7 | 4 | 3 | 2021-09-02 14:40:25 | 00:02:30 | 00:37:30 | 00:03:20 | {30} + 8 | 1 | 1 | 8 | 6 | -1 | 2021-09-02 15:22:05 | 00:03:20 | 00:00:00 | 00:00:00 | {30} + 9 | 2 | 2 | 1 | 1 | -1 | 2021-09-02 09:04:35 | 00:00:00 | 00:00:00 | 00:00:00 | {70} + 10 | 2 | 2 | 2 | 5 | 2 | 2021-09-02 09:04:35 | 00:00:00 | 00:00:10 | 00:00:00 | {70} + 11 | 2 | 2 | 3 | 2 | 5 | 2021-09-02 09:06:00 | 00:01:15 | 00:04:10 | 00:11:05 | {70} + 12 | 2 | 2 | 4 | 2 | 3 | 2021-09-02 09:22:05 | 00:02:05 | 00:04:10 | 00:23:20 | {70} + 13 | 2 | 2 | 5 | 2 | 4 | 2021-09-02 09:49:35 | 00:02:05 | 00:04:10 | 00:09:10 | {70} + 14 | 2 | 2 | 6 | 6 | -1 | 2021-09-02 10:02:55 | 00:02:05 | 00:00:00 | 00:00:00 | {70} + 15 | 3 | 3 | 1 | 1 | -1 | 2021-09-02 09:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | {20} + 16 | 3 | 3 | 2 | 5 | 3 | 2021-09-02 09:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | {20} + 17 | 3 | 3 | 3 | 2 | 1 | 2021-09-02 09:00:00 | 00:00:00 | 00:04:10 | 01:00:25 | {20} + 18 | 3 | 3 | 4 | 3 | 4 | 2021-09-02 10:04:35 | 00:00:00 | 00:37:30 | 00:41:40 | {40} + 19 | 3 | 3 | 5 | 4 | 4 | 2021-09-02 11:25:00 | 00:01:15 | 00:37:30 | 00:03:45 | {20} + 20 | 3 | 3 | 6 | 6 | -1 | 2021-09-02 12:07:30 | 00:02:30 | 00:00:00 | 00:00:00 | {20} + 21 | 4 | 4 | 1 | 1 | -1 | 2021-09-02 09:04:10 | 00:00:00 | 00:00:00 | 00:00:00 | {0} + 22 | 4 | 4 | 2 | 5 | 4 | 2021-09-02 09:04:10 | 00:00:00 | 00:00:00 | 00:00:00 | {0} + 23 | 4 | 4 | 3 | 3 | 2 | 2021-09-02 09:04:35 | 00:00:25 | 00:37:30 | 00:01:40 | {10} + 24 | 4 | 4 | 4 | 3 | 1 | 2021-09-02 09:44:10 | 00:00:50 | 00:37:30 | 00:00:00 | {20} + 25 | 4 | 4 | 5 | 4 | 2 | 2021-09-02 10:23:10 | 00:02:20 | 00:37:30 | 00:00:00 | {10} + 26 | 4 | 4 | 6 | 4 | 1 | 2021-09-02 11:02:31 | 00:04:11 | 00:37:30 | 04:52:54 | {0} + 27 | 4 | 4 | 7 | 6 | -1 | 2021-09-02 16:33:20 | 00:04:36 | 00:00:00 | 00:00:00 | {0} (27 rows) --- q2 +/* -- q2 */ SELECT * FROM vrp_vroom( $jobs$ @@ -76,16 +101,16 @@ FROM vrp_vroom( ) AS C(start_vid, end_vid, agg_cost) $matrix$ ); - seq | vehicle_seq | vehicle_id | step_seq | step_type | task_id | arrival | travel_time | service_time | waiting_time | load ------+-------------+------------+----------+-----------+---------+---------+-------------+--------------+--------------+------ - 1 | 1 | 1 | 1 | 1 | -1 | 0 | 0 | 0 | 0 | {} - 2 | 1 | 1 | 2 | 3 | 100 | 0 | 0 | 0 | 0 | {} - 3 | 1 | 1 | 3 | 2 | 1414 | 2104 | 2104 | 0 | 0 | {} - 4 | 1 | 1 | 4 | 2 | 1515 | 4359 | 4359 | 0 | 0 | {} - 5 | 1 | 1 | 5 | 4 | 100 | 5461 | 5461 | 0 | 0 | {} - 6 | 1 | 1 | 6 | 6 | -1 | 5461 | 5461 | 0 | 0 | {} + seq | vehicle_seq | vehicle_id | step_seq | step_type | task_id | arrival | travel_time | service_time | waiting_time | load +-----+-------------+------------+----------+-----------+---------+---------------------+-------------+--------------+--------------+------ + 1 | 1 | 1 | 1 | 1 | -1 | 1970-01-01 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | {} + 2 | 1 | 1 | 2 | 3 | 100 | 1970-01-01 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | {} + 3 | 1 | 1 | 3 | 2 | 1414 | 1970-01-01 00:35:04 | 00:35:04 | 00:00:00 | 00:00:00 | {} + 4 | 1 | 1 | 4 | 2 | 1515 | 1970-01-01 01:12:39 | 01:12:39 | 00:00:00 | 00:00:00 | {} + 5 | 1 | 1 | 5 | 4 | 100 | 1970-01-01 01:31:01 | 01:31:01 | 00:00:00 | 00:00:00 | {} + 6 | 1 | 1 | 6 | 6 | -1 | 1970-01-01 01:31:01 | 01:31:01 | 00:00:00 | 00:00:00 | {} (6 rows) --- q3 +/* -- q3 */ ROLLBACK; ROLLBACK diff --git a/docqueries/vroom/doc-vrp_vroom.test.sql b/docqueries/vroom/doc-vrp_vroom.test.sql index c0ce92438..dc9494d3b 100644 --- a/docqueries/vroom/doc-vrp_vroom.test.sql +++ b/docqueries/vroom/doc-vrp_vroom.test.sql @@ -1,4 +1,17 @@ -\echo -- q1 +/* -- q0 */ +ALTER TABLE vroom.jobs ALTER COLUMN service TYPE INTERVAL USING make_interval(secs => service); +ALTER TABLE vroom.shipments ALTER COLUMN p_service TYPE INTERVAL USING make_interval(secs => p_service); +ALTER TABLE vroom.shipments ALTER COLUMN d_service TYPE INTERVAL USING make_interval(secs => d_service); +ALTER TABLE vroom.vehicles ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.vehicles ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.breaks ALTER COLUMN service TYPE INTERVAL USING make_interval(secs => service); +ALTER TABLE vroom.jobs_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.jobs_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.shipments_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.shipments_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +/* -- q1 */ SELECT * FROM vrp_vroom( 'SELECT * FROM vroom.jobs', @@ -10,7 +23,7 @@ FROM vrp_vroom( 'SELECT * FROM vroom.breaks_time_windows', 'SELECT * FROM vroom.matrix' ); -\echo -- q2 +/* -- q2 */ SELECT * FROM vrp_vroom( $jobs$ @@ -41,4 +54,4 @@ FROM vrp_vroom( ) AS C(start_vid, end_vid, agg_cost) $matrix$ ); -\echo -- q3 +/* -- q3 */ diff --git a/docqueries/vroom/doc-vrp_vroomJobs.result b/docqueries/vroom/doc-vrp_vroomJobs.result index db6a8f149..990086503 100644 --- a/docqueries/vroom/doc-vrp_vroomJobs.result +++ b/docqueries/vroom/doc-vrp_vroomJobs.result @@ -2,7 +2,32 @@ BEGIN; BEGIN SET client_min_messages TO NOTICE; SET --- q1 +/* -- q0 */ +ALTER TABLE vroom.jobs ALTER COLUMN service TYPE INTERVAL USING make_interval(secs => service); +ALTER TABLE +ALTER TABLE vroom.shipments ALTER COLUMN p_service TYPE INTERVAL USING make_interval(secs => p_service); +ALTER TABLE +ALTER TABLE vroom.shipments ALTER COLUMN d_service TYPE INTERVAL USING make_interval(secs => d_service); +ALTER TABLE +ALTER TABLE vroom.vehicles ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE +ALTER TABLE vroom.vehicles ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE +ALTER TABLE vroom.breaks ALTER COLUMN service TYPE INTERVAL USING make_interval(secs => service); +ALTER TABLE +ALTER TABLE vroom.jobs_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE +ALTER TABLE vroom.jobs_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE +ALTER TABLE vroom.shipments_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE +ALTER TABLE vroom.shipments_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE +ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE +ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE +/* -- q1 */ SELECT * FROM vrp_vroomJobs( 'SELECT * FROM vroom.jobs', @@ -12,22 +37,22 @@ FROM vrp_vroomJobs( 'SELECT * FROM vroom.breaks_time_windows', 'SELECT * FROM vroom.matrix' ); - seq | vehicle_seq | vehicle_id | step_seq | step_type | task_id | arrival | travel_time | service_time | waiting_time | load ------+-------------+------------+----------+-----------+---------+---------+-------------+--------------+--------------+------- - 1 | 1 | 1 | 1 | 1 | -1 | 300 | 0 | 0 | 0 | {20} - 2 | 1 | 1 | 2 | 5 | 1 | 300 | 0 | 0 | 0 | {20} - 3 | 1 | 1 | 3 | 2 | 1 | 300 | 0 | 250 | 3325 | {20} - 4 | 1 | 1 | 4 | 6 | -1 | 3875 | 0 | 0 | 0 | {20} - 5 | 2 | 2 | 1 | 1 | -1 | 275 | 0 | 0 | 0 | {100} - 6 | 2 | 2 | 2 | 5 | 2 | 275 | 0 | 10 | 0 | {100} - 7 | 2 | 2 | 3 | 2 | 2 | 335 | 50 | 250 | 915 | {100} - 8 | 2 | 2 | 4 | 2 | 5 | 1590 | 140 | 250 | 0 | {100} - 9 | 2 | 2 | 5 | 2 | 3 | 1890 | 190 | 250 | 835 | {100} - 10 | 2 | 2 | 6 | 2 | 4 | 2975 | 190 | 250 | 550 | {100} - 11 | 2 | 2 | 7 | 6 | -1 | 3775 | 190 | 0 | 0 | {100} + seq | vehicle_seq | vehicle_id | step_seq | step_type | task_id | arrival | travel_time | service_time | waiting_time | load +-----+-------------+------------+----------+-----------+---------+---------------------+-------------+--------------+--------------+------- + 1 | 1 | 1 | 1 | 1 | -1 | 2021-09-02 09:05:00 | 00:00:00 | 00:00:00 | 00:00:00 | {20} + 2 | 1 | 1 | 2 | 5 | 1 | 2021-09-02 09:05:00 | 00:00:00 | 00:00:00 | 00:00:00 | {20} + 3 | 1 | 1 | 3 | 2 | 1 | 2021-09-02 09:05:00 | 00:00:00 | 00:04:10 | 00:55:25 | {20} + 4 | 1 | 1 | 4 | 6 | -1 | 2021-09-02 10:04:35 | 00:00:00 | 00:00:00 | 00:00:00 | {20} + 5 | 2 | 2 | 1 | 1 | -1 | 2021-09-02 09:04:35 | 00:00:00 | 00:00:00 | 00:00:00 | {100} + 6 | 2 | 2 | 2 | 5 | 2 | 2021-09-02 09:04:35 | 00:00:00 | 00:00:10 | 00:00:00 | {100} + 7 | 2 | 2 | 3 | 2 | 2 | 2021-09-02 09:05:35 | 00:00:50 | 00:04:10 | 00:15:15 | {100} + 8 | 2 | 2 | 4 | 2 | 5 | 2021-09-02 09:26:30 | 00:02:20 | 00:04:10 | 00:00:00 | {100} + 9 | 2 | 2 | 5 | 2 | 3 | 2021-09-02 09:31:30 | 00:03:10 | 00:04:10 | 00:13:55 | {100} + 10 | 2 | 2 | 6 | 2 | 4 | 2021-09-02 09:49:35 | 00:03:10 | 00:04:10 | 00:09:10 | {100} + 11 | 2 | 2 | 7 | 6 | -1 | 2021-09-02 10:02:55 | 00:03:10 | 00:00:00 | 00:00:00 | {100} (11 rows) --- q2 +/* -- q2 */ SELECT * FROM vrp_vroomJobs( $jobs$ @@ -52,14 +77,14 @@ FROM vrp_vroomJobs( ) AS C(start_vid, end_vid, agg_cost) $matrix$ ); - seq | vehicle_seq | vehicle_id | step_seq | step_type | task_id | arrival | travel_time | service_time | waiting_time | load ------+-------------+------------+----------+-----------+---------+---------+-------------+--------------+--------------+------ - 1 | 1 | 1 | 1 | 1 | -1 | 0 | 0 | 0 | 0 | {} - 2 | 1 | 1 | 2 | 2 | 1414 | 2104 | 2104 | 0 | 0 | {} - 3 | 1 | 1 | 3 | 2 | 1515 | 4359 | 4359 | 0 | 0 | {} - 4 | 1 | 1 | 4 | 6 | -1 | 5461 | 5461 | 0 | 0 | {} + seq | vehicle_seq | vehicle_id | step_seq | step_type | task_id | arrival | travel_time | service_time | waiting_time | load +-----+-------------+------------+----------+-----------+---------+---------------------+-------------+--------------+--------------+------ + 1 | 1 | 1 | 1 | 1 | -1 | 1970-01-01 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | {} + 2 | 1 | 1 | 2 | 2 | 1414 | 1970-01-01 00:35:04 | 00:35:04 | 00:00:00 | 00:00:00 | {} + 3 | 1 | 1 | 3 | 2 | 1515 | 1970-01-01 01:12:39 | 01:12:39 | 00:00:00 | 00:00:00 | {} + 4 | 1 | 1 | 4 | 6 | -1 | 1970-01-01 01:31:01 | 01:31:01 | 00:00:00 | 00:00:00 | {} (4 rows) --- q3 +/* -- q3 */ ROLLBACK; ROLLBACK diff --git a/docqueries/vroom/doc-vrp_vroomJobs.test.sql b/docqueries/vroom/doc-vrp_vroomJobs.test.sql index c2d39c778..5974cb279 100644 --- a/docqueries/vroom/doc-vrp_vroomJobs.test.sql +++ b/docqueries/vroom/doc-vrp_vroomJobs.test.sql @@ -1,4 +1,17 @@ -\echo -- q1 +/* -- q0 */ +ALTER TABLE vroom.jobs ALTER COLUMN service TYPE INTERVAL USING make_interval(secs => service); +ALTER TABLE vroom.shipments ALTER COLUMN p_service TYPE INTERVAL USING make_interval(secs => p_service); +ALTER TABLE vroom.shipments ALTER COLUMN d_service TYPE INTERVAL USING make_interval(secs => d_service); +ALTER TABLE vroom.vehicles ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.vehicles ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.breaks ALTER COLUMN service TYPE INTERVAL USING make_interval(secs => service); +ALTER TABLE vroom.jobs_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.jobs_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.shipments_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.shipments_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +/* -- q1 */ SELECT * FROM vrp_vroomJobs( 'SELECT * FROM vroom.jobs', @@ -8,7 +21,7 @@ FROM vrp_vroomJobs( 'SELECT * FROM vroom.breaks_time_windows', 'SELECT * FROM vroom.matrix' ); -\echo -- q2 +/* -- q2 */ SELECT * FROM vrp_vroomJobs( $jobs$ @@ -33,4 +46,4 @@ FROM vrp_vroomJobs( ) AS C(start_vid, end_vid, agg_cost) $matrix$ ); -\echo -- q3 +/* -- q3 */ diff --git a/docqueries/vroom/doc-vrp_vroomJobsPlain.result b/docqueries/vroom/doc-vrp_vroomJobsPlain.result new file mode 100644 index 000000000..d520a7371 --- /dev/null +++ b/docqueries/vroom/doc-vrp_vroomJobsPlain.result @@ -0,0 +1,65 @@ +BEGIN; +BEGIN +SET client_min_messages TO NOTICE; +SET +/* -- q1 */ +SELECT * +FROM vrp_vroomJobsPlain( + 'SELECT * FROM vroom.jobs', + 'SELECT * FROM vroom.jobs_time_windows', + 'SELECT * FROM vroom.vehicles', + 'SELECT * FROM vroom.breaks', + 'SELECT * FROM vroom.breaks_time_windows', + 'SELECT * FROM vroom.matrix' +); + seq | vehicle_seq | vehicle_id | step_seq | step_type | task_id | arrival | travel_time | service_time | waiting_time | load +-----+-------------+------------+----------+-----------+---------+---------+-------------+--------------+--------------+------- + 1 | 1 | 1 | 1 | 1 | -1 | 300 | 0 | 0 | 0 | {20} + 2 | 1 | 1 | 2 | 5 | 1 | 300 | 0 | 0 | 0 | {20} + 3 | 1 | 1 | 3 | 2 | 1 | 300 | 0 | 250 | 3325 | {20} + 4 | 1 | 1 | 4 | 6 | -1 | 3875 | 0 | 0 | 0 | {20} + 5 | 2 | 2 | 1 | 1 | -1 | 275 | 0 | 0 | 0 | {100} + 6 | 2 | 2 | 2 | 5 | 2 | 275 | 0 | 10 | 0 | {100} + 7 | 2 | 2 | 3 | 2 | 2 | 335 | 50 | 250 | 915 | {100} + 8 | 2 | 2 | 4 | 2 | 5 | 1590 | 140 | 250 | 0 | {100} + 9 | 2 | 2 | 5 | 2 | 3 | 1890 | 190 | 250 | 835 | {100} + 10 | 2 | 2 | 6 | 2 | 4 | 2975 | 190 | 250 | 550 | {100} + 11 | 2 | 2 | 7 | 6 | -1 | 3775 | 190 | 0 | 0 | {100} +(11 rows) + +/* -- q2 */ +SELECT * +FROM vrp_vroomJobsPlain( + $jobs$ + SELECT * FROM ( + VALUES (1414, 2), (1515, 3) + ) AS C(id, location_index) + $jobs$, + NULL, + $vehicles$ + SELECT * FROM ( + VALUES (1, 1, 4) + ) AS C(id, start_index, end_index) + $vehicles$, + NULL, + NULL, + $matrix$ + SELECT * FROM ( + VALUES (1, 2, 2104), (1, 3, 197), (1, 4, 1299), + (2, 1, 2103), (2, 3, 2255), (2, 4, 3152), + (3, 1, 197), (3, 2, 2256), (3, 4, 1102), + (4, 1, 1299), (4, 2, 3153), (4, 3, 1102) + ) AS C(start_vid, end_vid, agg_cost) + $matrix$ +); + seq | vehicle_seq | vehicle_id | step_seq | step_type | task_id | arrival | travel_time | service_time | waiting_time | load +-----+-------------+------------+----------+-----------+---------+---------+-------------+--------------+--------------+------ + 1 | 1 | 1 | 1 | 1 | -1 | 0 | 0 | 0 | 0 | {} + 2 | 1 | 1 | 2 | 2 | 1414 | 2104 | 2104 | 0 | 0 | {} + 3 | 1 | 1 | 3 | 2 | 1515 | 4359 | 4359 | 0 | 0 | {} + 4 | 1 | 1 | 4 | 6 | -1 | 5461 | 5461 | 0 | 0 | {} +(4 rows) + +/* -- q3 */ +ROLLBACK; +ROLLBACK diff --git a/docqueries/vroom/doc-vrp_vroomJobsPlain.test.sql b/docqueries/vroom/doc-vrp_vroomJobsPlain.test.sql new file mode 100644 index 000000000..aa82a70c4 --- /dev/null +++ b/docqueries/vroom/doc-vrp_vroomJobsPlain.test.sql @@ -0,0 +1,36 @@ +/* -- q1 */ +SELECT * +FROM vrp_vroomJobsPlain( + 'SELECT * FROM vroom.jobs', + 'SELECT * FROM vroom.jobs_time_windows', + 'SELECT * FROM vroom.vehicles', + 'SELECT * FROM vroom.breaks', + 'SELECT * FROM vroom.breaks_time_windows', + 'SELECT * FROM vroom.matrix' +); +/* -- q2 */ +SELECT * +FROM vrp_vroomJobsPlain( + $jobs$ + SELECT * FROM ( + VALUES (1414, 2), (1515, 3) + ) AS C(id, location_index) + $jobs$, + NULL, + $vehicles$ + SELECT * FROM ( + VALUES (1, 1, 4) + ) AS C(id, start_index, end_index) + $vehicles$, + NULL, + NULL, + $matrix$ + SELECT * FROM ( + VALUES (1, 2, 2104), (1, 3, 197), (1, 4, 1299), + (2, 1, 2103), (2, 3, 2255), (2, 4, 3152), + (3, 1, 197), (3, 2, 2256), (3, 4, 1102), + (4, 1, 1299), (4, 2, 3153), (4, 3, 1102) + ) AS C(start_vid, end_vid, agg_cost) + $matrix$ +); +/* -- q3 */ diff --git a/docqueries/vroom/doc-vrp_vroomPlain.result b/docqueries/vroom/doc-vrp_vroomPlain.result new file mode 100644 index 000000000..32a9adadf --- /dev/null +++ b/docqueries/vroom/doc-vrp_vroomPlain.result @@ -0,0 +1,91 @@ +BEGIN; +BEGIN +SET client_min_messages TO NOTICE; +SET +/* -- q1 */ +SELECT * +FROM vrp_vroomPlain( + 'SELECT * FROM vroom.jobs', + 'SELECT * FROM vroom.jobs_time_windows', + 'SELECT * FROM vroom.shipments', + 'SELECT * FROM vroom.shipments_time_windows', + 'SELECT * FROM vroom.vehicles', + 'SELECT * FROM vroom.breaks', + 'SELECT * FROM vroom.breaks_time_windows', + 'SELECT * FROM vroom.matrix' +); + seq | vehicle_seq | vehicle_id | step_seq | step_type | task_id | arrival | travel_time | service_time | waiting_time | load +-----+-------------+------------+----------+-----------+---------+---------+-------------+--------------+--------------+------ + 1 | 1 | 1 | 1 | 1 | -1 | 300 | 0 | 0 | 0 | {30} + 2 | 1 | 1 | 2 | 5 | 1 | 300 | 0 | 0 | 0 | {30} + 3 | 1 | 1 | 3 | 2 | 2 | 350 | 50 | 250 | 900 | {30} + 4 | 1 | 1 | 4 | 3 | 5 | 1500 | 50 | 2250 | 11850 | {40} + 5 | 1 | 1 | 5 | 3 | 3 | 15650 | 100 | 2250 | 0 | {60} + 6 | 1 | 1 | 6 | 4 | 5 | 17950 | 150 | 2250 | 225 | {50} + 7 | 1 | 1 | 7 | 4 | 3 | 20425 | 150 | 2250 | 200 | {30} + 8 | 1 | 1 | 8 | 6 | -1 | 22925 | 200 | 0 | 0 | {30} + 9 | 2 | 2 | 1 | 1 | -1 | 275 | 0 | 0 | 0 | {70} + 10 | 2 | 2 | 2 | 5 | 2 | 275 | 0 | 10 | 0 | {70} + 11 | 2 | 2 | 3 | 2 | 5 | 360 | 75 | 250 | 665 | {70} + 12 | 2 | 2 | 4 | 2 | 3 | 1325 | 125 | 250 | 1400 | {70} + 13 | 2 | 2 | 5 | 2 | 4 | 2975 | 125 | 250 | 550 | {70} + 14 | 2 | 2 | 6 | 6 | -1 | 3775 | 125 | 0 | 0 | {70} + 15 | 3 | 3 | 1 | 1 | -1 | 0 | 0 | 0 | 0 | {20} + 16 | 3 | 3 | 2 | 5 | 3 | 0 | 0 | 0 | 0 | {20} + 17 | 3 | 3 | 3 | 2 | 1 | 0 | 0 | 250 | 3625 | {20} + 18 | 3 | 3 | 4 | 3 | 4 | 3875 | 0 | 2250 | 2500 | {40} + 19 | 3 | 3 | 5 | 4 | 4 | 8700 | 75 | 2250 | 225 | {20} + 20 | 3 | 3 | 6 | 6 | -1 | 11250 | 150 | 0 | 0 | {20} + 21 | 4 | 4 | 1 | 1 | -1 | 250 | 0 | 0 | 0 | {0} + 22 | 4 | 4 | 2 | 5 | 4 | 250 | 0 | 0 | 0 | {0} + 23 | 4 | 4 | 3 | 3 | 2 | 275 | 25 | 2250 | 100 | {10} + 24 | 4 | 4 | 4 | 3 | 1 | 2650 | 50 | 2250 | 0 | {20} + 25 | 4 | 4 | 5 | 4 | 2 | 4990 | 140 | 2250 | 0 | {10} + 26 | 4 | 4 | 6 | 4 | 1 | 7351 | 251 | 2250 | 17574 | {0} + 27 | 4 | 4 | 7 | 6 | -1 | 27200 | 276 | 0 | 0 | {0} +(27 rows) + +/* -- q2 */ +SELECT * +FROM vrp_vroomPlain( + $jobs$ + SELECT * FROM ( + VALUES (1414, 2), (1515, 3) + ) AS C(id, location_index) + $jobs$, + NULL, + $shipments$ + SELECT * FROM ( + VALUES (100, 1, 4) + ) AS C(id, p_location_index, d_location_index) + $shipments$, + NULL, + $vehicles$ + SELECT * FROM ( + VALUES (1, 1, 4) + ) AS C(id, start_index, end_index) + $vehicles$, + NULL, + NULL, + $matrix$ + SELECT * FROM ( + VALUES (1, 2, 2104), (1, 3, 197), (1, 4, 1299), + (2, 1, 2103), (2, 3, 2255), (2, 4, 3152), + (3, 1, 197), (3, 2, 2256), (3, 4, 1102), + (4, 1, 1299), (4, 2, 3153), (4, 3, 1102) + ) AS C(start_vid, end_vid, agg_cost) + $matrix$ +); + seq | vehicle_seq | vehicle_id | step_seq | step_type | task_id | arrival | travel_time | service_time | waiting_time | load +-----+-------------+------------+----------+-----------+---------+---------+-------------+--------------+--------------+------ + 1 | 1 | 1 | 1 | 1 | -1 | 0 | 0 | 0 | 0 | {} + 2 | 1 | 1 | 2 | 3 | 100 | 0 | 0 | 0 | 0 | {} + 3 | 1 | 1 | 3 | 2 | 1414 | 2104 | 2104 | 0 | 0 | {} + 4 | 1 | 1 | 4 | 2 | 1515 | 4359 | 4359 | 0 | 0 | {} + 5 | 1 | 1 | 5 | 4 | 100 | 5461 | 5461 | 0 | 0 | {} + 6 | 1 | 1 | 6 | 6 | -1 | 5461 | 5461 | 0 | 0 | {} +(6 rows) + +/* -- q3 */ +ROLLBACK; +ROLLBACK diff --git a/docqueries/vroom/doc-vrp_vroomPlain.test.sql b/docqueries/vroom/doc-vrp_vroomPlain.test.sql new file mode 100644 index 000000000..11140d50e --- /dev/null +++ b/docqueries/vroom/doc-vrp_vroomPlain.test.sql @@ -0,0 +1,44 @@ +/* -- q1 */ +SELECT * +FROM vrp_vroomPlain( + 'SELECT * FROM vroom.jobs', + 'SELECT * FROM vroom.jobs_time_windows', + 'SELECT * FROM vroom.shipments', + 'SELECT * FROM vroom.shipments_time_windows', + 'SELECT * FROM vroom.vehicles', + 'SELECT * FROM vroom.breaks', + 'SELECT * FROM vroom.breaks_time_windows', + 'SELECT * FROM vroom.matrix' +); +/* -- q2 */ +SELECT * +FROM vrp_vroomPlain( + $jobs$ + SELECT * FROM ( + VALUES (1414, 2), (1515, 3) + ) AS C(id, location_index) + $jobs$, + NULL, + $shipments$ + SELECT * FROM ( + VALUES (100, 1, 4) + ) AS C(id, p_location_index, d_location_index) + $shipments$, + NULL, + $vehicles$ + SELECT * FROM ( + VALUES (1, 1, 4) + ) AS C(id, start_index, end_index) + $vehicles$, + NULL, + NULL, + $matrix$ + SELECT * FROM ( + VALUES (1, 2, 2104), (1, 3, 197), (1, 4, 1299), + (2, 1, 2103), (2, 3, 2255), (2, 4, 3152), + (3, 1, 197), (3, 2, 2256), (3, 4, 1102), + (4, 1, 1299), (4, 2, 3153), (4, 3, 1102) + ) AS C(start_vid, end_vid, agg_cost) + $matrix$ +); +/* -- q3 */ diff --git a/docqueries/vroom/doc-vrp_vroomShipments.result b/docqueries/vroom/doc-vrp_vroomShipments.result index 625293f5e..9b180bc5b 100644 --- a/docqueries/vroom/doc-vrp_vroomShipments.result +++ b/docqueries/vroom/doc-vrp_vroomShipments.result @@ -2,7 +2,32 @@ BEGIN; BEGIN SET client_min_messages TO NOTICE; SET --- q1 +/* -- q0 */ +ALTER TABLE vroom.jobs ALTER COLUMN service TYPE INTERVAL USING make_interval(secs => service); +ALTER TABLE +ALTER TABLE vroom.shipments ALTER COLUMN p_service TYPE INTERVAL USING make_interval(secs => p_service); +ALTER TABLE +ALTER TABLE vroom.shipments ALTER COLUMN d_service TYPE INTERVAL USING make_interval(secs => d_service); +ALTER TABLE +ALTER TABLE vroom.vehicles ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE +ALTER TABLE vroom.vehicles ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE +ALTER TABLE vroom.breaks ALTER COLUMN service TYPE INTERVAL USING make_interval(secs => service); +ALTER TABLE +ALTER TABLE vroom.jobs_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE +ALTER TABLE vroom.jobs_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE +ALTER TABLE vroom.shipments_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE +ALTER TABLE vroom.shipments_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE +ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE +ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE +/* -- q1 */ SELECT * FROM vrp_vroomShipments( 'SELECT * FROM vroom.shipments', @@ -12,27 +37,27 @@ FROM vrp_vroomShipments( 'SELECT * FROM vroom.breaks_time_windows', 'SELECT * FROM vroom.matrix' ); - seq | vehicle_seq | vehicle_id | step_seq | step_type | task_id | arrival | travel_time | service_time | waiting_time | load ------+-------------+------------+----------+-----------+---------+---------+-------------+--------------+--------------+------ - 1 | 1 | 1 | 1 | 1 | -1 | 300 | 0 | 0 | 0 | {0} - 2 | 1 | 1 | 2 | 5 | 1 | 300 | 0 | 0 | 0 | {0} - 3 | 1 | 1 | 3 | 3 | 4 | 300 | 0 | 2250 | 6075 | {20} - 4 | 1 | 1 | 4 | 4 | 4 | 8700 | 75 | 2250 | 225 | {0} - 5 | 1 | 1 | 5 | 3 | 5 | 11265 | 165 | 2250 | 2085 | {10} - 6 | 1 | 1 | 6 | 3 | 3 | 15650 | 215 | 2250 | 0 | {30} - 7 | 1 | 1 | 7 | 4 | 5 | 17950 | 265 | 2250 | 225 | {20} - 8 | 1 | 1 | 8 | 4 | 3 | 20425 | 265 | 2250 | 200 | {0} - 9 | 1 | 1 | 9 | 6 | -1 | 22925 | 315 | 0 | 0 | {0} - 10 | 2 | 4 | 1 | 1 | -1 | 250 | 0 | 0 | 0 | {0} - 11 | 2 | 4 | 2 | 5 | 4 | 250 | 0 | 0 | 0 | {0} - 12 | 2 | 4 | 3 | 3 | 2 | 275 | 25 | 2250 | 100 | {10} - 13 | 2 | 4 | 4 | 3 | 1 | 2650 | 50 | 2250 | 0 | {20} - 14 | 2 | 4 | 5 | 4 | 2 | 4990 | 140 | 2250 | 0 | {10} - 15 | 2 | 4 | 6 | 4 | 1 | 7351 | 251 | 2250 | 17574 | {0} - 16 | 2 | 4 | 7 | 6 | -1 | 27200 | 276 | 0 | 0 | {0} + seq | vehicle_seq | vehicle_id | step_seq | step_type | task_id | arrival | travel_time | service_time | waiting_time | load +-----+-------------+------------+----------+-----------+---------+---------------------+-------------+--------------+--------------+------ + 1 | 1 | 1 | 1 | 1 | -1 | 2021-09-02 09:05:00 | 00:00:00 | 00:00:00 | 00:00:00 | {0} + 2 | 1 | 1 | 2 | 5 | 1 | 2021-09-02 09:05:00 | 00:00:00 | 00:00:00 | 00:00:00 | {0} + 3 | 1 | 1 | 3 | 3 | 4 | 2021-09-02 09:05:00 | 00:00:00 | 00:37:30 | 01:41:15 | {20} + 4 | 1 | 1 | 4 | 4 | 4 | 2021-09-02 11:25:00 | 00:01:15 | 00:37:30 | 00:03:45 | {0} + 5 | 1 | 1 | 5 | 3 | 5 | 2021-09-02 12:07:45 | 00:02:45 | 00:37:30 | 00:34:45 | {10} + 6 | 1 | 1 | 6 | 3 | 3 | 2021-09-02 13:20:50 | 00:03:35 | 00:37:30 | 00:00:00 | {30} + 7 | 1 | 1 | 7 | 4 | 5 | 2021-09-02 13:59:10 | 00:04:25 | 00:37:30 | 00:03:45 | {20} + 8 | 1 | 1 | 8 | 4 | 3 | 2021-09-02 14:40:25 | 00:04:25 | 00:37:30 | 00:03:20 | {0} + 9 | 1 | 1 | 9 | 6 | -1 | 2021-09-02 15:22:05 | 00:05:15 | 00:00:00 | 00:00:00 | {0} + 10 | 2 | 4 | 1 | 1 | -1 | 2021-09-02 09:04:10 | 00:00:00 | 00:00:00 | 00:00:00 | {0} + 11 | 2 | 4 | 2 | 5 | 4 | 2021-09-02 09:04:10 | 00:00:00 | 00:00:00 | 00:00:00 | {0} + 12 | 2 | 4 | 3 | 3 | 2 | 2021-09-02 09:04:35 | 00:00:25 | 00:37:30 | 00:01:40 | {10} + 13 | 2 | 4 | 4 | 3 | 1 | 2021-09-02 09:44:10 | 00:00:50 | 00:37:30 | 00:00:00 | {20} + 14 | 2 | 4 | 5 | 4 | 2 | 2021-09-02 10:23:10 | 00:02:20 | 00:37:30 | 00:00:00 | {10} + 15 | 2 | 4 | 6 | 4 | 1 | 2021-09-02 11:02:31 | 00:04:11 | 00:37:30 | 04:52:54 | {0} + 16 | 2 | 4 | 7 | 6 | -1 | 2021-09-02 16:33:20 | 00:04:36 | 00:00:00 | 00:00:00 | {0} (16 rows) --- q2 +/* -- q2 */ SELECT * FROM vrp_vroomShipments( $shipments$ @@ -57,14 +82,14 @@ FROM vrp_vroomShipments( ) AS C(start_vid, end_vid, agg_cost) $matrix$ ); - seq | vehicle_seq | vehicle_id | step_seq | step_type | task_id | arrival | travel_time | service_time | waiting_time | load ------+-------------+------------+----------+-----------+---------+---------+-------------+--------------+--------------+------ - 1 | 1 | 1 | 1 | 1 | -1 | 0 | 0 | 0 | 0 | {} - 2 | 1 | 1 | 2 | 3 | 100 | 0 | 0 | 0 | 0 | {} - 3 | 1 | 1 | 3 | 4 | 100 | 1299 | 1299 | 0 | 0 | {} - 4 | 1 | 1 | 4 | 6 | -1 | 1299 | 1299 | 0 | 0 | {} + seq | vehicle_seq | vehicle_id | step_seq | step_type | task_id | arrival | travel_time | service_time | waiting_time | load +-----+-------------+------------+----------+-----------+---------+---------------------+-------------+--------------+--------------+------ + 1 | 1 | 1 | 1 | 1 | -1 | 1970-01-01 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | {} + 2 | 1 | 1 | 2 | 3 | 100 | 1970-01-01 00:00:00 | 00:00:00 | 00:00:00 | 00:00:00 | {} + 3 | 1 | 1 | 3 | 4 | 100 | 1970-01-01 00:21:39 | 00:21:39 | 00:00:00 | 00:00:00 | {} + 4 | 1 | 1 | 4 | 6 | -1 | 1970-01-01 00:21:39 | 00:21:39 | 00:00:00 | 00:00:00 | {} (4 rows) --- q3 +/* -- q3 */ ROLLBACK; ROLLBACK diff --git a/docqueries/vroom/doc-vrp_vroomShipments.test.sql b/docqueries/vroom/doc-vrp_vroomShipments.test.sql index 71fc684a6..d7ad0754f 100644 --- a/docqueries/vroom/doc-vrp_vroomShipments.test.sql +++ b/docqueries/vroom/doc-vrp_vroomShipments.test.sql @@ -1,4 +1,17 @@ -\echo -- q1 +/* -- q0 */ +ALTER TABLE vroom.jobs ALTER COLUMN service TYPE INTERVAL USING make_interval(secs => service); +ALTER TABLE vroom.shipments ALTER COLUMN p_service TYPE INTERVAL USING make_interval(secs => p_service); +ALTER TABLE vroom.shipments ALTER COLUMN d_service TYPE INTERVAL USING make_interval(secs => d_service); +ALTER TABLE vroom.vehicles ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.vehicles ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.breaks ALTER COLUMN service TYPE INTERVAL USING make_interval(secs => service); +ALTER TABLE vroom.jobs_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.jobs_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.shipments_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.shipments_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +/* -- q1 */ SELECT * FROM vrp_vroomShipments( 'SELECT * FROM vroom.shipments', @@ -8,7 +21,7 @@ FROM vrp_vroomShipments( 'SELECT * FROM vroom.breaks_time_windows', 'SELECT * FROM vroom.matrix' ); -\echo -- q2 +/* -- q2 */ SELECT * FROM vrp_vroomShipments( $shipments$ @@ -33,4 +46,4 @@ FROM vrp_vroomShipments( ) AS C(start_vid, end_vid, agg_cost) $matrix$ ); -\echo -- q3 +/* -- q3 */ diff --git a/docqueries/vroom/doc-vrp_vroomShipmentsPlain.result b/docqueries/vroom/doc-vrp_vroomShipmentsPlain.result new file mode 100644 index 000000000..e6d4e89b9 --- /dev/null +++ b/docqueries/vroom/doc-vrp_vroomShipmentsPlain.result @@ -0,0 +1,70 @@ +BEGIN; +BEGIN +SET client_min_messages TO NOTICE; +SET +/* -- q1 */ +SELECT * +FROM vrp_vroomShipmentsPlain( + 'SELECT * FROM vroom.shipments', + 'SELECT * FROM vroom.shipments_time_windows', + 'SELECT * FROM vroom.vehicles', + 'SELECT * FROM vroom.breaks', + 'SELECT * FROM vroom.breaks_time_windows', + 'SELECT * FROM vroom.matrix' +); + seq | vehicle_seq | vehicle_id | step_seq | step_type | task_id | arrival | travel_time | service_time | waiting_time | load +-----+-------------+------------+----------+-----------+---------+---------+-------------+--------------+--------------+------ + 1 | 1 | 1 | 1 | 1 | -1 | 300 | 0 | 0 | 0 | {0} + 2 | 1 | 1 | 2 | 5 | 1 | 300 | 0 | 0 | 0 | {0} + 3 | 1 | 1 | 3 | 3 | 4 | 300 | 0 | 2250 | 6075 | {20} + 4 | 1 | 1 | 4 | 4 | 4 | 8700 | 75 | 2250 | 225 | {0} + 5 | 1 | 1 | 5 | 3 | 5 | 11265 | 165 | 2250 | 2085 | {10} + 6 | 1 | 1 | 6 | 3 | 3 | 15650 | 215 | 2250 | 0 | {30} + 7 | 1 | 1 | 7 | 4 | 5 | 17950 | 265 | 2250 | 225 | {20} + 8 | 1 | 1 | 8 | 4 | 3 | 20425 | 265 | 2250 | 200 | {0} + 9 | 1 | 1 | 9 | 6 | -1 | 22925 | 315 | 0 | 0 | {0} + 10 | 2 | 4 | 1 | 1 | -1 | 250 | 0 | 0 | 0 | {0} + 11 | 2 | 4 | 2 | 5 | 4 | 250 | 0 | 0 | 0 | {0} + 12 | 2 | 4 | 3 | 3 | 2 | 275 | 25 | 2250 | 100 | {10} + 13 | 2 | 4 | 4 | 3 | 1 | 2650 | 50 | 2250 | 0 | {20} + 14 | 2 | 4 | 5 | 4 | 2 | 4990 | 140 | 2250 | 0 | {10} + 15 | 2 | 4 | 6 | 4 | 1 | 7351 | 251 | 2250 | 17574 | {0} + 16 | 2 | 4 | 7 | 6 | -1 | 27200 | 276 | 0 | 0 | {0} +(16 rows) + +/* -- q2 */ +SELECT * +FROM vrp_vroomShipmentsPlain( + $shipments$ + SELECT * FROM ( + VALUES (100, 1, 4) + ) AS C(id, p_location_index, d_location_index) + $shipments$, + NULL, + $vehicles$ + SELECT * FROM ( + VALUES (1, 1, 4) + ) AS C(id, start_index, end_index) + $vehicles$, + NULL, + NULL, + $matrix$ + SELECT * FROM ( + VALUES (1, 2, 2104), (1, 3, 197), (1, 4, 1299), + (2, 1, 2103), (2, 3, 2255), (2, 4, 3152), + (3, 1, 197), (3, 2, 2256), (3, 4, 1102), + (4, 1, 1299), (4, 2, 3153), (4, 3, 1102) + ) AS C(start_vid, end_vid, agg_cost) + $matrix$ +); + seq | vehicle_seq | vehicle_id | step_seq | step_type | task_id | arrival | travel_time | service_time | waiting_time | load +-----+-------------+------------+----------+-----------+---------+---------+-------------+--------------+--------------+------ + 1 | 1 | 1 | 1 | 1 | -1 | 0 | 0 | 0 | 0 | {} + 2 | 1 | 1 | 2 | 3 | 100 | 0 | 0 | 0 | 0 | {} + 3 | 1 | 1 | 3 | 4 | 100 | 1299 | 1299 | 0 | 0 | {} + 4 | 1 | 1 | 4 | 6 | -1 | 1299 | 1299 | 0 | 0 | {} +(4 rows) + +/* -- q3 */ +ROLLBACK; +ROLLBACK diff --git a/docqueries/vroom/doc-vrp_vroomShipmentsPlain.test.sql b/docqueries/vroom/doc-vrp_vroomShipmentsPlain.test.sql new file mode 100644 index 000000000..ba20c6937 --- /dev/null +++ b/docqueries/vroom/doc-vrp_vroomShipmentsPlain.test.sql @@ -0,0 +1,36 @@ +/* -- q1 */ +SELECT * +FROM vrp_vroomShipmentsPlain( + 'SELECT * FROM vroom.shipments', + 'SELECT * FROM vroom.shipments_time_windows', + 'SELECT * FROM vroom.vehicles', + 'SELECT * FROM vroom.breaks', + 'SELECT * FROM vroom.breaks_time_windows', + 'SELECT * FROM vroom.matrix' +); +/* -- q2 */ +SELECT * +FROM vrp_vroomShipmentsPlain( + $shipments$ + SELECT * FROM ( + VALUES (100, 1, 4) + ) AS C(id, p_location_index, d_location_index) + $shipments$, + NULL, + $vehicles$ + SELECT * FROM ( + VALUES (1, 1, 4) + ) AS C(id, start_index, end_index) + $vehicles$, + NULL, + NULL, + $matrix$ + SELECT * FROM ( + VALUES (1, 2, 2104), (1, 3, 197), (1, 4, 1299), + (2, 1, 2103), (2, 3, 2255), (2, 4, 3152), + (3, 1, 197), (3, 2, 2256), (3, 4, 1102), + (4, 1, 1299), (4, 2, 3153), (4, 3, 1102) + ) AS C(start_vid, end_vid, agg_cost) + $matrix$ +); +/* -- q3 */ diff --git a/docqueries/vroom/test.conf b/docqueries/vroom/test.conf index 8cd4cabd0..7f7210a44 100644 --- a/docqueries/vroom/test.conf +++ b/docqueries/vroom/test.conf @@ -8,11 +8,17 @@ doc-vrp_vroom doc-vrp_vroomJobs doc-vrp_vroomShipments + doc-vrp_vroomPlain + doc-vrp_vroomJobsPlain + doc-vrp_vroomShipmentsPlain )], 'documentation' => [qw( doc-vrp_vroom doc-vrp_vroomJobs doc-vrp_vroomShipments + doc-vrp_vroomPlain + doc-vrp_vroomJobsPlain + doc-vrp_vroomShipmentsPlain )] }, diff --git a/include/c_common/vroom/breaks_input.h b/include/c_common/vroom/breaks_input.h index 9ced90937..7dec72a15 100644 --- a/include/c_common/vroom/breaks_input.h +++ b/include/c_common/vroom/breaks_input.h @@ -46,6 +46,7 @@ void get_vroom_breaks( char *breaks_sql, Vroom_break_t **breaks, - size_t *total_breaks); + size_t *total_breaks, + bool is_plain); #endif // INCLUDE_C_COMMON_VROOM_BREAKS_INPUT_H_ diff --git a/include/c_common/vroom/jobs_input.h b/include/c_common/vroom/jobs_input.h index 8cc5a51ac..9c4e33076 100644 --- a/include/c_common/vroom/jobs_input.h +++ b/include/c_common/vroom/jobs_input.h @@ -46,6 +46,7 @@ void get_vroom_jobs( char *jobs_sql, Vroom_job_t **jobs, - size_t *total_jobs); + size_t *total_jobs, + bool is_plain); #endif // INCLUDE_C_COMMON_VROOM_JOBS_INPUT_H_ diff --git a/include/c_common/vroom/shipments_input.h b/include/c_common/vroom/shipments_input.h index 22bc7fa06..7cf074e48 100644 --- a/include/c_common/vroom/shipments_input.h +++ b/include/c_common/vroom/shipments_input.h @@ -46,6 +46,7 @@ void get_vroom_shipments( char *shipments_sql, Vroom_shipment_t **shipments, - size_t *total_shipments); + size_t *total_shipments, + bool is_plain); #endif // INCLUDE_C_COMMON_VROOM_SHIPMENTS_INPUT_H_ diff --git a/include/c_common/vroom/time_windows_input.h b/include/c_common/vroom/time_windows_input.h index a252a0d43..1ffa8bc16 100644 --- a/include/c_common/vroom/time_windows_input.h +++ b/include/c_common/vroom/time_windows_input.h @@ -47,13 +47,15 @@ void get_vroom_time_windows( char *time_windows_sql, Vroom_time_window_t **time_windows, - size_t *total_time_windows); + size_t *total_time_windows, + bool is_plain); /** @brief Reads the VROOM shipments time windows */ void get_vroom_shipments_time_windows( char *time_windows_sql, Vroom_time_window_t **time_windows, - size_t *total_time_windows); + size_t *total_time_windows, + bool is_plain); #endif // INCLUDE_C_COMMON_VROOM_TIME_WINDOWS_INPUT_H_ diff --git a/include/c_common/vroom/vehicles_input.h b/include/c_common/vroom/vehicles_input.h index 298f2a7c5..851b15392 100644 --- a/include/c_common/vroom/vehicles_input.h +++ b/include/c_common/vroom/vehicles_input.h @@ -46,6 +46,7 @@ void get_vroom_vehicles( char *vehicles_sql, Vroom_vehicle_t **vehicles, - size_t *total_vehicles); + size_t *total_vehicles, + bool is_plain); #endif // INCLUDE_C_COMMON_VROOM_VEHICLES_INPUT_H_ diff --git a/pgtap/vroom/edge_cases.sql b/pgtap/vroom/edge_cases.sql index 39bb24f3f..8a3af4711 100644 --- a/pgtap/vroom/edge_cases.sql +++ b/pgtap/vroom/edge_cases.sql @@ -44,7 +44,7 @@ BEGIN PREPARE empty_matrix AS SELECT * FROM matrix WHERE start_vid = -1; PREPARE vroom_sql AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', 'shipments', @@ -59,7 +59,7 @@ BEGIN -- tests for no jobs/shipments, no vehicles, or no matrix PREPARE no_jobs_and_shipments AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'empty_jobs', 'jobs_time_windows', 'empty_shipments', @@ -73,7 +73,7 @@ BEGIN SELECT is_empty('no_jobs_and_shipments', 'Problem with no jobs and shipments'); PREPARE no_vehicles AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', 'shipments', @@ -87,7 +87,7 @@ BEGIN SELECT is_empty('no_vehicles', 'Problem with no vehicles'); PREPARE no_matrix AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', 'shipments', @@ -104,7 +104,7 @@ BEGIN -- priority range test (jobs) PREPARE jobs_neg_priority AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'SELECT id, location_index, service, delivery, pickup, skills, -1 AS priority FROM jobs', 'jobs_time_windows', 'shipments', @@ -123,7 +123,7 @@ BEGIN ); PREPARE jobs_101_priority AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'SELECT id, location_index, service, delivery, pickup, skills, 101 AS priority FROM jobs', 'jobs_time_windows', 'shipments', @@ -142,7 +142,7 @@ BEGIN ); PREPARE jobs_zero_priority AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'SELECT id, location_index, service, delivery, pickup, skills, 0 AS priority FROM jobs', 'jobs_time_windows', 'shipments', @@ -156,7 +156,7 @@ BEGIN SELECT lives_ok('jobs_zero_priority', 'Problem with 0 priority jobs'); PREPARE jobs_100_priority AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'SELECT id, location_index, service, delivery, pickup, skills, 0 AS priority FROM jobs', 'jobs_time_windows', 'shipments', @@ -173,7 +173,7 @@ BEGIN -- priority range tests (shipments) PREPARE shipments_neg_priority AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', 'SELECT id, p_location_index, p_service, d_location_index, d_service, @@ -193,7 +193,7 @@ BEGIN ); PREPARE shipments_101_priority AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', 'SELECT id, p_location_index, p_service, d_location_index, d_service, @@ -213,7 +213,7 @@ BEGIN ); PREPARE shipments_zero_priority AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', 'SELECT id, p_location_index, p_service, d_location_index, d_service, @@ -228,7 +228,7 @@ BEGIN SELECT lives_ok('shipments_zero_priority', 'Problem with 0 priority shipments'); PREPARE shipments_100_priority AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', 'SELECT id, p_location_index, p_service, d_location_index, d_service, @@ -246,7 +246,7 @@ BEGIN -- Missing id on matrix test PREPARE missing_id_on_matrix AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', 'shipments', @@ -265,7 +265,7 @@ BEGIN ); PREPARE missing_same_vid_on_matrix AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', 'shipments', @@ -279,7 +279,7 @@ BEGIN SELECT set_eq('missing_same_vid_on_matrix', 'vroom_sql', 'Cost between same vertex is always 0'); PREPARE missing_reverse_cost_on_matrix AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', 'shipments', @@ -299,7 +299,7 @@ BEGIN PREPARE jobs_invalid_tw AS SELECT id, 3001 AS tw_open, 3000 AS tw_close FROM jobs_time_windows; PREPARE jobs_equal_tw_problem AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_equal_tw', 'shipments', @@ -313,7 +313,7 @@ BEGIN SELECT lives_ok('jobs_equal_tw_problem', 'Problem with jobs having equal time windows'); PREPARE jobs_invalid_tw_problem AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_invalid_tw', 'shipments', @@ -338,7 +338,7 @@ BEGIN PREPARE shipments_invalid_tw AS SELECT id, kind, 3001 AS tw_open, 3000 AS tw_close FROM shipments_time_windows; PREPARE shipments_equal_tw_problem AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', 'shipments', @@ -352,7 +352,7 @@ BEGIN SELECT lives_ok('shipments_equal_tw_problem', 'Problem with shipments having equal time windows'); PREPARE shipments_invalid_tw_problem AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', 'shipments', @@ -377,7 +377,7 @@ BEGIN PREPARE breaks_invalid_tw AS SELECT id, 3001 AS tw_open, 3000 AS tw_close FROM breaks_time_windows; PREPARE breaks_equal_tw_problem AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', 'shipments', @@ -391,7 +391,7 @@ BEGIN SELECT lives_ok('breaks_equal_tw_problem', 'Problem with breaks having equal time windows'); PREPARE breaks_invalid_tw_problem AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', 'shipments', @@ -418,7 +418,7 @@ BEGIN SELECT id, start_index, end_index, capacity, skills, 3001 AS tw_open, 3000 AS tw_close, speed_factor FROM vehicles; PREPARE vehicles_equal_tw_problem AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', 'shipments', @@ -432,7 +432,7 @@ BEGIN SELECT lives_ok('vehicles_equal_tw_problem', 'Problem with vehicles having equal time windows'); PREPARE vehicles_invalid_tw_problem AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', 'shipments', @@ -456,7 +456,7 @@ BEGIN PREPARE jobs_only_delivery AS SELECT id, location_index, service, delivery, skills, priority FROM jobs; PREPARE jobs_only_pickup AS SELECT id, location_index, service, pickup, skills, priority FROM jobs; PREPARE jobs_only_delivery_problem AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs_only_delivery', 'jobs_time_windows', 'shipments', @@ -467,7 +467,7 @@ BEGIN 'matrix' ); PREPARE jobs_only_pickup_problem AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs_only_pickup', 'jobs_time_windows', 'shipments', @@ -486,7 +486,7 @@ BEGIN PREPARE vehicles_only_start_index AS SELECT id, start_index, capacity, skills, tw_open, tw_close, speed_factor FROM vehicles; PREPARE vehicles_only_end_index AS SELECT id, end_index, capacity, skills, tw_open, tw_close, speed_factor FROM vehicles; PREPARE vehicles_only_start_index_problem AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', 'shipments', @@ -497,7 +497,7 @@ BEGIN 'matrix' ); PREPARE vehicles_only_end_index_problem AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', 'shipments', @@ -515,7 +515,7 @@ BEGIN PREPARE vehicles_no_index AS SELECT id, capacity, skills, tw_open, tw_close, speed_factor FROM vehicles; PREPARE vehicles_no_index_problem AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', 'shipments', @@ -546,7 +546,7 @@ BEGIN SELECT id, start_index, end_index, ARRAY[10, 20]::BIGINT[] AS capacity, skills, tw_open, tw_close, speed_factor FROM vehicles; PREPARE jobs_inconsistent_delivery_problem AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs_inconsistent_delivery', 'jobs_time_windows', 'shipments', @@ -557,7 +557,7 @@ BEGIN 'matrix' ); PREPARE jobs_inconsistent_pickup_problem AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs_inconsistent_pickup', 'jobs_time_windows', 'shipments', @@ -568,7 +568,7 @@ BEGIN 'matrix' ); PREPARE shipments_inconsistent_amount_problem AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', 'shipments_inconsistent_amount', @@ -579,7 +579,7 @@ BEGIN 'matrix' ); PREPARE vehicles_inconsistent_capacity_problem AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', 'shipments', @@ -639,7 +639,7 @@ BEGIN SELECT start_vid, end_vid, 4 * agg_cost AS agg_cost FROM matrix; PREPARE vehicles_2x_speed_problem AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', 'shipments', @@ -650,7 +650,7 @@ BEGIN 'matrix_2x_distance' ); PREPARE vehicles_4x_speed_problem AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'jobs', 'jobs_time_windows', 'shipments', @@ -673,7 +673,7 @@ BEGIN -- arrival, travel_time, service_time, waiting_time, load PREPARE one_job_q1 AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'SELECT * FROM jobs WHERE id = 1', 'jobs_time_windows', 'empty_shipments', @@ -696,7 +696,7 @@ BEGIN ); PREPARE one_job_q2 AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'SELECT * FROM jobs WHERE id = 5', 'jobs_time_windows', 'empty_shipments', @@ -719,7 +719,7 @@ BEGIN ); PREPARE one_shipment_q1 AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'empty_jobs', 'jobs_time_windows', 'SELECT * FROM shipments WHERE id = 1', @@ -743,7 +743,7 @@ BEGIN ); PREPARE one_shipment_q2 AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'empty_jobs', 'jobs_time_windows', 'SELECT * FROM shipments WHERE id = 5', @@ -767,7 +767,7 @@ BEGIN ); PREPARE one_job_shipment AS - SELECT * FROM vrp_vroom( + SELECT * FROM vrp_vroomPlain( 'SELECT * FROM jobs WHERE id = 2', 'jobs_time_windows', 'SELECT * FROM shipments WHERE id = 2', diff --git a/pgtap/vroom/inner_query.sql b/pgtap/vroom/inner_query.sql index a94be6995..d0a33a2de 100644 --- a/pgtap/vroom/inner_query.sql +++ b/pgtap/vroom/inner_query.sql @@ -1,10 +1,10 @@ BEGIN; SET search_path TO 'vroom', 'public'; -SELECT CASE WHEN min_version('0.2.0') THEN plan (564) ELSE plan(1) END; +SELECT CASE WHEN min_version('0.2.0') THEN plan (1099) ELSE plan(1) END; /* -SELECT * FROM vrp_vroom( +SELECT * FROM vrp_vroomPlain( $$SELECT id, location_index, service, delivery, pickup, skills, priority FROM jobs$$, $$SELECT id, tw_open, tw_close FROM jobs_time_windows$$, $$SELECT id, p_location_index, p_service, d_location_index, d_service, amount, skills, priority FROM shipments$$, @@ -114,14 +114,39 @@ RETURNS SETOF TEXT AS $BODY$ DECLARE accept TEXT[] := ARRAY['CHAR']; - reject TEXT[] := ARRAY['VARCHAR', 'TEXT']::TEXT[]; + reject TEXT[] := ARRAY['VARCHAR', 'TEXT']; BEGIN RETURN query SELECT test_value(fn, inner_query_table, start_sql, rest_sql, params, parameter, accept, reject); END; $BODY$ LANGUAGE plpgsql; -CREATE OR REPLACE FUNCTION inner_query_jobs(fn TEXT, start_sql TEXT, rest_sql TEXT) +CREATE OR REPLACE FUNCTION test_Interval(fn TEXT, inner_query_table TEXT, start_sql TEXT, rest_sql TEXT, params TEXT[], parameter TEXT) +RETURNS SETOF TEXT AS +$BODY$ +DECLARE + accept TEXT[] := ARRAY['INTERVAL']; + reject TEXT[] := ARRAY['TIMESTAMP', 'DATE', 'TIME', 'INTEGER']; +BEGIN + RETURN query SELECT test_value(fn, inner_query_table, start_sql, rest_sql, params, parameter, accept, reject); +END; +$BODY$ LANGUAGE plpgsql; + + +CREATE OR REPLACE FUNCTION test_Timestamp(fn TEXT, inner_query_table TEXT, start_sql TEXT, rest_sql TEXT, params TEXT[], parameter TEXT) +RETURNS SETOF TEXT AS +$BODY$ +DECLARE + accept TEXT[] := ARRAY['TIMESTAMP']; + reject TEXT[] := ARRAY['INTERVAL', 'DATE', 'TIME', 'INTEGER']; +BEGIN + RETURN query SELECT test_value(fn, inner_query_table, start_sql, rest_sql, params, parameter, accept, reject); +END; +$BODY$ LANGUAGE plpgsql; + + + +CREATE OR REPLACE FUNCTION inner_query_jobs(fn TEXT, start_sql TEXT, rest_sql TEXT, is_plain BOOLEAN) RETURNS SETOF TEXT AS $BODY$ DECLARE @@ -130,17 +155,21 @@ DECLARE BEGIN RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'id'); RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'location_index'); - RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'service'); RETURN QUERY SELECT test_anyArrayInteger(fn, inner_query_table, start_sql, rest_sql, params, 'delivery'); RETURN QUERY SELECT test_anyArrayInteger(fn, inner_query_table, start_sql, rest_sql, params, 'pickup'); RETURN QUERY SELECT test_arrayInteger(fn, inner_query_table, start_sql, rest_sql, params, 'skills'); RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'priority'); + IF is_plain = TRUE THEN + RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'service'); + ELSE + RETURN QUERY SELECT test_Interval(fn, inner_query_table, start_sql, rest_sql, params, 'service'); + END IF; END; $BODY$ LANGUAGE plpgsql; -CREATE OR REPLACE FUNCTION inner_query_shipments(fn TEXT, start_sql TEXT, rest_sql TEXT) +CREATE OR REPLACE FUNCTION inner_query_shipments(fn TEXT, start_sql TEXT, rest_sql TEXT, is_plain BOOLEAN) RETURNS SETOF TEXT AS $BODY$ DECLARE @@ -150,17 +179,22 @@ BEGIN RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'id'); RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'p_location_index'); RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'd_location_index'); - RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'p_service'); - RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'd_service'); RETURN QUERY SELECT test_anyArrayInteger(fn, inner_query_table, start_sql, rest_sql, params, 'amount'); RETURN QUERY SELECT test_arrayInteger(fn, inner_query_table, start_sql, rest_sql, params, 'skills'); RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'priority'); + IF is_plain = TRUE THEN + RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'p_service'); + RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'd_service'); + ELSE + RETURN QUERY SELECT test_Interval(fn, inner_query_table, start_sql, rest_sql, params, 'p_service'); + RETURN QUERY SELECT test_Interval(fn, inner_query_table, start_sql, rest_sql, params, 'd_service'); + END IF; END; $BODY$ LANGUAGE plpgsql; -CREATE OR REPLACE FUNCTION inner_query_vehicles(fn TEXT, start_sql TEXT, rest_sql TEXT) +CREATE OR REPLACE FUNCTION inner_query_vehicles(fn TEXT, start_sql TEXT, rest_sql TEXT, is_plain BOOLEAN) RETURNS SETOF TEXT AS $BODY$ DECLARE @@ -172,15 +206,20 @@ BEGIN RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'end_index'); RETURN QUERY SELECT test_anyArrayInteger(fn, inner_query_table, start_sql, rest_sql, params, 'capacity'); RETURN QUERY SELECT test_arrayInteger(fn, inner_query_table, start_sql, rest_sql, params, 'skills'); - RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'tw_open'); - RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'tw_close'); RETURN QUERY SELECT test_anyNumerical(fn, inner_query_table, start_sql, rest_sql, params, 'speed_factor'); + IF is_plain = TRUE THEN + RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'tw_open'); + RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'tw_close'); + ELSE + RETURN QUERY SELECT test_Timestamp(fn, inner_query_table, start_sql, rest_sql, params, 'tw_open'); + RETURN QUERY SELECT test_Timestamp(fn, inner_query_table, start_sql, rest_sql, params, 'tw_close'); + END IF; END; $BODY$ LANGUAGE plpgsql; -CREATE OR REPLACE FUNCTION inner_query_matrix(fn TEXT, start_sql TEXT, rest_sql TEXT) +CREATE OR REPLACE FUNCTION inner_query_matrix(fn TEXT, start_sql TEXT, rest_sql TEXT, is_plain BOOLEAN) RETURNS SETOF TEXT AS $BODY$ DECLARE @@ -195,7 +234,7 @@ $BODY$ LANGUAGE plpgsql; -CREATE OR REPLACE FUNCTION inner_query_breaks(fn TEXT, start_sql TEXT, rest_sql TEXT) +CREATE OR REPLACE FUNCTION inner_query_breaks(fn TEXT, start_sql TEXT, rest_sql TEXT, is_plain BOOLEAN) RETURNS SETOF TEXT AS $BODY$ DECLARE @@ -204,27 +243,36 @@ DECLARE BEGIN RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'id'); RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'vehicle_id'); - RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'service'); + IF is_plain = TRUE THEN + RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'service'); + ELSE + RETURN QUERY SELECT test_Interval(fn, inner_query_table, start_sql, rest_sql, params, 'service'); + END IF; END; $BODY$ LANGUAGE plpgsql; -CREATE OR REPLACE FUNCTION inner_query_time_windows(fn TEXT, inner_query_table TEXT, start_sql TEXT, rest_sql TEXT) +CREATE OR REPLACE FUNCTION inner_query_time_windows(fn TEXT, inner_query_table TEXT, start_sql TEXT, rest_sql TEXT, is_plain BOOLEAN) RETURNS SETOF TEXT AS $BODY$ DECLARE params TEXT[] := ARRAY['id', 'tw_open', 'tw_close']; BEGIN RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'id'); - RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'tw_open'); - RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'tw_close'); + IF is_plain = TRUE THEN + RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'tw_open'); + RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'tw_close'); + ELSE + RETURN QUERY SELECT test_Timestamp(fn, inner_query_table, start_sql, rest_sql, params, 'tw_open'); + RETURN QUERY SELECT test_Timestamp(fn, inner_query_table, start_sql, rest_sql, params, 'tw_close'); + END IF; END; $BODY$ LANGUAGE plpgsql; -CREATE OR REPLACE FUNCTION inner_query_shipments_time_windows(fn TEXT, inner_query_table TEXT, start_sql TEXT, rest_sql TEXT) +CREATE OR REPLACE FUNCTION inner_query_shipments_time_windows(fn TEXT, inner_query_table TEXT, start_sql TEXT, rest_sql TEXT, is_plain BOOLEAN) RETURNS SETOF TEXT AS $BODY$ DECLARE @@ -232,14 +280,19 @@ DECLARE BEGIN RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'id'); RETURN QUERY SELECT test_Char(fn, inner_query_table, start_sql, rest_sql, params, 'kind'); - RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'tw_open'); - RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'tw_close'); + IF is_plain = TRUE THEN + RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'tw_open'); + RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'tw_close'); + ELSE + RETURN QUERY SELECT test_Timestamp(fn, inner_query_table, start_sql, rest_sql, params, 'tw_open'); + RETURN QUERY SELECT test_Timestamp(fn, inner_query_table, start_sql, rest_sql, params, 'tw_close'); + END IF; END; $BODY$ LANGUAGE plpgsql; -CREATE OR REPLACE FUNCTION inner_query() +CREATE OR REPLACE FUNCTION inner_query(is_plain BOOLEAN) RETURNS SETOF TEXT AS $BODY$ DECLARE @@ -257,132 +310,161 @@ BEGIN -- vrp_vroom - fn := 'vrp_vroom'; + IF is_plain = TRUE THEN + fn := 'vrp_vroomPlain'; + ELSE + fn := 'vrp_vroom'; + END IF; start_sql := ''; rest_sql := ', $$SELECT * FROM jobs_time_windows$$, $$SELECT * FROM shipments$$, $$SELECT * FROM shipments_time_windows$$, ' || '$$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$, ' || '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; - RETURN QUERY SELECT inner_query_jobs(fn, start_sql, rest_sql); + RETURN QUERY SELECT inner_query_jobs(fn, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM jobs$$, '; rest_sql := ', $$SELECT * FROM shipments$$, $$SELECT * FROM shipments_time_windows$$, ' || '$$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$, ' || '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; inner_query_table := 'jobs_time_windows'; - RETURN QUERY SELECT inner_query_time_windows(fn, inner_query_table, start_sql, rest_sql); + RETURN QUERY SELECT inner_query_time_windows(fn, inner_query_table, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM jobs$$, $$SELECT * FROM jobs_time_windows$$, '; rest_sql := ', $$SELECT * FROM shipments_time_windows$$, ' || '$$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$, ' || '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; - RETURN QUERY SELECT inner_query_shipments(fn, start_sql, rest_sql); + RETURN QUERY SELECT inner_query_shipments(fn, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM jobs$$, $$SELECT * FROM jobs_time_windows$$, $$SELECT * FROM shipments$$, '; rest_sql := ', $$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$, ' || '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; inner_query_table := 'shipments_time_windows'; - RETURN QUERY SELECT inner_query_shipments_time_windows(fn, inner_query_table, start_sql, rest_sql); + RETURN QUERY SELECT inner_query_shipments_time_windows(fn, inner_query_table, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM jobs$$, $$SELECT * FROM jobs_time_windows$$, $$SELECT * FROM shipments$$, ' || '$$SELECT * FROM shipments_time_windows$$, '; rest_sql := ', $$SELECT * FROM breaks$$, ' || '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; - RETURN QUERY SELECT inner_query_vehicles(fn, start_sql, rest_sql); + RETURN QUERY SELECT inner_query_vehicles(fn, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM jobs$$, $$SELECT * FROM jobs_time_windows$$, $$SELECT * FROM shipments$$, ' || '$$SELECT * FROM shipments_time_windows$$, $$SELECT * FROM vehicles$$, '; rest_sql := ', $$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; - RETURN QUERY SELECT inner_query_breaks(fn, start_sql, rest_sql); + RETURN QUERY SELECT inner_query_breaks(fn, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM jobs$$, $$SELECT * FROM jobs_time_windows$$, $$SELECT * FROM shipments$$, ' || '$$SELECT * FROM shipments_time_windows$$, $$SELECT * FROM vehicles$$, ' || '$$SELECT * FROM breaks$$, '; rest_sql := ', $$SELECT * FROM matrix$$)'; inner_query_table := 'breaks_time_windows'; - RETURN QUERY SELECT inner_query_time_windows(fn, inner_query_table, start_sql, rest_sql); + RETURN QUERY SELECT inner_query_time_windows(fn, inner_query_table, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM jobs$$, $$SELECT * FROM jobs_time_windows$$, $$SELECT * FROM shipments$$, ' || '$$SELECT * FROM shipments_time_windows$$, $$SELECT * FROM vehicles$$, ' || '$$SELECT * FROM breaks$$, $$SELECT * FROM breaks_time_windows$$, '; rest_sql := ')'; - RETURN QUERY SELECT inner_query_matrix(fn, start_sql, rest_sql); + RETURN QUERY SELECT inner_query_matrix(fn, start_sql, rest_sql, is_plain); -- vrp_vroomJobs - fn := 'vrp_vroomJobs'; + IF is_plain = TRUE THEN + fn := 'vrp_vroomJobsPlain'; + ELSE + fn := 'vrp_vroomJobs'; + END IF; start_sql := ''; rest_sql := ', $$SELECT * FROM jobs_time_windows$$, $$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$, ' || '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; - RETURN QUERY SELECT inner_query_jobs(fn, start_sql, rest_sql); + RETURN QUERY SELECT inner_query_jobs(fn, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM jobs$$, '; rest_sql := ', $$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$, ' || '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; inner_query_table := 'jobs_time_windows'; - RETURN QUERY SELECT inner_query_time_windows(fn, inner_query_table, start_sql, rest_sql); + RETURN QUERY SELECT inner_query_time_windows(fn, inner_query_table, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM jobs$$, $$SELECT * FROM jobs_time_windows$$, '; rest_sql := ', $$SELECT * FROM breaks$$, ' || '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; - RETURN QUERY SELECT inner_query_vehicles(fn, start_sql, rest_sql); + RETURN QUERY SELECT inner_query_vehicles(fn, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM jobs$$, $$SELECT * FROM jobs_time_windows$$, ' || '$$SELECT * FROM vehicles$$, '; rest_sql := ', $$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; - RETURN QUERY SELECT inner_query_breaks(fn, start_sql, rest_sql); + RETURN QUERY SELECT inner_query_breaks(fn, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM jobs$$, $$SELECT * FROM jobs_time_windows$$, ' || '$$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$, '; rest_sql := ', $$SELECT * FROM matrix$$)'; inner_query_table := 'breaks_time_windows'; - RETURN QUERY SELECT inner_query_time_windows(fn, inner_query_table, start_sql, rest_sql); + RETURN QUERY SELECT inner_query_time_windows(fn, inner_query_table, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM jobs$$, $$SELECT * FROM jobs_time_windows$$, ' || '$$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$, $$SELECT * FROM breaks_time_windows$$, '; rest_sql := ')'; - RETURN QUERY SELECT inner_query_matrix(fn, start_sql, rest_sql); + RETURN QUERY SELECT inner_query_matrix(fn, start_sql, rest_sql, is_plain); -- vrp_vroomShipments - fn := 'vrp_vroomShipments'; + IF is_plain = TRUE THEN + fn := 'vrp_vroomShipmentsPlain'; + ELSE + fn := 'vrp_vroomShipments'; + END IF; start_sql := ''; rest_sql := ', $$SELECT * FROM shipments_time_windows$$, $$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$, ' || '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; - RETURN QUERY SELECT inner_query_shipments(fn, start_sql, rest_sql); + RETURN QUERY SELECT inner_query_shipments(fn, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM shipments$$, '; rest_sql := ', $$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$, ' || '$$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; inner_query_table := 'shipments_time_windows'; - RETURN QUERY SELECT inner_query_shipments_time_windows(fn, inner_query_table, start_sql, rest_sql); + RETURN QUERY SELECT inner_query_shipments_time_windows(fn, inner_query_table, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM shipments$$, $$SELECT * FROM shipments_time_windows$$, '; rest_sql := ', $$SELECT * FROM breaks$$, $$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; - RETURN QUERY SELECT inner_query_vehicles(fn, start_sql, rest_sql); + RETURN QUERY SELECT inner_query_vehicles(fn, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM shipments$$, $$SELECT * FROM shipments_time_windows$$, ' || '$$SELECT * FROM vehicles$$, '; rest_sql := ', $$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; - RETURN QUERY SELECT inner_query_breaks(fn, start_sql, rest_sql); + RETURN QUERY SELECT inner_query_breaks(fn, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM shipments$$, $$SELECT * FROM shipments_time_windows$$, ' || '$$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$, '; rest_sql := ', $$SELECT * FROM matrix$$)'; inner_query_table := 'breaks_time_windows'; - RETURN QUERY SELECT inner_query_time_windows(fn, inner_query_table, start_sql, rest_sql); + RETURN QUERY SELECT inner_query_time_windows(fn, inner_query_table, start_sql, rest_sql, is_plain); start_sql := '$$SELECT * FROM shipments$$, $$SELECT * FROM shipments_time_windows$$, ' || '$$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$, $$SELECT * FROM breaks_time_windows$$, '; rest_sql := ')'; - RETURN QUERY SELECT inner_query_matrix(fn, start_sql, rest_sql); + RETURN QUERY SELECT inner_query_matrix(fn, start_sql, rest_sql, is_plain); + END; $BODY$ LANGUAGE plpgsql; -SELECT inner_query(); +SELECT inner_query(is_plain => TRUE); + +-- Adjust the column types to the expected types for vroom functions with timestamps/interval +ALTER TABLE vroom.jobs ALTER COLUMN service TYPE INTERVAL USING make_interval(secs => service); +ALTER TABLE vroom.shipments ALTER COLUMN p_service TYPE INTERVAL USING make_interval(secs => p_service); +ALTER TABLE vroom.shipments ALTER COLUMN d_service TYPE INTERVAL USING make_interval(secs => d_service); +ALTER TABLE vroom.vehicles ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.vehicles ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.breaks ALTER COLUMN service TYPE INTERVAL USING make_interval(secs => service); +ALTER TABLE vroom.jobs_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.jobs_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.shipments_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.shipments_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; + +SELECT inner_query(is_plain => FALSE); SELECT * FROM finish(); ROLLBACK; diff --git a/pgtap/vroom/no_crash_test.sql b/pgtap/vroom/no_crash_test.sql index f9e779b5a..c8db335e2 100644 --- a/pgtap/vroom/no_crash_test.sql +++ b/pgtap/vroom/no_crash_test.sql @@ -2,18 +2,9 @@ BEGIN; SET search_path TO 'vroom', 'public'; SET client_min_messages TO ERROR; -SELECT CASE WHEN min_version('0.2.0') THEN plan (46) ELSE plan(1) END; - -PREPARE jobs AS SELECT * FROM jobs; -PREPARE jobs_time_windows AS SELECT * FROM jobs_time_windows; -PREPARE shipments AS SELECT * FROM shipments; -PREPARE shipments_time_windows AS SELECT * FROM shipments_time_windows; -PREPARE vehicles AS SELECT * FROM vehicles; -PREPARE breaks AS SELECT * FROM breaks; -PREPARE breaks_time_windows AS SELECT * FROM breaks_time_windows; -PREPARE matrix AS SELECT * FROM matrix; - -CREATE OR REPLACE FUNCTION no_crash() +SELECT CASE WHEN min_version('0.2.0') THEN plan (92) ELSE plan(1) END; + +CREATE OR REPLACE FUNCTION no_crash(is_plain BOOLEAN) RETURNS SETOF TEXT AS $BODY$ DECLARE @@ -28,6 +19,15 @@ BEGIN RETURN; END IF; + PREPARE jobs AS SELECT * FROM jobs; + PREPARE jobs_time_windows AS SELECT * FROM jobs_time_windows; + PREPARE shipments AS SELECT * FROM shipments; + PREPARE shipments_time_windows AS SELECT * FROM shipments_time_windows; + PREPARE vehicles AS SELECT * FROM vehicles; + PREPARE breaks AS SELECT * FROM breaks; + PREPARE breaks_time_windows AS SELECT * FROM breaks_time_windows; + PREPARE matrix AS SELECT * FROM matrix; + RETURN QUERY SELECT isnt_empty('jobs', 'Should be not empty to tests be meaningful'); RETURN QUERY @@ -77,7 +77,11 @@ BEGIN ]::TEXT[]; non_empty_args = ARRAY[0, 1, 2, 3, 4, 6, 7]::INTEGER[]; - RETURN query SELECT * FROM no_crash_test('vrp_vroom', params, subs, error_messages, non_empty_args); + IF is_plain = TRUE THEN + RETURN query SELECT * FROM no_crash_test('vrp_vroomPlain', params, subs, error_messages, non_empty_args); + ELSE + RETURN query SELECT * FROM no_crash_test('vrp_vroom', params, subs, error_messages, non_empty_args); + END IF; params = ARRAY[ '$$jobs$$', @@ -105,7 +109,11 @@ BEGIN ]::TEXT[]; non_empty_args = ARRAY[0, 2, 4, 5]::INTEGER[]; - RETURN query SELECT * FROM no_crash_test('vrp_vroomJobs', params, subs, error_messages, non_empty_args); + IF is_plain = TRUE THEN + RETURN query SELECT * FROM no_crash_test('vrp_vroomJobsPlain', params, subs, error_messages, non_empty_args); + ELSE + RETURN query SELECT * FROM no_crash_test('vrp_vroomJobs', params, subs, error_messages, non_empty_args); + END IF; params = ARRAY[ '$$shipments$$', @@ -133,13 +141,35 @@ BEGIN ]::TEXT[]; non_empty_args = ARRAY[0, 2, 4, 5]::INTEGER[]; - RETURN query SELECT * FROM no_crash_test('vrp_vroomShipments'::TEXT, params, subs, error_messages, non_empty_args); + IF is_plain = TRUE THEN + RETURN query SELECT * FROM no_crash_test('vrp_vroomShipmentsPlain', params, subs, error_messages, non_empty_args); + ELSE + RETURN query SELECT * FROM no_crash_test('vrp_vroomShipments', params, subs, error_messages, non_empty_args); + END IF; + + DEALLOCATE ALL; END $BODY$ LANGUAGE plpgsql VOLATILE; -SELECT * FROM no_crash(); +SELECT * FROM no_crash(is_plain => TRUE); + +-- Adjust the column types to the expected types for vroom functions with timestamps/interval +ALTER TABLE vroom.jobs ALTER COLUMN service TYPE INTERVAL USING make_interval(secs => service); +ALTER TABLE vroom.shipments ALTER COLUMN p_service TYPE INTERVAL USING make_interval(secs => p_service); +ALTER TABLE vroom.shipments ALTER COLUMN d_service TYPE INTERVAL USING make_interval(secs => d_service); +ALTER TABLE vroom.vehicles ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.vehicles ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.breaks ALTER COLUMN service TYPE INTERVAL USING make_interval(secs => service); +ALTER TABLE vroom.jobs_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.jobs_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.shipments_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.shipments_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_open TYPE TIMESTAMP USING (to_timestamp(tw_open + 1630573200) at time zone 'UTC')::TIMESTAMP; +ALTER TABLE vroom.breaks_time_windows ALTER COLUMN tw_close TYPE TIMESTAMP USING (to_timestamp(tw_close + 1630573200) at time zone 'UTC')::TIMESTAMP; + +SELECT * FROM no_crash(is_plain => FALSE); ROLLBACK; diff --git a/pgtap/vroom/types_check.sql b/pgtap/vroom/types_check.sql index 336e22672..ee296c513 100644 --- a/pgtap/vroom/types_check.sql +++ b/pgtap/vroom/types_check.sql @@ -1,7 +1,7 @@ BEGIN; SET search_path TO 'vroom', 'public'; -SELECT CASE WHEN min_version('0.2.0') THEN plan (15) ELSE plan(1) END; +SELECT CASE WHEN min_version('0.2.0') THEN plan (30) ELSE plan(1) END; CREATE OR REPLACE FUNCTION types_check() RETURNS SETOF TEXT AS @@ -14,6 +14,32 @@ BEGIN RETURN; END IF; + -- vrp_vroomPlain + RETURN QUERY + SELECT has_function('vrp_vroomplain'); + RETURN QUERY + SELECT has_function('vrp_vroomplain', ARRAY['text', 'text', 'text', 'text', 'text', 'text', 'text', 'text']); + RETURN QUERY + SELECT function_returns('vrp_vroomplain', ARRAY['text', 'text', 'text', 'text', 'text', 'text', 'text', 'text'], 'setof record'); + + -- parameter names + RETURN QUERY + SELECT bag_has( + $$SELECT proargnames from pg_proc where proname = 'vrp_vroomplain'$$, + $$SELECT '{"","","","","","","","","seq","vehicle_seq","vehicle_id","step_seq","step_type",' + '"task_id","arrival","travel_time","service_time","waiting_time","load"}'::TEXT[]$$ + ); + + -- parameter types + RETURN QUERY + SELECT set_eq( + $$SELECT proallargtypes from pg_proc where proname = 'vrp_vroomplain'$$, + $$VALUES + ('{25,25,25,25,25,25,25,25,20,20,20,20,23,20,23,23,23,23,1016}'::OID[]) + $$ + ); + + -- vrp_vroom RETURN QUERY SELECT has_function('vrp_vroom'); @@ -35,7 +61,33 @@ BEGIN SELECT set_eq( $$SELECT proallargtypes from pg_proc where proname = 'vrp_vroom'$$, $$VALUES - ('{25,25,25,25,25,25,25,25,20,20,20,20,23,20,23,23,23,23,1016}'::OID[]) + ('{25,25,25,25,25,25,25,25,20,20,20,20,23,20,1114,1186,1186,1186,1016}'::OID[]) + $$ + ); + + + -- vrp_vroomJobsPlain + RETURN QUERY + SELECT has_function('vrp_vroomjobsplain'); + RETURN QUERY + SELECT has_function('vrp_vroomjobsplain', ARRAY['text', 'text', 'text', 'text', 'text', 'text']); + RETURN QUERY + SELECT function_returns('vrp_vroomjobsplain', ARRAY['text', 'text', 'text', 'text', 'text', 'text'], 'setof record'); + + -- parameter names + RETURN QUERY + SELECT bag_has( + $$SELECT proargnames from pg_proc where proname = 'vrp_vroomjobsplain'$$, + $$SELECT '{"","","","","","","seq","vehicle_seq","vehicle_id","step_seq","step_type",' + '"task_id","arrival","travel_time","service_time","waiting_time","load"}'::TEXT[]$$ + ); + + -- parameter types + RETURN QUERY + SELECT set_eq( + $$SELECT proallargtypes from pg_proc where proname = 'vrp_vroomjobsplain'$$, + $$VALUES + ('{25,25,25,25,25,25,20,20,20,20,23,20,23,23,23,23,1016}'::OID[]) $$ ); @@ -60,6 +112,32 @@ BEGIN RETURN QUERY SELECT set_eq( $$SELECT proallargtypes from pg_proc where proname = 'vrp_vroomjobs'$$, + $$VALUES + ('{25,25,25,25,25,25,20,20,20,20,23,20,1114,1186,1186,1186,1016}'::OID[]) + $$ + ); + + + -- vrp_vroomShipmentsPlain + RETURN QUERY + SELECT has_function('vrp_vroomshipmentsplain'); + RETURN QUERY + SELECT has_function('vrp_vroomshipmentsplain', ARRAY['text', 'text', 'text', 'text', 'text', 'text']); + RETURN QUERY + SELECT function_returns('vrp_vroomshipmentsplain', ARRAY['text', 'text', 'text', 'text', 'text', 'text'], 'setof record'); + + -- parameter names + RETURN QUERY + SELECT bag_has( + $$SELECT proargnames from pg_proc where proname = 'vrp_vroomshipmentsplain'$$, + $$SELECT '{"","","","","","","seq","vehicle_seq","vehicle_id","step_seq","step_type",' + '"task_id","arrival","travel_time","service_time","waiting_time","load"}'::TEXT[]$$ + ); + + -- parameter types + RETURN QUERY + SELECT set_eq( + $$SELECT proallargtypes from pg_proc where proname = 'vrp_vroomshipmentsplain'$$, $$VALUES ('{25,25,25,25,25,25,20,20,20,20,23,20,23,23,23,23,1016}'::OID[]) $$ @@ -87,7 +165,7 @@ BEGIN SELECT set_eq( $$SELECT proallargtypes from pg_proc where proname = 'vrp_vroomshipments'$$, $$VALUES - ('{25,25,25,25,25,25,20,20,20,20,23,20,23,23,23,23,1016}'::OID[]) + ('{25,25,25,25,25,25,20,20,20,20,23,20,1114,1186,1186,1186,1016}'::OID[]) $$ ); END; diff --git a/pgtap/vroom/vroom-plain-eq-timestamp.test.sql b/pgtap/vroom/vroom-plain-eq-timestamp.test.sql new file mode 100644 index 000000000..6c9cdcc01 --- /dev/null +++ b/pgtap/vroom/vroom-plain-eq-timestamp.test.sql @@ -0,0 +1,115 @@ +BEGIN; +SET search_path TO 'vroom', 'public'; +SET client_min_messages TO ERROR; + +SELECT CASE WHEN min_version('0.2.0') THEN plan (22) ELSE plan(1) END; + +CREATE or REPLACE FUNCTION vroom_plain_eq_timestamp() +RETURNS SETOF TEXT AS +$BODY$ +DECLARE + ids BIGINT[] := ARRAY[1, 2, 3, 4, 5]; + + jobsPlain TEXT := '$$SELECT * FROM jobs'; + jobsPlain_sql TEXT; + jobs TEXT := '$$SELECT id, location_index, make_interval(secs => service) AS service, delivery, pickup, skills, priority FROM jobs'; + jobs_sql TEXT; + + shipmentsPlain TEXT := '$$SELECT * FROM shipments'; + shipmentsPlain_sql TEXT; + shipments TEXT := '$$SELECT id, p_location_index, make_interval(secs => p_service) AS p_service, ' || + 'd_location_index, make_interval(secs => d_service) AS d_service, amount, skills, priority FROM shipments'; + shipments_sql TEXT; + + jobsPlain_time_windows TEXT := '$$SELECT * FROM jobs_time_windows$$'; + jobs_time_windows TEXT := '$$SELECT id, (to_timestamp(tw_open) at time zone ''UTC'')::TIMESTAMP AS tw_open, ' || + '(to_timestamp(tw_close) at time zone ''UTC'')::TIMESTAMP AS tw_close FROM jobs_time_windows$$'; + + shipmentsPlain_time_windows TEXT := '$$SELECT * FROM shipments_time_windows$$'; + shipments_time_windows TEXT := '$$SELECT id, kind, (to_timestamp(tw_open) at time zone ''UTC'')::TIMESTAMP AS tw_open, ' || + '(to_timestamp(tw_close) at time zone ''UTC'')::TIMESTAMP AS tw_close FROM shipments_time_windows$$'; + + restPlain_sql TEXT := ', $$SELECT * FROM vehicles$$, $$SELECT * FROM breaks$$' || + ', $$SELECT * FROM breaks_time_windows$$, $$SELECT * FROM matrix$$)'; + + rest_sql TEXT := ', $$SELECT id, start_index, end_index, capacity, skills, (to_timestamp(tw_open) at time zone ''UTC'')::TIMESTAMP AS tw_open' || + ', (to_timestamp(tw_close) at time zone ''UTC'')::TIMESTAMP AS tw_close, speed_factor FROM vehicles$$' || + ', $$SELECT id, vehicle_id, make_interval(secs => service) AS service FROM breaks$$' || + ', $$SELECT id, (to_timestamp(tw_open) at time zone ''UTC'')::TIMESTAMP AS tw_open' || + ', (to_timestamp(tw_close) at time zone ''UTC'')::TIMESTAMP AS tw_close FROM breaks_time_windows$$, ' || + '$$SELECT * FROM matrix$$)'; + + returnPlain_sql TEXT := 'SELECT * FROM vrp_vroomPlain('; + return_sql TEXT := 'SELECT seq, vehicle_seq, vehicle_id, step_seq, step_type, task_id, ' || + 'EXTRACT (EPOCH FROM arrival) AS arrival, EXTRACT (EPOCH FROM travel_time) AS travel_time, ' || + 'EXTRACT (EPOCH FROM service_time) AS service_time, EXTRACT (EPOCH FROM waiting_time) AS waiting_time, ' || + 'load FROM vrp_vroom('; + + vroom_sql TEXT; + vroomPlain_sql TEXT; + id_filter TEXT; +data TEXT; +BEGIN + IF NOT min_version('0.2.0') THEN + RETURN QUERY + SELECT skip(1, 'Function is new on 0.2.0'); + RETURN; + END IF; + + -- Two jobs and shipments + FOR i in 1..array_length(ids, 1) LOOP + FOR j in (i+1)..array_length(ids, 1) LOOP + id_filter := ' WHERE id in (' || i || ', ' || j || ')$$, '; + jobs_sql := jobs || id_filter || jobs_time_windows; + shipments_sql := shipments || id_filter || shipments_time_windows; + vroom_sql := return_sql || jobs_sql || ', ' || shipments_sql || rest_sql; + jobsPlain_sql := jobsPlain || id_filter || jobsPlain_time_windows; + shipmentsPlain_sql := shipmentsPlain || id_filter || shipmentsPlain_time_windows; + vroomPlain_sql := returnPlain_sql || jobsPlain_sql || ', ' || shipmentsPlain_sql || restPlain_sql; + RETURN query SELECT set_eq(vroom_sql, vroomPlain_sql); + END LOOP; + END LOOP; + + -- Three jobs and shipments + FOR i in 1..array_length(ids, 1) LOOP + FOR j in (i+1)..array_length(ids, 1) LOOP + FOR k in (j+1)..array_length(ids, 1) LOOP + id_filter := ' WHERE id in (' || i || ', ' || j || ', ' || k || ')$$, '; + jobs_sql := jobs || id_filter || jobs_time_windows; + shipments_sql := shipments || id_filter || shipments_time_windows; + vroom_sql := return_sql || jobs_sql || ', ' || shipments_sql || rest_sql; + jobsPlain_sql := jobsPlain || id_filter || jobsPlain_time_windows; + shipmentsPlain_sql := shipmentsPlain || id_filter || shipmentsPlain_time_windows; + vroomPlain_sql := returnPlain_sql || jobsPlain_sql || ', ' || shipmentsPlain_sql || restPlain_sql; + RETURN query SELECT set_eq(vroom_sql, vroomPlain_sql); + END LOOP; + END LOOP; + END LOOP; + + -- All the five jobs and shipments + id_filter := '$$, '; + jobs_sql := jobs || id_filter || jobs_time_windows; + shipments_sql := shipments || id_filter || shipments_time_windows; + vroom_sql := return_sql || jobs_sql || ', ' || shipments_sql || rest_sql; + jobsPlain_sql := jobsPlain || id_filter || jobsPlain_time_windows; + shipmentsPlain_sql := shipmentsPlain || id_filter || shipmentsPlain_time_windows; + vroomPlain_sql := returnPlain_sql || jobsPlain_sql || ', ' || shipmentsPlain_sql || restPlain_sql; + RETURN query SELECT set_eq(vroom_sql, vroomPlain_sql); + + -- No jobs or shipments + id_filter := ' WHERE id in (-1)$$, '; + jobs_sql := jobs || id_filter || jobs_time_windows; + shipments_sql := shipments || id_filter || shipments_time_windows; + vroom_sql := return_sql || jobs_sql || ', ' || shipments_sql || rest_sql; + jobsPlain_sql := jobsPlain || id_filter || jobsPlain_time_windows; + shipmentsPlain_sql := shipmentsPlain || id_filter || shipmentsPlain_time_windows; + vroomPlain_sql := returnPlain_sql || jobsPlain_sql || ', ' || shipmentsPlain_sql || restPlain_sql; + RETURN query SELECT set_eq(vroom_sql, vroomPlain_sql); +END +$BODY$ +language plpgsql; + +SELECT vroom_plain_eq_timestamp(); + +SELECT * FROM finish(); +ROLLBACK; diff --git a/pgtap/vroom/vroomJobs-eq-vroom.test.sql b/pgtap/vroom/vroomJobs-eq-vroom.test.sql index 9d83e2b78..0e77c3e1a 100644 --- a/pgtap/vroom/vroomJobs-eq-vroom.test.sql +++ b/pgtap/vroom/vroomJobs-eq-vroom.test.sql @@ -28,8 +28,8 @@ BEGIN FOR i in 1..array_length(ids, 1) LOOP FOR j in (i+1)..array_length(ids, 1) LOOP jobs_sql := '$$SELECT * FROM jobs WHERE id in (' || i || ', ' || j || ')$$, ' || empty_time_windows; - vroom_sql := 'SELECT * FROM vrp_vroom(' || jobs_sql || shipments_sql || rest_sql; - vroomJobs_sql := 'SELECT * FROM vrp_vroomJobs(' || jobs_sql || rest_sql; + vroom_sql := 'SELECT * FROM vrp_vroomPlain(' || jobs_sql || shipments_sql || rest_sql; + vroomJobs_sql := 'SELECT * FROM vrp_vroomJobsPlain(' || jobs_sql || rest_sql; RETURN query SELECT set_eq(vroom_sql, vroomJobs_sql); END LOOP; END LOOP; @@ -39,8 +39,8 @@ BEGIN FOR j in (i+1)..array_length(ids, 1) LOOP FOR k in (j+1)..array_length(ids, 1) LOOP jobs_sql := '$$SELECT * FROM jobs WHERE id in (' || i || ', ' || j || ', ' || k || ')$$, ' || empty_time_windows; - vroom_sql := 'SELECT * FROM vrp_vroom(' || jobs_sql || shipments_sql || rest_sql; - vroomJobs_sql := 'SELECT * FROM vrp_vroomJobs(' || jobs_sql || rest_sql; + vroom_sql := 'SELECT * FROM vrp_vroomPlain(' || jobs_sql || shipments_sql || rest_sql; + vroomJobs_sql := 'SELECT * FROM vrp_vroomJobsPlain(' || jobs_sql || rest_sql; RETURN query SELECT set_eq(vroom_sql, vroomJobs_sql); END LOOP; END LOOP; @@ -48,14 +48,14 @@ BEGIN -- All the five jobs jobs_sql := '$$SELECT * FROM jobs$$, ' || empty_time_windows; - vroom_sql := 'SELECT * FROM vrp_vroom(' || jobs_sql || shipments_sql || rest_sql; - vroomJobs_sql := 'SELECT * FROM vrp_vroomJobs(' || jobs_sql || rest_sql; + vroom_sql := 'SELECT * FROM vrp_vroomPlain(' || jobs_sql || shipments_sql || rest_sql; + vroomJobs_sql := 'SELECT * FROM vrp_vroomJobsPlain(' || jobs_sql || rest_sql; RETURN query SELECT set_eq(vroom_sql, vroomJobs_sql); -- No jobs jobs_sql := '$$SELECT * FROM jobs WHERE id = -1$$, ' || empty_time_windows; - vroom_sql := 'SELECT * FROM vrp_vroom(' || jobs_sql || shipments_sql || rest_sql; - vroomJobs_sql := 'SELECT * FROM vrp_vroomJobs(' || jobs_sql || rest_sql; + vroom_sql := 'SELECT * FROM vrp_vroomPlain(' || jobs_sql || shipments_sql || rest_sql; + vroomJobs_sql := 'SELECT * FROM vrp_vroomJobsPlain(' || jobs_sql || rest_sql; RETURN query SELECT set_eq(vroom_sql, vroomJobs_sql); END $BODY$ diff --git a/pgtap/vroom/vroomShipments-eq-vroom.test.sql b/pgtap/vroom/vroomShipments-eq-vroom.test.sql index fe16d68a7..f801f69e9 100644 --- a/pgtap/vroom/vroomShipments-eq-vroom.test.sql +++ b/pgtap/vroom/vroomShipments-eq-vroom.test.sql @@ -28,8 +28,8 @@ BEGIN FOR i in 1..array_length(ids, 1) LOOP FOR j in (i+1)..array_length(ids, 1) LOOP shipments_sql := '$$SELECT * FROM shipments WHERE id in (' || i || ', ' || j || ')$$, ' || empty_time_windows; - vroom_sql := 'SELECT * FROM vrp_vroom(' || jobs_sql || shipments_sql || rest_sql; - vroomShipments_sql := 'SELECT * FROM vrp_vroomShipments(' || shipments_sql || rest_sql; + vroom_sql := 'SELECT * FROM vrp_vroomPlain(' || jobs_sql || shipments_sql || rest_sql; + vroomShipments_sql := 'SELECT * FROM vrp_vroomShipmentsPlain(' || shipments_sql || rest_sql; RETURN query SELECT set_eq(vroom_sql, vroomShipments_sql); END LOOP; END LOOP; @@ -39,8 +39,8 @@ BEGIN FOR j in (i+1)..array_length(ids, 1) LOOP FOR k in (j+1)..array_length(ids, 1) LOOP shipments_sql := '$$SELECT * FROM shipments WHERE id in (' || i || ', ' || j || ', ' || k || ')$$, ' || empty_time_windows; - vroom_sql := 'SELECT * FROM vrp_vroom(' || jobs_sql || shipments_sql || rest_sql; - vroomShipments_sql := 'SELECT * FROM vrp_vroomShipments(' || shipments_sql || rest_sql; + vroom_sql := 'SELECT * FROM vrp_vroomPlain(' || jobs_sql || shipments_sql || rest_sql; + vroomShipments_sql := 'SELECT * FROM vrp_vroomShipmentsPlain(' || shipments_sql || rest_sql; RETURN query SELECT set_eq(vroom_sql, vroomShipments_sql); END LOOP; END LOOP; @@ -48,14 +48,14 @@ BEGIN -- All the five shipments shipments_sql := '$$SELECT * FROM shipments$$, ' || empty_time_windows; - vroom_sql := 'SELECT * FROM vrp_vroom(' || jobs_sql || shipments_sql || rest_sql; - vroomShipments_sql := 'SELECT * FROM vrp_vroomShipments(' || shipments_sql || rest_sql; + vroom_sql := 'SELECT * FROM vrp_vroomPlain(' || jobs_sql || shipments_sql || rest_sql; + vroomShipments_sql := 'SELECT * FROM vrp_vroomShipmentsPlain(' || shipments_sql || rest_sql; RETURN query SELECT set_eq(vroom_sql, vroomShipments_sql); -- No shipments shipments_sql := '$$SELECT * FROM shipments WHERE id = -1$$, ' || empty_time_windows; - vroom_sql := 'SELECT * FROM vrp_vroom(' || jobs_sql || shipments_sql || rest_sql; - vroomShipments_sql := 'SELECT * FROM vrp_vroomShipments(' || shipments_sql || rest_sql; + vroom_sql := 'SELECT * FROM vrp_vroomPlain(' || jobs_sql || shipments_sql || rest_sql; + vroomShipments_sql := 'SELECT * FROM vrp_vroomShipmentsPlain(' || shipments_sql || rest_sql; RETURN query SELECT set_eq(vroom_sql, vroomShipments_sql); END $BODY$ diff --git a/sql/sigs/vrprouting--0.2.sig b/sql/sigs/vrprouting--0.2.sig index 0d35746a9..18a1cca00 100644 --- a/sql/sigs/vrprouting--0.2.sig +++ b/sql/sigs/vrprouting--0.2.sig @@ -32,7 +32,10 @@ _vrp_vehiclesattime(text,timestamp without time zone,boolean) vrp_version() vrp_viewrouteraw(text,text,text,text,bigint,double precision) vrp_viewroute(text,text,text,text,bigint,double precision) +vrp_vroomjobsplain(text,text,text,text,text,text) vrp_vroomjobs(text,text,text,text,text,text) +vrp_vroomplain(text,text,text,text,text,text,text,text) +vrp_vroomshipmentsplain(text,text,text,text,text,text) vrp_vroomshipments(text,text,text,text,text,text) vrp_vroom(text,text,text,text,text,text,text,text) -_vrp_vroom(text,text,text,text,text,text,text,text,smallint) +_vrp_vroom(text,text,text,text,text,text,text,text,smallint,boolean) diff --git a/sql/vroom/CMakeLists.txt b/sql/vroom/CMakeLists.txt index d50610ef3..9c629ae95 100644 --- a/sql/vroom/CMakeLists.txt +++ b/sql/vroom/CMakeLists.txt @@ -3,6 +3,9 @@ SET(LOCAL_FILES vrp_vroom.sql vrp_vroomJobs.sql vrp_vroomShipments.sql + vrp_vroomPlain.sql + vrp_vroomJobsPlain.sql + vrp_vroomShipmentsPlain.sql ) foreach (f ${LOCAL_FILES}) diff --git a/sql/vroom/_vrp_vroom.sql b/sql/vroom/_vrp_vroom.sql index 2c5334393..6d3fa62b5 100644 --- a/sql/vroom/_vrp_vroom.sql +++ b/sql/vroom/_vrp_vroom.sql @@ -37,6 +37,7 @@ CREATE FUNCTION _vrp_vroom( breaks_time_windows_sql TEXT, matrix_sql TEXT, fn SMALLINT, + is_plain BOOLEAN, OUT seq BIGINT, OUT vehicle_seq BIGINT, @@ -55,5 +56,5 @@ LANGUAGE C VOLATILE; -- COMMENTS -COMMENT ON FUNCTION _vrp_vroom(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, SMALLINT) +COMMENT ON FUNCTION _vrp_vroom(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, SMALLINT, BOOLEAN) IS 'pgRouting internal function'; diff --git a/sql/vroom/vrp_vroom.sql b/sql/vroom/vrp_vroom.sql index 8f982ae07..bcd6597b6 100644 --- a/sql/vroom/vrp_vroom.sql +++ b/sql/vroom/vrp_vroom.sql @@ -68,43 +68,58 @@ parameters end result start -=================== ============= ================================================= -Column Type Description -=================== ============= ================================================= -**seq** ``BIGINT`` Sequential value starting from **1**. +Returns set of -**vehicle_seq** ``BIGINT`` Sequential value starting from **1** for current vehicles. - The :math:`n^{th}` vehicle in the solution. +.. code-block:: none + + (seq, vehicle_seq, vehicle_id, step_seq, step_type, task_id, + arrival, travel_time, service_time, waiting_time, load) + +=================== ================= ================================================= +Column Type Description +=================== ================= ================================================= +**seq** ``BIGINT`` Sequential value starting from **1**. + +**vehicle_seq** ``BIGINT`` Sequential value starting from **1** for current vehicles. + The :math:`n^{th}` vehicle in the solution. + +**vehicle_id** ``BIGINT`` Current vehicle identifier. + +**step_seq** ``BIGINT`` Sequential value starting from **1** for the stops + made by the current vehicle. The :math:`m^{th}` stop + of the current vehicle. + +**step_type** ``INTEGER`` Kind of the step location the vehicle is at: + + - ``1``: Starting location + - ``2``: Job location + - ``3``: Pickup location + - ``4``: Delivery location + - ``5``: Break location + - ``6``: Ending location -**vehicle_id** ``BIGINT`` Current vehicle identifier. +**task_id** ``BIGINT`` Identifier of the task performed at this step. -**step_seq** ``BIGINT`` Sequential value starting from **1** for the stops - made by the current vehicle. The :math:`m^{th}` stop - of the current vehicle. + - ``-1``: If the step is starting/ending location. -**step_type** ``INTEGER`` Kind of the step location the vehicle is at: +**arrival** ``TIMESTAMP`` Estimated time of arrival at this step, in seconds. - - ``1``: Starting location - - ``2``: Job location - - ``3``: Pickup location - - ``4``: Delivery location - - ``5``: Break location - - ``6``: Ending location + - ``INTEGER`` for plain VROOM functions. -**task_id** ``BIGINT`` Identifier of the task performed at this step. +**travel_time** ``INTERVAL`` Cumulated travel time upon arrival at this step, in seconds - - ``-1``: If the step is starting/ending location. + - ``INTEGER`` for plain VROOM functions. -**arrival** ``INTEGER`` Estimated time of arrival at this step, in seconds. +**service_time** ``INTERVAL`` Service time at this step, in seconds -**travel_time** ``INTEGER`` Cumulated travel time upon arrival at this step, in seconds + - ``INTEGER`` for plain VROOM functions. -**service_time** ``INTEGER`` Service time at this step, in seconds +**waiting_time** ``INTERVAL`` Waiting time upon arrival at this step, in seconds. -**waiting_time** ``INTEGER`` Waiting time upon arrival at this step, in seconds. + - ``INTEGER`` for plain VROOM functions. -**load** ``BIGINT`` Vehicle load after step completion (with capacity constraints) -=================== ============= ================================================= +**load** ``BIGINT`` Vehicle load after step completion (with capacity constraints) +=================== ================= ================================================= result end */ @@ -126,17 +141,28 @@ CREATE FUNCTION vrp_vroom( OUT step_seq BIGINT, OUT step_type INTEGER, OUT task_id BIGINT, - OUT arrival INTEGER, - OUT travel_time INTEGER, - OUT service_time INTEGER, - OUT waiting_time INTEGER, + OUT arrival TIMESTAMP, + OUT travel_time INTERVAL, + OUT service_time INTERVAL, + OUT waiting_time INTERVAL, OUT load BIGINT[]) RETURNS SETOF RECORD AS $BODY$ - SELECT * + SELECT + seq, + vehicle_seq, + vehicle_id, + step_seq, + step_type, + task_id, + (to_timestamp(arrival) at time zone 'UTC')::TIMESTAMP, + make_interval(secs => travel_time), + make_interval(secs => service_time), + make_interval(secs => waiting_time), + load FROM _vrp_vroom(_pgr_get_statement($1), _pgr_get_statement($2), _pgr_get_statement($3), _pgr_get_statement($4), _pgr_get_statement($5), _pgr_get_statement($6), - _pgr_get_statement($7), _pgr_get_statement($8), 0::SMALLINT); + _pgr_get_statement($7), _pgr_get_statement($8), 0::SMALLINT, false); $BODY$ LANGUAGE SQL VOLATILE; diff --git a/sql/vroom/vrp_vroomJobs.sql b/sql/vroom/vrp_vroomJobs.sql index 37b4d1efc..4c493a733 100644 --- a/sql/vroom/vrp_vroomJobs.sql +++ b/sql/vroom/vrp_vroomJobs.sql @@ -78,17 +78,28 @@ CREATE FUNCTION vrp_vroomJobs( OUT step_seq BIGINT, OUT step_type INTEGER, OUT task_id BIGINT, - OUT arrival INTEGER, - OUT travel_time INTEGER, - OUT service_time INTEGER, - OUT waiting_time INTEGER, + OUT arrival TIMESTAMP, + OUT travel_time INTERVAL, + OUT service_time INTERVAL, + OUT waiting_time INTERVAL, OUT load BIGINT[]) RETURNS SETOF RECORD AS $BODY$ - SELECT * + SELECT + seq, + vehicle_seq, + vehicle_id, + step_seq, + step_type, + task_id, + (to_timestamp(arrival) at time zone 'UTC')::TIMESTAMP, + make_interval(secs => travel_time), + make_interval(secs => service_time), + make_interval(secs => waiting_time), + load FROM _vrp_vroom(_pgr_get_statement($1), _pgr_get_statement($2), NULL, NULL, _pgr_get_statement($3), _pgr_get_statement($4), - _pgr_get_statement($5), _pgr_get_statement($6), 1::SMALLINT); + _pgr_get_statement($5), _pgr_get_statement($6), 1::SMALLINT, false); $BODY$ LANGUAGE SQL VOLATILE; diff --git a/sql/vroom/vrp_vroomJobsPlain.sql b/sql/vroom/vrp_vroomJobsPlain.sql new file mode 100644 index 000000000..fb6dd9061 --- /dev/null +++ b/sql/vroom/vrp_vroomJobsPlain.sql @@ -0,0 +1,80 @@ +/*PGR-GNU***************************************************************** +File: vrp_vroomJobsPlain.sql + +Copyright (c) 2021 pgRouting developers +Mail: project@pgrouting.org + +Function's developer: +Copyright (c) 2021 Ashish Kumar +Mail: ashishkr23438@gmail.com + +------ + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + ********************************************************************PGR-GNU*/ + +-- v0.2 +CREATE FUNCTION vrp_vroomJobsPlain( + TEXT, -- jobs_sql (required) + TEXT, -- jobs_time_windows_sql (required) + TEXT, -- vehicles_sql (required) + TEXT, -- breaks_sql (required) + TEXT, -- breaks_time_windows_sql (required) + TEXT, -- matrix_sql (required) + + OUT seq BIGINT, + OUT vehicle_seq BIGINT, + OUT vehicle_id BIGINT, + OUT step_seq BIGINT, + OUT step_type INTEGER, + OUT task_id BIGINT, + OUT arrival INTEGER, + OUT travel_time INTEGER, + OUT service_time INTEGER, + OUT waiting_time INTEGER, + OUT load BIGINT[]) +RETURNS SETOF RECORD AS +$BODY$ + SELECT * + FROM _vrp_vroom(_pgr_get_statement($1), _pgr_get_statement($2), NULL, NULL, + _pgr_get_statement($3), _pgr_get_statement($4), + _pgr_get_statement($5), _pgr_get_statement($6), 1::SMALLINT, true); +$BODY$ +LANGUAGE SQL VOLATILE; + + +-- COMMENTS + +COMMENT ON FUNCTION vrp_vroomJobsPlain(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT) +IS 'vrp_vroomJobsPlain + - EXPERIMENTAL + - Parameters: + - Jobs SQL with columns: + id, location_index [, service, delivery, pickup, skills, priority, time_windows] + - Jobs Time Windows SQL with columns: + id, tw_open, tw_close + - Vehicles SQL with columns: + id, start_index, end_index + [, service, delivery, pickup, skills, priority, time_window, breaks_sql, steps_sql] + - Breaks SQL with columns: + id [, service] + - Breaks Time Windows SQL with columns: + id, tw_open, tw_close + - Matrix SQL with columns: + start_vid, end_vid, agg_cost + - Documentation: + - ${PROJECT_DOC_LINK}/vrp_vroomJobsPlain.html +'; diff --git a/sql/vroom/vrp_vroomPlain.sql b/sql/vroom/vrp_vroomPlain.sql new file mode 100644 index 000000000..3d533d0c5 --- /dev/null +++ b/sql/vroom/vrp_vroomPlain.sql @@ -0,0 +1,88 @@ +/*PGR-GNU***************************************************************** +File: vrp_vroomPlain.sql + +Copyright (c) 2021 pgRouting developers +Mail: project@pgrouting.org + +Function's developer: +Copyright (c) 2021 Ashish Kumar +Mail: ashishkr23438@gmail.com + +------ + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + ********************************************************************PGR-GNU*/ + + +-- v0.2 +CREATE FUNCTION vrp_vroomPlain( + TEXT, -- jobs_sql (required) + TEXT, -- jobs_time_windows_sql (required) + TEXT, -- shipments_sql (required) + TEXT, -- shipments_time_windows_sql (required) + TEXT, -- vehicles_sql (required) + TEXT, -- breaks_sql (required) + TEXT, -- breaks_time_windows_sql (required) + TEXT, -- matrix_sql (required) + + OUT seq BIGINT, + OUT vehicle_seq BIGINT, + OUT vehicle_id BIGINT, + OUT step_seq BIGINT, + OUT step_type INTEGER, + OUT task_id BIGINT, + OUT arrival INTEGER, + OUT travel_time INTEGER, + OUT service_time INTEGER, + OUT waiting_time INTEGER, + OUT load BIGINT[]) +RETURNS SETOF RECORD AS +$BODY$ + SELECT * + FROM _vrp_vroom(_pgr_get_statement($1), _pgr_get_statement($2), _pgr_get_statement($3), + _pgr_get_statement($4), _pgr_get_statement($5), _pgr_get_statement($6), + _pgr_get_statement($7), _pgr_get_statement($8), 0::SMALLINT, true); +$BODY$ +LANGUAGE SQL VOLATILE; + + +-- COMMENTS + +COMMENT ON FUNCTION vrp_vroomPlain(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT) +IS 'vrp_vroomPlain + - EXPERIMENTAL + - Parameters: + - Jobs SQL with columns: + id, location_index [, service, delivery, pickup, skills, priority, time_windows] + - Jobs Time Windows SQL with columns: + id, tw_open, tw_close + - Shipments SQL with columns: + p_id, p_location_index [, p_service, p_time_windows], + d_id, d_location_index [, d_service, d_time_windows] [, amount, skills, priority] + - Shipments Time Windows SQL with columns: + id, kind, tw_open, tw_close + - Vehicles SQL with columns: + id, start_index, end_index + [, service, delivery, pickup, skills, priority, time_window, breaks_sql, steps_sql] + - Breaks SQL with columns: + id [, service] + - Breaks Time Windows SQL with columns: + id, tw_open, tw_close + - Matrix SQL with columns: + start_vid, end_vid, agg_cost + - Documentation: + - ${PROJECT_DOC_LINK}/vrp_vroomPlain.html +'; diff --git a/sql/vroom/vrp_vroomShipments.sql b/sql/vroom/vrp_vroomShipments.sql index 0d4a66bd9..6bde8157c 100644 --- a/sql/vroom/vrp_vroomShipments.sql +++ b/sql/vroom/vrp_vroomShipments.sql @@ -78,18 +78,29 @@ CREATE FUNCTION vrp_vroomShipments( OUT step_seq BIGINT, OUT step_type INTEGER, OUT task_id BIGINT, - OUT arrival INTEGER, - OUT travel_time INTEGER, - OUT service_time INTEGER, - OUT waiting_time INTEGER, + OUT arrival TIMESTAMP, + OUT travel_time INTERVAL, + OUT service_time INTERVAL, + OUT waiting_time INTERVAL, OUT load BIGINT[]) RETURNS SETOF RECORD AS $BODY$ - SELECT * + SELECT + seq, + vehicle_seq, + vehicle_id, + step_seq, + step_type, + task_id, + (to_timestamp(arrival) at time zone 'UTC')::TIMESTAMP, + make_interval(secs => travel_time), + make_interval(secs => service_time), + make_interval(secs => waiting_time), + load FROM _vrp_vroom(NULL, NULL, _pgr_get_statement($1), _pgr_get_statement($2), _pgr_get_statement($3), _pgr_get_statement($4), _pgr_get_statement($5), - _pgr_get_statement($6), 2::SMALLINT); + _pgr_get_statement($6), 2::SMALLINT, false); $BODY$ LANGUAGE SQL VOLATILE; diff --git a/sql/vroom/vrp_vroomShipmentsPlain.sql b/sql/vroom/vrp_vroomShipmentsPlain.sql new file mode 100644 index 000000000..de9bca901 --- /dev/null +++ b/sql/vroom/vrp_vroomShipmentsPlain.sql @@ -0,0 +1,83 @@ +/*PGR-GNU***************************************************************** +File: vrp_vroomShipmentsPlain.sql + +Copyright (c) 2021 pgRouting developers +Mail: project@pgrouting.org + +Function's developer: +Copyright (c) 2021 Ashish Kumar +Mail: ashishkr23438@gmail.com + +------ + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + ********************************************************************PGR-GNU*/ + + +-- v0.2 +CREATE FUNCTION vrp_vroomShipmentsPlain( + TEXT, -- shipments_sql (required) + TEXT, -- shipments_time_windows_sql (required) + TEXT, -- vehicles_sql (required) + TEXT, -- breaks_sql (required) + TEXT, -- breaks_time_windows_sql (required) + TEXT, -- matrix_sql (required) + + OUT seq BIGINT, + OUT vehicle_seq BIGINT, + OUT vehicle_id BIGINT, + OUT step_seq BIGINT, + OUT step_type INTEGER, + OUT task_id BIGINT, + OUT arrival INTEGER, + OUT travel_time INTEGER, + OUT service_time INTEGER, + OUT waiting_time INTEGER, + OUT load BIGINT[]) +RETURNS SETOF RECORD AS +$BODY$ + SELECT * + FROM _vrp_vroom(NULL, NULL, _pgr_get_statement($1), + _pgr_get_statement($2), _pgr_get_statement($3), + _pgr_get_statement($4), _pgr_get_statement($5), + _pgr_get_statement($6), 2::SMALLINT, true); +$BODY$ +LANGUAGE SQL VOLATILE; + + +-- COMMENTS + +COMMENT ON FUNCTION vrp_vroomShipmentsPlain(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT) +IS 'vrp_vroomShipmentsPlain + - EXPERIMENTAL + - Parameters: + - Shipments SQL with columns: + p_id, p_location_index [, p_service, p_time_windows], + d_id, d_location_index [, d_service, d_time_windows] [, amount, skills, priority] + - Shipments Time Windows SQL with columns: + id, kind, tw_open, tw_close + - Vehicles SQL with columns: + id, start_index, end_index + [, service, delivery, pickup, skills, priority, time_window, breaks_sql, steps_sql] + - Breaks SQL with columns: + id [, service] + - Breaks Time Windows SQL with columns: + id, tw_open, tw_close + - Matrix SQL with columns: + start_vid, end_vid, agg_cost + - Documentation: + - ${PROJECT_DOC_LINK}/vrp_vroomShipmentsPlain.html +'; diff --git a/src/common/vroom/breaks_input.c b/src/common/vroom/breaks_input.c index 801e9deb1..14dbfd351 100644 --- a/src/common/vroom/breaks_input.c +++ b/src/common/vroom/breaks_input.c @@ -45,7 +45,9 @@ Column Type Default Description **vehicle_id** ``ANY-INTEGER`` Non-negative unique identifier of the vehicle. -**service** ``INTEGER`` 0 The break duration, in seconds +**service** ``INTERVAL`` 0 The break duration, in seconds. + + - ``INTEGER`` for plain VROOM functions. ==================== ========================= =========== ================================================ .. vrp_vroom end @@ -56,10 +58,16 @@ void fetch_breaks( HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t *info, - Vroom_break_t *vroom_break) { + Vroom_break_t *vroom_break, + bool is_plain) { vroom_break->id = get_Idx(tuple, tupdesc, info[0], 0); vroom_break->vehicle_id = get_Idx(tuple, tupdesc, info[1], 0); - vroom_break->service = get_Duration(tuple, tupdesc, info[2], 0); + if (is_plain) { + vroom_break->service = get_Duration(tuple, tupdesc, info[2], 0); + } else { + vroom_break->service = + (Duration)get_PositiveTInterval(tuple, tupdesc, info[2], 0); + } } @@ -70,7 +78,8 @@ void db_get_breaks( size_t *total_breaks, Column_info_t *info, - const int column_count) { + const int column_count, + bool is_plain) { #ifdef PROFILE clock_t start_t = clock(); PGR_DBG("%s", breaks_sql); @@ -116,7 +125,7 @@ void db_get_breaks( for (t = 0; t < ntuples; t++) { HeapTuple tuple = tuptable->vals[t]; fetch_breaks(&tuple, &tupdesc, info, - &(*breaks)[total_tuples - ntuples + t]); + &(*breaks)[total_tuples - ntuples + t], is_plain); } SPI_freetuptable(tuptable); } else { @@ -148,7 +157,8 @@ void get_vroom_breaks( char *sql, Vroom_break_t **rows, - size_t *total_rows) { + size_t *total_rows, + bool is_plain) { int kColumnCount = 3; Column_info_t info[kColumnCount]; @@ -165,8 +175,12 @@ get_vroom_breaks( info[2].eType = INTEGER; // service + if (!is_plain) { + info[2].eType = INTERVAL; // service + } + /* service is not mandatory */ info[2].strict = false; - db_get_breaks(sql, rows, total_rows, info, kColumnCount); + db_get_breaks(sql, rows, total_rows, info, kColumnCount, is_plain); } diff --git a/src/common/vroom/jobs_input.c b/src/common/vroom/jobs_input.c index 332e28e00..1516ef9f4 100644 --- a/src/common/vroom/jobs_input.c +++ b/src/common/vroom/jobs_input.c @@ -46,7 +46,9 @@ Column Type Default Description **location_index** ``ANY-INTEGER`` Non-negative identifier of the job location. -**service** ``INTEGER`` 0 Job service duration, in seconds +**service** ``INTERVAL`` 0 Job service duration, in seconds + + - ``INTEGER`` for plain VROOM functions. **delivery** ``ARRAY[ANY-INTEGER]`` Array of non-negative integers describing multidimensional quantities for delivery such @@ -82,10 +84,16 @@ void fetch_jobs( HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t *info, - Vroom_job_t *job) { + Vroom_job_t *job, + bool is_plain) { job->id = get_Idx(tuple, tupdesc, info[0], 0); job->location_index = get_MatrixIndex(tuple, tupdesc, info[1], 0); - job->service = get_Duration(tuple, tupdesc, info[2], 0); + + if (is_plain) { + job->service = get_Duration(tuple, tupdesc, info[2], 0); + } else { + job->service = (Duration)get_PositiveTInterval(tuple, tupdesc, info[2], 0); + } /* * The deliveries @@ -119,7 +127,8 @@ void db_get_jobs( size_t *total_jobs, Column_info_t *info, - const int column_count) { + const int column_count, + bool is_plain) { #ifdef PROFILE clock_t start_t = clock(); PGR_DBG("%s", jobs_sql); @@ -165,7 +174,7 @@ void db_get_jobs( for (t = 0; t < ntuples; t++) { HeapTuple tuple = tuptable->vals[t]; fetch_jobs(&tuple, &tupdesc, info, - &(*jobs)[total_tuples - ntuples + t]); + &(*jobs)[total_tuples - ntuples + t], is_plain); } SPI_freetuptable(tuptable); } else { @@ -196,7 +205,8 @@ void get_vroom_jobs( char *sql, Vroom_job_t **rows, - size_t *total_rows) { + size_t *total_rows, + bool is_plain) { int kColumnCount = 7; Column_info_t info[kColumnCount]; @@ -221,9 +231,13 @@ get_vroom_jobs( info[5].eType = INTEGER_ARRAY; // skills info[6].eType = INTEGER; // priority + if (!is_plain) { + info[2].eType = INTERVAL; // service + } + /* Only id and location_index are mandatory */ info[0].strict = true; info[1].strict = true; - db_get_jobs(sql, rows, total_rows, info, kColumnCount); + db_get_jobs(sql, rows, total_rows, info, kColumnCount, is_plain); } diff --git a/src/common/vroom/shipments_input.c b/src/common/vroom/shipments_input.c index 864b4dc71..40ede8f6d 100644 --- a/src/common/vroom/shipments_input.c +++ b/src/common/vroom/shipments_input.c @@ -46,11 +46,15 @@ Column Type Default Description **p_location_index** ``ANY-INTEGER`` Non-negative identifier of the pickup location. -**p_service** ``INTEGER`` 0 Pickup service duration, in seconds +**p_service** ``INTERVAL`` 0 Pickup service duration, in seconds + + - ``INTEGER`` for plain VROOM functions. **d_location_index** ``ANY-INTEGER`` Non-negative identifier of the delivery location. -**d_service** ``INTEGER`` 0 Delivery service duration, in seconds +**d_service** ``INTERVAL`` 0 Delivery service duration, in seconds + + - ``INTEGER`` for plain VROOM functions. **amount** ``ARRAY[ANY-INTEGER]`` Array of non-negative integers describing multidimensional quantities such as number @@ -80,20 +84,22 @@ void fetch_shipments( HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t *info, - Vroom_shipment_t *shipment) { + Vroom_shipment_t *shipment, + bool is_plain) { shipment->id = get_Idx(tuple, tupdesc, info[0], 0); - /* - * The pickups - */ shipment->p_location_index = get_MatrixIndex(tuple, tupdesc, info[1], 0); - shipment->p_service = get_Duration(tuple, tupdesc, info[2], 0); - - /* - * The deliveries - */ shipment->d_location_index = get_MatrixIndex(tuple, tupdesc, info[3], 0); - shipment->d_service = get_Duration(tuple, tupdesc, info[4], 0); + + if (is_plain) { + shipment->p_service = get_Duration(tuple, tupdesc, info[2], 0); + shipment->d_service = get_Duration(tuple, tupdesc, info[4], 0); + } else { + shipment->p_service = + (Duration)get_PositiveTInterval(tuple, tupdesc, info[2], 0); + shipment->d_service = + (Duration)get_PositiveTInterval(tuple, tupdesc, info[4], 0); + } shipment->amount_size = 0; shipment->amount = column_found(info[5].colNumber) ? @@ -116,7 +122,8 @@ void db_get_shipments( size_t *total_shipments, Column_info_t *info, - const int column_count) { + const int column_count, + bool is_plain) { #ifdef PROFILE clock_t start_t = clock(); PGR_DBG("%s", shipments_sql); @@ -162,7 +169,7 @@ void db_get_shipments( for (t = 0; t < ntuples; t++) { HeapTuple tuple = tuptable->vals[t]; fetch_shipments(&tuple, &tupdesc, info, - &(*shipments)[total_tuples - ntuples + t]); + &(*shipments)[total_tuples - ntuples + t], is_plain); } SPI_freetuptable(tuptable); } else { @@ -193,7 +200,8 @@ void get_vroom_shipments( char *sql, Vroom_shipment_t **rows, - size_t *total_rows) { + size_t *total_rows, + bool is_plain) { int kColumnCount = 8; Column_info_t info[kColumnCount]; @@ -224,10 +232,15 @@ get_vroom_shipments( info[6].eType = INTEGER_ARRAY; // skills info[7].eType = INTEGER; // priority + if (!is_plain) { + info[2].eType = INTERVAL; // p_service + info[4].eType = INTERVAL; // d_service + } + /* id and location_index of pickup and delivery are mandatory */ info[0].strict = true; info[1].strict = true; info[3].strict = true; - db_get_shipments(sql, rows, total_rows, info, kColumnCount); + db_get_shipments(sql, rows, total_rows, info, kColumnCount, is_plain); } diff --git a/src/common/vroom/time_windows_input.c b/src/common/vroom/time_windows_input.c index b45979317..86311d16d 100644 --- a/src/common/vroom/time_windows_input.c +++ b/src/common/vroom/time_windows_input.c @@ -49,9 +49,13 @@ Column Type Description - Pickup shipment, or - Delivery shipment. -**tw_open** ``INTEGER`` Time window opening time. +**tw_open** ``TIMESTAMP`` Time window opening time. -**tw_close** ``INTEGER`` Time window closing time. + - ``INTEGER`` for plain VROOM functions. + +**tw_close** ``TIMESTAMP`` Time window closing time. + + - ``INTEGER`` for plain VROOM functions. ==================== ====================================== ===================================================== **Note**: @@ -72,7 +76,8 @@ void fetch_time_windows( TupleDesc *tupdesc, Column_info_t *info, Vroom_time_window_t *time_window, - bool is_shipment) { + bool is_shipment, + bool is_plain) { time_window->id = get_Idx(tuple, tupdesc, info[0], 0); @@ -83,11 +88,25 @@ void fetch_time_windows( errhint("Kind must be either 'p' or 'd'"))); } time_window->kind = kind; - time_window->start_time = get_Duration(tuple, tupdesc, info[2], 0); - time_window->end_time = get_Duration(tuple, tupdesc, info[3], 0); + if (is_plain) { + time_window->start_time = get_Duration(tuple, tupdesc, info[2], 0); + time_window->end_time = get_Duration(tuple, tupdesc, info[3], 0); + } else { + time_window->start_time = + (Duration)get_PositiveTTimestamp(tuple, tupdesc, info[2], 0); + time_window->end_time = + (Duration)get_PositiveTTimestamp(tuple, tupdesc, info[3], 0); + } } else { - time_window->start_time = get_Duration(tuple, tupdesc, info[1], 0); - time_window->end_time = get_Duration(tuple, tupdesc, info[2], 0); + if (is_plain) { + time_window->start_time = get_Duration(tuple, tupdesc, info[1], 0); + time_window->end_time = get_Duration(tuple, tupdesc, info[2], 0); + } else { + time_window->start_time = + (Duration)get_PositiveTTimestamp(tuple, tupdesc, info[1], 0); + time_window->end_time = + (Duration)get_PositiveTTimestamp(tuple, tupdesc, info[2], 0); + } } if (time_window->start_time > time_window->end_time) { @@ -109,7 +128,8 @@ void db_get_time_windows( Column_info_t *info, const int column_count, - bool is_shipment) { + bool is_shipment, + bool is_plain) { #ifdef PROFILE clock_t start_t = clock(); PGR_DBG("%s", time_windows_sql); @@ -155,7 +175,8 @@ void db_get_time_windows( for (t = 0; t < ntuples; t++) { HeapTuple tuple = tuptable->vals[t]; fetch_time_windows(&tuple, &tupdesc, info, - &(*time_windows)[total_tuples - ntuples + t], is_shipment); + &(*time_windows)[total_tuples - ntuples + t], + is_shipment, is_plain); } SPI_freetuptable(tuptable); } else { @@ -186,7 +207,8 @@ void get_vroom_time_windows( char *sql, Vroom_time_window_t **rows, - size_t *total_rows) { + size_t *total_rows, + bool is_plain) { int kColumnCount = 3; Column_info_t info[kColumnCount]; @@ -203,7 +225,12 @@ get_vroom_time_windows( info[0].eType = ANY_INTEGER; // id - db_get_time_windows(sql, rows, total_rows, info, kColumnCount, 0); + if (!is_plain) { + info[1].eType = TIMESTAMP; // tw_open + info[2].eType = TIMESTAMP; // tw_close + } + + db_get_time_windows(sql, rows, total_rows, info, kColumnCount, 0, is_plain); } /** @@ -215,7 +242,8 @@ void get_vroom_shipments_time_windows( char *sql, Vroom_time_window_t **rows, - size_t *total_rows) { + size_t *total_rows, + bool is_plain) { int kColumnCount = 4; Column_info_t info[kColumnCount]; @@ -234,5 +262,10 @@ get_vroom_shipments_time_windows( info[0].eType = ANY_INTEGER; // id info[1].eType = CHAR1; // kind - db_get_time_windows(sql, rows, total_rows, info, kColumnCount, 1); + if (!is_plain) { + info[2].eType = TIMESTAMP; // tw_open + info[3].eType = TIMESTAMP; // tw_close + } + + db_get_time_windows(sql, rows, total_rows, info, kColumnCount, 1, is_plain); } diff --git a/src/common/vroom/vehicles_input.c b/src/common/vroom/vehicles_input.c index 73fd69dc5..c63f1a6d7 100644 --- a/src/common/vroom/vehicles_input.c +++ b/src/common/vroom/vehicles_input.c @@ -58,9 +58,13 @@ Column Type Description **skills** ``ARRAY[INTEGER]`` Array of non-negative integers defining mandatory skills. -**tw_open** ``INTEGER`` Time window opening time. +**tw_open** ``TIMESTAMP`` Time window opening time. -**tw_close** ``INTEGER`` Time window closing time. + - ``INTEGER`` for plain VROOM functions. + +**tw_close** ``TIMESTAMP`` Time window closing time. + + - ``INTEGER`` for plain VROOM functions. **speed_factor** ``ANY-NUMERICAL`` Vehicle travel time multiplier. ====================== ================================= ================================================ @@ -83,7 +87,8 @@ void fetch_vehicles( HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t *info, - Vroom_vehicle_t *vehicle) { + Vroom_vehicle_t *vehicle, + bool is_plain) { vehicle->id = get_Idx(tuple, tupdesc, info[0], 0); vehicle->start_index = get_MatrixIndex(tuple, tupdesc, info[1], -1); vehicle->end_index = get_MatrixIndex(tuple, tupdesc, info[2], -1); @@ -98,8 +103,15 @@ void fetch_vehicles( spi_getPositiveIntArr_allowEmpty(tuple, tupdesc, info[4], &vehicle->skills_size) : NULL; - vehicle->time_window_start = get_Duration(tuple, tupdesc, info[5], 0); - vehicle->time_window_end = get_Duration(tuple, tupdesc, info[6], UINT_MAX); + if (is_plain) { + vehicle->time_window_start = get_Duration(tuple, tupdesc, info[5], 0); + vehicle->time_window_end = get_Duration(tuple, tupdesc, info[6], UINT_MAX); + } else { + vehicle->time_window_start = + (Duration)get_PositiveTTimestamp(tuple, tupdesc, info[5], 0); + vehicle->time_window_end = + (Duration)get_PositiveTTimestamp(tuple, tupdesc, info[6], UINT_MAX); + } if (vehicle->time_window_start > vehicle->time_window_end) { ereport(ERROR, @@ -123,7 +135,8 @@ void db_get_vehicles( size_t *total_vehicles, Column_info_t *info, - const int column_count) { + const int column_count, + bool is_plain) { #ifdef PROFILE clock_t start_t = clock(); PGR_DBG("%s", vehicles_sql); @@ -175,7 +188,7 @@ void db_get_vehicles( for (t = 0; t < ntuples; t++) { HeapTuple tuple = tuptable->vals[t]; fetch_vehicles(&tuple, &tupdesc, info, - &(*vehicles)[total_tuples - ntuples + t]); + &(*vehicles)[total_tuples - ntuples + t], is_plain); } SPI_freetuptable(tuptable); } else { @@ -206,7 +219,8 @@ void get_vroom_vehicles( char *sql, Vroom_vehicle_t **rows, - size_t *total_rows) { + size_t *total_rows, + bool is_plain) { int kColumnCount = 8; Column_info_t info[kColumnCount]; @@ -230,14 +244,18 @@ get_vroom_vehicles( info[4].eType = INTEGER_ARRAY; // skills info[5].eType = INTEGER; // tw_open info[6].eType = INTEGER; // tw_close - info[7].eType = ANY_NUMERICAL; // speed_factor + if (!is_plain) { + info[5].eType = TIMESTAMP; // tw_open + info[6].eType = TIMESTAMP; // tw_close + } + /** * id is mandatory. * At least one out of start_index or end_index must be present, but that is checked later. */ info[0].strict = true; - db_get_vehicles(sql, rows, total_rows, info, kColumnCount); + db_get_vehicles(sql, rows, total_rows, info, kColumnCount, is_plain); } diff --git a/src/vroom/vroom.c b/src/vroom/vroom.c index b54039d4e..0d2723609 100644 --- a/src/vroom/vroom.c +++ b/src/vroom/vroom.c @@ -81,6 +81,7 @@ PG_FUNCTION_INFO_V1(_vrp_vroom); * @param breaks_tws_sql SQL query describing the time windows for break start. * @param matrix_sql SQL query describing the cells of the cost matrix * @param fn Value denoting the function used. + * @param is_plain Value denoting whether the plain/timestamp function is used. * @param result_tuples the rows in the result * @param result_count the count of rows in the result * @@ -98,6 +99,7 @@ process( char *breaks_tws_sql, char *matrix_sql, int16_t fn, + bool is_plain, Vroom_rt **result_tuples, size_t *result_count) { @@ -109,13 +111,13 @@ process( Vroom_job_t *jobs = NULL; size_t total_jobs = 0; if (jobs_sql) { - get_vroom_jobs(jobs_sql, &jobs, &total_jobs); + get_vroom_jobs(jobs_sql, &jobs, &total_jobs, is_plain); } Vroom_shipment_t *shipments = NULL; size_t total_shipments = 0; if (shipments_sql) { - get_vroom_shipments(shipments_sql, &shipments, &total_shipments); + get_vroom_shipments(shipments_sql, &shipments, &total_shipments, is_plain); } if (total_jobs == 0 && total_shipments == 0) { @@ -138,18 +140,20 @@ process( Vroom_time_window_t *jobs_tws = NULL; size_t total_jobs_tws = 0; if (jobs_tws_sql) { - get_vroom_time_windows(jobs_tws_sql, &jobs_tws, &total_jobs_tws); + get_vroom_time_windows(jobs_tws_sql, &jobs_tws, &total_jobs_tws, + is_plain); } Vroom_time_window_t *shipments_tws = NULL; size_t total_shipments_tws = 0; if (shipments_tws_sql) { - get_vroom_shipments_time_windows(shipments_tws_sql, &shipments_tws, &total_shipments_tws); + get_vroom_shipments_time_windows(shipments_tws_sql, &shipments_tws, + &total_shipments_tws, is_plain); } Vroom_vehicle_t *vehicles = NULL; size_t total_vehicles = 0; - get_vroom_vehicles(vehicles_sql, &vehicles, &total_vehicles); + get_vroom_vehicles(vehicles_sql, &vehicles, &total_vehicles, is_plain); if (total_vehicles == 0) { ereport(WARNING, (errmsg("Insufficient data found on Vehicles SQL query."), @@ -163,13 +167,14 @@ process( Vroom_break_t *breaks = NULL; size_t total_breaks = 0; if (breaks_sql) { - get_vroom_breaks(breaks_sql, &breaks, &total_breaks); + get_vroom_breaks(breaks_sql, &breaks, &total_breaks, is_plain); } Vroom_time_window_t *breaks_tws = NULL; size_t total_breaks_tws = 0; if (breaks_tws_sql) { - get_vroom_time_windows(breaks_tws_sql, &breaks_tws, &total_breaks_tws); + get_vroom_time_windows(breaks_tws_sql, &breaks_tws, &total_breaks_tws, + is_plain); } Matrix_cell_t *matrix_cells_arr = NULL; @@ -274,6 +279,7 @@ PGDLLEXPORT Datum _vrp_vroom(PG_FUNCTION_ARGS) { } int16_t fn = PG_GETARG_INT16(8); + bool is_plain = PG_GETARG_BOOL(9); // Verify that both jobs_sql and shipments_sql are not NULL if (args[0] == NULL && args[2] == NULL) { @@ -304,6 +310,7 @@ PGDLLEXPORT Datum _vrp_vroom(PG_FUNCTION_ARGS) { args[6], args[7], fn, + is_plain, &result_tuples, &result_count);