From fd0c38d8f7c5bbe257aa8a66e52edc9ef818c50b Mon Sep 17 00:00:00 2001 From: cvvergara Date: Mon, 15 May 2017 10:28:45 -0500 Subject: [PATCH 01/40] added factor parameter --- VERSION | 2 +- sql/pickDeliver/pickDeliver.sql | 3 +- sql/sigs/pgrouting--2.5.0.sig | 1 + .../pgrouting--2.0.0--2.5.0.sql | 28 +++++++++++++++++++ .../pgrouting--2.0.1--2.5.0.sql | 28 +++++++++++++++++++ .../pgrouting--2.1.0--2.5.0.sql | 28 +++++++++++++++++++ .../pgrouting--2.2.0--2.5.0.sql | 28 +++++++++++++++++++ .../pgrouting--2.2.1--2.5.0.sql | 28 +++++++++++++++++++ .../pgrouting--2.2.2--2.5.0.sql | 28 +++++++++++++++++++ .../pgrouting--2.2.3--2.5.0.sql | 28 +++++++++++++++++++ .../pgrouting--2.2.4--2.5.0.sql | 28 +++++++++++++++++++ .../pgrouting--2.3.0--2.5.0.sql | 28 +++++++++++++++++++ .../pgrouting--2.3.1--2.5.0.sql | 28 +++++++++++++++++++ .../pgrouting--2.3.2--2.5.0.sql | 28 +++++++++++++++++++ .../pgrouting--2.4.0--2.5.0.sql | 28 +++++++++++++++++++ .../pgrouting--2.4.1--2.5.0.sql | 28 +++++++++++++++++++ tools/sql-update-scripts/pgrouting--2.5.0.sql | 28 +++++++++++++++++++ 17 files changed, 396 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 7a91e93fa2a..cc39143b2e0 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -5332-de02a9548 vrppdtw/docfix +5332-de02a9548 release/2.5 diff --git a/sql/pickDeliver/pickDeliver.sql b/sql/pickDeliver/pickDeliver.sql index 1ea2f622f1d..1062ff87de2 100644 --- a/sql/pickDeliver/pickDeliver.sql +++ b/sql/pickDeliver/pickDeliver.sql @@ -31,8 +31,9 @@ CREATE OR REPLACE FUNCTION pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, + factor FLOAT DEFAULT 1, max_cycles INTEGER DEFAULT 10, - initial_id INTEGER DEFAULT 4, + initial_sol INTEGER DEFAULT 4, OUT seq INTEGER, OUT vehicle_number INTEGER, diff --git a/sql/sigs/pgrouting--2.5.0.sig b/sql/sigs/pgrouting--2.5.0.sig index a317af774c2..d80ab65bb8c 100644 --- a/sql/sigs/pgrouting--2.5.0.sig +++ b/sql/sigs/pgrouting--2.5.0.sig @@ -130,6 +130,7 @@ _pgr_onerror(boolean,integer,text,text,text,text) _pgr_parameter_check(text,text,boolean) _pgr_pickdelivereuclidean(text,text,double precision,integer,integer) _pgr_pickdeliver(text,integer,double precision,double precision,integer) +pgr_pickdeliver(text,text,text,integer,integer) pgr_pointsaspolygon(character varying,double precision) pgr_pointstodmatrix(geometry[],integer) pgr_pointstovids(geometry[],text,double precision) diff --git a/tools/sql-update-scripts/pgrouting--2.0.0--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.0.0--2.5.0.sql index cff2a10f79b..3279e6962cb 100644 --- a/tools/sql-update-scripts/pgrouting--2.0.0--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.0.0--2.5.0.sql @@ -3216,6 +3216,34 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( +CREATE OR REPLACE FUNCTION pgr_pickDeliver( + orders_sql TEXT, + vehicles_sql TEXT, + matrix_cell_sql TEXT, + max_cycles INTEGER DEFAULT 10, + initial_id INTEGER DEFAULT 4, + + OUT seq INTEGER, + OUT vehicle_number INTEGER, + OUT vehicle_id BIGINT, + OUT vehicle_seq INTEGER, + OUT order_id BIGINT, + OUT stop_type INT, + OUT cargo FLOAT, + OUT travel_time FLOAT, + OUT arrival_time FLOAT, + OUT wait_time FLOAT, + OUT service_time FLOAT, + OUT departure_time FLOAT +) + +RETURNS SETOF RECORD AS + 'MODULE_PATHNAME', 'pickDeliver' +LANGUAGE c VOLATILE; + + + + CREATE OR REPLACE FUNCTION _pgr_pickDeliverEuclidean ( orders_sql TEXT, vehicles_sql TEXT, diff --git a/tools/sql-update-scripts/pgrouting--2.0.1--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.0.1--2.5.0.sql index 8c4bc8ad80d..b3427be6d49 100644 --- a/tools/sql-update-scripts/pgrouting--2.0.1--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.0.1--2.5.0.sql @@ -3216,6 +3216,34 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( +CREATE OR REPLACE FUNCTION pgr_pickDeliver( + orders_sql TEXT, + vehicles_sql TEXT, + matrix_cell_sql TEXT, + max_cycles INTEGER DEFAULT 10, + initial_id INTEGER DEFAULT 4, + + OUT seq INTEGER, + OUT vehicle_number INTEGER, + OUT vehicle_id BIGINT, + OUT vehicle_seq INTEGER, + OUT order_id BIGINT, + OUT stop_type INT, + OUT cargo FLOAT, + OUT travel_time FLOAT, + OUT arrival_time FLOAT, + OUT wait_time FLOAT, + OUT service_time FLOAT, + OUT departure_time FLOAT +) + +RETURNS SETOF RECORD AS + 'MODULE_PATHNAME', 'pickDeliver' +LANGUAGE c VOLATILE; + + + + CREATE OR REPLACE FUNCTION _pgr_pickDeliverEuclidean ( orders_sql TEXT, vehicles_sql TEXT, diff --git a/tools/sql-update-scripts/pgrouting--2.1.0--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.1.0--2.5.0.sql index 24a28f652db..47c8501a164 100644 --- a/tools/sql-update-scripts/pgrouting--2.1.0--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.1.0--2.5.0.sql @@ -3314,6 +3314,34 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( +CREATE OR REPLACE FUNCTION pgr_pickDeliver( + orders_sql TEXT, + vehicles_sql TEXT, + matrix_cell_sql TEXT, + max_cycles INTEGER DEFAULT 10, + initial_id INTEGER DEFAULT 4, + + OUT seq INTEGER, + OUT vehicle_number INTEGER, + OUT vehicle_id BIGINT, + OUT vehicle_seq INTEGER, + OUT order_id BIGINT, + OUT stop_type INT, + OUT cargo FLOAT, + OUT travel_time FLOAT, + OUT arrival_time FLOAT, + OUT wait_time FLOAT, + OUT service_time FLOAT, + OUT departure_time FLOAT +) + +RETURNS SETOF RECORD AS + 'MODULE_PATHNAME', 'pickDeliver' +LANGUAGE c VOLATILE; + + + + CREATE OR REPLACE FUNCTION _pgr_pickDeliverEuclidean ( orders_sql TEXT, vehicles_sql TEXT, diff --git a/tools/sql-update-scripts/pgrouting--2.2.0--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.2.0--2.5.0.sql index dca91669206..93046535fad 100644 --- a/tools/sql-update-scripts/pgrouting--2.2.0--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.2.0--2.5.0.sql @@ -3168,6 +3168,34 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( +CREATE OR REPLACE FUNCTION pgr_pickDeliver( + orders_sql TEXT, + vehicles_sql TEXT, + matrix_cell_sql TEXT, + max_cycles INTEGER DEFAULT 10, + initial_id INTEGER DEFAULT 4, + + OUT seq INTEGER, + OUT vehicle_number INTEGER, + OUT vehicle_id BIGINT, + OUT vehicle_seq INTEGER, + OUT order_id BIGINT, + OUT stop_type INT, + OUT cargo FLOAT, + OUT travel_time FLOAT, + OUT arrival_time FLOAT, + OUT wait_time FLOAT, + OUT service_time FLOAT, + OUT departure_time FLOAT +) + +RETURNS SETOF RECORD AS + 'MODULE_PATHNAME', 'pickDeliver' +LANGUAGE c VOLATILE; + + + + CREATE OR REPLACE FUNCTION _pgr_pickDeliverEuclidean ( orders_sql TEXT, vehicles_sql TEXT, diff --git a/tools/sql-update-scripts/pgrouting--2.2.1--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.2.1--2.5.0.sql index 851ca61657d..d7b624d526a 100644 --- a/tools/sql-update-scripts/pgrouting--2.2.1--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.2.1--2.5.0.sql @@ -3168,6 +3168,34 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( +CREATE OR REPLACE FUNCTION pgr_pickDeliver( + orders_sql TEXT, + vehicles_sql TEXT, + matrix_cell_sql TEXT, + max_cycles INTEGER DEFAULT 10, + initial_id INTEGER DEFAULT 4, + + OUT seq INTEGER, + OUT vehicle_number INTEGER, + OUT vehicle_id BIGINT, + OUT vehicle_seq INTEGER, + OUT order_id BIGINT, + OUT stop_type INT, + OUT cargo FLOAT, + OUT travel_time FLOAT, + OUT arrival_time FLOAT, + OUT wait_time FLOAT, + OUT service_time FLOAT, + OUT departure_time FLOAT +) + +RETURNS SETOF RECORD AS + 'MODULE_PATHNAME', 'pickDeliver' +LANGUAGE c VOLATILE; + + + + CREATE OR REPLACE FUNCTION _pgr_pickDeliverEuclidean ( orders_sql TEXT, vehicles_sql TEXT, diff --git a/tools/sql-update-scripts/pgrouting--2.2.2--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.2.2--2.5.0.sql index e58ac8ee83d..72611b9b798 100644 --- a/tools/sql-update-scripts/pgrouting--2.2.2--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.2.2--2.5.0.sql @@ -3168,6 +3168,34 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( +CREATE OR REPLACE FUNCTION pgr_pickDeliver( + orders_sql TEXT, + vehicles_sql TEXT, + matrix_cell_sql TEXT, + max_cycles INTEGER DEFAULT 10, + initial_id INTEGER DEFAULT 4, + + OUT seq INTEGER, + OUT vehicle_number INTEGER, + OUT vehicle_id BIGINT, + OUT vehicle_seq INTEGER, + OUT order_id BIGINT, + OUT stop_type INT, + OUT cargo FLOAT, + OUT travel_time FLOAT, + OUT arrival_time FLOAT, + OUT wait_time FLOAT, + OUT service_time FLOAT, + OUT departure_time FLOAT +) + +RETURNS SETOF RECORD AS + 'MODULE_PATHNAME', 'pickDeliver' +LANGUAGE c VOLATILE; + + + + CREATE OR REPLACE FUNCTION _pgr_pickDeliverEuclidean ( orders_sql TEXT, vehicles_sql TEXT, diff --git a/tools/sql-update-scripts/pgrouting--2.2.3--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.2.3--2.5.0.sql index bfec31963ec..9d3776aefc2 100644 --- a/tools/sql-update-scripts/pgrouting--2.2.3--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.2.3--2.5.0.sql @@ -3168,6 +3168,34 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( +CREATE OR REPLACE FUNCTION pgr_pickDeliver( + orders_sql TEXT, + vehicles_sql TEXT, + matrix_cell_sql TEXT, + max_cycles INTEGER DEFAULT 10, + initial_id INTEGER DEFAULT 4, + + OUT seq INTEGER, + OUT vehicle_number INTEGER, + OUT vehicle_id BIGINT, + OUT vehicle_seq INTEGER, + OUT order_id BIGINT, + OUT stop_type INT, + OUT cargo FLOAT, + OUT travel_time FLOAT, + OUT arrival_time FLOAT, + OUT wait_time FLOAT, + OUT service_time FLOAT, + OUT departure_time FLOAT +) + +RETURNS SETOF RECORD AS + 'MODULE_PATHNAME', 'pickDeliver' +LANGUAGE c VOLATILE; + + + + CREATE OR REPLACE FUNCTION _pgr_pickDeliverEuclidean ( orders_sql TEXT, vehicles_sql TEXT, diff --git a/tools/sql-update-scripts/pgrouting--2.2.4--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.2.4--2.5.0.sql index 29e04ad1075..5b12948605e 100644 --- a/tools/sql-update-scripts/pgrouting--2.2.4--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.2.4--2.5.0.sql @@ -3168,6 +3168,34 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( +CREATE OR REPLACE FUNCTION pgr_pickDeliver( + orders_sql TEXT, + vehicles_sql TEXT, + matrix_cell_sql TEXT, + max_cycles INTEGER DEFAULT 10, + initial_id INTEGER DEFAULT 4, + + OUT seq INTEGER, + OUT vehicle_number INTEGER, + OUT vehicle_id BIGINT, + OUT vehicle_seq INTEGER, + OUT order_id BIGINT, + OUT stop_type INT, + OUT cargo FLOAT, + OUT travel_time FLOAT, + OUT arrival_time FLOAT, + OUT wait_time FLOAT, + OUT service_time FLOAT, + OUT departure_time FLOAT +) + +RETURNS SETOF RECORD AS + 'MODULE_PATHNAME', 'pickDeliver' +LANGUAGE c VOLATILE; + + + + CREATE OR REPLACE FUNCTION _pgr_pickDeliverEuclidean ( orders_sql TEXT, vehicles_sql TEXT, diff --git a/tools/sql-update-scripts/pgrouting--2.3.0--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.3.0--2.5.0.sql index 33d0e8d5f1e..9d0be39b814 100644 --- a/tools/sql-update-scripts/pgrouting--2.3.0--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.3.0--2.5.0.sql @@ -3198,6 +3198,34 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( +CREATE OR REPLACE FUNCTION pgr_pickDeliver( + orders_sql TEXT, + vehicles_sql TEXT, + matrix_cell_sql TEXT, + max_cycles INTEGER DEFAULT 10, + initial_id INTEGER DEFAULT 4, + + OUT seq INTEGER, + OUT vehicle_number INTEGER, + OUT vehicle_id BIGINT, + OUT vehicle_seq INTEGER, + OUT order_id BIGINT, + OUT stop_type INT, + OUT cargo FLOAT, + OUT travel_time FLOAT, + OUT arrival_time FLOAT, + OUT wait_time FLOAT, + OUT service_time FLOAT, + OUT departure_time FLOAT +) + +RETURNS SETOF RECORD AS + 'MODULE_PATHNAME', 'pickDeliver' +LANGUAGE c VOLATILE; + + + + CREATE OR REPLACE FUNCTION _pgr_pickDeliverEuclidean ( orders_sql TEXT, vehicles_sql TEXT, diff --git a/tools/sql-update-scripts/pgrouting--2.3.1--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.3.1--2.5.0.sql index a8811e99883..0d02efcc100 100644 --- a/tools/sql-update-scripts/pgrouting--2.3.1--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.3.1--2.5.0.sql @@ -3198,6 +3198,34 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( +CREATE OR REPLACE FUNCTION pgr_pickDeliver( + orders_sql TEXT, + vehicles_sql TEXT, + matrix_cell_sql TEXT, + max_cycles INTEGER DEFAULT 10, + initial_id INTEGER DEFAULT 4, + + OUT seq INTEGER, + OUT vehicle_number INTEGER, + OUT vehicle_id BIGINT, + OUT vehicle_seq INTEGER, + OUT order_id BIGINT, + OUT stop_type INT, + OUT cargo FLOAT, + OUT travel_time FLOAT, + OUT arrival_time FLOAT, + OUT wait_time FLOAT, + OUT service_time FLOAT, + OUT departure_time FLOAT +) + +RETURNS SETOF RECORD AS + 'MODULE_PATHNAME', 'pickDeliver' +LANGUAGE c VOLATILE; + + + + CREATE OR REPLACE FUNCTION _pgr_pickDeliverEuclidean ( orders_sql TEXT, vehicles_sql TEXT, diff --git a/tools/sql-update-scripts/pgrouting--2.3.2--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.3.2--2.5.0.sql index 71377bff661..0271b976983 100644 --- a/tools/sql-update-scripts/pgrouting--2.3.2--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.3.2--2.5.0.sql @@ -3198,6 +3198,34 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( +CREATE OR REPLACE FUNCTION pgr_pickDeliver( + orders_sql TEXT, + vehicles_sql TEXT, + matrix_cell_sql TEXT, + max_cycles INTEGER DEFAULT 10, + initial_id INTEGER DEFAULT 4, + + OUT seq INTEGER, + OUT vehicle_number INTEGER, + OUT vehicle_id BIGINT, + OUT vehicle_seq INTEGER, + OUT order_id BIGINT, + OUT stop_type INT, + OUT cargo FLOAT, + OUT travel_time FLOAT, + OUT arrival_time FLOAT, + OUT wait_time FLOAT, + OUT service_time FLOAT, + OUT departure_time FLOAT +) + +RETURNS SETOF RECORD AS + 'MODULE_PATHNAME', 'pickDeliver' +LANGUAGE c VOLATILE; + + + + CREATE OR REPLACE FUNCTION _pgr_pickDeliverEuclidean ( orders_sql TEXT, vehicles_sql TEXT, diff --git a/tools/sql-update-scripts/pgrouting--2.4.0--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.4.0--2.5.0.sql index 53288529de7..aacdf0fefa2 100644 --- a/tools/sql-update-scripts/pgrouting--2.4.0--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.4.0--2.5.0.sql @@ -3159,6 +3159,34 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( +CREATE OR REPLACE FUNCTION pgr_pickDeliver( + orders_sql TEXT, + vehicles_sql TEXT, + matrix_cell_sql TEXT, + max_cycles INTEGER DEFAULT 10, + initial_id INTEGER DEFAULT 4, + + OUT seq INTEGER, + OUT vehicle_number INTEGER, + OUT vehicle_id BIGINT, + OUT vehicle_seq INTEGER, + OUT order_id BIGINT, + OUT stop_type INT, + OUT cargo FLOAT, + OUT travel_time FLOAT, + OUT arrival_time FLOAT, + OUT wait_time FLOAT, + OUT service_time FLOAT, + OUT departure_time FLOAT +) + +RETURNS SETOF RECORD AS + 'MODULE_PATHNAME', 'pickDeliver' +LANGUAGE c VOLATILE; + + + + CREATE OR REPLACE FUNCTION _pgr_pickDeliverEuclidean ( orders_sql TEXT, vehicles_sql TEXT, diff --git a/tools/sql-update-scripts/pgrouting--2.4.1--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.4.1--2.5.0.sql index f9f8d9aeb64..26fbf91187b 100644 --- a/tools/sql-update-scripts/pgrouting--2.4.1--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.4.1--2.5.0.sql @@ -3159,6 +3159,34 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( +CREATE OR REPLACE FUNCTION pgr_pickDeliver( + orders_sql TEXT, + vehicles_sql TEXT, + matrix_cell_sql TEXT, + max_cycles INTEGER DEFAULT 10, + initial_id INTEGER DEFAULT 4, + + OUT seq INTEGER, + OUT vehicle_number INTEGER, + OUT vehicle_id BIGINT, + OUT vehicle_seq INTEGER, + OUT order_id BIGINT, + OUT stop_type INT, + OUT cargo FLOAT, + OUT travel_time FLOAT, + OUT arrival_time FLOAT, + OUT wait_time FLOAT, + OUT service_time FLOAT, + OUT departure_time FLOAT +) + +RETURNS SETOF RECORD AS + 'MODULE_PATHNAME', 'pickDeliver' +LANGUAGE c VOLATILE; + + + + CREATE OR REPLACE FUNCTION _pgr_pickDeliverEuclidean ( orders_sql TEXT, vehicles_sql TEXT, diff --git a/tools/sql-update-scripts/pgrouting--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.5.0.sql index 5782e8dcaa0..dfdc5cd452f 100644 --- a/tools/sql-update-scripts/pgrouting--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.5.0.sql @@ -3066,6 +3066,34 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( +CREATE OR REPLACE FUNCTION pgr_pickDeliver( + orders_sql TEXT, + vehicles_sql TEXT, + matrix_cell_sql TEXT, + max_cycles INTEGER DEFAULT 10, + initial_id INTEGER DEFAULT 4, + + OUT seq INTEGER, + OUT vehicle_number INTEGER, + OUT vehicle_id BIGINT, + OUT vehicle_seq INTEGER, + OUT order_id BIGINT, + OUT stop_type INT, + OUT cargo FLOAT, + OUT travel_time FLOAT, + OUT arrival_time FLOAT, + OUT wait_time FLOAT, + OUT service_time FLOAT, + OUT departure_time FLOAT +) + +RETURNS SETOF RECORD AS + 'MODULE_PATHNAME', 'pickDeliver' +LANGUAGE c VOLATILE; + + + + CREATE OR REPLACE FUNCTION _pgr_pickDeliverEuclidean ( orders_sql TEXT, vehicles_sql TEXT, From 2ab96fe77715cc3f09f10f59f0b6274bfcfe2943 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Mon, 15 May 2017 10:31:18 -0500 Subject: [PATCH 02/40] code compiles --- CMakeLists.txt | 2 +- include/pickDeliver/dnode.h | 2 +- sql/pickDeliver/CMakeLists.txt | 4 +- src/pickDeliver/src/CMakeLists.txt | 3 - src/pickDeliver/src/pickDeliver.c | 19 ++++- src/pickDeliverE/src/pgr_pickDeliver.cpp | 90 +++++++++++------------- 6 files changed, 62 insertions(+), 58 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5141f4be557..874913c05e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,7 +104,7 @@ set(PgRouting_SOURCE_NAMES #---------------------- "max_flow" # 2.3 "contraction" # 2.3 - #"pickDeliver" # 2.3 + "pickDeliver" # 2.3 "pickDeliverE" # 2.5 "vrp_basic" # 2.0 "withPoints" # 2.2 diff --git a/include/pickDeliver/dnode.h b/include/pickDeliver/dnode.h index 9820987596f..5fddae99875 100644 --- a/include/pickDeliver/dnode.h +++ b/include/pickDeliver/dnode.h @@ -31,7 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "pickDeliver/base_node.h" +#include "vrp/base_node.h" #include "pickDeliver/pd_problem.h" namespace pgrouting { diff --git a/sql/pickDeliver/CMakeLists.txt b/sql/pickDeliver/CMakeLists.txt index 20ff541bea1..c451f32fc35 100644 --- a/sql/pickDeliver/CMakeLists.txt +++ b/sql/pickDeliver/CMakeLists.txt @@ -1,8 +1,6 @@ SET(LOCAL_FILES - pickDeliverEuclidean.sql - #pickDeliver.sql - reginabook.sql + pickDeliver.sql ) foreach (f ${LOCAL_FILES}) diff --git a/src/pickDeliver/src/CMakeLists.txt b/src/pickDeliver/src/CMakeLists.txt index f55b04034a3..5ceb279e1f2 100644 --- a/src/pickDeliver/src/CMakeLists.txt +++ b/src/pickDeliver/src/CMakeLists.txt @@ -1,6 +1,4 @@ ADD_LIBRARY(pickDeliver OBJECT - base_node.cpp - node.cpp dnode.cpp tw_node.cpp vehicle_node.cpp @@ -18,7 +16,6 @@ ADD_LIBRARY(pickDeliver OBJECT optimize.cpp pgr_pickDeliver.cpp - pgr_messages.cpp pickDeliver_driver.cpp diff --git a/src/pickDeliver/src/pickDeliver.c b/src/pickDeliver/src/pickDeliver.c index e45d71d7c76..ef5a2d5ee43 100644 --- a/src/pickDeliver/src/pickDeliver.c +++ b/src/pickDeliver/src/pickDeliver.c @@ -47,11 +47,22 @@ process( char* pd_orders_sql, char* vehicles_sql, char* matrix_sql, + double factor, int max_cycles, int initial_solution_id, General_vehicle_orders_t **result_tuples, size_t *result_count) { + if (factor <= 0) { + ereport(ERROR, + (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("Illegal value in parameter: factor"), + errhint("Value found: %f <= 0", factor))); + (*result_count) = 0; + (*result_tuples) = NULL; + return; + } + if (max_cycles < 0) { elog(ERROR, "Illegal value in parameter: max_cycles"); (*result_count) = 0; @@ -188,16 +199,18 @@ pickDeliver(PG_FUNCTION_ARGS) { orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, - max_cycles INTEGER DEFAULT 10, + factor FLOAT DEFAULT 1, + max_cycles INTEGER DEFAULT 10, + initial_sol INTEGER DEFAULT 4, **********************************************************************/ - PGR_DBG("Calling process"); process( text_to_cstring(PG_GETARG_TEXT_P(0)), text_to_cstring(PG_GETARG_TEXT_P(1)), text_to_cstring(PG_GETARG_TEXT_P(2)), - PG_GETARG_INT32(3), + PG_GETARG_FLOAT8(3), PG_GETARG_INT32(4), + PG_GETARG_INT32(5), &result_tuples, &result_count); diff --git a/src/pickDeliverE/src/pgr_pickDeliver.cpp b/src/pickDeliverE/src/pgr_pickDeliver.cpp index 8ac2532e98b..7dd3e087723 100644 --- a/src/pickDeliverE/src/pgr_pickDeliver.cpp +++ b/src/pickDeliverE/src/pgr_pickDeliver.cpp @@ -163,7 +163,6 @@ Pgr_pickDeliver::get_postgres_result() const { /** Constructor for the matrix version * */ - Pgr_pickDeliver::Pgr_pickDeliver( const std::vector &pd_orders, const std::vector &vehicles, @@ -174,9 +173,6 @@ Pgr_pickDeliver::Pgr_pickDeliver( PD_problem(this), m_initial_id(initial), m_max_cycles(p_max_cycles), - /* - * the problem has cost_matrix.size() nodes - */ m_node_id(0), m_nodes(), m_cost_matrix(cost_matrix), @@ -189,9 +185,8 @@ Pgr_pickDeliver::Pgr_pickDeliver( pgassert(m_initial_id > 0 && m_initial_id < 7); pgassert(msg.get_error().empty()); - std::ostringstream tmplog; - msg.log << "\n *** Constructor for the matrix version ***\n"; + ENTERING(); if (!msg.get_error().empty()) { return; @@ -199,12 +194,15 @@ Pgr_pickDeliver::Pgr_pickDeliver( pgassert(msg.get_error().empty()); +#if 0 if (!m_trucks.is_fleet_ok()) { // TODO(vicky) revise the function pgassert(false); msg.error << m_trucks.msg.get_error(); return; } +#endif + EXITING(); } // constructor @@ -220,69 +218,67 @@ Pgr_pickDeliver::Pgr_pickDeliver( PD_problem(this), m_initial_id(initial), m_max_cycles(p_max_cycles), - /* - * the problem has unknown number of nodes - */ m_node_id(0), m_nodes(), m_base_nodes(), m_orders(pd_orders), m_trucks(vehicles, factor) { - pgassert(!pd_orders.empty()); - pgassert(!vehicles.empty()); - pgassert(m_initial_id > 0 && m_initial_id < 7); - - std::ostringstream tmplog; + pgassert(!pd_orders.empty()); + pgassert(!vehicles.empty()); + pgassert(factor > 0); + pgassert(m_initial_id > 0 && m_initial_id < 7); - msg.log << "\n *** Constructor of problem ***\n"; + ENTERING(); - if (!msg.get_error().empty()) { - return; - } + if (!msg.get_error().empty()) { + return; + } - pgassert(msg.get_error().empty()); - msg.log << "\n Building fleet"; - if (!m_trucks.is_fleet_ok()) { pgassert(msg.get_error().empty()); - pgassert(!m_trucks.msg.get_error().empty()); - msg.error << m_trucks.msg.get_error(); - return; - } + + msg.log << "\n Checking fleet"; + if (!m_trucks.is_fleet_ok()) { + pgassert(msg.get_error().empty()); + pgassert(!m_trucks.msg.get_error().empty()); + msg.error << m_trucks.msg.get_error(); + return; + } #ifndef NDEBUG - for (const auto t : m_trucks) { - msg.log << t << "\n"; - } + for (const auto t : m_trucks) { + msg.log << t << "\n"; + } #endif - msg.log << "\n Building orders"; - msg.log << " ---> OK\n"; + msg.log << "\n Building orders"; + msg.log << " ---> OK\n"; #ifndef NDEBUG - for (const auto &o : m_orders) { - msg.log << o << "\n"; - } + for (const auto &o : m_orders) { + msg.log << o << "\n"; + } #endif - /* - * check the (S, P, D, E) order on all vehicles - * stop when a feasible truck is found - */ - for (const auto &o : m_orders) { - if (!m_trucks.is_order_ok(o)) { - msg.error << "The order " - << o.pickup().order() - << " is not feasible on any truck"; - msg.log << "\n" << o; - return; + /* + * check the (S, P, D, E) order on all vehicles + * stop when a feasible truck is found + */ + for (const auto &o : m_orders) { + if (!m_trucks.is_order_ok(o)) { + msg.error << "The order " + << o.pickup().order() + << " is not feasible on any truck"; + msg.log << "\n" << o; + return; + } } - } - m_trucks.set_compatibles(m_orders); -} // constructor + m_trucks.set_compatibles(m_orders); + EXITING(); + } // constructor const Order From 2ae05d5067ee1175dae38c1dc6b4a188fedf9b6a Mon Sep 17 00:00:00 2001 From: cvvergara Date: Mon, 15 May 2017 10:32:22 -0500 Subject: [PATCH 03/40] code compiles --- sql/sigs/pgrouting--2.5.0.sig | 2 +- tools/sql-update-scripts/pgrouting--2.0.0--2.5.0.sql | 3 ++- tools/sql-update-scripts/pgrouting--2.0.1--2.5.0.sql | 3 ++- tools/sql-update-scripts/pgrouting--2.1.0--2.5.0.sql | 3 ++- tools/sql-update-scripts/pgrouting--2.2.0--2.5.0.sql | 3 ++- tools/sql-update-scripts/pgrouting--2.2.1--2.5.0.sql | 3 ++- tools/sql-update-scripts/pgrouting--2.2.2--2.5.0.sql | 3 ++- tools/sql-update-scripts/pgrouting--2.2.3--2.5.0.sql | 3 ++- tools/sql-update-scripts/pgrouting--2.2.4--2.5.0.sql | 3 ++- tools/sql-update-scripts/pgrouting--2.3.0--2.5.0.sql | 3 ++- tools/sql-update-scripts/pgrouting--2.3.1--2.5.0.sql | 3 ++- tools/sql-update-scripts/pgrouting--2.3.2--2.5.0.sql | 3 ++- tools/sql-update-scripts/pgrouting--2.4.0--2.5.0.sql | 3 ++- tools/sql-update-scripts/pgrouting--2.4.1--2.5.0.sql | 3 ++- tools/sql-update-scripts/pgrouting--2.5.0.sql | 3 ++- 15 files changed, 29 insertions(+), 15 deletions(-) diff --git a/sql/sigs/pgrouting--2.5.0.sig b/sql/sigs/pgrouting--2.5.0.sig index d80ab65bb8c..d99384d07be 100644 --- a/sql/sigs/pgrouting--2.5.0.sig +++ b/sql/sigs/pgrouting--2.5.0.sig @@ -130,7 +130,7 @@ _pgr_onerror(boolean,integer,text,text,text,text) _pgr_parameter_check(text,text,boolean) _pgr_pickdelivereuclidean(text,text,double precision,integer,integer) _pgr_pickdeliver(text,integer,double precision,double precision,integer) -pgr_pickdeliver(text,text,text,integer,integer) +pgr_pickdeliver(text,text,text,double precision,integer,integer) pgr_pointsaspolygon(character varying,double precision) pgr_pointstodmatrix(geometry[],integer) pgr_pointstovids(geometry[],text,double precision) diff --git a/tools/sql-update-scripts/pgrouting--2.0.0--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.0.0--2.5.0.sql index 3279e6962cb..e5a71c69201 100644 --- a/tools/sql-update-scripts/pgrouting--2.0.0--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.0.0--2.5.0.sql @@ -3220,8 +3220,9 @@ CREATE OR REPLACE FUNCTION pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, + factor FLOAT DEFAULT 1, max_cycles INTEGER DEFAULT 10, - initial_id INTEGER DEFAULT 4, + initial_sol INTEGER DEFAULT 4, OUT seq INTEGER, OUT vehicle_number INTEGER, diff --git a/tools/sql-update-scripts/pgrouting--2.0.1--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.0.1--2.5.0.sql index b3427be6d49..33585005727 100644 --- a/tools/sql-update-scripts/pgrouting--2.0.1--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.0.1--2.5.0.sql @@ -3220,8 +3220,9 @@ CREATE OR REPLACE FUNCTION pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, + factor FLOAT DEFAULT 1, max_cycles INTEGER DEFAULT 10, - initial_id INTEGER DEFAULT 4, + initial_sol INTEGER DEFAULT 4, OUT seq INTEGER, OUT vehicle_number INTEGER, diff --git a/tools/sql-update-scripts/pgrouting--2.1.0--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.1.0--2.5.0.sql index 47c8501a164..d277e1971c6 100644 --- a/tools/sql-update-scripts/pgrouting--2.1.0--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.1.0--2.5.0.sql @@ -3318,8 +3318,9 @@ CREATE OR REPLACE FUNCTION pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, + factor FLOAT DEFAULT 1, max_cycles INTEGER DEFAULT 10, - initial_id INTEGER DEFAULT 4, + initial_sol INTEGER DEFAULT 4, OUT seq INTEGER, OUT vehicle_number INTEGER, diff --git a/tools/sql-update-scripts/pgrouting--2.2.0--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.2.0--2.5.0.sql index 93046535fad..7a3d53aca0f 100644 --- a/tools/sql-update-scripts/pgrouting--2.2.0--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.2.0--2.5.0.sql @@ -3172,8 +3172,9 @@ CREATE OR REPLACE FUNCTION pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, + factor FLOAT DEFAULT 1, max_cycles INTEGER DEFAULT 10, - initial_id INTEGER DEFAULT 4, + initial_sol INTEGER DEFAULT 4, OUT seq INTEGER, OUT vehicle_number INTEGER, diff --git a/tools/sql-update-scripts/pgrouting--2.2.1--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.2.1--2.5.0.sql index d7b624d526a..6013d13fdd9 100644 --- a/tools/sql-update-scripts/pgrouting--2.2.1--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.2.1--2.5.0.sql @@ -3172,8 +3172,9 @@ CREATE OR REPLACE FUNCTION pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, + factor FLOAT DEFAULT 1, max_cycles INTEGER DEFAULT 10, - initial_id INTEGER DEFAULT 4, + initial_sol INTEGER DEFAULT 4, OUT seq INTEGER, OUT vehicle_number INTEGER, diff --git a/tools/sql-update-scripts/pgrouting--2.2.2--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.2.2--2.5.0.sql index 72611b9b798..f4f70c6d5e9 100644 --- a/tools/sql-update-scripts/pgrouting--2.2.2--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.2.2--2.5.0.sql @@ -3172,8 +3172,9 @@ CREATE OR REPLACE FUNCTION pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, + factor FLOAT DEFAULT 1, max_cycles INTEGER DEFAULT 10, - initial_id INTEGER DEFAULT 4, + initial_sol INTEGER DEFAULT 4, OUT seq INTEGER, OUT vehicle_number INTEGER, diff --git a/tools/sql-update-scripts/pgrouting--2.2.3--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.2.3--2.5.0.sql index 9d3776aefc2..12f24e92c21 100644 --- a/tools/sql-update-scripts/pgrouting--2.2.3--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.2.3--2.5.0.sql @@ -3172,8 +3172,9 @@ CREATE OR REPLACE FUNCTION pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, + factor FLOAT DEFAULT 1, max_cycles INTEGER DEFAULT 10, - initial_id INTEGER DEFAULT 4, + initial_sol INTEGER DEFAULT 4, OUT seq INTEGER, OUT vehicle_number INTEGER, diff --git a/tools/sql-update-scripts/pgrouting--2.2.4--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.2.4--2.5.0.sql index 5b12948605e..cadc002ea8b 100644 --- a/tools/sql-update-scripts/pgrouting--2.2.4--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.2.4--2.5.0.sql @@ -3172,8 +3172,9 @@ CREATE OR REPLACE FUNCTION pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, + factor FLOAT DEFAULT 1, max_cycles INTEGER DEFAULT 10, - initial_id INTEGER DEFAULT 4, + initial_sol INTEGER DEFAULT 4, OUT seq INTEGER, OUT vehicle_number INTEGER, diff --git a/tools/sql-update-scripts/pgrouting--2.3.0--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.3.0--2.5.0.sql index 9d0be39b814..b463b7f2d1f 100644 --- a/tools/sql-update-scripts/pgrouting--2.3.0--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.3.0--2.5.0.sql @@ -3202,8 +3202,9 @@ CREATE OR REPLACE FUNCTION pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, + factor FLOAT DEFAULT 1, max_cycles INTEGER DEFAULT 10, - initial_id INTEGER DEFAULT 4, + initial_sol INTEGER DEFAULT 4, OUT seq INTEGER, OUT vehicle_number INTEGER, diff --git a/tools/sql-update-scripts/pgrouting--2.3.1--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.3.1--2.5.0.sql index 0d02efcc100..ab2e5ecbcac 100644 --- a/tools/sql-update-scripts/pgrouting--2.3.1--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.3.1--2.5.0.sql @@ -3202,8 +3202,9 @@ CREATE OR REPLACE FUNCTION pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, + factor FLOAT DEFAULT 1, max_cycles INTEGER DEFAULT 10, - initial_id INTEGER DEFAULT 4, + initial_sol INTEGER DEFAULT 4, OUT seq INTEGER, OUT vehicle_number INTEGER, diff --git a/tools/sql-update-scripts/pgrouting--2.3.2--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.3.2--2.5.0.sql index 0271b976983..68f9aa84029 100644 --- a/tools/sql-update-scripts/pgrouting--2.3.2--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.3.2--2.5.0.sql @@ -3202,8 +3202,9 @@ CREATE OR REPLACE FUNCTION pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, + factor FLOAT DEFAULT 1, max_cycles INTEGER DEFAULT 10, - initial_id INTEGER DEFAULT 4, + initial_sol INTEGER DEFAULT 4, OUT seq INTEGER, OUT vehicle_number INTEGER, diff --git a/tools/sql-update-scripts/pgrouting--2.4.0--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.4.0--2.5.0.sql index aacdf0fefa2..d34b936751c 100644 --- a/tools/sql-update-scripts/pgrouting--2.4.0--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.4.0--2.5.0.sql @@ -3163,8 +3163,9 @@ CREATE OR REPLACE FUNCTION pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, + factor FLOAT DEFAULT 1, max_cycles INTEGER DEFAULT 10, - initial_id INTEGER DEFAULT 4, + initial_sol INTEGER DEFAULT 4, OUT seq INTEGER, OUT vehicle_number INTEGER, diff --git a/tools/sql-update-scripts/pgrouting--2.4.1--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.4.1--2.5.0.sql index 26fbf91187b..5dbf598cdcd 100644 --- a/tools/sql-update-scripts/pgrouting--2.4.1--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.4.1--2.5.0.sql @@ -3163,8 +3163,9 @@ CREATE OR REPLACE FUNCTION pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, + factor FLOAT DEFAULT 1, max_cycles INTEGER DEFAULT 10, - initial_id INTEGER DEFAULT 4, + initial_sol INTEGER DEFAULT 4, OUT seq INTEGER, OUT vehicle_number INTEGER, diff --git a/tools/sql-update-scripts/pgrouting--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.5.0.sql index dfdc5cd452f..ade8c0b3104 100644 --- a/tools/sql-update-scripts/pgrouting--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.5.0.sql @@ -3070,8 +3070,9 @@ CREATE OR REPLACE FUNCTION pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, + factor FLOAT DEFAULT 1, max_cycles INTEGER DEFAULT 10, - initial_id INTEGER DEFAULT 4, + initial_sol INTEGER DEFAULT 4, OUT seq INTEGER, OUT vehicle_number INTEGER, From 12761958cdae71284cec8be3a2462b1399929352 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Mon, 15 May 2017 11:01:31 -0500 Subject: [PATCH 04/40] code compiles --- .../drivers/pickDeliver/pickDeliver_driver.h | 1 + include/pickDeliver/dnode.h | 4 +-- include/vrp/base_node.h | 2 -- include/vrp/pgr_pickDeliver.h | 4 +-- src/pickDeliver/src/CMakeLists.txt | 26 +++++++++---------- src/pickDeliver/src/dnode.cpp | 4 +-- src/pickDeliver/src/pickDeliver.c | 2 ++ src/pickDeliver/src/pickDeliver_driver.cpp | 11 +++++--- src/pickDeliverE/src/base_node.cpp | 2 -- src/pickDeliverE/src/fleet.cpp | 4 +-- src/pickDeliverE/src/pd_orders.cpp | 4 +-- src/pickDeliverE/src/pgr_pickDeliver.cpp | 11 +++++--- 12 files changed, 38 insertions(+), 37 deletions(-) diff --git a/include/drivers/pickDeliver/pickDeliver_driver.h b/include/drivers/pickDeliver/pickDeliver_driver.h index 19df8d11b57..56974adf605 100644 --- a/include/drivers/pickDeliver/pickDeliver_driver.h +++ b/include/drivers/pickDeliver/pickDeliver_driver.h @@ -52,6 +52,7 @@ extern "C" { Vehicle_t *vehicles_arr, size_t total_vehicles, Matrix_cell_t *matrix_cells_arr, size_t total_cells, + double factor, int max_cycles, int initial_solution_id, diff --git a/include/pickDeliver/dnode.h b/include/pickDeliver/dnode.h index 5fddae99875..8338de705db 100644 --- a/include/pickDeliver/dnode.h +++ b/include/pickDeliver/dnode.h @@ -32,11 +32,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include "vrp/base_node.h" -#include "pickDeliver/pd_problem.h" +#include "vrp/pd_problem.h" namespace pgrouting { namespace vrp { -namespace pickdeliver { /*! @class Dnode * @brief The Dnode class defines a the operations when its a matrix. @@ -65,7 +64,6 @@ class Dnode : public Base_node, public PD_problem { friend std::ostream& operator << (std::ostream &log, const Dnode &node); }; -} // namespace pickdeliver } // namespace vrp } // namespace pgrouting diff --git a/include/vrp/base_node.h b/include/vrp/base_node.h index 0be24d872a7..8011fda4119 100644 --- a/include/vrp/base_node.h +++ b/include/vrp/base_node.h @@ -41,7 +41,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. namespace pgrouting { namespace vrp { -namespace pickdeliver { /*! \class Base_node * \brief The Base_node class defines the operations that can be performed in a 2D node. @@ -98,7 +97,6 @@ class Base_node : public Identifier { #endif }; -} // namespace pickdeliver } // namespace vrp } // namespace pgrouting diff --git a/include/vrp/pgr_pickDeliver.h b/include/vrp/pgr_pickDeliver.h index 56d63f6fe52..7856f5ebc8f 100644 --- a/include/vrp/pgr_pickDeliver.h +++ b/include/vrp/pgr_pickDeliver.h @@ -110,7 +110,7 @@ class Pgr_pickDeliver : public PD_problem { m_nodes.push_back(node); } - void add_base_node(std::unique_ptr node_ptr) { + void add_base_node(std::unique_ptr node_ptr) { m_base_nodes.push_back(std::move(node_ptr)); } @@ -135,7 +135,7 @@ class Pgr_pickDeliver : public PD_problem { public: // TODO(vicky) make this private - std::vector> m_base_nodes; + std::vector> m_base_nodes; private: pgrouting::tsp::Dmatrix m_cost_matrix; diff --git a/src/pickDeliver/src/CMakeLists.txt b/src/pickDeliver/src/CMakeLists.txt index 5ceb279e1f2..2b94826ebf1 100644 --- a/src/pickDeliver/src/CMakeLists.txt +++ b/src/pickDeliver/src/CMakeLists.txt @@ -1,21 +1,21 @@ ADD_LIBRARY(pickDeliver OBJECT dnode.cpp - tw_node.cpp - vehicle_node.cpp + #tw_node.cpp + #vehicle_node.cpp - order.cpp - pd_orders.cpp - fleet.cpp - vehicle.cpp - pd_problem.cpp - vehicle_pickDeliver.cpp - book_keeping.cpp + #order.cpp + #pd_orders.cpp + #fleet.cpp + #vehicle.cpp + #pd_problem.cpp + #vehicle_pickDeliver.cpp + #book_keeping.cpp - solution.cpp - initial_solution.cpp - optimize.cpp + #solution.cpp + #initial_solution.cpp + #optimize.cpp - pgr_pickDeliver.cpp + #pgr_pickDeliver.cpp pickDeliver_driver.cpp diff --git a/src/pickDeliver/src/dnode.cpp b/src/pickDeliver/src/dnode.cpp index ba0115b2440..8a51b5a05ee 100644 --- a/src/pickDeliver/src/dnode.cpp +++ b/src/pickDeliver/src/dnode.cpp @@ -24,12 +24,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ #include "pickDeliver/dnode.h" -#include "pickDeliver/pgr_pickDeliver.h" +#include "vrp/pgr_pickDeliver.h" #include "cpp_common/pgr_messages.h" namespace pgrouting { namespace vrp { -namespace pickdeliver { #if 0 bool Dnode::isSamePos(const Dnode &other) const { @@ -101,7 +100,6 @@ Dnode::operator ==(const Dnode &rhs) const { } #endif -} // namespace pickdeliver } // namespace vrp } // namespace pgrouting diff --git a/src/pickDeliver/src/pickDeliver.c b/src/pickDeliver/src/pickDeliver.c index ef5a2d5ee43..f418d1c6383 100644 --- a/src/pickDeliver/src/pickDeliver.c +++ b/src/pickDeliver/src/pickDeliver.c @@ -142,6 +142,8 @@ process( pd_orders_arr, total_pd_orders, vehicles_arr, total_vehicles, matrix_cells_arr, total_cells, + + factor, max_cycles, initial_solution_id, diff --git a/src/pickDeliver/src/pickDeliver_driver.cpp b/src/pickDeliver/src/pickDeliver_driver.cpp index d3c497e2ec9..fa23ce10003 100644 --- a/src/pickDeliver/src/pickDeliver_driver.cpp +++ b/src/pickDeliver/src/pickDeliver_driver.cpp @@ -36,7 +36,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "pickDeliver/pgr_pickDeliver.h" +#include "vrp/pgr_pickDeliver.h" #include "cpp_common/Dmatrix.h" #include "cpp_common/pgr_assert.h" @@ -53,6 +53,7 @@ do_pgr_pickDeliver( Matrix_cell_t *matrix_cells_arr, size_t total_cells, + double factor, int max_cycles, int initial_solution_id, @@ -99,13 +100,15 @@ do_pgr_pickDeliver( } log << "Read data\n"; - pgrouting::vrp::pickdeliver::Pgr_pickDeliver pd_problem( + pgrouting::vrp::Pgr_pickDeliver pd_problem( orders, vehicles, cost_matrix, + factor, max_cycles, initial_solution_id); +#if 0 if (!pd_problem.msg.has_error()) { log << "ERROR found\n"; log << pd_problem.msg.get_log(); @@ -119,7 +122,7 @@ do_pgr_pickDeliver( log << "Finish Reading data\n"; pd_problem.msg.clear(); -#if 1 +#if 0 log << pd_problem; log << pd_problem.msg.get_log(); log << "Finish printing read data\n"; @@ -155,7 +158,7 @@ do_pgr_pickDeliver( } } (*return_count) = solution.size(); - +#endif pgassert(*err_msg == NULL); *log_msg = log.str().empty()? nullptr : diff --git a/src/pickDeliverE/src/base_node.cpp b/src/pickDeliverE/src/base_node.cpp index d66b94d0ecf..b2b310a3678 100644 --- a/src/pickDeliverE/src/base_node.cpp +++ b/src/pickDeliverE/src/base_node.cpp @@ -28,7 +28,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. namespace pgrouting { namespace vrp { -namespace pickdeliver { bool Base_node::isSamePos(const Base_node &rhs) const { @@ -83,7 +82,6 @@ Base_node::operator ==(const Base_node &rhs) const { && (id() == rhs.id()); } -} // namespace pickdeliver } // namespace vrp } // namespace pgrouting diff --git a/src/pickDeliverE/src/fleet.cpp b/src/pickDeliverE/src/fleet.cpp index 17ab7ecebfa..b0099d6747f 100644 --- a/src/pickDeliverE/src/fleet.cpp +++ b/src/pickDeliverE/src/fleet.cpp @@ -170,7 +170,7 @@ Fleet::build_fleet( return false; } - std::unique_ptr b_start(new pickdeliver::Node( + std::unique_ptr b_start(new pickdeliver::Node( problem->node_id(), vehicle.start_node_id, vehicle.start_x, @@ -178,7 +178,7 @@ Fleet::build_fleet( auto starting_site = Vehicle_node( {problem->node_id()++, vehicle, Tw_node::NodeType::kStart}); - std::unique_ptr b_end(new pickdeliver::Node( + std::unique_ptr b_end(new pickdeliver::Node( problem->node_id(), vehicle.end_node_id, vehicle.end_x, diff --git a/src/pickDeliverE/src/pd_orders.cpp b/src/pickDeliverE/src/pd_orders.cpp index c410410ed7a..471dfa38775 100644 --- a/src/pickDeliverE/src/pd_orders.cpp +++ b/src/pickDeliverE/src/pd_orders.cpp @@ -62,7 +62,7 @@ PD_Orders::build_orders( /* * Creating the pickup & delivery nodes */ - std::unique_ptr b_pick(new pickdeliver::Node( + std::unique_ptr b_pick(new pickdeliver::Node( problem->node_id(), order.pick_node_id, order.pick_x, @@ -79,7 +79,7 @@ PD_Orders::build_orders( msg.log << pickup.id() << "\n"; #endif - std::unique_ptr b_drop(new pickdeliver::Node( + std::unique_ptr b_drop(new pickdeliver::Node( problem->node_id(), order.deliver_node_id, order.deliver_x, diff --git a/src/pickDeliverE/src/pgr_pickDeliver.cpp b/src/pickDeliverE/src/pgr_pickDeliver.cpp index 7dd3e087723..66b5980aa93 100644 --- a/src/pickDeliverE/src/pgr_pickDeliver.cpp +++ b/src/pickDeliverE/src/pgr_pickDeliver.cpp @@ -170,13 +170,18 @@ Pgr_pickDeliver::Pgr_pickDeliver( double factor, size_t p_max_cycles, int initial) : - PD_problem(this), + PD_problem(this) +#if 0 m_initial_id(initial), m_max_cycles(p_max_cycles), m_node_id(0), m_nodes(), m_cost_matrix(cost_matrix), - m_trucks(vehicles, factor) { + m_trucks(vehicles, factor) +#endif +{ + ENTERING(); +#if 0 pgassert(msg.get_error().empty()); pgassert(!pd_orders.empty()); @@ -186,7 +191,6 @@ Pgr_pickDeliver::Pgr_pickDeliver( pgassert(msg.get_error().empty()); - ENTERING(); if (!msg.get_error().empty()) { return; @@ -194,7 +198,6 @@ Pgr_pickDeliver::Pgr_pickDeliver( pgassert(msg.get_error().empty()); -#if 0 if (!m_trucks.is_fleet_ok()) { // TODO(vicky) revise the function pgassert(false); From adde41063fdc1d34297236c9f4c24cc26b8e87c4 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Mon, 15 May 2017 11:08:19 -0500 Subject: [PATCH 05/40] initial test pass --- src/pickDeliver/test/doc-pickDeliver.result | 5 +++-- src/pickDeliver/test/doc-pickDeliver.test.sql | 6 ++++-- src/pickDeliver/test/test.conf | 3 +-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/pickDeliver/test/doc-pickDeliver.result b/src/pickDeliver/test/doc-pickDeliver.result index ff12b423bb7..f1bc20f7d37 100644 --- a/src/pickDeliver/test/doc-pickDeliver.result +++ b/src/pickDeliver/test/doc-pickDeliver.result @@ -6,6 +6,7 @@ SET SELECT * FROM pgr_pickDeliver( 'SELECT * FROM orders ORDER BY id', 'SELECT * from vehicles', + 'WITH A AS ( SELECT p_node_id AS id, p_x AS x, p_y AS y FROM orders @@ -15,8 +16,8 @@ SELECT * FROM pgr_pickDeliver( SELECT start_node_id, start_x, start_y FROM vehicles ) SELECT A.id AS start_vid, B.id AS end_vid, sqrt( (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) AS agg_cost - FROM A, A AS B WHERE A.id != B.id', - 30); + FROM A, A AS B WHERE A.id != B.id' + ); seq | vehicle_number | vehicle_id | vehicle_seq | order_id | stop_type | cargo | travel_time | arrival_time | wait_time | service_time | departure_time -----+----------------+------------+-------------+----------+-----------+-------+-------------+--------------+-----------+--------------+---------------- (0 rows) diff --git a/src/pickDeliver/test/doc-pickDeliver.test.sql b/src/pickDeliver/test/doc-pickDeliver.test.sql index f43e94a3b2b..d06ed5dfed8 100644 --- a/src/pickDeliver/test/doc-pickDeliver.test.sql +++ b/src/pickDeliver/test/doc-pickDeliver.test.sql @@ -1,7 +1,9 @@ \echo --q1 +-- using the default values SELECT * FROM pgr_pickDeliver( 'SELECT * FROM orders ORDER BY id', 'SELECT * from vehicles', + -- matrix query 'WITH A AS ( SELECT p_node_id AS id, p_x AS x, p_y AS y FROM orders @@ -11,7 +13,7 @@ SELECT * FROM pgr_pickDeliver( SELECT start_node_id, start_x, start_y FROM vehicles ) SELECT A.id AS start_vid, B.id AS end_vid, sqrt( (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) AS agg_cost - FROM A, A AS B WHERE A.id != B.id', - 30); + FROM A, A AS B WHERE A.id != B.id' + ); \echo --q2 diff --git a/src/pickDeliver/test/test.conf b/src/pickDeliver/test/test.conf index bf3aadcbba4..9882e5b7126 100644 --- a/src/pickDeliver/test/test.conf +++ b/src/pickDeliver/test/test.conf @@ -16,7 +16,7 @@ differentVechiles-cygwin )], 'linux' => [qw( - doc-pickDeliverEuclidean + doc-pickDeliver )], 'documentation' => [qw( doc-pickDeliverEuclidean @@ -33,7 +33,6 @@ jet_customers1 jet_customers differentVechiles - doc-pickDeliver book_from_query jet_customers1 From c90662a28d5c7edcae58f99a9ae2515a594e1ae1 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Mon, 15 May 2017 11:18:57 -0500 Subject: [PATCH 06/40] test pass, reading matrix --- src/pickDeliver/src/pickDeliver_driver.cpp | 10 ++++++++++ src/pickDeliverE/src/pd_orders.cpp | 2 ++ src/pickDeliverE/src/pgr_pickDeliver.cpp | 7 +++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/pickDeliver/src/pickDeliver_driver.cpp b/src/pickDeliver/src/pickDeliver_driver.cpp index fa23ce10003..363cb78c62f 100644 --- a/src/pickDeliver/src/pickDeliver_driver.cpp +++ b/src/pickDeliver/src/pickDeliver_driver.cpp @@ -108,6 +108,16 @@ do_pgr_pickDeliver( max_cycles, initial_solution_id); + err << pd_problem.msg.get_error(); + if (!err.str().empty()) { + log << pd_problem.msg.get_log(); + *log_msg = pgr_msg(log.str().c_str()); + *err_msg = pgr_msg(err.str().c_str()); + return; + } + log << pd_problem.msg.get_log(); + log << "Finish Reading data\n"; + #if 0 if (!pd_problem.msg.has_error()) { log << "ERROR found\n"; diff --git a/src/pickDeliverE/src/pd_orders.cpp b/src/pickDeliverE/src/pd_orders.cpp index 471dfa38775..c8ea35a3d46 100644 --- a/src/pickDeliverE/src/pd_orders.cpp +++ b/src/pickDeliverE/src/pd_orders.cpp @@ -52,6 +52,7 @@ PD_Orders::build_orders( ) { OID order_id(0); for (const auto order : pd_orders) { + ENTERING(); /* * SAMPLE CORRECT INFORMATION * @@ -131,6 +132,7 @@ PD_Orders::build_orders( o.setCompatibles(); } #endif + EXITING(); } bool diff --git a/src/pickDeliverE/src/pgr_pickDeliver.cpp b/src/pickDeliverE/src/pgr_pickDeliver.cpp index 66b5980aa93..bad31fafe8f 100644 --- a/src/pickDeliverE/src/pgr_pickDeliver.cpp +++ b/src/pickDeliverE/src/pgr_pickDeliver.cpp @@ -170,13 +170,15 @@ Pgr_pickDeliver::Pgr_pickDeliver( double factor, size_t p_max_cycles, int initial) : - PD_problem(this) -#if 0 + PD_problem(this), m_initial_id(initial), m_max_cycles(p_max_cycles), m_node_id(0), m_nodes(), + m_base_nodes(), m_cost_matrix(cost_matrix), + m_orders(pd_orders) +#if 0 m_trucks(vehicles, factor) #endif { @@ -224,6 +226,7 @@ Pgr_pickDeliver::Pgr_pickDeliver( m_node_id(0), m_nodes(), m_base_nodes(), + m_cost_matrix(), m_orders(pd_orders), m_trucks(vehicles, factor) { pgassert(!pd_orders.empty()); From a8091e9669512062d518edf4e04685a9f44b1d97 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Mon, 15 May 2017 11:21:44 -0500 Subject: [PATCH 07/40] test pass, reading matrix --- include/vrp/pgr_pickDeliver.h | 2 +- src/pickDeliverE/src/pd_orders.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/vrp/pgr_pickDeliver.h b/include/vrp/pgr_pickDeliver.h index 7856f5ebc8f..b7a61bf2f0f 100644 --- a/include/vrp/pgr_pickDeliver.h +++ b/include/vrp/pgr_pickDeliver.h @@ -136,9 +136,9 @@ class Pgr_pickDeliver : public PD_problem { public: // TODO(vicky) make this private std::vector> m_base_nodes; + pgrouting::tsp::Dmatrix m_cost_matrix; private: - pgrouting::tsp::Dmatrix m_cost_matrix; PD_Orders m_orders; Fleet m_trucks; std::vector solutions; diff --git a/src/pickDeliverE/src/pd_orders.cpp b/src/pickDeliverE/src/pd_orders.cpp index c8ea35a3d46..59de5352dd6 100644 --- a/src/pickDeliverE/src/pd_orders.cpp +++ b/src/pickDeliverE/src/pd_orders.cpp @@ -73,6 +73,7 @@ PD_Orders::build_orders( Vehicle_node pickup( {problem->node_id()++, order, Tw_node::NodeType::kPickup}); + pgassert(!problem->m_cost_matrix.empty()); #if 0 msg.log << b_pick->idx() << ","; msg.log << b_pick->id() << "\n"; From 79cc4eac201a8a9a9211204bbb71a4e6e5de4489 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Mon, 15 May 2017 11:46:49 -0500 Subject: [PATCH 08/40] code compiles --- doxygen/Doxyfile.in | 2 +- include/vrp/pd_orders.h | 40 ++++++++++++++++++++++++++++-- src/pickDeliverE/src/pd_orders.cpp | 2 +- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/doxygen/Doxyfile.in b/doxygen/Doxyfile.in index d62af86274f..5322e3443e2 100644 --- a/doxygen/Doxyfile.in +++ b/doxygen/Doxyfile.in @@ -806,7 +806,7 @@ EXCLUDE_SYMLINKS = NO # Note that the wildcards are matched against the file with absolute path, so to # exclude all test directories for example use the pattern */test/* -EXCLUDE_PATTERNS = */notUsed/* */test/* */src/trsp/doc/README.md */pickDeliver/* +EXCLUDE_PATTERNS = */notUsed/* */test/* */src/trsp/doc/README.md # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names # (namespaces, classes, functions, etc.) that should be excluded from the diff --git a/include/vrp/pd_orders.h b/include/vrp/pd_orders.h index 31d5d026e65..84617b822cc 100644 --- a/include/vrp/pd_orders.h +++ b/include/vrp/pd_orders.h @@ -38,7 +38,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. namespace pgrouting { namespace vrp { -class Pgr_pickDeliver; class Order; class PD_Orders : public PD_problem { @@ -86,8 +85,45 @@ class PD_Orders : public PD_problem { // TODO(vicky) this should be private called by the constructor void build_orders( const std::vector &pd_orders); -}; +#if 0 + template void add_order( + const std::vector&) { + std::unique_ptr b_pick(new T( + problem->node_id(), + order.pick_node_id, + order.pick_x, + order.pick_y)); + msg.log << order.id << ": " << problem->node_id() + << "," << order.pick_node_id << "\n"; + Vehicle_node pickup( + {problem->node_id()++, order, Tw_node::NodeType::kPickup}); + + + std::unique_ptr b_drop(new T( + problem->node_id(), + order.deliver_node_id, + order.deliver_x, + order.deliver_y)); + Vehicle_node delivery( + {problem->node_id()++, order, Tw_node::NodeType::kDelivery}); + + problem->add_base_node(std::move(b_pick)); + problem->add_base_node(std::move(b_drop)); + problem->add_node(pickup); + problem->add_node(delivery); + + pgassert(problem->nodesOK()); + /* + * add into an order + */ + m_orders.push_back( + Order(order_id++, order.id, + pickup, + delivery)); + } +#endif +}; } // namespace vrp } // namespace pgrouting diff --git a/src/pickDeliverE/src/pd_orders.cpp b/src/pickDeliverE/src/pd_orders.cpp index 59de5352dd6..74861ca1a19 100644 --- a/src/pickDeliverE/src/pd_orders.cpp +++ b/src/pickDeliverE/src/pd_orders.cpp @@ -73,8 +73,8 @@ PD_Orders::build_orders( Vehicle_node pickup( {problem->node_id()++, order, Tw_node::NodeType::kPickup}); - pgassert(!problem->m_cost_matrix.empty()); #if 0 + pgassert(!problem->m_cost_matrix.empty()); msg.log << b_pick->idx() << ","; msg.log << b_pick->id() << "\n"; msg.log << pickup.idx() << ","; From 651dcfe1c763e66cb933bee104e4d8f38139f609 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Mon, 15 May 2017 12:05:26 -0500 Subject: [PATCH 09/40] compiles & pde test pass --- include/vrp/pd_orders.h | 41 +++++++++++------------------- src/pickDeliverE/src/pd_orders.cpp | 6 ++++- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/include/vrp/pd_orders.h b/include/vrp/pd_orders.h index 84617b822cc..5a125c8c70e 100644 --- a/include/vrp/pd_orders.h +++ b/include/vrp/pd_orders.h @@ -30,8 +30,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #pragma once #include +#include +#include #include "c_types/pickDeliver/pickDeliveryOrders_t.h" #include "cpp_common/identifiers.hpp" +#include "vrp/base_node.h" #include "vrp/pd_problem.h" @@ -86,41 +89,27 @@ class PD_Orders : public PD_problem { void build_orders( const std::vector &pd_orders); -#if 0 - template void add_order( - const std::vector&) { +#if 1 + template std::unique_ptr create_b_pick ( + const PickDeliveryOrders_t &order, + size_t node_id) { std::unique_ptr b_pick(new T( - problem->node_id(), + node_id, order.pick_node_id, order.pick_x, order.pick_y)); - msg.log << order.id << ": " << problem->node_id() - << "," << order.pick_node_id << "\n"; - Vehicle_node pickup( - {problem->node_id()++, order, Tw_node::NodeType::kPickup}); - + return std::move(b_pick); + } + template std::unique_ptr create_b_deliver ( + const PickDeliveryOrders_t &order, + size_t node_id) { std::unique_ptr b_drop(new T( - problem->node_id(), + node_id, order.deliver_node_id, order.deliver_x, order.deliver_y)); - Vehicle_node delivery( - {problem->node_id()++, order, Tw_node::NodeType::kDelivery}); - - problem->add_base_node(std::move(b_pick)); - problem->add_base_node(std::move(b_drop)); - problem->add_node(pickup); - problem->add_node(delivery); - - pgassert(problem->nodesOK()); - /* - * add into an order - */ - m_orders.push_back( - Order(order_id++, order.id, - pickup, - delivery)); + return std::move(b_drop); } #endif }; diff --git a/src/pickDeliverE/src/pd_orders.cpp b/src/pickDeliverE/src/pd_orders.cpp index 74861ca1a19..41b284deee2 100644 --- a/src/pickDeliverE/src/pd_orders.cpp +++ b/src/pickDeliverE/src/pd_orders.cpp @@ -63,6 +63,7 @@ PD_Orders::build_orders( /* * Creating the pickup & delivery nodes */ +#if 0 std::unique_ptr b_pick(new pickdeliver::Node( problem->node_id(), order.pick_node_id, @@ -70,6 +71,8 @@ PD_Orders::build_orders( order.pick_y)); msg.log << order.id << ": " << problem->node_id() << "," << order.pick_node_id << "\n"; +#endif + auto b_pick = create_b_pick(order, problem->node_id()); Vehicle_node pickup( {problem->node_id()++, order, Tw_node::NodeType::kPickup}); @@ -79,13 +82,14 @@ PD_Orders::build_orders( msg.log << b_pick->id() << "\n"; msg.log << pickup.idx() << ","; msg.log << pickup.id() << "\n"; -#endif std::unique_ptr b_drop(new pickdeliver::Node( problem->node_id(), order.deliver_node_id, order.deliver_x, order.deliver_y)); +#endif + auto b_drop = create_b_deliver(order, problem->node_id()); Vehicle_node delivery( {problem->node_id()++, order, Tw_node::NodeType::kDelivery}); From b2139701c8de065c308960bf2bbdffaab1ab5036 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Mon, 15 May 2017 12:11:45 -0500 Subject: [PATCH 10/40] compiles & pde test pass --- src/pickDeliverE/src/pd_orders.cpp | 125 +++++++++++++---------------- 1 file changed, 55 insertions(+), 70 deletions(-) diff --git a/src/pickDeliverE/src/pd_orders.cpp b/src/pickDeliverE/src/pd_orders.cpp index 41b284deee2..b384343ccc7 100644 --- a/src/pickDeliverE/src/pd_orders.cpp +++ b/src/pickDeliverE/src/pd_orders.cpp @@ -31,6 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "vrp/order.h" #include "vrp/node.h" +#include "pickDeliver/dnode.h" #include "vrp/tw_node.h" #include "vrp/vehicle_node.h" #include "vrp/pgr_pickDeliver.h" @@ -51,8 +52,8 @@ PD_Orders::build_orders( const std::vector &pd_orders ) { OID order_id(0); + ENTERING(); for (const auto order : pd_orders) { - ENTERING(); /* * SAMPLE CORRECT INFORMATION * @@ -60,76 +61,60 @@ PD_Orders::build_orders( * 1 | 10 | 35 | 69 | 448 | 505 | 90 | 45 | 68 | 912 | 967 | 90 | 35 */ - /* - * Creating the pickup & delivery nodes - */ -#if 0 - std::unique_ptr b_pick(new pickdeliver::Node( - problem->node_id(), - order.pick_node_id, - order.pick_x, - order.pick_y)); - msg.log << order.id << ": " << problem->node_id() - << "," << order.pick_node_id << "\n"; -#endif - auto b_pick = create_b_pick(order, problem->node_id()); - Vehicle_node pickup( - {problem->node_id()++, order, Tw_node::NodeType::kPickup}); + if (problem->m_cost_matrix.empty()) { + /* + * Euclidean version + */ + auto b_pick = create_b_pick(order, problem->node_id()); + Vehicle_node pickup( + {problem->node_id()++, order, Tw_node::NodeType::kPickup}); + + auto b_drop = create_b_deliver(order, problem->node_id()); + Vehicle_node delivery( + {problem->node_id()++, order, Tw_node::NodeType::kDelivery}); + + + problem->add_base_node(std::move(b_pick)); + problem->add_base_node(std::move(b_drop)); + problem->add_node(pickup); + problem->add_node(delivery); + + pgassert(problem->nodesOK()); + /* + * add into an order + */ + m_orders.push_back( + Order(order_id++, order.id, + pickup, + delivery)); + } else { + /* + * Creating the pickup & delivery nodes + */ + auto b_pick = create_b_pick(order, problem->node_id()); + Vehicle_node pickup( + {problem->node_id()++, order, Tw_node::NodeType::kPickup}); + + auto b_drop = create_b_deliver(order, problem->node_id()); + Vehicle_node delivery( + {problem->node_id()++, order, Tw_node::NodeType::kDelivery}); + + + problem->add_base_node(std::move(b_pick)); + problem->add_base_node(std::move(b_drop)); + problem->add_node(pickup); + problem->add_node(delivery); + + pgassert(problem->nodesOK()); + /* + * add into an order + */ + m_orders.push_back( + Order(order_id++, order.id, + pickup, + delivery)); -#if 0 - pgassert(!problem->m_cost_matrix.empty()); - msg.log << b_pick->idx() << ","; - msg.log << b_pick->id() << "\n"; - msg.log << pickup.idx() << ","; - msg.log << pickup.id() << "\n"; - - std::unique_ptr b_drop(new pickdeliver::Node( - problem->node_id(), - order.deliver_node_id, - order.deliver_x, - order.deliver_y)); -#endif - auto b_drop = create_b_deliver(order, problem->node_id()); - Vehicle_node delivery( - {problem->node_id()++, order, Tw_node::NodeType::kDelivery}); - -#if 0 - msg.log << "pick " << pickup << "\n"; - msg.log << "drop " << delivery << "\n"; - msg.log << "distance " << pickup.distance(delivery) << "\n"; - msg.log << ".............\n"; - msg.log << "pick " << *b_pick << "\n"; - msg.log << "drop " << *b_drop << "\n"; - pickdeliver::Node p = *dynamic_cast(b_pick.get()); - pickdeliver::Node d = *dynamic_cast(b_drop.get()); - msg.log << "distance " << p.distance(d) << "\n"; - msg.log << "distance " << p.distance(b_drop.get()) << "\n"; - msg.log << "distance " << b_pick->distance(*b_drop.get()) << "\n"; - - pgassertwm( - pickup.distance(delivery) == b_pick->distance(*b_drop.get()), - msg.get_log().c_str()); - - pickup.set_Did(delivery.idx()); - delivery.set_Pid(pickup.idx()); -#endif - - problem->add_base_node(std::move(b_pick)); - problem->add_base_node(std::move(b_drop)); - problem->add_node(pickup); - problem->add_node(delivery); - - pgassert(problem->nodesOK()); - - - - /* - * add into an order - */ - m_orders.push_back( - Order(order_id++, order.id, - pickup, - delivery)); + } } // for (creating orders) #if 0 From bd5d205d8445fa448dfb9e0c5c8ffa9d3cd5a613 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Mon, 15 May 2017 12:25:54 -0500 Subject: [PATCH 11/40] compiles & pde test pass --- include/vrp/pd_orders.h | 11 +++++++++-- src/pickDeliverE/src/pd_orders.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/include/vrp/pd_orders.h b/include/vrp/pd_orders.h index 5a125c8c70e..5936f3ac7d5 100644 --- a/include/vrp/pd_orders.h +++ b/include/vrp/pd_orders.h @@ -42,6 +42,7 @@ namespace pgrouting { namespace vrp { class Order; +class Vehicle_node; class PD_Orders : public PD_problem { typedef std::vector Orders; @@ -89,7 +90,14 @@ class PD_Orders : public PD_problem { void build_orders( const std::vector &pd_orders); -#if 1 + private: + void add_order( + int64_t, + std::unique_ptr, + Vehicle_node, + std::unique_ptr, + Vehicle_node); + template std::unique_ptr create_b_pick ( const PickDeliveryOrders_t &order, size_t node_id) { @@ -111,7 +119,6 @@ class PD_Orders : public PD_problem { order.deliver_y)); return std::move(b_drop); } -#endif }; } // namespace vrp diff --git a/src/pickDeliverE/src/pd_orders.cpp b/src/pickDeliverE/src/pd_orders.cpp index b384343ccc7..1d57f584da3 100644 --- a/src/pickDeliverE/src/pd_orders.cpp +++ b/src/pickDeliverE/src/pd_orders.cpp @@ -47,6 +47,29 @@ PD_Orders::PD_Orders( } +void +PD_Orders:: add_order( + int64_t order_id, + std::unique_ptr b_pick, + Vehicle_node pick, + std::unique_ptr b_drop, + Vehicle_node drop) { + problem->add_base_node(std::move(b_pick)); + problem->add_base_node(std::move(b_drop)); + problem->add_node(pick); + problem->add_node(drop); + + pgassert(problem->nodesOK()); + /* + * add into an order + */ + m_orders.push_back( + Order(m_orders.size(), order_id, + pick, + drop)); +} + + void PD_Orders::build_orders( const std::vector &pd_orders @@ -74,6 +97,10 @@ PD_Orders::build_orders( {problem->node_id()++, order, Tw_node::NodeType::kDelivery}); + add_order(order.id, + std::move(b_pick), pickup, + std::move(b_drop), delivery); +#if 0 problem->add_base_node(std::move(b_pick)); problem->add_base_node(std::move(b_drop)); problem->add_node(pickup); @@ -87,6 +114,7 @@ PD_Orders::build_orders( Order(order_id++, order.id, pickup, delivery)); +#endif } else { /* * Creating the pickup & delivery nodes From 770ad5e2678af683974172b8c3a25a32ebd4d7b8 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Mon, 15 May 2017 12:30:15 -0500 Subject: [PATCH 12/40] compiles & pde test pass --- src/pickDeliverE/src/pd_orders.cpp | 39 +++--------------------------- 1 file changed, 3 insertions(+), 36 deletions(-) diff --git a/src/pickDeliverE/src/pd_orders.cpp b/src/pickDeliverE/src/pd_orders.cpp index 1d57f584da3..01f958067e2 100644 --- a/src/pickDeliverE/src/pd_orders.cpp +++ b/src/pickDeliverE/src/pd_orders.cpp @@ -74,7 +74,6 @@ void PD_Orders::build_orders( const std::vector &pd_orders ) { - OID order_id(0); ENTERING(); for (const auto order : pd_orders) { /* @@ -100,21 +99,6 @@ PD_Orders::build_orders( add_order(order.id, std::move(b_pick), pickup, std::move(b_drop), delivery); -#if 0 - problem->add_base_node(std::move(b_pick)); - problem->add_base_node(std::move(b_drop)); - problem->add_node(pickup); - problem->add_node(delivery); - - pgassert(problem->nodesOK()); - /* - * add into an order - */ - m_orders.push_back( - Order(order_id++, order.id, - pickup, - delivery)); -#endif } else { /* * Creating the pickup & delivery nodes @@ -127,29 +111,12 @@ PD_Orders::build_orders( Vehicle_node delivery( {problem->node_id()++, order, Tw_node::NodeType::kDelivery}); - - problem->add_base_node(std::move(b_pick)); - problem->add_base_node(std::move(b_drop)); - problem->add_node(pickup); - problem->add_node(delivery); - - pgassert(problem->nodesOK()); - /* - * add into an order - */ - m_orders.push_back( - Order(order_id++, order.id, - pickup, - delivery)); - + add_order(order.id, + std::move(b_pick), pickup, + std::move(b_drop), delivery); } } // for (creating orders) -#if 0 - for (auto &o : m_orders) { - o.setCompatibles(); - } -#endif EXITING(); } From 623da2d6ba78a86214755a4b82b32e8499a0933d Mon Sep 17 00:00:00 2001 From: cvvergara Date: Mon, 15 May 2017 13:00:57 -0500 Subject: [PATCH 13/40] compiles & pde test pass --- include/vrp/fleet.h | 31 +++++++++++++++++++ src/pickDeliverE/src/fleet.cpp | 54 +++++++++++++++++++++++++++++++++- 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/include/vrp/fleet.h b/include/vrp/fleet.h index 6e24d70f158..986e63a088e 100644 --- a/include/vrp/fleet.h +++ b/include/vrp/fleet.h @@ -111,6 +111,37 @@ class Fleet : public PD_problem { bool build_fleet( std::vector vehicles, double factor); + + void add_vehicle( + Vehicle_t, + double factor, + std::unique_ptr, + Vehicle_node, + std::unique_ptr, + Vehicle_node); + + template std::unique_ptr create_b_start ( + const Vehicle_t &vehicle, + size_t node_id) { + std::unique_ptr b_start(new T( + node_id, + vehicle.start_node_id, + vehicle.start_x, + vehicle.start_y)); + return std::move(b_start); + } + + template std::unique_ptr create_b_end ( + const Vehicle_t &vehicle, + size_t node_id) { + std::unique_ptr b_end(new T( + node_id, + vehicle.end_node_id, + vehicle.end_x, + vehicle.end_y)); + return std::move(b_end); + } + }; diff --git a/src/pickDeliverE/src/fleet.cpp b/src/pickDeliverE/src/fleet.cpp index b0099d6747f..ec4f28bf142 100644 --- a/src/pickDeliverE/src/fleet.cpp +++ b/src/pickDeliverE/src/fleet.cpp @@ -114,6 +114,45 @@ Fleet::get_truck(const Order order) { } +void +Fleet::add_vehicle( + Vehicle_t vehicle, + double factor, + std::unique_ptr b_start, + Vehicle_node starting_site, + std::unique_ptr b_end, + Vehicle_node ending_site) { + + problem->add_base_node(std::move(b_start)); + problem->add_base_node(std::move(b_end)); + problem->add_node(starting_site); + problem->add_node(ending_site); + + pgassert(problem->nodesOK()); + + if (!(starting_site.is_start() + && ending_site.is_end())) { + msg.error << "Illegal values found on vehicle"; + msg.log << "id: " << vehicle.id; + pgassert(!msg.get_error().empty()); + } + pgassert(starting_site.is_start() && ending_site.is_end()); + + for (int i = 0; i < vehicle.cant_v; ++i) { + m_trucks.push_back(Vehicle_pickDeliver( + m_trucks.size(), + vehicle.id, + starting_site, + ending_site, + vehicle.capacity, + vehicle.speed, + factor)); + msg.log << "inserting " << m_trucks.back().idx(); + pgassert((m_trucks.back().idx() + 1) == m_trucks.size()); + } + +} + /*! builds a fleet from a vector of Vehicle_t @@ -123,7 +162,7 @@ Fleet::get_truck(const Order order) { @param[in] vehicles the list of vehicles @param[in] factor the multiplier to speed up or slow down -*/ + */ bool Fleet::build_fleet( std::vector vehicles, @@ -170,22 +209,34 @@ Fleet::build_fleet( return false; } +#if 0 std::unique_ptr b_start(new pickdeliver::Node( problem->node_id(), vehicle.start_node_id, vehicle.start_x, vehicle.start_y)); +#endif + auto b_start = create_b_start(vehicle, problem->node_id()); + auto starting_site = Vehicle_node( {problem->node_id()++, vehicle, Tw_node::NodeType::kStart}); + auto b_end = create_b_end(vehicle, problem->node_id()); +#if 0 std::unique_ptr b_end(new pickdeliver::Node( problem->node_id(), vehicle.end_node_id, vehicle.end_x, vehicle.end_y)); +#endif auto ending_site = Vehicle_node( {problem->node_id()++, vehicle, Tw_node::NodeType::kEnd}); + add_vehicle(vehicle, factor, + std::move(b_start), starting_site, + std::move(b_end), ending_site); + +#if 0 problem->add_base_node(std::move(b_start)); problem->add_base_node(std::move(b_end)); problem->add_node(starting_site); @@ -214,6 +265,7 @@ Fleet::build_fleet( msg.log << "inserting " << m_trucks.back().idx(); pgassert((m_trucks.back().idx() + 1) == m_trucks.size()); } +#endif } Identifiers unused(m_trucks.size()); un_used = unused; From b7487db94e3516013327eb35968ea27ad087f8d0 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Mon, 15 May 2017 13:16:40 -0500 Subject: [PATCH 14/40] compiles & pde test passi & pdm starting next step --- src/pickDeliverE/src/fleet.cpp | 87 +++++++++--------------- src/pickDeliverE/src/pd_orders.cpp | 2 +- src/pickDeliverE/src/pgr_pickDeliver.cpp | 4 +- 3 files changed, 33 insertions(+), 60 deletions(-) diff --git a/src/pickDeliverE/src/fleet.cpp b/src/pickDeliverE/src/fleet.cpp index ec4f28bf142..03c6376c47a 100644 --- a/src/pickDeliverE/src/fleet.cpp +++ b/src/pickDeliverE/src/fleet.cpp @@ -32,6 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "vrp/pd_orders.h" +#include "pickDeliver/dnode.h" #include "vrp/tw_node.h" #include "vrp/vehicle_pickDeliver.h" #include "vrp/pgr_pickDeliver.h" @@ -209,63 +210,37 @@ Fleet::build_fleet( return false; } -#if 0 - std::unique_ptr b_start(new pickdeliver::Node( - problem->node_id(), - vehicle.start_node_id, - vehicle.start_x, - vehicle.start_y)); -#endif - auto b_start = create_b_start(vehicle, problem->node_id()); - - auto starting_site = Vehicle_node( - {problem->node_id()++, vehicle, Tw_node::NodeType::kStart}); - - auto b_end = create_b_end(vehicle, problem->node_id()); -#if 0 - std::unique_ptr b_end(new pickdeliver::Node( - problem->node_id(), - vehicle.end_node_id, - vehicle.end_x, - vehicle.end_y)); -#endif - auto ending_site = Vehicle_node( - {problem->node_id()++, vehicle, Tw_node::NodeType::kEnd}); - - add_vehicle(vehicle, factor, - std::move(b_start), starting_site, - std::move(b_end), ending_site); - -#if 0 - problem->add_base_node(std::move(b_start)); - problem->add_base_node(std::move(b_end)); - problem->add_node(starting_site); - problem->add_node(ending_site); - - pgassert(problem->nodesOK()); - - if (!(starting_site.is_start() - && ending_site.is_end())) { - msg.error << "Illegal values found on vehicle"; - msg.log << "id: " << vehicle.id; - pgassert(!msg.get_error().empty()); - return false; - } - pgassert(starting_site.is_start() && ending_site.is_end()); - - for (int i = 0; i < vehicle.cant_v; ++i) { - m_trucks.push_back(Vehicle_pickDeliver( - m_trucks.size(), - vehicle.id, - starting_site, - ending_site, - vehicle.capacity, - vehicle.speed, - factor)); - msg.log << "inserting " << m_trucks.back().idx(); - pgassert((m_trucks.back().idx() + 1) == m_trucks.size()); + if (problem->m_cost_matrix.empty()) { + /* + * Euclidean version + */ + auto b_start = create_b_start(vehicle, problem->node_id()); + auto starting_site = Vehicle_node( + {problem->node_id()++, vehicle, Tw_node::NodeType::kStart}); + + auto b_end = create_b_end(vehicle, problem->node_id()); + auto ending_site = Vehicle_node( + {problem->node_id()++, vehicle, Tw_node::NodeType::kEnd}); + + add_vehicle(vehicle, factor, + std::move(b_start), starting_site, + std::move(b_end), ending_site); + } else { + /* + * Matrix version + */ + auto b_start = create_b_start(vehicle, problem->node_id()); + auto starting_site = Vehicle_node( + {problem->node_id()++, vehicle, Tw_node::NodeType::kStart}); + + auto b_end = create_b_end(vehicle, problem->node_id()); + auto ending_site = Vehicle_node( + {problem->node_id()++, vehicle, Tw_node::NodeType::kEnd}); + + add_vehicle(vehicle, factor, + std::move(b_start), starting_site, + std::move(b_end), ending_site); } -#endif } Identifiers unused(m_trucks.size()); un_used = unused; diff --git a/src/pickDeliverE/src/pd_orders.cpp b/src/pickDeliverE/src/pd_orders.cpp index 01f958067e2..dd6d7f8a028 100644 --- a/src/pickDeliverE/src/pd_orders.cpp +++ b/src/pickDeliverE/src/pd_orders.cpp @@ -101,7 +101,7 @@ PD_Orders::build_orders( std::move(b_drop), delivery); } else { /* - * Creating the pickup & delivery nodes + * matrix version */ auto b_pick = create_b_pick(order, problem->node_id()); Vehicle_node pickup( diff --git a/src/pickDeliverE/src/pgr_pickDeliver.cpp b/src/pickDeliverE/src/pgr_pickDeliver.cpp index bad31fafe8f..81a940fe59e 100644 --- a/src/pickDeliverE/src/pgr_pickDeliver.cpp +++ b/src/pickDeliverE/src/pgr_pickDeliver.cpp @@ -177,10 +177,8 @@ Pgr_pickDeliver::Pgr_pickDeliver( m_nodes(), m_base_nodes(), m_cost_matrix(cost_matrix), - m_orders(pd_orders) -#if 0 + m_orders(pd_orders), m_trucks(vehicles, factor) -#endif { ENTERING(); #if 0 From 4532bf760a1e1609cc0e9ed74181392bd0faee9d Mon Sep 17 00:00:00 2001 From: cvvergara Date: Mon, 15 May 2017 14:09:44 -0500 Subject: [PATCH 15/40] compiles & pde test pass --- include/pickDeliver/dnode.h | 2 +- include/vrp/base_node.h | 2 +- include/vrp/vehicle.h | 2 +- src/pickDeliver/src/dnode.cpp | 4 ++-- src/pickDeliverE/src/fleet.cpp | 7 ++++++- src/pickDeliverE/src/pgr_pickDeliver.cpp | 1 + src/pickDeliverE/src/tw_node.cpp | 13 ++++++++----- src/pickDeliverE/src/vehicle.cpp | 4 ++++ src/pickDeliverE/src/vehicle_pickDeliver.cpp | 2 ++ 9 files changed, 26 insertions(+), 11 deletions(-) diff --git a/include/pickDeliver/dnode.h b/include/pickDeliver/dnode.h index 8338de705db..da1264d726e 100644 --- a/include/pickDeliver/dnode.h +++ b/include/pickDeliver/dnode.h @@ -57,7 +57,7 @@ class Dnode : public Base_node, public PD_problem { @}*/ double distance(const Dnode &other) const; - double distance(const Base_node &) const; + double distance(const Base_node *) const; double comparable_distance(const Dnode &other) const; diff --git a/include/vrp/base_node.h b/include/vrp/base_node.h index 8011fda4119..5ffc317fe80 100644 --- a/include/vrp/base_node.h +++ b/include/vrp/base_node.h @@ -82,7 +82,7 @@ class Base_node : public Identifier { @{ */ #if 1 - virtual double distance(const Base_node &node) const = 0; + virtual double distance(const Base_node *node) const = 0; #endif virtual double comparable_distance(const Base_node &other) const; /*!@}*/ diff --git a/include/vrp/vehicle.h b/include/vrp/vehicle.h index d93160527c0..37ee43c9079 100644 --- a/include/vrp/vehicle.h +++ b/include/vrp/vehicle.h @@ -69,7 +69,7 @@ namespace vrp { * @sa @ref Vehicle_node */ -class Vehicle : public Identifier { +class Vehicle : public Identifier, public PD_problem { protected: typedef size_t POS; std::deque< Vehicle_node > m_path; diff --git a/src/pickDeliver/src/dnode.cpp b/src/pickDeliver/src/dnode.cpp index 8a51b5a05ee..e739dcad8ab 100644 --- a/src/pickDeliver/src/dnode.cpp +++ b/src/pickDeliver/src/dnode.cpp @@ -72,10 +72,10 @@ Dnode::distance(const Dnode &other) const { } double -Dnode::distance(const Base_node &other) const { +Dnode::distance(const Base_node *other) const { return problem->m_cost_matrix.distance( problem->m_cost_matrix.get_index(id()), - problem->m_cost_matrix.get_index(other.id())); + problem->m_cost_matrix.get_index(other->id())); } double diff --git a/src/pickDeliverE/src/fleet.cpp b/src/pickDeliverE/src/fleet.cpp index 03c6376c47a..71cc7ae2693 100644 --- a/src/pickDeliverE/src/fleet.cpp +++ b/src/pickDeliverE/src/fleet.cpp @@ -148,7 +148,7 @@ Fleet::add_vehicle( vehicle.capacity, vehicle.speed, factor)); - msg.log << "inserting " << m_trucks.back().idx(); + msg.log << "inserting vehicle: " << m_trucks.back().idx() << "\n"; pgassert((m_trucks.back().idx() + 1) == m_trucks.size()); } @@ -250,6 +250,7 @@ Fleet::build_fleet( bool Fleet::is_fleet_ok() const { + ENTERING(); if (!msg.get_error().empty()) return false; for (auto truck : m_trucks) { if (!(truck.start_site().is_start() @@ -263,6 +264,7 @@ Fleet::is_fleet_ok() const { return false; } } + EXITING(); return true; } @@ -273,6 +275,7 @@ Fleet::is_fleet_ok() const { */ bool Fleet::is_order_ok(const Order &order) const { + ENTERING(); for (const auto truck : m_trucks) { if (!order.is_valid(truck.speed())) continue; if (truck.is_order_feasable(order)) { @@ -290,9 +293,11 @@ Fleet::is_order_ok(const Order &order) const { * if its feasible, then the one truck is found */ if (truck.is_order_feasable(order)) { + EXITING(); return true; } } + EXITING(); return false; } diff --git a/src/pickDeliverE/src/pgr_pickDeliver.cpp b/src/pickDeliverE/src/pgr_pickDeliver.cpp index 81a940fe59e..64085764536 100644 --- a/src/pickDeliverE/src/pgr_pickDeliver.cpp +++ b/src/pickDeliverE/src/pgr_pickDeliver.cpp @@ -74,6 +74,7 @@ Pgr_pickDeliver::nodesOK() const { pgassertwm(m_nodes[i].idx() == m_base_nodes[i]->idx(), msg.get_log().c_str()); } + EXITING(); return true; } #endif diff --git a/src/pickDeliverE/src/tw_node.cpp b/src/pickDeliverE/src/tw_node.cpp index e7d34600209..0b00904ba5d 100644 --- a/src/pickDeliverE/src/tw_node.cpp +++ b/src/pickDeliverE/src/tw_node.cpp @@ -38,13 +38,16 @@ namespace vrp { double Tw_node::travel_time_to(const Tw_node &to, double speed) const { - auto from = static_cast( - *problem->m_base_nodes[idx()].get()); - auto destination = static_cast( - *problem->m_base_nodes[to.idx()].get()); + /** TODO(vicky) + * shall call Node or Dnode + * static cast wont work I think + * + */ + auto from = problem->m_base_nodes[idx()].get(); + auto destination = problem->m_base_nodes[to.idx()].get(); pgassert(speed != 0); /*! @todo TODO evaluate with matrix also*/ - return from.distance(destination) / speed; + return from->distance(destination) / speed; } diff --git a/src/pickDeliverE/src/vehicle.cpp b/src/pickDeliverE/src/vehicle.cpp index b697705f7c4..b0f4d0b160a 100644 --- a/src/pickDeliverE/src/vehicle.cpp +++ b/src/pickDeliverE/src/vehicle.cpp @@ -472,12 +472,16 @@ Vehicle::Vehicle( m_capacity(p_m_capacity), m_factor(p_factor), m_speed(p_speed) { + ENTERING(); m_path.clear(); m_path.push_back(starting_site); m_path.push_back(ending_site); /*! @todo TODO(vicky) evaluate with matrix also*/ + msg.log << "before calling evaluate\n"; evaluate(0); + msg.log << "after calling evaluate\n"; invariant(); + EXITING(); } diff --git a/src/pickDeliverE/src/vehicle_pickDeliver.cpp b/src/pickDeliverE/src/vehicle_pickDeliver.cpp index 13f7dc63535..8e5c5fc3334 100644 --- a/src/pickDeliverE/src/vehicle_pickDeliver.cpp +++ b/src/pickDeliverE/src/vehicle_pickDeliver.cpp @@ -87,9 +87,11 @@ Vehicle_pickDeliver::Vehicle_pickDeliver( double factor) : Vehicle(id, kind, starting_site, ending_site, p_capacity, p_speed, factor), cost((std::numeric_limits::max)()) { + ENTERING(); m_orders_in_vehicle.clear(); invariant(); + EXITING(); } From 0d1f4f3383a273bd84afe1136226a928a27cfbfe Mon Sep 17 00:00:00 2001 From: cvvergara Date: Mon, 15 May 2017 14:22:57 -0500 Subject: [PATCH 16/40] commenting out unused code & pdm reads the vehicles & pde tests pass --- include/pickDeliver/dnode.h | 4 ++++ include/vrp/base_node.h | 2 ++ include/vrp/node.h | 2 ++ src/pickDeliver/src/dnode.cpp | 9 ++++++--- src/pickDeliverE/src/base_node.cpp | 2 +- src/pickDeliverE/src/node.cpp | 9 +++++++-- 6 files changed, 22 insertions(+), 6 deletions(-) diff --git a/include/pickDeliver/dnode.h b/include/pickDeliver/dnode.h index da1264d726e..db371433a36 100644 --- a/include/pickDeliver/dnode.h +++ b/include/pickDeliver/dnode.h @@ -56,10 +56,14 @@ class Dnode : public Base_node, public PD_problem { bool operator==(const Dnode &rhs) const; @}*/ +#if 0 double distance(const Dnode &other) const; +#endif double distance(const Base_node *) const; +#if 0 double comparable_distance(const Dnode &other) const; +#endif friend std::ostream& operator << (std::ostream &log, const Dnode &node); }; diff --git a/include/vrp/base_node.h b/include/vrp/base_node.h index 5ffc317fe80..94a39085d6e 100644 --- a/include/vrp/base_node.h +++ b/include/vrp/base_node.h @@ -84,7 +84,9 @@ class Base_node : public Identifier { #if 1 virtual double distance(const Base_node *node) const = 0; #endif +#if 0 virtual double comparable_distance(const Base_node &other) const; +#endif /*!@}*/ diff --git a/include/vrp/node.h b/include/vrp/node.h index 8dd7467eb28..516510b8010 100644 --- a/include/vrp/node.h +++ b/include/vrp/node.h @@ -63,8 +63,10 @@ class Node : public Base_node , public PD_problem { double distance(const Node &) const; double distance(const Base_node *) const; +#if 0 double distance(const Base_node &) const; double comparable_distance(const Node &other) const; +#endif friend std::ostream& operator << (std::ostream &log, const Node &node); void print(std::ostream& os) const; diff --git a/src/pickDeliver/src/dnode.cpp b/src/pickDeliver/src/dnode.cpp index e739dcad8ab..9a873884687 100644 --- a/src/pickDeliver/src/dnode.cpp +++ b/src/pickDeliver/src/dnode.cpp @@ -42,10 +42,10 @@ std::ostream& operator << (std::ostream &log, const Dnode &node) { return log; } +#if 0 double Dnode::distance(const Dnode &other) const { ENTERING(); -#if 0 msg.log << "idx" << idx() << "\t id " << id() << "\t matrix.get_id " << problem->m_cost_matrix.get_id(id()) @@ -64,26 +64,29 @@ Dnode::distance(const Dnode &other) const { problem->m_cost_matrix.get_index(id()), problem->m_cost_matrix.get_index(other.id())) << "\n\n"; -#endif EXITING(); return problem->m_cost_matrix.distance( problem->m_cost_matrix.get_index(id()), problem->m_cost_matrix.get_index(other.id())); } +#endif double Dnode::distance(const Base_node *other) const { + ENTERING(); + EXITING(); return problem->m_cost_matrix.distance( problem->m_cost_matrix.get_index(id()), problem->m_cost_matrix.get_index(other->id())); } +#if 0 double Dnode::comparable_distance(const Dnode &other) const { distance(other); return problem->m_cost_matrix.comparable_distance(0,0); } - +#endif Dnode::Dnode(size_t id, int64_t original_id, double, double) : Base_node(id, original_id) { diff --git a/src/pickDeliverE/src/base_node.cpp b/src/pickDeliverE/src/base_node.cpp index b2b310a3678..8c5f1f8254a 100644 --- a/src/pickDeliverE/src/base_node.cpp +++ b/src/pickDeliverE/src/base_node.cpp @@ -63,11 +63,11 @@ double Base_node::distance(const Base_node &node) const { return 0; } -#endif double Base_node::comparable_distance(const Base_node &) const { return 0; } +#endif Base_node::Base_node(size_t _idx, int64_t _id) diff --git a/src/pickDeliverE/src/node.cpp b/src/pickDeliverE/src/node.cpp index b0215e015a2..b2262e185fa 100644 --- a/src/pickDeliverE/src/node.cpp +++ b/src/pickDeliverE/src/node.cpp @@ -32,7 +32,7 @@ namespace vrp { namespace pickdeliver { bool Node::isSamePos(const Node &other) const { - return comparable_distance(other) == 0; + return distance(other) == 0; } std::ostream& operator << (std::ostream &log, const Node &node) { @@ -53,15 +53,18 @@ Node::distance(const Node &other) const { ENTERING(); auto dx = m_point.x() - other.m_point.x(); auto dy = m_point.y() - other.m_point.y(); +#if 0 msg.log << *this << "\n"; msg.log << other << "\n"; msg.log << "dx: " << dx << "\n"; msg.log << "dy: " << dx << "\n"; msg.log << "d: " << sqrt(dx * dx + dy * dy) << "\n"; +#endif EXITING(); return sqrt(dx * dx + dy * dy); } +#if 0 double Node::distance(const Base_node &node) const { if (auto other = dynamic_cast(&node)) { @@ -78,6 +81,7 @@ Node::distance(const Base_node &node) const { } return 0; } +#endif double Node::distance(const Base_node *n) const { @@ -86,13 +90,14 @@ Node::distance(const Base_node *n) const { return distance(*dynamic_cast(n)); } +#if 0 double Node::comparable_distance(const Node &other) const { auto dx = m_point.x() - other.m_point.x(); auto dy = m_point.y() - other.m_point.y(); return dx * dx + dy * dy; } - +#endif Node::Node(size_t _idx, int64_t _id, double _x, double _y) : Base_node(_idx, _id), From fe1ac5ef20ec99ac180e3d42b3d1ed6e86914c7a Mon Sep 17 00:00:00 2001 From: cvvergara Date: Mon, 15 May 2017 14:47:00 -0500 Subject: [PATCH 17/40] saving before removing unused code --- src/pickDeliverE/src/pgr_pickDeliver.cpp | 63 ++++++++++++++++-------- 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/src/pickDeliverE/src/pgr_pickDeliver.cpp b/src/pickDeliverE/src/pgr_pickDeliver.cpp index 64085764536..0261981399c 100644 --- a/src/pickDeliverE/src/pgr_pickDeliver.cpp +++ b/src/pickDeliverE/src/pgr_pickDeliver.cpp @@ -53,6 +53,7 @@ Pgr_pickDeliver::nodesOK() const { ENTERING(); if (m_nodes.empty() && m_base_nodes.empty()) return true; +#if 0 msg.log << " m_nodes: " << m_nodes.size(); for (const auto n : m_nodes) { msg.log << n.id() << ","; @@ -64,10 +65,11 @@ Pgr_pickDeliver::nodesOK() const { for (auto const &n : m_base_nodes) { msg.log << n->id() << ","; } - +#endif pgassertwm(m_nodes.size() == m_base_nodes.size(), msg.get_log().c_str()); +#if 0 msg.log << "\n"; - +#endif for (size_t i = 0; i < m_nodes.size() ; ++i) { pgassertwm(m_nodes[i].id() == m_base_nodes[i]->id(), msg.get_log().c_str()); @@ -182,29 +184,56 @@ Pgr_pickDeliver::Pgr_pickDeliver( m_trucks(vehicles, factor) { ENTERING(); -#if 0 - pgassert(msg.get_error().empty()); - pgassert(!pd_orders.empty()); pgassert(!vehicles.empty()); - pgassert(!cost_matrix.empty()); + pgassert(!m_cost_matrix.empty()); pgassert(m_initial_id > 0 && m_initial_id < 7); - pgassert(msg.get_error().empty()); - - if (!msg.get_error().empty()) { return; } pgassert(msg.get_error().empty()); + msg.log << "\n Checking fleet ..."; if (!m_trucks.is_fleet_ok()) { - // TODO(vicky) revise the function - pgassert(false); + pgassert(msg.get_error().empty()); + pgassert(!m_trucks.msg.get_error().empty()); msg.error << m_trucks.msg.get_error(); return; } + msg.log << "fleet OK \n"; + +#if 0 + for (const auto t : m_trucks) { + msg.log << t << "\n"; + } +#endif +#if 0 + for (const auto &o : m_orders) { + msg.log << o << "\n"; + } +#endif + + /* + * check the (S, P, D, E) order on all vehicles + * stop when a feasible truck is found + */ + msg.log << "\n Checking orders"; + for (const auto &o : m_orders) { +#if 1 + if (!m_trucks.is_order_ok(o)) { + msg.error << "The order " + << o.pickup().order() + << " is not feasible on any truck"; + msg.log << "\n" << o; + return; + } +#endif + } + msg.log << "orders OK \n"; +#if 0 + m_trucks.set_compatibles(m_orders); #endif EXITING(); } // constructor @@ -228,13 +257,13 @@ Pgr_pickDeliver::Pgr_pickDeliver( m_cost_matrix(), m_orders(pd_orders), m_trucks(vehicles, factor) { + ENTERING(); pgassert(!pd_orders.empty()); pgassert(!vehicles.empty()); + pgassert(m_cost_matrix.empty()); pgassert(factor > 0); pgassert(m_initial_id > 0 && m_initial_id < 7); - ENTERING(); - if (!msg.get_error().empty()) { return; } @@ -255,13 +284,6 @@ Pgr_pickDeliver::Pgr_pickDeliver( for (const auto t : m_trucks) { msg.log << t << "\n"; } -#endif - - msg.log << "\n Building orders"; - msg.log << " ---> OK\n"; - - -#ifndef NDEBUG for (const auto &o : m_orders) { msg.log << o << "\n"; } @@ -271,6 +293,7 @@ Pgr_pickDeliver::Pgr_pickDeliver( * check the (S, P, D, E) order on all vehicles * stop when a feasible truck is found */ + msg.log << "\n Checking orders"; for (const auto &o : m_orders) { if (!m_trucks.is_order_ok(o)) { msg.error << "The order " From c33bcfc1fa53bccc00611bde588fe11537387b31 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Mon, 15 May 2017 14:50:04 -0500 Subject: [PATCH 18/40] setting correct test before pushing --- src/pickDeliver/test/test.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pickDeliver/test/test.conf b/src/pickDeliver/test/test.conf index 9882e5b7126..bc498b2c21d 100644 --- a/src/pickDeliver/test/test.conf +++ b/src/pickDeliver/test/test.conf @@ -16,7 +16,7 @@ differentVechiles-cygwin )], 'linux' => [qw( - doc-pickDeliver + doc-pickDeliverEuclidean )], 'documentation' => [qw( doc-pickDeliverEuclidean From 149cc2a14433ad8490b800528d3ca11a2cff1525 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Mon, 15 May 2017 18:01:00 -0500 Subject: [PATCH 19/40] removing unused files --- src/pickDeliver/src/book_keeping.cpp | 77 --- src/pickDeliver/src/fleet.cpp | 296 --------- src/pickDeliver/src/initial_solution.cpp | 142 ----- src/pickDeliver/src/optimize.cpp | 647 -------------------- src/pickDeliver/src/order.cpp | 183 ------ src/pickDeliver/src/pd_orders.cpp | 192 ------ src/pickDeliver/src/pd_problem.cpp | 48 -- src/pickDeliver/src/pgr_pickDeliver.cpp | 350 ----------- src/pickDeliver/src/solution.cpp | 242 -------- src/pickDeliver/src/tw_node.cpp | 298 --------- src/pickDeliver/src/vehicle.cpp | 539 ---------------- src/pickDeliver/src/vehicle_node.cpp | 165 ----- src/pickDeliver/src/vehicle_pickDeliver.cpp | 447 -------------- src/pickDeliver/test/test.conf | 3 +- 14 files changed, 1 insertion(+), 3628 deletions(-) delete mode 100644 src/pickDeliver/src/book_keeping.cpp delete mode 100644 src/pickDeliver/src/fleet.cpp delete mode 100644 src/pickDeliver/src/initial_solution.cpp delete mode 100644 src/pickDeliver/src/optimize.cpp delete mode 100644 src/pickDeliver/src/order.cpp delete mode 100644 src/pickDeliver/src/pd_orders.cpp delete mode 100644 src/pickDeliver/src/pd_problem.cpp delete mode 100644 src/pickDeliver/src/pgr_pickDeliver.cpp delete mode 100644 src/pickDeliver/src/solution.cpp delete mode 100644 src/pickDeliver/src/tw_node.cpp delete mode 100644 src/pickDeliver/src/vehicle.cpp delete mode 100644 src/pickDeliver/src/vehicle_node.cpp delete mode 100644 src/pickDeliver/src/vehicle_pickDeliver.cpp diff --git a/src/pickDeliver/src/book_keeping.cpp b/src/pickDeliver/src/book_keeping.cpp deleted file mode 100644 index 5354896181a..00000000000 --- a/src/pickDeliver/src/book_keeping.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/*PGR-GNU***************************************************************** - -FILE: book_keeping.cpp - -Copyright (c) 2017 pgRouting developers -Mail: project@pgrouting.org - ------- - -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*/ - - -#include "pickDeliver/book_keeping.h" - -#include -#include - -namespace pgrouting { -namespace vrp { -namespace pickdeliver { - -Swap_info::Swap_info(const Vehicle_pickDeliver &from, - const Vehicle_pickDeliver &to, - size_t from_o, - size_t to_o, - double delta) : - from_truck(from), - to_truck(to), - from_order(from_o), - to_order(to_o), - estimated_delta(delta) - { } - -std::ostream& operator << (std::ostream& log, const Swap_info &d) { - log << "\n" << d.from_truck.tau() << " --> " - << d.from_order - << "(" - << d.from_truck.orders()[d.from_order].pickup().id() - << ")" - << "\n" << d.to_truck.tau() << " --> " - << d.to_order - << "(" - << d.to_truck.orders()[d.to_order].pickup().id() - << ")" - << "\n" << "delta = " << d.estimated_delta; - return log; -} - - -std::ostream& operator<< (std::ostream &log, const Swap_bk &data) { - auto q = data.m_swaps; - while (!q.empty()) { - log << q.top() << " "; - q.pop(); - } - log << '\n'; - return log; -} - - -} // namespace pickdeliver -} // namespace vrp -} // namespace pgrouting diff --git a/src/pickDeliver/src/fleet.cpp b/src/pickDeliver/src/fleet.cpp deleted file mode 100644 index 6e860a9dd44..00000000000 --- a/src/pickDeliver/src/fleet.cpp +++ /dev/null @@ -1,296 +0,0 @@ -/*PGR-GNU***************************************************************** - -FILE: solution.cpp - -Copyright (c) 2015 pgRouting developers -Mail: project@pgrouting.org - ------- - -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*/ - -#include "pickDeliver/fleet.h" - -#include -#include -#include - -#include "cpp_common/identifiers.hpp" -#include "cpp_common/Dmatrix.h" - -#include "pickDeliver/pd_orders.h" -#include "pickDeliver/tw_node.h" -#include "pickDeliver/vehicle_pickDeliver.h" -#include "pickDeliver/pgr_pickDeliver.h" - - -namespace pgrouting { -namespace vrp { -namespace pickdeliver { - - -Fleet::Fleet(const Fleet &fleet) : - PD_problem(), - m_trucks(fleet.m_trucks), - used(fleet.used), - un_used(fleet.un_used) - {} - -Fleet::Fleet( - const std::vector &vehicles) : - PD_problem(), - used(), - un_used() { - ENTERING(); - build_fleet(vehicles); - Identifiers unused(m_trucks.size()); - un_used = unused; - EXITING(); - } - - -Vehicle_pickDeliver -Fleet::get_truck() { - auto id = un_used.front(); - msg.log << "id" << id - << "size" << m_trucks.size(); - pgassertwm(id < m_trucks.size(), msg.log.str()); - used += id; - if (un_used.size() > 1) un_used -= id; - return m_trucks[id]; -} - -void -Fleet::release_truck(size_t id) { - used -= id; - un_used += id; -} - -Vehicle_pickDeliver -Fleet::get_truck(size_t order) { - auto id = m_trucks.front().idx(); - for (auto truck : m_trucks) { - if (truck.feasable_orders().has(order)) { - id = truck.idx(); - msg.log << "id" << id - << "size" << m_trucks.size(); - pgassertwm(id < m_trucks.size(), msg.get_log()); - used += id; - if (un_used.size() > 1) un_used -= id; - break; - } - } - return m_trucks[id]; -} - - -Vehicle_pickDeliver -Fleet::get_truck(const Order order) { - ENTERING(); - auto id = m_trucks.front().idx(); - for (auto truck : m_trucks) { - if (truck.feasable_orders().has(order.idx())) { - id = truck.idx(); - msg.log << "id" << id - << "size" << m_trucks.size(); - pgassertwm(id < m_trucks.size(), msg.get_log()); - used += id; - if (un_used.size() > 1) un_used -= id; - break; - } - } - return m_trucks[id]; -} - - -/*! - builds a fleet from a vector of Vehicle_t - - - creates a phoney truck with unlimited capacity and unlimited closing times - - checks that the number of vehicles is a legal value - - creates the requested vehicles - - ERROR when cant_v <= 0 -*/ -bool -Fleet::build_fleet( - std::vector vehicles) { - ENTERING(); - /* - * creating a phoney truck with max capacity and max window - * with the start & end points of the first vehicle given - */ - vehicles.push_back({ - /* - * id, capacity - */ - -1, - std::numeric_limits::infinity(), - - vehicles[0].speed, - vehicles[0].start_x, - vehicles[0].start_y, - vehicles[0].start_node_id, - - /* - * cant_v, start_open_t, start_close_t, start_service_t - */ - 1, - 0, - std::numeric_limits::infinity(), - 0, - - vehicles[0].end_x, - vehicles[0].end_y, - vehicles[0].end_node_id, - /* - * end_open_t, end_close_t, end_service_t - */ - 0, - std::numeric_limits::infinity(), - 0}); - - - for (auto vehicle : vehicles) { - if (vehicle.cant_v <= 0) { - msg.error << "Illegal number of vehicles found vehicle"; - msg.log << vehicle.cant_v << "<= 0 on vehicle " << vehicle.id; - EXITING(); - return false; - } - - auto starting_site = Vehicle_node( - {problem->node_id()++, vehicle, Tw_node::NodeType::kStart}); - auto ending_site = Vehicle_node( - {problem->node_id()++, vehicle, Tw_node::NodeType::kEnd}); - - problem->add_node(starting_site); - problem->add_node(ending_site); - - pgassert(starting_site.is_start() && ending_site.is_end()); - - for (int i = 0; i < vehicle.cant_v; ++i) { - m_trucks.push_back(Vehicle_pickDeliver( - m_trucks.size(), - vehicle.id, - starting_site, - ending_site, - vehicle.capacity, - vehicle.speed)); -#if 0 - msg.log << "inserted Vehicle" << m_trucks.back().idx(); - msg.log << "\n"; -#endif - pgassert((m_trucks.back().idx() + 1) == m_trucks.size()); - } - } - Identifiers unused(m_trucks.size()); - un_used = unused; - EXITING(); - return true; -} - -/*! - * - * Not ok when: - * - there was an error building the fleet - * - a truck is not feasable - * - */ -bool -Fleet::is_fleet_ok() const { - ENTERING(); - if (!msg.get_error().empty()) return false; - for (auto truck : m_trucks) { - if (!truck.is_feasable()) { - msg.error << "Vehicle is not feasible"; - msg.log << "Check vehicle #:" << truck.idx(); - EXITING(); - return false; - } - } - EXITING(); - return true; -} - -/** - * Given an order, - * Cycle trhugh all the trucks to verify if the order can be served by - * at least one truck - */ -bool -Fleet::is_order_ok(const Order &order) const { - ENTERING(); - for (const auto truck : m_trucks) { -#if 0 - if (!order.is_valid(truck.speed())) continue; - if (truck.is_order_feasable(order)) { - return true; - } - msg.log << "checking order " << order.id() - << "on truck " << truck.id() << "\n"; -#endif - /* - * The order must be valid given the speed - */ - if (!order.is_valid(truck.speed())) continue; - - /* - * if its feasible, then the one truck is found - */ - if (truck.is_order_feasable(order)) { - EXITING(); - return true; - } - } - EXITING(); - return false; -} - -Vehicle_pickDeliver& -Fleet::operator[](size_t i) { - pgassert(i < m_trucks.size()); - return m_trucks[i]; -} - -void -Fleet::set_compatibles(const PD_Orders &orders) { - ENTERING(); - for (auto &truck : m_trucks) { - truck.set_compatibles(orders); - } -} - -/* - * FRIENDS - */ - -std::ostream& -operator << (std::ostream &log, const Fleet &f) { - log << "fleet\n"; - for (const auto v : f.m_trucks) { - log << v; - } - log << "end fleet\n"; - - return log; -} - - -} // namespace pickdeliver -} // namespace vrp -} // namespace pgrouting diff --git a/src/pickDeliver/src/initial_solution.cpp b/src/pickDeliver/src/initial_solution.cpp deleted file mode 100644 index bbe482aff96..00000000000 --- a/src/pickDeliver/src/initial_solution.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/*PGR-GNU***************************************************************** - -FILE: initial_solution.cpp - -Copyright (c) 2015 pgRouting developers -Mail: project@pgrouting.org - ------- - -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*/ - - -#include "pickDeliver/initial_solution.h" -#include -#include -#include -#include "cpp_common/pgr_assert.h" -#include "pickDeliver/solution.h" -#include "pickDeliver/pgr_pickDeliver.h" - -namespace pgrouting { -namespace vrp { -namespace pickdeliver { - -void -Initial_solution::invariant() const { - /* this checks there is no order duplicated */ - pgassert(all_orders == (assigned + unassigned)); - pgassert((assigned * unassigned).empty()); -} - - -Initial_solution::Initial_solution( - int kind, - size_t number_of_orders) : - Solution(), - all_orders(number_of_orders), - unassigned(number_of_orders), - assigned() { - invariant(); - pgassert(kind >= 0 && kind < 7); - - switch (kind) { - case 0: - one_truck_all_orders(); - break; - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - do_while_foo(kind); - break; - default: pgassert(false); - } - - invariant(); -} - - - -void -Initial_solution::do_while_foo(int kind) { - ENTERING(); - invariant(); - pgassert(kind > 0 && kind < 7); - - Identifiers notused; - bool out_of_trucks(true); - - while (!unassigned.empty()) { - auto truck = out_of_trucks? - trucks.get_truck(unassigned.front()) : - trucks.get_truck(); - /* - * kind 1 to 7 work with the same code structure - */ - truck.do_while_feasable(kind, unassigned, assigned); - msg.log << truck; - pgassertwm(false, msg.get_log().c_str()); - - if (truck.orders_in_vehicle().empty()) { - out_of_trucks = notused.has(truck.idx()); - if (out_of_trucks) { - for (auto t : notused) { - trucks.release_truck(t); - } - } - notused += truck.idx(); - continue; - } - fleet.push_back(truck); - invariant(); - } - - pgassert(is_feasable()); - invariant(); -} - - - - -void -Initial_solution::one_truck_all_orders() { - invariant(); - msg.log << "\nInitial_solution::one_truck_all_orders\n"; - auto truck = trucks.get_truck(); - while (!unassigned.empty()) { - auto order(truck.orders()[*unassigned.begin()]); - - truck.insert(order); - - assigned += unassigned.front(); - unassigned.pop_front(); - - invariant(); - } - fleet.push_back(truck); - invariant(); -} - - - - -} // namespace pickdeliver -} // namespace vrp -} // namespace pgrouting diff --git a/src/pickDeliver/src/optimize.cpp b/src/pickDeliver/src/optimize.cpp deleted file mode 100644 index fb4950e1055..00000000000 --- a/src/pickDeliver/src/optimize.cpp +++ /dev/null @@ -1,647 +0,0 @@ -/*PGR-GNU***************************************************************** - -FILE: optimize.cpp - -Copyright (c) 2015 pgRouting developers -Mail: project@pgrouting.org - ------- - -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*/ - - -#include -#include -#include - -#include "cpp_common/pgr_assert.h" - -#include "pickDeliver/solution.h" -#include "pickDeliver/book_keeping.h" -#include "pickDeliver/optimize.h" -#include "pickDeliver/pgr_pickDeliver.h" - -namespace pgrouting { -namespace vrp { -namespace pickdeliver { - - -Optimize::Optimize( - const Solution &old_solution) : - Solution(old_solution), - best_solution(old_solution) { - decrease_truck(); - inter_swap(fleet.size()); - } -Optimize::Optimize( - const Solution &old_solution, - size_t times) : - Solution(old_solution), - best_solution(old_solution) { - decrease_truck(); - inter_swap(times); - } - - -void -Optimize::inter_swap(size_t times) { - msg.log << tau("before sort"); - sort_by_size(); - msg.log << tau("after sort"); - - size_t i = 0; - while (inter_swap() && (++i < times)) { - msg.log << "\n***************************" << i; - std::rotate(fleet.begin(), fleet.begin() + 1, fleet.end()); - } - msg.log << tau("before sort"); - best_solution.sort_by_id(); - this->fleet = best_solution.fleet; - msg.log << tau("after sort"); - msg.log << best_solution.tau(); -} - -/* - * ordering the trucks by number of orders it has - * - the truck with more orders wants to: - * - make less time - * - do more orders - * The inter_swap objective is to make the trucks with more orders - * - less time consuming - */ -bool -Optimize::inter_swap() { - msg.log - << "\n" < bool { - return lhs.orders_in_vehicle().size() - > rhs.orders_in_vehicle().size(); - }); -} - -void -Optimize::sort_by_size() { - std::sort(fleet.begin(), fleet.end(), [] - (const Vehicle_pickDeliver &lhs, const Vehicle_pickDeliver &rhs) - -> bool { - return lhs.orders_in_vehicle().size() - > rhs.orders_in_vehicle().size(); - }); -} - -void -Optimize::sort_by_duration() { - std::sort(fleet.begin(), fleet.end(), [] - (const Vehicle_pickDeliver &lhs, const Vehicle_pickDeliver &rhs) - -> bool { - return lhs.duration() > rhs.duration(); - }); -} - -void -Optimize::delete_empty_truck() { - fleet.erase(std::remove_if( - fleet.begin(), - fleet.end(), - [](const Vehicle_pickDeliver &v){ - return v.orders_in_vehicle().empty();}), - fleet.end()); - save_if_best(); -} - -#if 0 -void -Optimize::move_duration_based() { - auto local_limit(fleet.size()); - size_t i(0); - - sort_by_duration(); - msg.log << tau("\nmove duration based"); - while (move_reduce_cost() && (++i < local_limit)) { } - delete_empty_truck(); - - i = 0; - sort_by_duration(); - std::reverse(fleet.begin(), fleet.end()); - msg.log << tau("\nmove duration based"); - while (move_reduce_cost() && (++i < local_limit)) { } - sort_by_duration(); - delete_empty_truck(); - this->fleet = best_solution.fleet; -} - - -void -Optimize::move_wait_time_based() { - this->fleet = best_solution.fleet; - - auto local_limit(fleet.size()); - size_t i(0); - - sort_for_move(); - msg.log << tau("\nmove wait_time based"); - while (move_reduce_cost() && (++i < local_limit)) { } - delete_empty_truck(); - - i = 0; - sort_for_move(); - std::reverse(fleet.begin(), fleet.end()); - msg.log << tau("\nmove wait_time based"); - while (move_reduce_cost() && (++i < local_limit)) { } - sort_by_duration(); - delete_empty_truck(); - this->fleet = best_solution.fleet; -} -#endif - -#if 0 -/* - * On the current order of the fleet - * T1 .......Tn-1 Tn Tn+1...... Tsize - * Tn tries to move orders to trucks - * T1 .... Tn-1 - * So that it gets space for the orders given by - * Tn+1 .... Tsize - * On the first move possible it returns - * - * When a truck is emptied, then it removes the truck from the fleet - * - * Returns true: when a move was possible - * Returns false: when a move was not possible - */ - - -bool -Optimize::move_reduce_cost() { - if (fleet.size() < 2) return false; - bool moved = false; - - size_t from_pos(fleet.size() - 1); - while (from_pos > 1) { - for (size_t to_pos = 0; to_pos < from_pos; ++to_pos) { - moved = move_reduce_cost(from_pos, to_pos) || moved; - } - --from_pos; - } - return moved; -} -#endif - -/* - * from_truck trying to make from_truck's duration smaller - * - maybe all orders can be moved - * - if that is the case, the from_truck could be removed - * - * Deleting an order on the from_truck - * - number of truck remains the same - * - from_truk duration() can not get larger - * - the overall duration can get larger - * - */ -bool -Optimize::move_reduce_cost( - Vehicle_pickDeliver &from, - Vehicle_pickDeliver &to) { - auto from_truck = from; - auto to_truck = to; - - /* - * don't move from a real truck to a phoney truck - */ - if (!from_truck.is_phony() && to_truck.is_phony()) { - return false; - } -#if 0 - from.id() > to.id() - ? to : from; -#endif - size_t from_pos = 0; - size_t to_pos = 0; - - for (; from_pos < fleet.size() - && fleet[from_pos].idx() != from_truck.idx() - ; ++from_pos) { - } - pgassert(from_pos < fleet.size()); - for (; to_pos < fleet.size() - && fleet[to_pos].idx() != to_truck.idx() - ; ++to_pos) { - } - pgassert(to_pos < fleet.size()); - - auto moved = false; - - auto from_orders = from_truck.orders_in_vehicle(); - while (!from_orders.empty()) { - /* - * removing an order decreases the duration - */ - auto order = from_truck.orders()[from_orders.front()]; - from_orders -= order.idx(); - - /* - * insert it in the "to" truck - */ - to_truck.insert(order); - if (to_truck.is_feasable()) { - msg.log - << "\n Move order " << order.pickup().id() - << " from truck " << from_truck.idx() - << " to truck " << to_truck.idx(); -#ifndef NDEBUG - msg.dbg_log << "\nMove before:"; - msg.dbg_log << "\n" << fleet[to_pos].tau(); - msg.dbg_log << "\n" << fleet[from_pos].tau(); -#endif - -#if 1 - from_truck.erase(order); -#else - to_truck.insert(order); - move_order(order, fleet[from_pos], fleet[to_pos]); -#endif - moved = true; - save_if_best(); - -#ifndef NDEBUG - msg.dbg_log << "\nMove after:"; - msg.dbg_log << "\n" << fleet[to_pos].tau(); - msg.dbg_log << "\n" << fleet[from_pos].tau(); -#endif - } else { - to_truck.erase(order); - } - } - return moved; -} - - - -/* - * from_truck: position of the truck where the order is - * to truck: truck to put the order - */ -void -Optimize::move_order( - Order order, - Vehicle_pickDeliver &from_truck, - Vehicle_pickDeliver &to_truck) { - pgassert(from_truck.has_order(order)); - pgassert(!to_truck.has_order(order)); - - from_truck.erase(order); - to_truck.insert(order); - - pgassert(!from_truck.has_order(order)); - pgassert(to_truck.has_order(order)); -} - -void -Optimize::sort_for_move() { - std::sort(fleet.begin(), fleet.end(), [] - (const Vehicle_pickDeliver &lhs, const Vehicle_pickDeliver &rhs) - -> bool { - return lhs.total_wait_time() > rhs.total_wait_time(); - }); - - std::stable_sort(fleet.begin(), fleet.end(), [] - (const Vehicle_pickDeliver &lhs, const Vehicle_pickDeliver &rhs) - -> bool { - return lhs.orders_size() > rhs.orders_size(); - }); -} - - -/* - * Optimize decreasing truck - * - * - Objective: try to remove truck with less duration - * - * Step 1: Sort the fleet, duration DESC - * Step 2: grab an order from the back of the the fleet - * Step 3: cycle the fleet & insert in best truck possible - */ -void -Optimize::decrease_truck() { - bool decreased(false); - for (auto i = fleet.size(); i > 1; --i) { - decreased = decrease_truck(i) || decreased; - } - if (decreased) { - delete_empty_truck(); - save_if_best(); - decrease_truck(); - } - save_if_best(); -} - -bool -Optimize::decrease_truck(size_t cycle) { - /* end recursion */ - if (cycle < 2) return false; - - - auto position = cycle - 1; - for (auto orders = fleet[position].orders_in_vehicle(); - !orders.empty(); - orders.pop_front()) { - /* Step 2: grab an order */ - auto order = fleet[position].orders()[orders.front()]; - pgassert(order.idx() == orders.front()); - - - /* Step 3: cycle the fleet (in reverse order) - * & insert in first truck possible */ - - // auto best_truck = fleet[position -1]; - for (size_t i = 0; i < position; ++i) { - fleet[i].insert(order); - if (!fleet[i].is_feasable()) { - fleet[i].erase(order); - } else { - /* - * delete the order from the current truck - */ - fleet[position].erase(order); - break; - } - } - } - return fleet[position].orders_in_vehicle().empty(); -} - -void -Optimize::save_if_best() { - if (duration() < best_solution.duration()) { - best_solution = (*this); - msg.log << "\n*********** best by duration" - << best_solution.cost_str(); -#ifndef NDEBUG - msg.dbg_log << best_solution.tau("best by duration"); -#endif - } - if (fleet.size() < best_solution.fleet.size()) { - best_solution = (*this); - msg.log << "\n*********** best by fleet size" - << best_solution.cost_str(); -#ifndef NDEBUG - msg.dbg_log << best_solution.tau("best by fleet size"); -#endif - } -} - - -} // namespace pickdeliver -} // namespace vrp -} // namespace pgrouting diff --git a/src/pickDeliver/src/order.cpp b/src/pickDeliver/src/order.cpp deleted file mode 100644 index 8bcd03f2cfd..00000000000 --- a/src/pickDeliver/src/order.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/*PGR-GNU***************************************************************** - -FILE: order.cpp - -Copyright (c) 2015 pgRouting developers -Mail: project@pgrouting.org - ------- - -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*/ - - -#include "pickDeliver/order.h" - -#include -#include "cpp_common/pgr_assert.h" -#include "pickDeliver/pgr_pickDeliver.h" - -namespace pgrouting { -namespace vrp { -namespace pickdeliver { - - -Identifiers -Order::subsetI(const Identifiers &I) const { - return m_compatibleI * I; -} - -Identifiers -Order::subsetJ(const Identifiers &J) const { - return m_compatibleJ * J; -} - - -Order::Order( - int64_t p_id, - size_t p_idx, - const Vehicle_node &p_pickup, - const Vehicle_node &p_delivery) : - Identifier(p_idx, p_id), - pickup_id(p_pickup.idx()), - delivery_id(p_delivery.idx()) { - } - -double -Order::distance() const { - return pickup().distance(delivery()); -} - -std::ostream& -operator << (std::ostream &log, const Order &order) { - log << "\n\nOrder " << order.id() << ":\n" -#if 0 - << "\tOrder idx: " << order.m_idx << "\n" -#endif - << "\tPickup: " << order.pickup() << "\n" - << "\tDelivery: " << order.delivery() << "\n\n"; -#if 0 - if (order.delivery().is_partially_compatible_IJ(order.pickup(), speed)) { - log << "\tis_partially_compatible_IJ: "; - } else if (order.delivery().is_tight_compatible_IJ(order.pickup(), speed)) { - log << "\tis_tight_compatible_IJ: "; - } else if (order.delivery().is_waitTime_compatible_IJ( - order.pickup(), speed)) { - log << "\tis_waitTime_compatible_IJ: "; - } else { - pgassert(false); - } -#endif - log << "There are | {I}| = " - << order.m_compatibleI.size() - << " -> order(" << order.id() - << ") -> | {J}| = " << order.m_compatibleJ.size() - << "\n {"; - for (const auto o : order.m_compatibleI) { - log << o << ", "; - } - log << "} -> " << order.id() << " -> {"; - for (const auto o : order.m_compatibleJ) { - log << o << ", "; - } - log << "}\n"; - - log << "Cost (distinace/time): " << order.distance(); - - return log; -} - - - -const Vehicle_node& -Order::delivery() const { - return problem->node(delivery_id); -} - - -const Vehicle_node& -Order::pickup() const { - return problem->node(pickup_id); -} - - -bool -Order::is_valid(double speed) const { - return - pickup().is_pickup() - && delivery().is_delivery() - /* IS P -> D */ - && delivery().is_compatible_IJ(pickup(), speed); -} - - -/* - * Initializing the set of nodes that can be placed - * inmediately after \bthis node - * - * (*this) -> J - * - */ -void -Order::set_compatibles(const Order J, double speed) { - if (J.idx() == idx()) return; - if (J.isCompatibleIJ(*this, speed)) { - /* - * this -> {J} - */ - m_compatibleJ += J.idx(); - } - if (this->isCompatibleIJ(J, speed)) { - /* - * {J} -> this - */ - m_compatibleI += J.idx(); - } -} - - -/* - * True when - * - * I -> (*this) - * - */ -bool -Order::isCompatibleIJ(const Order &I, double speed) const { - /* this is true in all cases */ - auto all_cases( - pickup().is_compatible_IJ(I.pickup(), speed) - && delivery().is_compatible_IJ(I.pickup(), speed)); - - /* case other(P) other(D) this(P) this(D) */ - auto case1(pickup().is_compatible_IJ(I.delivery(), speed) - && delivery().is_compatible_IJ(I.delivery(), speed)); - - /* case other(P) this(P) other(D) this(D) */ - auto case2(I.delivery().is_compatible_IJ(pickup(), speed) - && delivery().is_compatible_IJ(I.delivery(), speed)); - - /* case other(P) this(P) this(D) other(D) */ - auto case3(I.delivery().is_compatible_IJ(pickup(), speed) - && I.delivery().is_compatible_IJ(delivery(), speed)); - - return all_cases && (case1 || case2 || case3); -} - -} // namespace pickdeliver -} // namespace vrp -} // namespace pgrouting - diff --git a/src/pickDeliver/src/pd_orders.cpp b/src/pickDeliver/src/pd_orders.cpp deleted file mode 100644 index fdeca034b3d..00000000000 --- a/src/pickDeliver/src/pd_orders.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/*PGR-GNU***************************************************************** - -FILE: solution.cpp - -Copyright (c) 2015 pgRouting developers -Mail: project@pgrouting.org - ------- - -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*/ - -#include "pickDeliver/pd_orders.h" - -#include - -#include "pickDeliver/order.h" -#include "pickDeliver/tw_node.h" -#include "pickDeliver/vehicle_node.h" -#include "pickDeliver/pgr_pickDeliver.h" - -namespace pgrouting { -namespace vrp { -namespace pickdeliver { - -PD_Orders::PD_Orders( - const std::vector &pd_orders) { - build_orders(pd_orders); -} - -void -PD_Orders::build_orders( - const std::vector &pd_orders - ) { - ENTERING(); - OID order_ctr(0); - for (const auto order : pd_orders) { - /* - * SAMPLE CORRECT INFORMATION - * - * id | demand | p_node_id | p_x | p_y | p_open | p_close | p_service | d_node_id | d_x | d_y | d_open | d_close | d_service - * ----+--------+-----------+-----+-----+--------+---------+-----------+-----------+-----+-----+--------+---------+----------- - * 11 | 10 | 99 | 35 | 69 | 448 | 505 | 90 | 97 | 45 | 68 | 912 | 967 | 90 - * - */ - - - /* - * Creating the pickup & delivery nodes - */ - Vehicle_node pickup( - {problem->node_id()++, order, Tw_node::NodeType::kPickup}); - - pgassert(pickup.demand() == order.demand); - pgassert(pickup.opens() == order.pick_open_t); - pgassert(pickup.closes() == order.pick_close_t); - pgassert(pickup.id() == order.pick_node_id); - - Vehicle_node delivery( - {problem->node_id()++, order, Tw_node::NodeType::kDelivery}); - - pgassert(delivery.demand() == -order.demand); - pgassert(delivery.opens() == order.deliver_open_t); - pgassert(delivery.closes() == order.deliver_close_t); - pgassert(delivery.id() == order.deliver_node_id); - - pickup.set_Did(delivery.idx()); - delivery.set_Pid(pickup.idx()); - - - problem->add_node(pickup); - problem->add_node(delivery); - - - /* - * add into an order - */ - m_orders.push_back( - Order(order.id, order_ctr++, - pickup, - delivery)); - - } // for (creating orders) - EXITING(); -} - -bool -PD_Orders::is_valid(double speed) const { - ENTERING(); - for (const auto &o : m_orders) { - if (!o.is_valid(speed)) { - EXITING(); - return false; - } - pgassert(o.pickup().is_pickup()); - pgassert(o.delivery().is_delivery()); - /* P -> D */ - pgassert(o.delivery().is_compatible_IJ(o.pickup(), speed)); - } - EXITING(); - return true; -} - -Order& -PD_Orders::operator[](OID i) { - pgassert(i < m_orders.size()); - return m_orders[i]; -} - -const Order& -PD_Orders::operator[](OID i) const { - pgassert(i < m_orders.size()); - return m_orders[i]; -} - -void -PD_Orders::set_compatibles(double speed) { - ENTERING(); - for (auto &I : m_orders) { - for (const auto J : m_orders) { - I.set_compatibles(J, speed); - } - } - EXITING(); -} - -size_t -PD_Orders::find_best_J( - Identifiers &within_this_set) const { - ENTERING(); - pgassert(!within_this_set.empty()); - auto best_order = within_this_set.front(); - size_t max_size = 0; - - - for (auto o : within_this_set) { - auto size_J = m_orders[o].subsetJ(within_this_set).size(); - if (max_size < size_J) { - max_size = size_J; - best_order = o; - } - } - EXITING(); - return best_order; -} - - -size_t -PD_Orders::find_best_I( - Identifiers &within_this_set) const { - ENTERING(); - pgassert(!within_this_set.empty()); - auto best_order = within_this_set.front(); - size_t max_size = 0; - - - for (auto o : within_this_set) { - auto size_I = m_orders[o].subsetI(within_this_set).size(); - if (max_size < size_I) { - max_size = size_I; - best_order = o; - } - } - EXITING(); - return best_order; -} - -std::ostream& operator << (std::ostream &log, const PD_Orders &orders) { - log << "******* ORDERS *********\n"; - for (const auto o : orders) { - log << o << "\n"; - } - log << "*******\n"; - return log; -} - -} // namespace pickdeliver -} // namespace vrp -} // namespace pgrouting diff --git a/src/pickDeliver/src/pd_problem.cpp b/src/pickDeliver/src/pd_problem.cpp deleted file mode 100644 index 8db04563b35..00000000000 --- a/src/pickDeliver/src/pd_problem.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/*PGR-GNU***************************************************************** - -FILE: pgr_pickDeliver.h - -Copyright (c) 2015 pgRouting developers -Mail: project@pgrouting.org - ------- - -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*/ - - -#include "pickDeliver/pd_problem.h" - -namespace pgrouting { -namespace vrp { -namespace pickdeliver { - -Pgr_pickDeliver* PD_problem::problem; -Pgr_messages PD_problem::msg; - -PD_problem::PD_problem(Pgr_pickDeliver* p_problem) -{ - PD_problem::problem = p_problem; - msg.clear(); -} - -PD_problem::PD_problem(const PD_problem &) - { } - - -} // namespace pickdeliver -} // namespace vrp -} // namespace pgrouting diff --git a/src/pickDeliver/src/pgr_pickDeliver.cpp b/src/pickDeliver/src/pgr_pickDeliver.cpp deleted file mode 100644 index 61b9d913597..00000000000 --- a/src/pickDeliver/src/pgr_pickDeliver.cpp +++ /dev/null @@ -1,350 +0,0 @@ -/*PGR-GNU***************************************************************** - -FILE: pgr_pickDeliver.cpp - -Copyright (c) 2015 pgRouting developers -Mail: project@pgrouting.org - ------- - -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*/ - -#include "pickDeliver/pgr_pickDeliver.h" - -#include -#include -#include -#include -#include - -#include "cpp_common/pgr_assert.h" - -#include "pickDeliver/vehicle_node.h" -#include "pickDeliver/vehicle_pickDeliver.h" -#include "pickDeliver/order.h" -#include "pickDeliver/pd_orders.h" -#include "pickDeliver/fleet.h" -#include "pickDeliver/solution.h" -#include "pickDeliver/initial_solution.h" -#include "pickDeliver/optimize.h" - -namespace pgrouting { -namespace vrp { -namespace pickdeliver { - - - -Solution -Pgr_pickDeliver::optimize(const Solution solution) { - /* - * Optimize a solution - */ - Optimize opt_solution(solution, m_max_cycles); - msg.log << opt_solution.best_solution.tau("optimized"); - return opt_solution.best_solution; -} - -void -Pgr_pickDeliver::solve() { - ENTERING(); - auto initial_sols = solutions; - - if (m_initial_id == 0) { - msg.log << "trying all \n"; - return; - for (int i = 1; i < 7; ++i) { - initial_sols.push_back(Initial_solution(i, m_orders.size())); - msg.log << "solution " << i << "\n" << initial_sols.back().tau(); - // TODO calculate the time it takes - msg.log << "Initial solution " << i << " duration: " << initial_sols.back().duration(); - } - } else { - msg.log << "only trying " << m_initial_id << "\n"; - initial_sols.push_back(Initial_solution(m_initial_id, m_orders.size())); - // TODO calculate the time it takes - msg.log << "Initial solution " << m_initial_id << " duration: " << initial_sols[0].duration(); - EXITING(); - return; - } - - - /* - * Sorting solutions: the best is at the back - */ - pgassert(!initial_sols.empty()); - std::sort(initial_sols.begin(), initial_sols.end(), [] - (const Solution &lhs, const Solution &rhs) -> bool { - EXITING(); - return rhs < lhs; - }); - -#if 0 - solutions.push_back(Optimize(initial_sols.back())); - pgassert(!solutions.empty()); -#endif - msg.log << "best solution duration = " << solutions.back().duration(); - EXITING(); -} - - - -std::vector< General_vehicle_orders_t > -Pgr_pickDeliver::get_postgres_result() const { - if (solutions.empty()) return std::vector< General_vehicle_orders_t >(); - auto result = solutions.back().get_postgres_result(); - - General_vehicle_orders_t aggregates = { - /* - * Vehicle id = -2 indicates its an aggregate row - * - * (twv, cv, fleet, wait, duration) - */ - -2, // summary row on vehicle_number - solutions.back().twvTot(), // on vehicle_id - solutions.back().cvTot(), // on vehicle_seq - -1, // on order_id - -2, // on stop_type (gets increased later by one so it gets -1) - -1, // not accounting total loads - solutions.back().total_travel_time(), - -1, // not accounting arrival_travel_time - solutions.back().wait_time(), - solutions.back().total_service_time(), - solutions.back().duration(), - }; - result.push_back(aggregates); - - -#ifndef NDEBUG - for (const auto sol : solutions) { - msg.log << sol.tau(); - } -#endif - return result; -} - -/** Constructor for the matrix version - * - * - Builds the: - * matrix - * fleet - * orders - * nodes - * - * - Checks the: - * fleet - */ - -Pgr_pickDeliver::Pgr_pickDeliver( - const std::vector &pd_orders, - const std::vector &vehicles, - const pgrouting::tsp::Dmatrix &cost_matrix, - size_t p_max_cycles, - int initial) : - PD_problem(this), - m_cost_matrix(cost_matrix), - m_initial_id(initial), - m_max_cycles(p_max_cycles), - /* - * the problem has cost_matrix.size() nodes - */ - m_node_id(0), - m_nodes(), - m_trucks(vehicles), - m_orders(pd_orders) -{ - ENTERING(); - pgassert(!pd_orders.empty()); - pgassert(!vehicles.empty()); - pgassert(!cost_matrix.empty()); - pgassert(m_initial_id > 0 && m_initial_id < 7); - - msg.log << "\n *** Constructor for the matrix version ***\n"; - msg.log << "Check problem has no errors\n"; - - msg.error << m_trucks.msg.get_error(); - msg.error << m_orders.msg.get_error(); - if (msg.get_error().empty()) { - /* - * data has errors - */ - msg.log << m_trucks.msg.get_log(); - msg.log << m_orders.msg.get_log(); - return; - } - pgassert(msg.get_error().empty()); - pgassert(m_trucks.msg.get_error().empty()); - pgassert(m_orders.msg.get_error().empty()); - - - /* - * checking the fleet - */ - if (!m_trucks.is_fleet_ok()) { - msg.error << m_trucks.msg.get_error(); - msg.log << m_trucks.msg.get_log(); - return; - } - - /* - * check the (S, P, D, E) order on all vehicles - * stop when a feasible Vehicle is found - */ - for (const auto &o : m_orders) { - if (!m_trucks.is_order_ok(o)) { - msg.error << "An order is not feasible in all vehicles"; - // TODO should be id() - msg.log << "Check order #" << o.idx() << "\n" - << o << "\n"; - return; - } - } - - m_trucks.set_compatibles(m_orders); -} // constructor - - - -/***** Constructor for the eculedian version *******/ - -Pgr_pickDeliver::Pgr_pickDeliver( - const std::vector &pd_orders, - const std::vector &vehicles, - size_t p_max_cycles, - int initial) : - PD_problem(this), - m_initial_id(initial), - m_max_cycles(p_max_cycles), - /* - * the problem has unknown number of nodes - */ - m_node_id(0), - m_nodes(), - m_trucks(vehicles) -{ - ENTERING(); - pgassert(!pd_orders.empty()); - pgassert(!vehicles.empty()); - pgassert(m_initial_id > 0 && m_initial_id < 7); - - std::ostringstream tmplog; - - msg.log << "\n *** Constructor of problem ***\n"; - - if (!msg.get_error().empty()) { - return; - } - - pgassert(msg.get_error().empty()); - msg.log << "\n Building fleet"; - if (!m_trucks.is_fleet_ok()) { - pgassert(msg.get_error().empty()); - pgassert(!m_trucks.msg.get_error().empty()); - msg.error << m_trucks.msg.get_error(); - return; - } - - - -#ifndef NDEBUG - for (const auto t : m_trucks) { - msg.log << t << "\n"; - } -#endif - - msg.log << "\n Building orders"; - m_orders.build_orders(pd_orders); - msg.log << " ---> OK\n"; - - -#ifndef NDEBUG - for (const auto &o : m_orders) { - msg.log << o << "\n"; - } -#endif - - /* - * check the (S, P, D, E) order on all vehicles - * stop when a feasible truck is found - */ - for (const auto &o : m_orders) { - if (!m_trucks.is_order_ok(o)) { - msg.error << "The order " - << o.pickup().id() - << " is not feasible on any truck"; - msg.log << "\n" << o; - return; - } - } - - m_trucks.set_compatibles(m_orders); -} // constructor - - -const Order -Pgr_pickDeliver::order_of(const Vehicle_node &node) const { - pgassert(node.is_pickup() || node.is_delivery()); - if (node.is_pickup()) { - for (const auto o : m_orders) { - if (o.pickup().idx() == node.idx()) { - return o; - } - } - } - pgassert(node.is_delivery()); - - for (const auto o : m_orders) { - if (o.delivery().idx() == node.idx()) { - return o; - } - } -#ifndef NDEBUG - std::ostringstream err_log; - err_log << "Order of" << node << " not found"; -#endif - pgassertwm(false, err_log.str()); - return m_orders[0]; -} - - -const Vehicle_node& -Pgr_pickDeliver::node(ID id) const { - pgassert(id < m_nodes.size()); - msg.log << "id = " << id << "m_nodes[id].idx()" << m_nodes[id].idx() << "\n"; - pgassertwm(id == m_nodes[id].idx(), msg.get_log().c_str()); - return m_nodes[id]; -} - -std::ostream& operator<<( - std::ostream &log, - const Pgr_pickDeliver &pd_prob) { -#if 0 - log << "The matrix\n" << pd_prob.m_cost_matrix; - for (const auto n : pd_prob.m_nodes) { - log << n << "\n"; - } -#endif - log << "The vehicles\n" << pd_prob.m_trucks; - - log << "The nodes\n"; - log << "The orders\n" << pd_prob.m_orders; - return log; - -} - -} // namespace pickdeliver -} // namespace vrp -} // namespace pgrouting diff --git a/src/pickDeliver/src/solution.cpp b/src/pickDeliver/src/solution.cpp deleted file mode 100644 index 7d04e922557..00000000000 --- a/src/pickDeliver/src/solution.cpp +++ /dev/null @@ -1,242 +0,0 @@ -/*PGR-GNU***************************************************************** - -FILE: solution.cpp - -Copyright (c) 2015 pgRouting developers -Mail: project@pgrouting.org - ------- - -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*/ - -#include "pickDeliver/solution.h" - -#include -#include -#include - -#include "pickDeliver/pgr_pickDeliver.h" -#include "c_types/pickDeliver/general_vehicle_orders_t.h" - -namespace pgrouting { -namespace vrp { -namespace pickdeliver { - -std::vector -Solution::get_postgres_result() const { - std::vector result; - /* postgres numbering starts with 1 */ - int i(1); - for (const auto truck : fleet) { - std::vector data = - truck.get_postgres_result(i); - result.insert(result.end(), data.begin(), data.end()); - - ++i; - } - return result; -} - - - -bool -Solution::is_feasable() const { - for (const auto v : fleet) { - if (v.is_feasable()) continue; - return false; - } - return true; -} - -double -Solution::duration() const { - double total(0); - for (const auto v : fleet) { - total += v.duration(); - } - return total; -} - -int -Solution::twvTot() const { - int total(0); - for (const auto v : fleet) { - total += v.twvTot(); - } - return total; -} - -double -Solution::wait_time() const { - double total(0); - for (const auto v : fleet) { - total += v.total_wait_time(); - } - return total; -} - -double -Solution::total_travel_time() const { - double total(0); - for (const auto v : fleet) { - total += v.total_travel_time(); - } - return total; -} - -double -Solution::total_service_time() const { - double total(0); - for (const auto v : fleet) { - total += v.total_service_time(); - } - return total; -} - -int -Solution::cvTot() const { - int total(0); - for (const auto v : fleet) { - total += v.cvTot(); - } - return total; -} - -Vehicle::Cost -Solution::cost() const { - double total_duration(0); - double total_wait_time(0); - int total_twv(0); - int total_cv(0); - for (const auto v : fleet) { - total_duration += v.duration(); - total_wait_time += v.total_wait_time(); - total_twv += v.twvTot(); - total_cv += v.cvTot(); - } - return std::make_tuple( - total_twv, total_cv, fleet.size(), - total_wait_time, total_duration); -} - - - -std::string -Solution::cost_str() const { - Vehicle::Cost s_cost(cost()); - std::ostringstream log; - - log << "(twv, cv, fleet, wait, duration) = (" - << std::get<0>(s_cost) << ", " - << std::get<1>(s_cost) << ", " - << std::get<2>(s_cost) << ", " - << std::get<3>(s_cost) << ", " - << std::get<4>(s_cost) << ")"; - - return log.str(); -} - -std::string -Solution::tau(const std::string &title) const { - Vehicle::Cost s_cost(cost()); - std::ostringstream log; - - log << "\n" << title << ": " << std::endl; - for (const auto v : fleet) { - log << "\n" << v.tau(); - } - log << "\n" << cost_str() << "\n"; - return log.str(); -} - -void -Solution::sort_by_id() { - std::sort(fleet.begin(), fleet.end(), [] - (const Vehicle_pickDeliver &lhs, const Vehicle_pickDeliver &rhs) - -> bool { - return lhs.idx() < rhs.idx(); - }); -} - -std::ostream& -operator << (std::ostream &log, const Solution &solution) { - for (const auto vehicle : solution.fleet) { - log << vehicle; - } - - log << "\n SOLUTION:\n\n " - << solution.tau(); - - return log; -} - -bool -Solution::operator<(const Solution &s_rhs) const { - Vehicle::Cost lhs(cost()); - Vehicle::Cost rhs(s_rhs.cost()); - - /* - * capacity violations - */ - if (std::get<0>(lhs) < std::get<0>(rhs)) - return true; - if (std::get<0>(lhs) > std::get<0>(rhs)) - return false; - - /* - * time window violations - */ - if (std::get<1>(lhs) < std::get<1>(rhs)) - return true; - if (std::get<1>(lhs) > std::get<1>(rhs)) - return false; - - /* - * fleet size - */ - if (std::get<2>(lhs) < std::get<2>(rhs)) - return true; - if (std::get<2>(lhs) > std::get<2>(rhs)) - return false; - - /* - * waiting time - */ - if (std::get<3>(lhs) < std::get<3>(rhs)) - return true; - if (std::get<3>(lhs) > std::get<3>(rhs)) - return false; - - /* - * duration - */ - if (std::get<4>(lhs) < std::get<4>(rhs)) - return true; - if (std::get<4>(lhs) > std::get<4>(rhs)) - return false; - - return false; -} - -Solution::Solution() : - EPSILON(0.0001), - trucks(problem->trucks()) -{} - -} // namespace pickdeliver -} // namespace vrp -} // namespace pgrouting diff --git a/src/pickDeliver/src/tw_node.cpp b/src/pickDeliver/src/tw_node.cpp deleted file mode 100644 index 790ee00d35f..00000000000 --- a/src/pickDeliver/src/tw_node.cpp +++ /dev/null @@ -1,298 +0,0 @@ -/*PGR-GNU***************************************************************** - -FILE: tw_node.cpp - -Copyright (c) 2015 pgRouting developers -Mail: project@pgrouting.org - ------- - -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*/ - -#include "pickDeliver/tw_node.h" - -#include -#include - -#include "cpp_common/pgr_assert.h" - - -namespace pgrouting { -namespace vrp { -namespace pickdeliver { - - -double -Tw_node::travel_time_to(const Dnode &other, double speed) const { - pgassert(speed != 0); - /*! @todo TODO evaluate with matrix also*/ - return distance(other) / speed; -} - - -/* - * I -> J = (*this) - */ -double -Tw_node::arrival_j_opens_i(const Tw_node &I, double speed) const { - if (m_type == kStart) return (std::numeric_limits::max)(); - return I.opens() + I.service_time() + I.travel_time_to(*this, speed); -} - -double -Tw_node::arrival_j_closes_i(const Tw_node &I, double speed) const { - if (m_type == kStart) return (std::numeric_limits::max)(); - return I.closes() + I.service_time() + I.travel_time_to(*this, speed); -} - - - - -bool -Tw_node::is_compatible_IJ(const Tw_node &I, double speed) const { - /* - * I /-> kStart - */ - if (m_type == kStart) return false; - /* - * kEnd /-> (*this) - */ - if (I.m_type == kEnd) return false; - - return !is_late_arrival(arrival_j_opens_i(I, speed)); -} - -bool -Tw_node::is_partially_compatible_IJ(const Tw_node &I, double speed) const { - return - is_compatible_IJ(I, speed) - && !is_early_arrival(arrival_j_opens_i(I, speed)) - && is_late_arrival(arrival_j_closes_i(I, speed)); -} - -bool -Tw_node::is_tight_compatible_IJ(const Tw_node &I, double speed) const { - return - is_compatible_IJ(I, speed) - && !is_early_arrival(arrival_j_opens_i(I, speed)) - && !is_late_arrival(arrival_j_closes_i(I, speed)); -} - -bool -Tw_node::is_partially_waitTime_compatible_IJ( - const Tw_node &I, - double speed) const { - return - is_compatible_IJ(I, speed) - && is_early_arrival(arrival_j_opens_i(I, speed)); -} - -bool -Tw_node::is_waitTime_compatible_IJ(const Tw_node &I, double speed) const { - return - is_compatible_IJ(I, speed) - && is_early_arrival(arrival_j_opens_i(I, speed)); -} - - -std::string Tw_node::type_str() const { - switch (type()) { - case kStart: return "START"; break; - case kEnd: return "END"; break; - case kDump: return "DUMP"; break; - case kLoad: return "LOAD"; break; - case kPickup: return "PICKUP"; break; - case kDelivery: return "DELIVERY"; break; - default: return "UNKNOWN"; - } -} - -bool -Tw_node::is_start() const { - return - m_type == kStart - && (0 <= opens()) - && (opens() < closes()) - && (service_time() >= 0) - && (demand() == 0); -} - -bool -Tw_node::is_pickup() const { - return m_type == kPickup - && (0 <= opens()) - && (opens() < closes()) - && (service_time() >= 0) - && (demand() > 0); -} - - -bool -Tw_node::is_delivery() const { - return m_type == kDelivery - && (0 <= opens()) - && (opens() < closes()) - && (service_time() >= 0) - && (demand() < 0); -} - - -bool -Tw_node::is_dump() const { - return m_type == kDump - && (0 <= opens()) - && (opens() < closes()) - && (service_time() >= 0) - && (demand() <= 0); -} - - -bool -Tw_node::is_load() const { - return m_type == kLoad - && (0 <= opens()) - && (opens() < closes()) - && (service_time() >= 0) - && (demand() >= 0); -} - - -bool -Tw_node::is_end() const { - return m_type == kEnd - && (0 <= opens()) - && (opens() < closes()) - && (service_time() >= 0) - && (demand() == 0); -} - - -bool -Tw_node::operator ==(const Tw_node &rhs) const { - if (&rhs == this) return true; - return (dynamic_cast(this) == dynamic_cast(&rhs)); -} - - - -bool Tw_node::is_valid() const { - switch (type()) { - case kStart: - return is_start(); - break; - - case kEnd: - return is_end(); - break; - - case kDump: - return is_dump(); - break; - - case kDelivery: - return is_delivery(); - break; - - case kPickup: - return is_pickup(); - break; - - case kLoad: - return is_load(); - break; - - default: - return false; - break; - } - - return false; -} - -/*! - * - * - Insert the node as if it was a pickup - * - if the node was a kDelivery modify the information - * - * @param[in] id index of the m_nodes container of the problem - * @param[in] data The original information - * @param[in] type the kind of node it is - */ -Tw_node::Tw_node( - size_t idx, - const PickDeliveryOrders_t data, - NodeType type) : - Dnode(idx, data.pick_node_id, data.pick_x, data.pick_y), - m_opens(data.pick_open_t), - m_closes(data.pick_close_t), - m_service_time(data.pick_service_t), - m_demand(data.demand), - m_type(type) { - if (m_type == kDelivery) { - //TODO this is used when its the Node - //m_point = pgrouting::Point(data.deliver_x, data.deliver_y); - reset_id(data.deliver_node_id); - m_opens = data.deliver_open_t; - m_closes = data.deliver_close_t; - m_service_time = data.deliver_service_t; - m_demand *= -1; - } - } - -Tw_node::Tw_node( - size_t idx, - Vehicle_t data, - NodeType type) : - Dnode(idx, data.start_node_id, data.start_x, data.start_y), - m_opens(data.start_open_t), - m_closes(data.start_close_t), - m_service_time(data.start_service_t), - m_demand(0), - m_type(type) { - if (m_type == kEnd) { - //m_point = pgrouting::Point(data.end_x, data.end_y); - reset_id(data.end_node_id); - m_opens = data.end_open_t; - m_closes = data.end_close_t; - m_service_time = data.end_service_t; - } - } - - -/*! * \brief Print the contents of a Twnode object. */ -std::ostream& operator<<(std::ostream &log, const Tw_node &n) { - log << static_cast(n) - << "[opens = " << n.m_opens - << "\tcloses = " << n.m_closes - << "\tservice = " << n.m_service_time - << "\tdemand = " << n.m_demand - << "\ttype = " << n.type_str() - << "]"; -#if 0 - if (n.is_pickup() || n.is_delivery()) { - log << "->" << n.m_otherid << "\n"; - } else { - log << "\n"; - } -#endif - return log; -} - -} // namespace pickdeliver -} // namespace vrp -} // namespace pgrouting - diff --git a/src/pickDeliver/src/vehicle.cpp b/src/pickDeliver/src/vehicle.cpp deleted file mode 100644 index bc877ef8b44..00000000000 --- a/src/pickDeliver/src/vehicle.cpp +++ /dev/null @@ -1,539 +0,0 @@ -/*PGR-GNU***************************************************************** - -FILE: vehicle.cpp - -Copyright (c) 2015 pgRouting developers -Mail: project@pgrouting.org - ------- - -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*/ - -#include "pickDeliver/vehicle.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "cpp_common/pgr_assert.h" - -#include "pickDeliver/pgr_pickDeliver.h" - - -namespace pgrouting { -namespace vrp { -namespace pickdeliver { - - -void -Vehicle::invariant() const { - pgassert(m_path.size() >= 2); - pgassert(m_path.front().is_start()); - pgassert(m_path.back().is_end()); -} - -size_t -Vehicle::insert(std::pair position_limits, const Vehicle_node &node) { - invariant(); - pgassert(position_limits.first <= m_path.size()); - pgassert(position_limits.second <= m_path.size()); - - auto low = position_limits.first; - auto high = position_limits.second; - auto best = low; - - - insert(low, node); - - Vehicle::Cost best_cost(cost()); - - - while (low < high) { - swap(low, low + 1); - ++low; - if (cost_compare(best_cost, cost())) { - best_cost = cost(); - best = low; - } - } - return best; - - pgassert(best < m_path.size()); - pgassert(m_path[best].idx() == node.idx()); - invariant(); -} - - - - -bool -Vehicle::cost_compare(const Cost &lhs, const Cost &rhs) const { - /* - * capacity violations - */ - if (std::get<1>(lhs) < std::get<1>(rhs)) - return true; - if (std::get<1>(lhs) > std::get<1>(rhs)) - return false; - - /* - * time window violations - */ - if (std::get<0>(lhs) < std::get<0>(rhs)) - return true; - if (std::get<0>(lhs) > std::get<0>(rhs)) - return false; - - /* - * waiting time - */ - if (std::get<3>(lhs) < std::get<3>(rhs)) - return true; - if (std::get<3>(lhs) > std::get<3>(rhs)) - return false; - - /* - * duration - */ - if (std::get<4>(lhs) < std::get<4>(rhs)) - return true; - if (std::get<4>(lhs) > std::get<4>(rhs)) - return false; - - /* - * truck size - */ - if (std::get<2>(lhs) < std::get<2>(rhs)) - return true; - if (std::get<2>(lhs) > std::get<2>(rhs)) - return false; - - return false; -} - - - -std::vector -Vehicle::get_postgres_result( - int vid) const { - std::vector result; - /* postgres numbering starts with 1 */ - int vehicle_seq(1); - for (const auto p_stop : m_path) { - General_vehicle_orders_t data = - {vid, id(), vehicle_seq, - /* - * The original_id is invalid for stops type 0 and 5 - */ - (p_stop.type() == 0 || p_stop.type() == 5)? -1 : p_stop.id(), - p_stop.type(), - p_stop.cargo(), - p_stop.travel_time(), - p_stop.arrival_time(), - p_stop.wait_time(), - p_stop.service_time(), - p_stop.departure_time()}; - result.push_back(data); - ++vehicle_seq; - } - return result; -} - - -Vehicle::Cost -Vehicle::cost() const { - return std::make_tuple( - twvTot(), cvTot(), m_path.size(), - total_wait_time(), duration()); -} - - -void -Vehicle::insert(POS at, Vehicle_node node) { - invariant(); - pgassert(at <= m_path.size()); - - m_path.insert(m_path.begin() + at, node); - /*! @todo TODO evaluate with matrix also*/ - evaluate(at); - - pgassert(at < m_path.size()); - pgassert(m_path[at].idx() == node.idx()); - invariant(); -} - - -double -Vehicle::deltaTime(const Vehicle_node &node, POS pos) const { - /* - * .... POS POS+1 .... - * .... POS node POS+1 .... - * - */ - auto prev = m_path[pos-1]; - auto next = m_path[pos]; - auto original_time = next.travel_time(); - auto tt_p_n = prev.travel_time_to(node, m_speed); - tt_p_n = node.is_early_arrival(prev.departure_time() + tt_p_n) ? - node.closes() - prev.departure_time() - : tt_p_n; - - auto tt_n_x = node.travel_time_to(next, m_speed); - tt_p_n = next.is_early_arrival( - prev.departure_time() + tt_p_n + node.service_time() + tt_n_x) ? - next.closes() - (prev.departure_time() + tt_p_n + node.service_time()) - : tt_n_x; - - return (tt_p_n + tt_n_x) - original_time; -} - - - - -size_t -Vehicle::insert_less_travel_time(const Vehicle_node &node, POS after_pos) { - invariant(); - - double min_delta = (std::numeric_limits::max)(); - POS min_pos = after_pos; - - for (POS pos = after_pos; pos < m_path.size(); ++pos) { - if (!m_path[pos].is_start()) { - auto tt = deltaTime(node, pos); - - if (tt < min_delta) { - min_delta = tt; - min_pos = pos; - } - } - } - insert(min_pos, node); - - invariant(); - return min_pos; -} - -void -Vehicle::erase(const Vehicle_node &node) { - invariant(); - - POS pos = 0; - for ( ; pos < m_path.size() ; ++pos) { - if (node.idx() == m_path[pos].idx()) - break; - } - - erase(pos); - /*! @todo TODO evaluate with matrix also*/ - evaluate(pos); - - invariant(); -} - - -/* - * before: S E - * after: S N E - * - * before: S n1 n2 ... n E - * after: S N n1 n2 ... n E - */ -void -Vehicle::push_front(const Vehicle_node &node) { - invariant(); - - /* insert evaluates */ - insert(1, node); - - invariant(); -} - -/* - * before: S E - * after: S N E - * - * before: S n1 n2 ... n E - * after: S n1 n2 ... n N E - */ -void -Vehicle::push_back(const Vehicle_node &node) { - invariant(); - - /* insert evaluates */ - insert(m_path.size() - 1, node); - - invariant(); -} - -void -Vehicle::pop_back() { - invariant(); - pgassert(m_path.size() > 2); - - /* erase evaluates */ - erase(m_path.size() - 2); - - invariant(); -} - -void -Vehicle::pop_front() { - invariant(); - pgassert(m_path.size() > 2); - - /* erase evaluates */ - erase(1); - - invariant(); -} - - - -void -Vehicle::erase(POS at) { - invariant(); - - pgassert(m_path.size() > 2); - pgassert(at < m_path.size()); - pgassert(!m_path[at].is_start()); - pgassert(!m_path[at].is_end()); - - m_path.erase(m_path.begin() + at); - /*! @todo TODO evaluate with matrix also*/ - evaluate(at); - - invariant(); -} - -void -Vehicle::swap(POS i, POS j) { - invariant(); - pgassert(m_path.size() > 3); - pgassert(!m_path[i].is_start()); - pgassert(!m_path[i].is_end()); - pgassert(!m_path[j].is_start()); - pgassert(!m_path[j].is_end()); - - std::swap(m_path[i], m_path[j]); - /*! @todo TODO evaluate with matrix also*/ - i < j ? evaluate(i) : evaluate(j); - - invariant(); -} - - -void -Vehicle::evaluate() { - invariant(); - - /*! @todo TODO evaluate with matrix also*/ - evaluate(0); - - invariant(); -} - -bool -Vehicle::empty() const { - invariant(); - return m_path.size() <= 2; -} - -void -Vehicle::evaluate(POS from) { - invariant(); - // preconditions - pgassert(from < m_path.size()); - - - auto node = m_path.begin() + from; - - while (node != m_path.end()) { - if (node == m_path.begin()) { - /*! @todo TODO evaluate with matrix also*/ - node->evaluate(m_capacity); - } else { - /*! @todo TODO evaluate with matrix also*/ - node->evaluate(*(node - 1), m_capacity, m_speed); - } - - ++node; - } - invariant(); -} - -std::deque< Vehicle_node > -Vehicle::path() const { - invariant(); - return m_path; -} - - -std::pair -Vehicle::position_limits(const Vehicle_node node) const { - POS high = getPosHighLimit(node); - POS low = getPosLowLimit(node); - return std::make_pair(low, high); -} - - -/* - * start searching from postition low = pos(E) - * - * S 1 2 3 4 5 6 7 ..... E - * node -> E - * node -> ... - * node -> 7 - * node -> 6 - * node -> 5 - * node /-> 4 - * - * return low_limit = 5 - * - */ -size_t -Vehicle::getPosLowLimit(const Vehicle_node &nodeI) const { - invariant(); - - POS low = 0; - POS high = m_path.size(); - POS low_limit = high; - - /* J == m_path[low_limit - 1] */ - while (low_limit > low - && m_path[low_limit - 1].is_compatible_IJ(nodeI, m_speed)) { - --low_limit; - } - - invariant(); - return low_limit; -} - - -/* - * start searching from postition low = pos(S) - * - * S 1 2 3 4 5 6 7 ..... E - * S -> node - * 1 -> node - * 2 -> node - * ... - * 6 -> node - * 7 /-> node - * - * returns high_limit = 7 - */ -size_t -Vehicle::getPosHighLimit(const Vehicle_node &nodeJ) const { - invariant(); - - POS low = 0; - POS high = m_path.size(); - POS high_limit = low; - - /* I == m_path[high_limit] */ - while (high_limit < high - && nodeJ.is_compatible_IJ(m_path[high_limit], m_speed)) { - ++high_limit; - } - - invariant(); - return high_limit; -} - - - -Vehicle::Vehicle( - size_t p_idx, - int64_t p_id, - const Vehicle_node &starting_site, - const Vehicle_node &ending_site, - double p_m_capacity, - double p_speed) : - Identifier(p_idx, p_id), - m_capacity(p_m_capacity), - m_speed(p_speed) - { - m_path.clear(); - m_path.push_back(starting_site); - m_path.push_back(ending_site); - /*! @todo TODO evaluate with matrix also*/ - evaluate(0); - invariant(); - } - - - - -std::string -Vehicle::tau() const { - std::ostringstream log; - log << "Truck " << idx() << " ("; - for (const auto p_stop : m_path) { - if (!(p_stop == m_path.front())) - log << ", "; - log << p_stop.id(); - } - log << ")" << " \t(cv, twv, wait_time, duration) = (" - << cvTot() << ", " - << twvTot() << ", " - << total_wait_time() << ", " - << duration() << ")"; - - return log.str(); -} - -/****** FRIENDS *******/ - -std::ostream& -operator << (std::ostream &log, const Vehicle &v) { - v.invariant(); - int i(0); - log << "\n\n****************** " << v.idx() << "th VEHICLE***************\n"; - log << "id = " << v.id() - << "\tcapacity = " << v.m_capacity - << "\tspeed = " << v.m_speed << "\n"; - - for (const auto &path_stop : v.path()) { - log << "Path_stop" << ++i << "\n"; - log << path_stop << "\n"; - } - return log; -} - -bool -operator<(const Vehicle &lhs, const Vehicle &rhs) { - lhs.invariant(); - rhs.invariant(); - - if (lhs.m_path.size() < rhs.m_path.size()) return true; - - /* here because sizes are equal */ - - if (lhs.m_path.back().total_travel_time() - < lhs.m_path.back().total_travel_time()) return true; - - return false; -} - -} // namespace pickdeliver -} // namespace vrp -} // namespace pgrouting diff --git a/src/pickDeliver/src/vehicle_node.cpp b/src/pickDeliver/src/vehicle_node.cpp deleted file mode 100644 index 7deb91fbfbd..00000000000 --- a/src/pickDeliver/src/vehicle_node.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/*PGR-GNU***************************************************************** - -FILE: vehicle_node.cpp - -Copyright (c) 2015 pgRouting developers -Mail: project@pgrouting.org - ------- - -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*/ - - -#include "pickDeliver/vehicle_node.h" - - -namespace pgrouting { -namespace vrp { -namespace pickdeliver { - - -/*! - * \param[in] cargoLimit of the vehicle - */ -void -Vehicle_node::evaluate(double cargoLimit) { - /*! @todo TODO evaluate with matrix also*/ - if (is_start()) { - /* time */ - m_travel_time = 0; - m_arrival_time = opens(); - m_wait_time = 0; - m_departure_time = arrival_time() + service_time(); - - /* time aggregates */ - m_tot_travel_time = 0; - m_tot_wait_time = 0; - m_tot_service_time = service_time(); - - /* cargo aggregates */ - m_cargo = demand(); - - /* violation aggregates */ - m_twvTot = m_cvTot = 0; - m_cvTot = has_cv(cargoLimit) ? 1 : 0; - m_delta_time = 0; - } -} - -/*! - \param[in] pred The node preceding this node in the path. - \param[in] cargoLimit of the vehicle. - \param[in] speed of the vehicle. - */ -void -Vehicle_node::evaluate( - const Vehicle_node &pred, - double cargoLimit, - double speed) { - /*! @todo TODO evaluate with matrix also*/ - /* time */ - m_travel_time = pred.travel_time_to(*this, speed); - m_arrival_time = pred.departure_time() + travel_time(); - m_wait_time = is_early_arrival(arrival_time()) ? - opens() - m_arrival_time : - 0; - m_departure_time = arrival_time() + wait_time() + service_time(); - - /* time aggregates */ - m_tot_travel_time = pred.total_travel_time() + travel_time(); - m_tot_wait_time = pred.total_wait_time() + wait_time(); - m_tot_service_time = pred.total_service_time() + service_time(); - - /* cargo aggregates */ - if (is_dump() && pred.cargo() >= 0) { - m_demand = -pred.cargo(); - } - m_cargo = pred.cargo() + demand(); - - /* cargo aggregates */ - - m_twvTot = has_twv() ? pred.twvTot() + 1 : pred.twvTot(); - m_cvTot = has_cv(cargoLimit) ? pred.cvTot() + 1 : pred.cvTot(); - m_delta_time = departure_time() - pred.departure_time(); -} - - - -std::ostream& -operator << (std::ostream &log, const Vehicle_node &v) { - log << static_cast(v) - << " twv = " << v.has_twv() - << ", twvTot = " << v.twvTot() - << ", cvTot = " << v.cvTot() - << ", cargo = " << v.cargo() - << ", travel _time = " << v.travel_time() - << ", arrival _time = " << v.arrival_time() - << ", wait _time = " << v.wait_time() - << ", service _time = " << v.service_time() - << ", departure _time = " << v.departure_time(); - return log; -} - - -/*! @brief Creates a disconected vehicle node - * - * A node that is not served by any vehicle - * - * @param[in] node Time window node - */ -Vehicle_node::Vehicle_node(const Tw_node &node) - : Tw_node(node), - m_travel_time(0), - m_arrival_time(0), - m_wait_time(0), - m_departure_time(0), - m_delta_time(0), - m_cargo(0), - m_twvTot(0), - m_cvTot(0), - m_tot_wait_time(0), - m_tot_travel_time(0), - m_tot_service_time(0) { - } - - - -bool -Vehicle_node::deltaGeneratesTWV(double delta_time) const { - /*! @todo TODO evaluate with matrix also*/ - return is_late_arrival(m_arrival_time + delta_time); -} - - -/*! - The actual arrival time at \b This node, given that: - \b this node is visited directly after \b other node - and that the actual arrival time at \b other node was arrival(other) - */ -double -Vehicle_node::arrival_i_arrives_j( - const Vehicle_node &other, - double speed) const { - /*! @todo TODO evaluate with matrix also*/ - return other.arrival_time() - + other.service_time() - + other.travel_time_to(*this, speed); -} - -} // namespace pickdeliver -} // namespace vrp -} // namespace pgrouting diff --git a/src/pickDeliver/src/vehicle_pickDeliver.cpp b/src/pickDeliver/src/vehicle_pickDeliver.cpp deleted file mode 100644 index 9da245e7862..00000000000 --- a/src/pickDeliver/src/vehicle_pickDeliver.cpp +++ /dev/null @@ -1,447 +0,0 @@ -/*PGR-GNU***************************************************************** - -FILE: vehicle_pickDeliver.cpp - -Copyright (c) 2016 pgRouting developers -Mail: project@pgrouting.org - ------- - -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*/ - -#include "pickDeliver/vehicle_pickDeliver.h" - -#include -#include -#include -#include -#include -#include - - -#include "cpp_common/pgr_assert.h" -#include "pickDeliver/order.h" -#include "pickDeliver/vehicle.h" -#include "pickDeliver/pgr_pickDeliver.h" - - - -namespace pgrouting { -namespace vrp { -namespace pickdeliver { - -Order -Vehicle_pickDeliver::get_worse_order( - Identifiers orders) const { - ENTERING(); - invariant(); - pgassert(!empty()); - - // auto orders(of_this_subset); - auto worse_order(m_orders[*orders.begin()]); - auto delta_duration((std::numeric_limits::max)()); - auto curr_duration(duration()); - while (!orders.empty()) { - auto truck(*this); - auto order = m_orders[*orders.begin()]; - pgassert(truck.has_order(order)); - orders -= order.idx(); - truck.erase(order); - auto delta = truck.duration() - curr_duration; - if (delta < delta_duration) { - worse_order = order; - delta_duration = delta; - } - } - EXITING(); - return worse_order; -} - - -Order -Vehicle_pickDeliver::get_first_order() const { - ENTERING(); - invariant(); - pgassert(!empty()); - EXITING(); - return m_orders[m_path[1].idx()]; -} - - -Vehicle_pickDeliver::Vehicle_pickDeliver( - size_t idx, - int64_t kind, - const Vehicle_node &starting_site, - const Vehicle_node &ending_site, - double p_capacity, - double p_speed) : - Vehicle(idx, kind, starting_site, ending_site, p_capacity, p_speed), - cost((std::numeric_limits::max)()) { - ENTERING(); - m_orders_in_vehicle.clear(); - - invariant(); - EXITING(); - } - - - -bool -Vehicle_pickDeliver::has_order(const Order &order) const { - ENTERING(); - return m_orders_in_vehicle.has(order.idx()); -} - - -void -Vehicle_pickDeliver::insert(const Order &order) { - ENTERING(); - invariant(); - pgassert(!has_order(order)); - - auto pick_pos(position_limits(order.pickup())); - auto deliver_pos(position_limits(order.delivery())); -#ifndef NDEBUG - std::ostringstream err_log; - err_log << "\n\tpickup limits (low, high) = (" - << pick_pos.first << ", " - << pick_pos.second << ") " - << "\n\tdeliver limits (low, high) = (" - << deliver_pos.first << ", " - << deliver_pos.second << ") " - << "\noriginal" << tau(); -#endif - - if (pick_pos.second < pick_pos.first) { - /* pickup generates twv evrywhere, - * so put the order as last */ - push_back(order); - EXITING(); - return; - } - - if (deliver_pos.second < deliver_pos.first) { - /* delivery generates twv evrywhere, - * so put the order as last */ - push_back(order); - EXITING(); - return; - } - /* - * Because delivery positions were estimated without - * the pickup: - * - increase the upper limit position estimation - */ - ++deliver_pos.second; - - - auto d_pos_backup(deliver_pos); - auto best_pick_pos = m_path.size(); - auto best_deliver_pos = m_path.size() + 1; - auto current_duration(duration()); - auto min_delta_duration = (std::numeric_limits::max)(); - auto found(false); - pgassertwm(!has_order(order), err_log.str()); - while (pick_pos.first <= pick_pos.second) { -#ifndef NDEBUG - err_log << "\n\tpickup cycle limits (low, high) = (" - << pick_pos.first << ", " - << pick_pos.second << ") "; -#endif - Vehicle::insert(pick_pos.first, order.pickup()); -#ifndef NDEBUG - err_log << "\npickup inserted: " << tau(); -#endif - - while (deliver_pos.first <= deliver_pos.second) { - Vehicle::insert(deliver_pos.first, order.delivery()); - m_orders_in_vehicle += order.idx(); - pgassertwm(has_order(order), err_log.str()); -#ifndef NDEBUG - err_log << "\ndelivery inserted: " << tau(); -#endif - if (is_feasable()) { - pgassert(is_feasable()); - auto delta_duration = duration()-current_duration; - if (delta_duration < min_delta_duration) { -#ifndef NDEBUG - err_log << "\nsuccess" << tau(); -#endif - min_delta_duration = delta_duration; - best_pick_pos = pick_pos.first; - best_deliver_pos = deliver_pos.first; - found = true; - } - } - Vehicle::erase(deliver_pos.first); -#ifndef NDEBUG - err_log << "\ndelivery erased: " << tau(); -#endif - ++deliver_pos.first; - } - Vehicle::erase(pick_pos.first); -#ifndef NDEBUG - err_log << "\npickup erased: " << tau(); -#endif - m_orders_in_vehicle -= order.idx(); - pgassertwm(!has_order(order), err_log.str()); - - deliver_pos = d_pos_backup; -#ifndef NDEBUG - err_log << "\n\trestoring deliver limits (low, high) = (" - << deliver_pos.first << ", " - << deliver_pos.second << ") "; -#endif - ++pick_pos.first; - } - pgassertwm(!has_order(order), err_log.str()); - if (!found) { - /* order causes twv - * so put the order as last */ - push_back(order); - EXITING(); - return; - } - Vehicle::insert(best_pick_pos, order.pickup()); - Vehicle::insert(best_deliver_pos, order.delivery()); - - m_orders_in_vehicle += order.idx(); - pgassertwm(is_feasable(), err_log.str()); - pgassertwm(has_order(order), err_log.str()); - pgassertwm(!has_cv(), err_log.str()); - invariant(); - EXITING(); -} - - -void -Vehicle_pickDeliver::push_back(const Order &order) { - ENTERING(); - invariant(); - pgassert(!has_order(order)); - - m_orders_in_vehicle += order.idx(); - m_path.insert(m_path.end() - 1, order.pickup()); - m_path.insert(m_path.end() - 1, order.delivery()); - evaluate(m_path.size() - 3); - - pgassert(has_order(order)); -#if 0 - pgassert(!has_cv()); -#endif - invariant(); - EXITING(); -} - - -void -Vehicle_pickDeliver::push_front(const Order &order) { - ENTERING(); - invariant(); - pgassert(!has_order(order)); - - m_orders_in_vehicle += order.idx(); - m_path.insert(m_path.begin() + 1, order.delivery()); - m_path.insert(m_path.begin() + 1, order.pickup()); - evaluate(1); - - pgassert(has_order(order)); -#if 0 - pgassert(!has_cv()); -#endif - invariant(); - EXITING(); -} - - -void -Vehicle_pickDeliver::do_while_feasable( - int kind, - Identifiers &unassigned, - Identifiers &assigned) { - ENTERING(); - pgassert(is_feasable()); - auto current_feasable = m_feasable_orders * unassigned; - - while (!current_feasable.empty()) { - auto order = m_orders[current_feasable.front()]; - - switch (kind) { - case 1: - push_back(order); - pgassert(is_feasable()); - assigned += order.idx(); - unassigned -= order.idx(); - invariant(); - return; - break; - case 2: - push_back(order); - break; - case 3: - push_front(order); - break; - case 4: - insert(order); - break; - case 5: - order = m_orders[m_orders.find_best_J(current_feasable)]; - insert(order); - break; - case 6: - order = m_orders[m_orders.find_best_I(current_feasable)]; - insert(order); - break; - default: pgassert(false); - } - if (orders_size() == 1 && !is_feasable()) { - pgassert(false); - } - - if (!is_feasable()) { - erase(order); - } else { - assigned += order.idx(); - unassigned -= order.idx(); - if (kind == 5) { - current_feasable = m_orders[order.idx()].subsetJ( - current_feasable); - } - if (kind == 6) { - current_feasable = m_orders[order.idx()].subsetI( - current_feasable); - } - } - - current_feasable -= order.idx(); - invariant(); - } - - pgassert(is_feasable()); - invariant(); - EXITING(); -} - - -void -Vehicle_pickDeliver::erase(const Order &order) { - ENTERING(); - invariant(); - pgassert(has_order(order)); - - - Vehicle::erase(order.pickup()); - Vehicle::erase(order.delivery()); - m_orders_in_vehicle -= order.idx(); - - invariant(); - pgassert(!has_order(order)); -} - - - -size_t -Vehicle_pickDeliver::pop_back() { - ENTERING(); - invariant(); - pgassert(!empty()); - - auto pick_itr = m_path.rbegin(); - while (pick_itr != m_path.rend() && !pick_itr->is_pickup()) { - ++pick_itr; - } - - pgassert(pick_itr->is_pickup()); - - size_t deleted_pick_idx = pick_itr->idx(); - - for (const auto o : m_orders) { - if (o.pickup().idx() == deleted_pick_idx) { - erase(o); - invariant(); - EXITING(); - return o.idx(); - } - } - pgassert(false); - EXITING(); - return 0; -} - - - -size_t -Vehicle_pickDeliver::pop_front() { - ENTERING(); - invariant(); - pgassert(!empty()); - - auto pick_itr = m_path.begin(); - while (pick_itr != m_path.end() && !pick_itr->is_pickup()) { - ++pick_itr; - } - - pgassert(pick_itr->is_pickup()); - - size_t deleted_pick_idx = pick_itr->idx(); - - for (const auto o : m_orders) { - if (o.pickup().idx() == deleted_pick_idx) { - erase(o); - invariant(); - return o.idx(); - } - } - - pgassert(false); - return 0; -} - -void -Vehicle_pickDeliver::set_compatibles(const PD_Orders &orders) { - ENTERING(); - m_orders = orders; - for (const auto o : orders) { - if (is_order_feasable(o)) m_feasable_orders += o.idx(); - } - m_orders.set_compatibles(m_speed); - EXITING(); -} - -bool -Vehicle_pickDeliver::is_order_feasable(const Order &order) const { - ENTERING(); - auto test_truck = *this; - test_truck.push_back(order); - msg.log << test_truck; - pgassertwm(false, msg.log.str().c_str()); - EXITING(); - return test_truck.is_feasable(); -} - -std::ostream& operator << (std::ostream &log, const Vehicle_pickDeliver &v) { - log << static_cast(v); - log << "feasable_orders " << v.m_feasable_orders; - return log; -} - - -} // namespace pickdeliver -} // namespace vrp -} // namespace pgrouting - - diff --git a/src/pickDeliver/test/test.conf b/src/pickDeliver/test/test.conf index bc498b2c21d..bd0402afe4b 100644 --- a/src/pickDeliver/test/test.conf +++ b/src/pickDeliver/test/test.conf @@ -16,7 +16,7 @@ differentVechiles-cygwin )], 'linux' => [qw( - doc-pickDeliverEuclidean + doc-pickDeliver )], 'documentation' => [qw( doc-pickDeliverEuclidean @@ -24,7 +24,6 @@ #put here the ones that you are not testing (just a place holder) 'nottesting' => [qw( - doc-pickDeliver doc-pickDeliverEuclidean doc-pickDeliverEuclidean From 7217eaa894495cb988981992f37ad0ca6bbdfe4c Mon Sep 17 00:00:00 2001 From: cvvergara Date: Mon, 15 May 2017 18:05:43 -0500 Subject: [PATCH 20/40] moving files around --- src/pickDeliver/src/CMakeLists.txt | 30 +++++++++++-------- .../src/base_node.cpp | 0 .../src/book_keeping.cpp | 0 .../src/fleet.cpp | 0 .../src/initial_solution.cpp | 0 .../src/node.cpp | 0 .../src/optimize.cpp | 0 .../src/order.cpp | 0 .../src/pd_orders.cpp | 0 .../src/pd_problem.cpp | 0 .../src/pgr_messages.cpp | 0 .../src/pgr_pickDeliver.cpp | 0 .../src/pickDeliverEuclidean.c | 0 .../src/pickDeliverEuclidean_driver.cpp | 0 .../src/solution.cpp | 0 .../src/tw_node.cpp | 0 .../src/vehicle.cpp | 0 .../src/vehicle_node.cpp | 0 .../src/vehicle_pickDeliver.cpp | 0 src/pickDeliverE/src/CMakeLists.txt | 22 -------------- 20 files changed, 17 insertions(+), 35 deletions(-) rename src/{pickDeliverE => pickDeliver}/src/base_node.cpp (100%) rename src/{pickDeliverE => pickDeliver}/src/book_keeping.cpp (100%) rename src/{pickDeliverE => pickDeliver}/src/fleet.cpp (100%) rename src/{pickDeliverE => pickDeliver}/src/initial_solution.cpp (100%) rename src/{pickDeliverE => pickDeliver}/src/node.cpp (100%) rename src/{pickDeliverE => pickDeliver}/src/optimize.cpp (100%) rename src/{pickDeliverE => pickDeliver}/src/order.cpp (100%) rename src/{pickDeliverE => pickDeliver}/src/pd_orders.cpp (100%) rename src/{pickDeliverE => pickDeliver}/src/pd_problem.cpp (100%) rename src/{pickDeliverE => pickDeliver}/src/pgr_messages.cpp (100%) rename src/{pickDeliverE => pickDeliver}/src/pgr_pickDeliver.cpp (100%) rename src/{pickDeliverE => pickDeliver}/src/pickDeliverEuclidean.c (100%) rename src/{pickDeliverE => pickDeliver}/src/pickDeliverEuclidean_driver.cpp (100%) rename src/{pickDeliverE => pickDeliver}/src/solution.cpp (100%) rename src/{pickDeliverE => pickDeliver}/src/tw_node.cpp (100%) rename src/{pickDeliverE => pickDeliver}/src/vehicle.cpp (100%) rename src/{pickDeliverE => pickDeliver}/src/vehicle_node.cpp (100%) rename src/{pickDeliverE => pickDeliver}/src/vehicle_pickDeliver.cpp (100%) diff --git a/src/pickDeliver/src/CMakeLists.txt b/src/pickDeliver/src/CMakeLists.txt index 2b94826ebf1..32eda0f06ec 100644 --- a/src/pickDeliver/src/CMakeLists.txt +++ b/src/pickDeliver/src/CMakeLists.txt @@ -1,24 +1,28 @@ ADD_LIBRARY(pickDeliver OBJECT + base_node.cpp dnode.cpp - #tw_node.cpp - #vehicle_node.cpp + node.cpp + tw_node.cpp + vehicle_node.cpp - #order.cpp - #pd_orders.cpp - #fleet.cpp - #vehicle.cpp - #pd_problem.cpp - #vehicle_pickDeliver.cpp - #book_keeping.cpp + order.cpp + pd_orders.cpp + fleet.cpp + vehicle.cpp + pd_problem.cpp + vehicle_pickDeliver.cpp + book_keeping.cpp - #solution.cpp - #initial_solution.cpp - #optimize.cpp + solution.cpp + initial_solution.cpp + optimize.cpp - #pgr_pickDeliver.cpp + pgr_pickDeliver.cpp + pickDeliverEuclidean_driver.cpp pickDeliver_driver.cpp + pickDeliverEuclidean.c pickDeliver.c ) diff --git a/src/pickDeliverE/src/base_node.cpp b/src/pickDeliver/src/base_node.cpp similarity index 100% rename from src/pickDeliverE/src/base_node.cpp rename to src/pickDeliver/src/base_node.cpp diff --git a/src/pickDeliverE/src/book_keeping.cpp b/src/pickDeliver/src/book_keeping.cpp similarity index 100% rename from src/pickDeliverE/src/book_keeping.cpp rename to src/pickDeliver/src/book_keeping.cpp diff --git a/src/pickDeliverE/src/fleet.cpp b/src/pickDeliver/src/fleet.cpp similarity index 100% rename from src/pickDeliverE/src/fleet.cpp rename to src/pickDeliver/src/fleet.cpp diff --git a/src/pickDeliverE/src/initial_solution.cpp b/src/pickDeliver/src/initial_solution.cpp similarity index 100% rename from src/pickDeliverE/src/initial_solution.cpp rename to src/pickDeliver/src/initial_solution.cpp diff --git a/src/pickDeliverE/src/node.cpp b/src/pickDeliver/src/node.cpp similarity index 100% rename from src/pickDeliverE/src/node.cpp rename to src/pickDeliver/src/node.cpp diff --git a/src/pickDeliverE/src/optimize.cpp b/src/pickDeliver/src/optimize.cpp similarity index 100% rename from src/pickDeliverE/src/optimize.cpp rename to src/pickDeliver/src/optimize.cpp diff --git a/src/pickDeliverE/src/order.cpp b/src/pickDeliver/src/order.cpp similarity index 100% rename from src/pickDeliverE/src/order.cpp rename to src/pickDeliver/src/order.cpp diff --git a/src/pickDeliverE/src/pd_orders.cpp b/src/pickDeliver/src/pd_orders.cpp similarity index 100% rename from src/pickDeliverE/src/pd_orders.cpp rename to src/pickDeliver/src/pd_orders.cpp diff --git a/src/pickDeliverE/src/pd_problem.cpp b/src/pickDeliver/src/pd_problem.cpp similarity index 100% rename from src/pickDeliverE/src/pd_problem.cpp rename to src/pickDeliver/src/pd_problem.cpp diff --git a/src/pickDeliverE/src/pgr_messages.cpp b/src/pickDeliver/src/pgr_messages.cpp similarity index 100% rename from src/pickDeliverE/src/pgr_messages.cpp rename to src/pickDeliver/src/pgr_messages.cpp diff --git a/src/pickDeliverE/src/pgr_pickDeliver.cpp b/src/pickDeliver/src/pgr_pickDeliver.cpp similarity index 100% rename from src/pickDeliverE/src/pgr_pickDeliver.cpp rename to src/pickDeliver/src/pgr_pickDeliver.cpp diff --git a/src/pickDeliverE/src/pickDeliverEuclidean.c b/src/pickDeliver/src/pickDeliverEuclidean.c similarity index 100% rename from src/pickDeliverE/src/pickDeliverEuclidean.c rename to src/pickDeliver/src/pickDeliverEuclidean.c diff --git a/src/pickDeliverE/src/pickDeliverEuclidean_driver.cpp b/src/pickDeliver/src/pickDeliverEuclidean_driver.cpp similarity index 100% rename from src/pickDeliverE/src/pickDeliverEuclidean_driver.cpp rename to src/pickDeliver/src/pickDeliverEuclidean_driver.cpp diff --git a/src/pickDeliverE/src/solution.cpp b/src/pickDeliver/src/solution.cpp similarity index 100% rename from src/pickDeliverE/src/solution.cpp rename to src/pickDeliver/src/solution.cpp diff --git a/src/pickDeliverE/src/tw_node.cpp b/src/pickDeliver/src/tw_node.cpp similarity index 100% rename from src/pickDeliverE/src/tw_node.cpp rename to src/pickDeliver/src/tw_node.cpp diff --git a/src/pickDeliverE/src/vehicle.cpp b/src/pickDeliver/src/vehicle.cpp similarity index 100% rename from src/pickDeliverE/src/vehicle.cpp rename to src/pickDeliver/src/vehicle.cpp diff --git a/src/pickDeliverE/src/vehicle_node.cpp b/src/pickDeliver/src/vehicle_node.cpp similarity index 100% rename from src/pickDeliverE/src/vehicle_node.cpp rename to src/pickDeliver/src/vehicle_node.cpp diff --git a/src/pickDeliverE/src/vehicle_pickDeliver.cpp b/src/pickDeliver/src/vehicle_pickDeliver.cpp similarity index 100% rename from src/pickDeliverE/src/vehicle_pickDeliver.cpp rename to src/pickDeliver/src/vehicle_pickDeliver.cpp diff --git a/src/pickDeliverE/src/CMakeLists.txt b/src/pickDeliverE/src/CMakeLists.txt index 3b6c90c83b9..3678739f7c4 100644 --- a/src/pickDeliverE/src/CMakeLists.txt +++ b/src/pickDeliverE/src/CMakeLists.txt @@ -1,25 +1,3 @@ ADD_LIBRARY(pickDeliverE OBJECT - base_node.cpp - node.cpp - tw_node.cpp - vehicle_node.cpp - pgr_messages.cpp - - order.cpp - pd_orders.cpp - fleet.cpp - vehicle.cpp - pd_problem.cpp - vehicle_pickDeliver.cpp - book_keeping.cpp - - solution.cpp - initial_solution.cpp - optimize.cpp - - pgr_pickDeliver.cpp - - pickDeliverEuclidean_driver.cpp - pickDeliverEuclidean.c ) From 65c16dd27e3f6a894be98ef2f9c004fffc365c00 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Mon, 15 May 2017 18:21:50 -0500 Subject: [PATCH 21/40] more on moving files around --- CMakeLists.txt | 1 - sql/pickDeliver/CMakeLists.txt | 2 ++ .../pickDeliverEuclidean.sql | 0 sql/{pickDeliverE => pickDeliver}/reginabook.sql | 0 sql/pickDeliverE/CMakeLists.txt | 12 ------------ src/pickDeliver/src/CMakeLists.txt | 1 + src/pickDeliverE/src/CMakeLists.txt | 3 --- 7 files changed, 3 insertions(+), 16 deletions(-) rename sql/{pickDeliverE => pickDeliver}/pickDeliverEuclidean.sql (100%) rename sql/{pickDeliverE => pickDeliver}/reginabook.sql (100%) delete mode 100644 sql/pickDeliverE/CMakeLists.txt delete mode 100644 src/pickDeliverE/src/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 874913c05e0..9c89afd8538 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,7 +105,6 @@ set(PgRouting_SOURCE_NAMES "max_flow" # 2.3 "contraction" # 2.3 "pickDeliver" # 2.3 - "pickDeliverE" # 2.5 "vrp_basic" # 2.0 "withPoints" # 2.2 diff --git a/sql/pickDeliver/CMakeLists.txt b/sql/pickDeliver/CMakeLists.txt index c451f32fc35..09fe9ec716e 100644 --- a/sql/pickDeliver/CMakeLists.txt +++ b/sql/pickDeliver/CMakeLists.txt @@ -1,6 +1,8 @@ SET(LOCAL_FILES pickDeliver.sql + pickDeliverEuclidean.sql + reginabook.sql ) foreach (f ${LOCAL_FILES}) diff --git a/sql/pickDeliverE/pickDeliverEuclidean.sql b/sql/pickDeliver/pickDeliverEuclidean.sql similarity index 100% rename from sql/pickDeliverE/pickDeliverEuclidean.sql rename to sql/pickDeliver/pickDeliverEuclidean.sql diff --git a/sql/pickDeliverE/reginabook.sql b/sql/pickDeliver/reginabook.sql similarity index 100% rename from sql/pickDeliverE/reginabook.sql rename to sql/pickDeliver/reginabook.sql diff --git a/sql/pickDeliverE/CMakeLists.txt b/sql/pickDeliverE/CMakeLists.txt deleted file mode 100644 index 2272b25c409..00000000000 --- a/sql/pickDeliverE/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ - -SET(LOCAL_FILES - pickDeliverEuclidean.sql - reginabook.sql - ) - -foreach (f ${LOCAL_FILES}) - configure_file(${f} ${f}) - list(APPEND PACKAGE_SQL_FILES ${CMAKE_CURRENT_BINARY_DIR}/${f}) -endforeach() - -set(PgRouting_SQL_FILES ${PgRouting_SQL_FILES} ${PACKAGE_SQL_FILES} PARENT_SCOPE) diff --git a/src/pickDeliver/src/CMakeLists.txt b/src/pickDeliver/src/CMakeLists.txt index 32eda0f06ec..4187ef2efad 100644 --- a/src/pickDeliver/src/CMakeLists.txt +++ b/src/pickDeliver/src/CMakeLists.txt @@ -17,6 +17,7 @@ ADD_LIBRARY(pickDeliver OBJECT initial_solution.cpp optimize.cpp + pgr_messages.cpp pgr_pickDeliver.cpp diff --git a/src/pickDeliverE/src/CMakeLists.txt b/src/pickDeliverE/src/CMakeLists.txt deleted file mode 100644 index 3678739f7c4..00000000000 --- a/src/pickDeliverE/src/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -ADD_LIBRARY(pickDeliverE OBJECT - - ) From 5213ef15b5af5f72c3520bd45116728a2d46db84 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Tue, 16 May 2017 09:42:44 -0500 Subject: [PATCH 22/40] cleaned basse_node and dnode --- include/pickDeliver/dnode.h | 26 +++++---------- include/vrp/base_node.h | 32 ++---------------- src/pickDeliver/src/base_node.cpp | 2 +- src/pickDeliver/src/dnode.cpp | 55 +------------------------------ 4 files changed, 14 insertions(+), 101 deletions(-) diff --git a/include/pickDeliver/dnode.h b/include/pickDeliver/dnode.h index db371433a36..208cf627686 100644 --- a/include/pickDeliver/dnode.h +++ b/include/pickDeliver/dnode.h @@ -30,7 +30,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #pragma once #include -#include +#include #include "vrp/base_node.h" #include "vrp/pd_problem.h" @@ -38,32 +38,24 @@ namespace pgrouting { namespace vrp { /*! @class Dnode - * @brief The Dnode class defines a the operations when its a matrix. + * @brief The Dnode class defines a the basic operations when data is a matrix. * + * currently needs the PD_problem */ - class Dnode : public Base_node, public PD_problem { public: + /*! @name constructors + * @{ + */ Dnode() = default; + /*! @brief data constructor */ Dnode(size_t id, int64_t original_id, double, double); + /*!@}*/ - using Base_node::isSamePos; using Base_node::operator==; - /*! @name to be or not to be - @{ - bool isSamePos(const Dnode &other) const; - bool operator==(const Dnode &rhs) const; - @}*/ - -#if 0 - double distance(const Dnode &other) const; -#endif - double distance(const Base_node *) const; -#if 0 - double comparable_distance(const Dnode &other) const; -#endif + double distance(const Base_node *) const; friend std::ostream& operator << (std::ostream &log, const Dnode &node); }; diff --git a/include/vrp/base_node.h b/include/vrp/base_node.h index 94a39085d6e..b64a4d0a760 100644 --- a/include/vrp/base_node.h +++ b/include/vrp/base_node.h @@ -29,11 +29,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_PICKDELIVER_BASE_NODE_H_ #pragma once -#include -#include -#include +#include #include "cpp_common/identifier.h" -#include "vrp/pd_problem.h" #if defined(__MINGW32__) || defined(_MSC_VER) #include @@ -49,27 +46,14 @@ namespace vrp { */ class Base_node : public Identifier { public: - /*! @name accessors - @{ - */ - -#if 0 - /*! @brief Returns the idx */ - size_t idx() const; - - /*! @brief Returns the original id */ - int64_t id() const; -#endif - ///@} Base_node() = default; Base_node(size_t, int64_t); /** @name to be or not to be */ - ///@ { + /*!@{*/ - virtual bool isSamePos(const Base_node &other) const; virtual bool operator ==(const Base_node &rhs) const; /*!@}*/ @@ -81,22 +65,12 @@ class Base_node : public Identifier { /*! @name distance @{ */ -#if 1 virtual double distance(const Base_node *node) const = 0; -#endif -#if 0 - virtual double comparable_distance(const Base_node &other) const; -#endif /*!@}*/ + private: virtual void print(std::ostream& os) const; - - protected: -#if 0 - size_t m_idx; ///< internal node number - int64_t m_id; ///< user supplied node number -#endif }; } // namespace vrp diff --git a/src/pickDeliver/src/base_node.cpp b/src/pickDeliver/src/base_node.cpp index 8c5f1f8254a..c422c4cf2a7 100644 --- a/src/pickDeliver/src/base_node.cpp +++ b/src/pickDeliver/src/base_node.cpp @@ -29,12 +29,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. namespace pgrouting { namespace vrp { +#if 0 bool Base_node::isSamePos(const Base_node &rhs) const { return id() == rhs.id(); } -#if 0 int64_t Base_node::id() const { return m_id; diff --git a/src/pickDeliver/src/dnode.cpp b/src/pickDeliver/src/dnode.cpp index 9a873884687..38ad41ff79c 100644 --- a/src/pickDeliver/src/dnode.cpp +++ b/src/pickDeliver/src/dnode.cpp @@ -24,17 +24,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ #include "pickDeliver/dnode.h" + #include "vrp/pgr_pickDeliver.h" -#include "cpp_common/pgr_messages.h" namespace pgrouting { namespace vrp { -#if 0 -bool Dnode::isSamePos(const Dnode &other) const { - return comparable_distance(other) == 0; -} -#endif std::ostream& operator << (std::ostream &log, const Dnode &node) { log << node.id() @@ -42,67 +37,19 @@ std::ostream& operator << (std::ostream &log, const Dnode &node) { return log; } -#if 0 -double -Dnode::distance(const Dnode &other) const { - ENTERING(); - msg.log << "idx" << idx() - << "\t id " << id() - << "\t matrix.get_id " << problem->m_cost_matrix.get_id(id()) - << "\t matrix.get_index " << problem->m_cost_matrix.get_index(id()) - << "\t matrix.get_index " << problem->m_cost_matrix.get_id(problem->m_cost_matrix.get_index(id())) - << "\n"; - - msg.log << "other idx" << other.idx() - << "\t id " << other.id() - << "\t matrix.get_id " << problem->m_cost_matrix.get_id(other.id()) - << "\t matrix.get_index " << problem->m_cost_matrix.get_index(other.id()) - << "\t matrix.get_index " << problem->m_cost_matrix.get_id(problem->m_cost_matrix.get_index(other.id())) - << "\n"; - - msg.log << "Distance " << problem->m_cost_matrix.distance( - problem->m_cost_matrix.get_index(id()), - problem->m_cost_matrix.get_index(other.id())) - << "\n\n"; - EXITING(); - return problem->m_cost_matrix.distance( - problem->m_cost_matrix.get_index(id()), - problem->m_cost_matrix.get_index(other.id())); -} -#endif double Dnode::distance(const Base_node *other) const { - ENTERING(); - EXITING(); return problem->m_cost_matrix.distance( problem->m_cost_matrix.get_index(id()), problem->m_cost_matrix.get_index(other->id())); } -#if 0 -double -Dnode::comparable_distance(const Dnode &other) const { - distance(other); - return problem->m_cost_matrix.comparable_distance(0,0); -} -#endif Dnode::Dnode(size_t id, int64_t original_id, double, double) : Base_node(id, original_id) { } -#if 0 -bool -Dnode::operator ==(const Dnode &rhs) const { - if (&rhs == this) return true; - return - (id() == rhs.id()) - && (id() == rhs.id()) - && (m_point == rhs.m_point); -} -#endif - } // namespace vrp } // namespace pgrouting From 9297b9948f172ff66dd11b5099a1e431d49499f4 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Tue, 16 May 2017 10:00:55 -0500 Subject: [PATCH 23/40] cleaned Node --- include/vrp/node.h | 29 ++++++---------- src/pickDeliver/src/fleet.cpp | 4 +-- src/pickDeliver/src/node.cpp | 57 ++++++------------------------- src/pickDeliver/src/pd_orders.cpp | 4 +-- src/pickDeliver/src/tw_node.cpp | 13 ++----- 5 files changed, 28 insertions(+), 79 deletions(-) diff --git a/include/vrp/node.h b/include/vrp/node.h index 516510b8010..5132964a081 100644 --- a/include/vrp/node.h +++ b/include/vrp/node.h @@ -30,14 +30,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #pragma once #include -#include +#include #include "vrp/base_node.h" #include "cpp_common/xy_vertex.h" #include "vrp/pd_problem.h" namespace pgrouting { namespace vrp { -namespace pickdeliver { /*! @class Node * @brief The Node class defines a point in 2D space with an id. @@ -48,38 +47,30 @@ namespace pickdeliver { * are built upon. * */ -class Node : public Base_node , public PD_problem { +class Node : public Base_node { public: Node() = default; Node(size_t id, int64_t original_id, double _x, double _y); - /** @name state */ - ///@ { - - bool isSamePos(const Node &other) const; - + /** @name to be or not to be */ + /*!@{*/ bool operator ==(const Node &rhs) const; + /*!@}*/ - double distance(const Node &) const; + /** @brief Calculates distance between two Node */ double distance(const Base_node *) const; -#if 0 - double distance(const Base_node &) const; - double comparable_distance(const Node &other) const; -#endif friend std::ostream& operator << (std::ostream &log, const Node &node); + + private: + double distance(const Node &) const; void print(std::ostream& os) const; - protected: + private: pgrouting::Point m_point; -#if 0 - size_t m_id; ///< internal node number - int64_t m_original_id; ///< user supplied node number -#endif }; -} // namespace pickdeliver } // namespace vrp } // namespace pgrouting diff --git a/src/pickDeliver/src/fleet.cpp b/src/pickDeliver/src/fleet.cpp index 71cc7ae2693..bffd2ea45de 100644 --- a/src/pickDeliver/src/fleet.cpp +++ b/src/pickDeliver/src/fleet.cpp @@ -214,11 +214,11 @@ Fleet::build_fleet( /* * Euclidean version */ - auto b_start = create_b_start(vehicle, problem->node_id()); + auto b_start = create_b_start(vehicle, problem->node_id()); auto starting_site = Vehicle_node( {problem->node_id()++, vehicle, Tw_node::NodeType::kStart}); - auto b_end = create_b_end(vehicle, problem->node_id()); + auto b_end = create_b_end(vehicle, problem->node_id()); auto ending_site = Vehicle_node( {problem->node_id()++, vehicle, Tw_node::NodeType::kEnd}); diff --git a/src/pickDeliver/src/node.cpp b/src/pickDeliver/src/node.cpp index b2262e185fa..d687144b919 100644 --- a/src/pickDeliver/src/node.cpp +++ b/src/pickDeliver/src/node.cpp @@ -29,11 +29,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. namespace pgrouting { namespace vrp { -namespace pickdeliver { - -bool Node::isSamePos(const Node &other) const { - return distance(other) == 0; -} std::ostream& operator << (std::ostream &log, const Node &node) { node.print(log); @@ -42,63 +37,34 @@ std::ostream& operator << (std::ostream &log, const Node &node) { void Node::print(std::ostream& os) const { - os << "USING NODE\n"; os << id() +#ifndef NDEBUG << "(" << idx() << ")" +#endif << " (x,y) = (" << m_point.x() << ", " << m_point.y() << ")"; } double Node::distance(const Node &other) const { - ENTERING(); auto dx = m_point.x() - other.m_point.x(); auto dy = m_point.y() - other.m_point.y(); -#if 0 - msg.log << *this << "\n"; - msg.log << other << "\n"; - msg.log << "dx: " << dx << "\n"; - msg.log << "dy: " << dx << "\n"; - msg.log << "d: " << sqrt(dx * dx + dy * dy) << "\n"; -#endif - EXITING(); return sqrt(dx * dx + dy * dy); } -#if 0 -double -Node::distance(const Base_node &node) const { - if (auto other = dynamic_cast(&node)) { - ENTERING(); - auto dx = m_point.x() - other->m_point.x(); - auto dy = m_point.y() - other->m_point.y(); - msg.log << *this << "\n"; - msg.log << other << "\n"; - msg.log << "dx: " << dx << "\n"; - msg.log << "dy: " << dx << "\n"; - msg.log << "d: " << sqrt(dx * dx + dy * dy) << "\n"; - EXITING(); - return sqrt(dx * dx + dy * dy); - } - return 0; -} -#endif - +/** + * para[in] n bas node to be casted as Node + */ double Node::distance(const Base_node *n) const { - ENTERING(); - EXITING(); return distance(*dynamic_cast(n)); } -#if 0 -double -Node::comparable_distance(const Node &other) const { - auto dx = m_point.x() - other.m_point.x(); - auto dy = m_point.y() - other.m_point.y(); - return dx * dx + dy * dy; -} -#endif - +/** + * @param[in] _idx index to a container + * @param[in] _id original identifier + * @param[in] _x coordinate value + * @param[in] _y coordinate value + */ Node::Node(size_t _idx, int64_t _id, double _x, double _y) : Base_node(_idx, _id), m_point(_x, _y) { @@ -113,6 +79,5 @@ Node::operator ==(const Node &rhs) const { && (m_point == rhs.m_point); } -} // namespace pickdeliver } // namespace vrp } // namespace pgrouting diff --git a/src/pickDeliver/src/pd_orders.cpp b/src/pickDeliver/src/pd_orders.cpp index dd6d7f8a028..39acc386038 100644 --- a/src/pickDeliver/src/pd_orders.cpp +++ b/src/pickDeliver/src/pd_orders.cpp @@ -87,11 +87,11 @@ PD_Orders::build_orders( /* * Euclidean version */ - auto b_pick = create_b_pick(order, problem->node_id()); + auto b_pick = create_b_pick(order, problem->node_id()); Vehicle_node pickup( {problem->node_id()++, order, Tw_node::NodeType::kPickup}); - auto b_drop = create_b_deliver(order, problem->node_id()); + auto b_drop = create_b_deliver(order, problem->node_id()); Vehicle_node delivery( {problem->node_id()++, order, Tw_node::NodeType::kDelivery}); diff --git a/src/pickDeliver/src/tw_node.cpp b/src/pickDeliver/src/tw_node.cpp index 0b00904ba5d..f0d8cafa325 100644 --- a/src/pickDeliver/src/tw_node.cpp +++ b/src/pickDeliver/src/tw_node.cpp @@ -223,9 +223,9 @@ Tw_node::is_end() const { bool Tw_node::operator ==(const Tw_node &other) const { if (&other == this) return true; - auto lhs = static_cast( + auto lhs = static_cast( *problem->m_base_nodes[idx()].get()); - auto rhs = static_cast( + auto rhs = static_cast( *problem->m_base_nodes[other.idx()].get()); return lhs == rhs; } @@ -308,7 +308,7 @@ Tw_node::Tw_node( /*! * \brief Print the contents of a Twnode object. */ std::ostream& operator << (std::ostream &log, const Tw_node &n) { - log << static_cast( + log << static_cast( *n.problem->m_base_nodes[n.idx()].get()) << "[opens = " << n.m_opens << "\tcloses = " << n.m_closes @@ -317,13 +317,6 @@ std::ostream& operator << (std::ostream &log, const Tw_node &n) { << "\ttype = " << n.type_str() << "]" << "\n"; -#if 0 - if (n.is_pickup() || n.is_delivery()) { - log << "->" << n.m_otherid << "\n"; - } else { - log << "\n"; - } -#endif return log; } From 9d3c36d64d26a003cbc5ff2bc418d28fd8d3b35c Mon Sep 17 00:00:00 2001 From: cvvergara Date: Tue, 16 May 2017 10:11:03 -0500 Subject: [PATCH 24/40] linted some files --- include/vrp/base_node.h | 7 +++--- include/vrp/fleet.h | 7 +++--- include/vrp/pd_orders.h | 4 ++-- include/vrp/tw_node.h | 50 ++++++++++------------------------------- include/vrp/vehicle.h | 1 + 5 files changed, 22 insertions(+), 47 deletions(-) diff --git a/include/vrp/base_node.h b/include/vrp/base_node.h index b64a4d0a760..a3053eaadbb 100644 --- a/include/vrp/base_node.h +++ b/include/vrp/base_node.h @@ -25,8 +25,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /*! @file */ -#ifndef INCLUDE_PICKDELIVER_BASE_NODE_H_ -#define INCLUDE_PICKDELIVER_BASE_NODE_H_ +#ifndef INCLUDE_VRP_BASE_NODE_H_ +#define INCLUDE_VRP_BASE_NODE_H_ #pragma once #include @@ -46,7 +46,6 @@ namespace vrp { */ class Base_node : public Identifier { public: - Base_node() = default; Base_node(size_t, int64_t); @@ -76,4 +75,4 @@ class Base_node : public Identifier { } // namespace vrp } // namespace pgrouting -#endif // INCLUDE_PICKDELIVER_BASE_NODE_H_ +#endif // INCLUDE_VRP_BASE_NODE_H_ diff --git a/include/vrp/fleet.h b/include/vrp/fleet.h index 986e63a088e..7624af703da 100644 --- a/include/vrp/fleet.h +++ b/include/vrp/fleet.h @@ -33,6 +33,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include +#include #include "cpp_common/identifiers.hpp" @@ -120,7 +122,7 @@ class Fleet : public PD_problem { std::unique_ptr, Vehicle_node); - template std::unique_ptr create_b_start ( + template std::unique_ptr create_b_start( const Vehicle_t &vehicle, size_t node_id) { std::unique_ptr b_start(new T( @@ -131,7 +133,7 @@ class Fleet : public PD_problem { return std::move(b_start); } - template std::unique_ptr create_b_end ( + template std::unique_ptr create_b_end( const Vehicle_t &vehicle, size_t node_id) { std::unique_ptr b_end(new T( @@ -141,7 +143,6 @@ class Fleet : public PD_problem { vehicle.end_y)); return std::move(b_end); } - }; diff --git a/include/vrp/pd_orders.h b/include/vrp/pd_orders.h index 5936f3ac7d5..06d21257470 100644 --- a/include/vrp/pd_orders.h +++ b/include/vrp/pd_orders.h @@ -98,7 +98,7 @@ class PD_Orders : public PD_problem { std::unique_ptr, Vehicle_node); - template std::unique_ptr create_b_pick ( + template std::unique_ptr create_b_pick( const PickDeliveryOrders_t &order, size_t node_id) { std::unique_ptr b_pick(new T( @@ -109,7 +109,7 @@ class PD_Orders : public PD_problem { return std::move(b_pick); } - template std::unique_ptr create_b_deliver ( + template std::unique_ptr create_b_deliver( const PickDeliveryOrders_t &order, size_t node_id) { std::unique_ptr b_drop(new T( diff --git a/include/vrp/tw_node.h b/include/vrp/tw_node.h index 64d98a2702a..efd119a6cdc 100644 --- a/include/vrp/tw_node.h +++ b/include/vrp/tw_node.h @@ -57,35 +57,15 @@ namespace vrp { class Tw_node : public Identifier, public PD_problem { public: typedef enum { - kStart = 0, // /< starting site - kPickup, // /< pickup site - kDelivery, // /< delivery site - kDump, // /< dump site, empties truck - kLoad, // /< load site, fills the truck + kStart = 0, ///< starting site + kPickup, ///< pickup site + kDelivery, ///< delivery site + kDump, ///< dump site, empties truck + kLoad, ///< load site, fills the truck kEnd ///< ending site } NodeType; -#if 0 - inline void set_Pid(size_t id) { - m_otherid = id; - } - - inline void set_Did(size_t id) { - m_otherid = id; - } - - inline size_t Did() const { - pgassert(is_pickup()); - return m_otherid; - } - - inline size_t Pid() const { - pgassert(is_delivery()); - return m_otherid; - } -#endif - /** @name accessors */ ///@ { @@ -102,18 +82,15 @@ class Tw_node : public Identifier, public PD_problem { inline double demand() const {return m_demand;} /*! * @brief Returns the service time for this node. */ - inline double service_time() const { return m_service_time;} + inline double service_time() const {return m_service_time;} /*! * @brief Returns the type of this node. */ - inline NodeType type() const { return m_type;} + inline NodeType type() const {return m_type;} /*! @brief Returns the length of time between the opening and closing. */ inline double window_length() const {return m_closes - m_opens;} /*! @brief time = distance / speed. */ -#if 0 - double travel_time_to(const pickdeliver::Node &other, double speed) const; -#endif double travel_time_to(const Tw_node &other, double speed) const; ///@} @@ -192,13 +169,15 @@ class Tw_node : public Identifier, public PD_problem { std::string type_str() const; - ///@} - + /*!@}*/ /*! * @brief Print the contents of a Twnode object. */ friend std::ostream& operator<< (std::ostream &log, const Tw_node &node); + /*! @name to be or not to be + * @{ + */ bool operator ==(const Tw_node &rhs) const; @@ -217,9 +196,7 @@ class Tw_node : public Identifier, public PD_problem { return !is_early_arrival(arrival_time) && !is_late_arrival(arrival_time); } - - - + /*!@}*/ /** @name document functions */ @@ -296,9 +273,6 @@ class Tw_node : public Identifier, public PD_problem { double m_closes; ///< closing time of the node double m_service_time; // /< time it takes to be served double m_demand; ///< The demand for the Node -#if 0 - size_t m_otherid; ///< the other's internal id -#endif NodeType m_type; ///< The demand for the Node }; diff --git a/include/vrp/vehicle.h b/include/vrp/vehicle.h index 37ee43c9079..e9daf52572c 100644 --- a/include/vrp/vehicle.h +++ b/include/vrp/vehicle.h @@ -73,6 +73,7 @@ class Vehicle : public Identifier, public PD_problem { protected: typedef size_t POS; std::deque< Vehicle_node > m_path; + private: double m_capacity; double m_factor; From 43124687bed7cee64f8b60a920555161c26377a5 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Tue, 16 May 2017 10:24:34 -0500 Subject: [PATCH 25/40] cleaned Vehicle_node --- include/vrp/tw_node.h | 2 ++ include/vrp/vehicle_node.h | 4 +--- src/pickDeliver/src/vehicle_node.cpp | 11 ++--------- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/include/vrp/tw_node.h b/include/vrp/tw_node.h index efd119a6cdc..21ca82b2272 100644 --- a/include/vrp/tw_node.h +++ b/include/vrp/tw_node.h @@ -80,6 +80,7 @@ class Tw_node : public Identifier, public PD_problem { /*! @brief Returns the demand associated with this node. */ inline double demand() const {return m_demand;} + inline void demand(double value) {m_demand = value;} /*! * @brief Returns the service time for this node. */ inline double service_time() const {return m_service_time;} @@ -268,6 +269,7 @@ class Tw_node : public Identifier, public PD_problem { protected: bool is_valid() const; + private: int64_t m_order; ///< order to which it belongs double m_opens; ///< opening time of the node double m_closes; ///< closing time of the node diff --git a/include/vrp/vehicle_node.h b/include/vrp/vehicle_node.h index ae06ac60c5c..44e7bc350b6 100644 --- a/include/vrp/vehicle_node.h +++ b/include/vrp/vehicle_node.h @@ -45,8 +45,6 @@ namespace vrp { * about the node in a path and provides the tools evaluate the node * and to set and get these attribute values. */ - - class Vehicle_node: public Tw_node { public: /** @name log */ @@ -161,7 +159,7 @@ class Vehicle_node: public Tw_node { Vehicle_node(const Vehicle_node &) = default; explicit Vehicle_node(const Tw_node &node); - protected: + private: /** @name Node evaluation members */ ///@ { diff --git a/src/pickDeliver/src/vehicle_node.cpp b/src/pickDeliver/src/vehicle_node.cpp index 7db68b9865b..0b9422faaa5 100644 --- a/src/pickDeliver/src/vehicle_node.cpp +++ b/src/pickDeliver/src/vehicle_node.cpp @@ -25,8 +25,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "vrp/vehicle_node.h" -#include "vrp/pd_problem.h" -#include "vrp/pgr_pickDeliver.h" namespace pgrouting { @@ -38,7 +36,6 @@ namespace vrp { */ void Vehicle_node::evaluate(double cargoLimit) { - /*! @todo TODO evaluate with matrix also*/ if (is_start()) { /* time */ m_travel_time = 0; @@ -72,9 +69,7 @@ Vehicle_node::evaluate( const Vehicle_node &pred, double cargoLimit, double speed) { - /*! @todo TODO evaluate with matrix also*/ /* time */ - m_travel_time = pred.travel_time_to(*this, speed); m_arrival_time = pred.departure_time() + travel_time(); m_wait_time = is_early_arrival(arrival_time()) ? @@ -89,11 +84,11 @@ Vehicle_node::evaluate( /* cargo aggregates */ if (is_dump() && pred.cargo() >= 0) { - m_demand = -pred.cargo(); + demand(-pred.cargo()); } m_cargo = pred.cargo() + demand(); - /* cargo aggregates */ + /* violations aggregates */ m_twvTot = has_twv() ? pred.twvTot() + 1 : pred.twvTot(); m_cvTot = has_cv(cargoLimit) ? pred.cvTot() + 1 : pred.cvTot(); @@ -143,7 +138,6 @@ Vehicle_node::Vehicle_node(const Tw_node &node) bool Vehicle_node::deltaGeneratesTWV(double delta_time) const { - /*! @todo TODO evaluate with matrix also*/ return is_late_arrival(m_arrival_time + delta_time); } @@ -157,7 +151,6 @@ double Vehicle_node::arrival_i_arrives_j( const Vehicle_node &other, double speed) const { - /*! @todo TODO evaluate with matrix also*/ return other.arrival_time() + other.service_time() + other.travel_time_to(*this, speed); From 1dace3ea80b7110d47e4b3d4778cb9924b54c1b5 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Tue, 16 May 2017 10:49:28 -0500 Subject: [PATCH 26/40] clening pd_orders --- include/vrp/initial_solution.h | 2 +- include/vrp/pd_orders.h | 25 ++++++++++----------- include/vrp/vehicle_pickDeliver.h | 6 ++--- src/pickDeliver/src/pd_orders.cpp | 22 ++++++++---------- src/pickDeliver/src/vehicle_pickDeliver.cpp | 4 ++-- src/pickDeliver/test/test.conf | 2 +- 6 files changed, 28 insertions(+), 33 deletions(-) diff --git a/include/vrp/initial_solution.h b/include/vrp/initial_solution.h index 804eb996535..bcd5f437266 100644 --- a/include/vrp/initial_solution.h +++ b/include/vrp/initial_solution.h @@ -61,7 +61,7 @@ class Initial_solution : public Solution { private: Identifiers all_orders; - Identifiers unassigned; + Identifiers unassigned; Identifiers assigned; }; diff --git a/include/vrp/pd_orders.h b/include/vrp/pd_orders.h index 06d21257470..b2a932adcea 100644 --- a/include/vrp/pd_orders.h +++ b/include/vrp/pd_orders.h @@ -32,8 +32,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include + #include "c_types/pickDeliver/pickDeliveryOrders_t.h" #include "cpp_common/identifiers.hpp" + #include "vrp/base_node.h" #include "vrp/pd_problem.h" @@ -50,11 +52,6 @@ class PD_Orders : public PD_problem { public: typedef Orders::iterator o_iterator; typedef Orders::const_iterator o_const_iterator; - typedef size_t OID; - typedef Identifiers setof_OID; - - protected: - Orders m_orders; public: /*! @name constructors @@ -66,7 +63,6 @@ class PD_Orders : public PD_problem { /*!@}*/ void set_compatibles(double speed); - // TODO(vicky) check if it has to be const size_t find_best_J(Identifiers &within_this_set) const; size_t find_best_I(Identifiers &within_this_set) const; @@ -77,8 +73,8 @@ class PD_Orders : public PD_problem { * functions with same "meaning" as an std container * @{ */ - Order& operator[](OID o); - const Order& operator[](OID o) const; + Order& operator[](size_t o); + const Order& operator[](size_t o) const; size_t size() const {return m_orders.size();} o_iterator begin() {return m_orders.begin();} o_iterator end() {return m_orders.end();} @@ -86,17 +82,16 @@ class PD_Orders : public PD_problem { o_const_iterator end() const {return m_orders.end();} /*!@}*/ - // TODO(vicky) this should be private called by the constructor + private: void build_orders( const std::vector &pd_orders); - private: void add_order( - int64_t, + const PickDeliveryOrders_t &, std::unique_ptr, - Vehicle_node, + const Vehicle_node&, std::unique_ptr, - Vehicle_node); + const Vehicle_node&); template std::unique_ptr create_b_pick( const PickDeliveryOrders_t &order, @@ -119,6 +114,10 @@ class PD_Orders : public PD_problem { order.deliver_y)); return std::move(b_drop); } + + private: + Orders m_orders; + }; } // namespace vrp diff --git a/include/vrp/vehicle_pickDeliver.h b/include/vrp/vehicle_pickDeliver.h index 8cb8b63c5bc..b320f5ba8ed 100644 --- a/include/vrp/vehicle_pickDeliver.h +++ b/include/vrp/vehicle_pickDeliver.h @@ -50,7 +50,7 @@ class Vehicle_pickDeliver : public Vehicle { Identifiers m_orders_in_vehicle; PD_Orders m_orders; //! orders that fit in the truck - Identifiers m_feasable_orders; + Identifiers m_feasable_orders; public: @@ -163,8 +163,8 @@ class Vehicle_pickDeliver : public Vehicle { void do_while_feasable( int kind, - Identifiers &unassigned, - Identifiers &assigned); + Identifiers &unassigned, + Identifiers &assigned); /*! diff --git a/src/pickDeliver/src/pd_orders.cpp b/src/pickDeliver/src/pd_orders.cpp index 39acc386038..dbb52ccf216 100644 --- a/src/pickDeliver/src/pd_orders.cpp +++ b/src/pickDeliver/src/pd_orders.cpp @@ -29,12 +29,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include -#include "vrp/order.h" -#include "vrp/node.h" -#include "pickDeliver/dnode.h" -#include "vrp/tw_node.h" -#include "vrp/vehicle_node.h" #include "vrp/pgr_pickDeliver.h" +#include "pickDeliver/dnode.h" namespace pgrouting { namespace vrp { @@ -49,11 +45,11 @@ PD_Orders::PD_Orders( void PD_Orders:: add_order( - int64_t order_id, + const PickDeliveryOrders_t &order, std::unique_ptr b_pick, - Vehicle_node pick, + const Vehicle_node &pick, std::unique_ptr b_drop, - Vehicle_node drop) { + const Vehicle_node &drop) { problem->add_base_node(std::move(b_pick)); problem->add_base_node(std::move(b_drop)); problem->add_node(pick); @@ -64,7 +60,7 @@ PD_Orders:: add_order( * add into an order */ m_orders.push_back( - Order(m_orders.size(), order_id, + Order(m_orders.size(), order.id, pick, drop)); } @@ -96,7 +92,7 @@ PD_Orders::build_orders( {problem->node_id()++, order, Tw_node::NodeType::kDelivery}); - add_order(order.id, + add_order(order, std::move(b_pick), pickup, std::move(b_drop), delivery); } else { @@ -111,7 +107,7 @@ PD_Orders::build_orders( Vehicle_node delivery( {problem->node_id()++, order, Tw_node::NodeType::kDelivery}); - add_order(order.id, + add_order(order, std::move(b_pick), pickup, std::move(b_drop), delivery); } @@ -135,13 +131,13 @@ PD_Orders::is_valid(double speed) const { } Order& -PD_Orders::operator[](OID i) { +PD_Orders::operator[](size_t i) { pgassert(i < m_orders.size()); return m_orders[i]; } const Order& -PD_Orders::operator[](OID i) const { +PD_Orders::operator[](size_t i) const { pgassert(i < m_orders.size()); return m_orders[i]; } diff --git a/src/pickDeliver/src/vehicle_pickDeliver.cpp b/src/pickDeliver/src/vehicle_pickDeliver.cpp index 8e5c5fc3334..0dc61da15ce 100644 --- a/src/pickDeliver/src/vehicle_pickDeliver.cpp +++ b/src/pickDeliver/src/vehicle_pickDeliver.cpp @@ -257,8 +257,8 @@ Vehicle_pickDeliver::push_front(const Order &order) { void Vehicle_pickDeliver::do_while_feasable( int kind, - Identifiers &unassigned, - Identifiers &assigned) { + Identifiers &unassigned, + Identifiers &assigned) { pgassert(is_feasable()); auto current_feasable = m_feasable_orders * unassigned; diff --git a/src/pickDeliver/test/test.conf b/src/pickDeliver/test/test.conf index bd0402afe4b..9b5de78856f 100644 --- a/src/pickDeliver/test/test.conf +++ b/src/pickDeliver/test/test.conf @@ -16,7 +16,7 @@ differentVechiles-cygwin )], 'linux' => [qw( - doc-pickDeliver + doc-pickDeliverEuclidean )], 'documentation' => [qw( doc-pickDeliverEuclidean From 321aff9ba1bb544c8716aebd11f3f97b82d9e720 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Tue, 16 May 2017 12:32:51 -0500 Subject: [PATCH 27/40] cleaned Order --- include/vrp/order.h | 9 ++++----- include/vrp/vehicle_pickDeliver.h | 2 +- src/pickDeliver/src/order.cpp | 23 ++++------------------- 3 files changed, 9 insertions(+), 25 deletions(-) diff --git a/include/vrp/order.h b/include/vrp/order.h index 79a517c1967..f1961203cd4 100644 --- a/include/vrp/order.h +++ b/include/vrp/order.h @@ -30,17 +30,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #pragma once -#include +#include #include "cpp_common/identifier.h" #include "cpp_common/identifiers.hpp" #include "vrp/vehicle_node.h" -#include "vrp/pd_problem.h" namespace pgrouting { namespace vrp { -class Order : public Identifier, public PD_problem { +class Order : public Identifier { public: /*! @name Constructors * @{ @@ -143,13 +142,13 @@ class Order : public Identifier, public PD_problem { * It hold's the idx of the node */ - size_t pickup_id; + Vehicle_node m_pickup; /*! The delivery node identifier * * It hold's the idx of the node */ - size_t delivery_id; + Vehicle_node m_delivery; /*! Stores all the orders that can be placed after this order * diff --git a/include/vrp/vehicle_pickDeliver.h b/include/vrp/vehicle_pickDeliver.h index b320f5ba8ed..bf8a27701c7 100644 --- a/include/vrp/vehicle_pickDeliver.h +++ b/include/vrp/vehicle_pickDeliver.h @@ -73,7 +73,7 @@ class Vehicle_pickDeliver : public Vehicle { bool is_order_feasable(const Order &order) const; Identifiers feasable_orders() const {return m_feasable_orders;} - PD_Orders orders() const {return m_orders;} + const PD_Orders& orders() const {return m_orders;} size_t orders_size() const {return m_orders_in_vehicle.size();} Identifiers orders_in_vehicle() const {return m_orders_in_vehicle;} diff --git a/src/pickDeliver/src/order.cpp b/src/pickDeliver/src/order.cpp index e5d8a52ce23..cde885da643 100644 --- a/src/pickDeliver/src/order.cpp +++ b/src/pickDeliver/src/order.cpp @@ -26,9 +26,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "vrp/order.h" -#include -#include "cpp_common/pgr_assert.h" -#include "vrp/pgr_pickDeliver.h" namespace pgrouting { namespace vrp { @@ -50,8 +47,8 @@ Order::Order( const Vehicle_node &p_pickup, const Vehicle_node &p_delivery) : Identifier(p_idx, p_id), - pickup_id(p_pickup.idx()), - delivery_id(p_delivery.idx()) { + m_pickup(p_pickup), + m_delivery(p_delivery) { } std::ostream& @@ -59,18 +56,6 @@ operator << (std::ostream &log, const Order &order) { log << "\n\nOrder " << order.idx() << ":\n" << "\tPickup: " << order.pickup() << "\n" << "\tDelivery: " << order.delivery() << "\n\n"; -#if 0 - if (order.delivery().is_partially_compatible_IJ(order.pickup(), speed)) { - log << "\tis_partially_compatible_IJ: "; - } else if (order.delivery().is_tight_compatible_IJ(order.pickup(), speed)) { - log << "\tis_tight_compatible_IJ: "; - } else if (order.delivery().is_waitTime_compatible_IJ( - order.pickup(), speed)) { - log << "\tis_waitTime_compatible_IJ: "; - } else { - pgassert(false); - } -#endif log << "\nThere are | {I}| = " << order.m_compatibleI.size() << " -> order(" << order.idx() @@ -92,13 +77,13 @@ operator << (std::ostream &log, const Order &order) { const Vehicle_node& Order::delivery() const { - return problem->node(delivery_id); + return m_delivery; } const Vehicle_node& Order::pickup() const { - return problem->node(pickup_id); + return m_pickup; } From 632fea6b9329433c1f56fb9dfb6357a2b0c493e2 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Tue, 16 May 2017 12:37:31 -0500 Subject: [PATCH 28/40] linting pd_orders --- include/vrp/fleet.h | 3 ++- include/vrp/pd_orders.h | 1 - src/pickDeliver/src/pd_orders.cpp | 16 ++++++++++------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/include/vrp/fleet.h b/include/vrp/fleet.h index 7624af703da..c741ff221fb 100644 --- a/include/vrp/fleet.h +++ b/include/vrp/fleet.h @@ -29,6 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_VRP_FLEET_H_ #pragma once +#if 0 #include #include #include @@ -40,7 +41,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "vrp/vehicle_pickDeliver.h" #include "vrp/pd_problem.h" - +#endif namespace pgrouting { diff --git a/include/vrp/pd_orders.h b/include/vrp/pd_orders.h index b2a932adcea..2026d2a755b 100644 --- a/include/vrp/pd_orders.h +++ b/include/vrp/pd_orders.h @@ -117,7 +117,6 @@ class PD_Orders : public PD_problem { private: Orders m_orders; - }; } // namespace vrp diff --git a/src/pickDeliver/src/pd_orders.cpp b/src/pickDeliver/src/pd_orders.cpp index dbb52ccf216..bf23d92fb0a 100644 --- a/src/pickDeliver/src/pd_orders.cpp +++ b/src/pickDeliver/src/pd_orders.cpp @@ -46,8 +46,8 @@ PD_Orders::PD_Orders( void PD_Orders:: add_order( const PickDeliveryOrders_t &order, - std::unique_ptr b_pick, - const Vehicle_node &pick, + std::unique_ptr b_pick, + const Vehicle_node &pick, std::unique_ptr b_drop, const Vehicle_node &drop) { problem->add_base_node(std::move(b_pick)); @@ -88,8 +88,10 @@ PD_Orders::build_orders( {problem->node_id()++, order, Tw_node::NodeType::kPickup}); auto b_drop = create_b_deliver(order, problem->node_id()); - Vehicle_node delivery( - {problem->node_id()++, order, Tw_node::NodeType::kDelivery}); + Vehicle_node delivery({ + problem->node_id()++, + order, + Tw_node::NodeType::kDelivery}); add_order(order, @@ -104,8 +106,10 @@ PD_Orders::build_orders( {problem->node_id()++, order, Tw_node::NodeType::kPickup}); auto b_drop = create_b_deliver(order, problem->node_id()); - Vehicle_node delivery( - {problem->node_id()++, order, Tw_node::NodeType::kDelivery}); + Vehicle_node delivery({ + problem->node_id()++, + order, + Tw_node::NodeType::kDelivery}); add_order(order, std::move(b_pick), pickup, From 30897d2de09419eaa7ca5d465d427a5862c3087d Mon Sep 17 00:00:00 2001 From: cvvergara Date: Tue, 16 May 2017 12:59:12 -0500 Subject: [PATCH 29/40] cleaned fleet --- include/vrp/fleet.h | 22 +++++----------------- src/pickDeliver/src/fleet.cpp | 11 +---------- 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/include/vrp/fleet.h b/include/vrp/fleet.h index c741ff221fb..9b934fd4b25 100644 --- a/include/vrp/fleet.h +++ b/include/vrp/fleet.h @@ -29,26 +29,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #define INCLUDE_VRP_FLEET_H_ #pragma once -#if 0 -#include -#include -#include +#include #include #include #include #include "cpp_common/identifiers.hpp" - -#include "vrp/vehicle_pickDeliver.h" #include "vrp/pd_problem.h" -#endif +#include "vrp/vehicle_pickDeliver.h" namespace pgrouting { - - -namespace tsp { -class Dmatrix; -} namespace vrp { class Pgr_pickDeliver; @@ -59,11 +49,6 @@ class Fleet : public PD_problem { typedef std::vector::iterator iterator; std::vector m_trucks; - protected: - Identifiers used; - Identifiers un_used; - - public: /*! @name constructor @@ -107,6 +92,9 @@ class Fleet : public PD_problem { friend std::ostream& operator << (std::ostream &log, const Fleet &v); private: + Identifiers used; + Identifiers un_used; + /*! @brief build the fleet * * @param[in] vehicles of type Vehicle_t diff --git a/src/pickDeliver/src/fleet.cpp b/src/pickDeliver/src/fleet.cpp index bffd2ea45de..e3d94f404f4 100644 --- a/src/pickDeliver/src/fleet.cpp +++ b/src/pickDeliver/src/fleet.cpp @@ -25,20 +25,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "vrp/fleet.h" -#include #include -#include #include #include +#include -#include "vrp/pd_orders.h" #include "pickDeliver/dnode.h" -#include "vrp/tw_node.h" -#include "vrp/vehicle_pickDeliver.h" #include "vrp/pgr_pickDeliver.h" -#include "cpp_common/identifiers.hpp" -#include "cpp_common/Dmatrix.h" - namespace pgrouting { namespace vrp { @@ -123,7 +116,6 @@ Fleet::add_vehicle( Vehicle_node starting_site, std::unique_ptr b_end, Vehicle_node ending_site) { - problem->add_base_node(std::move(b_start)); problem->add_base_node(std::move(b_end)); problem->add_node(starting_site); @@ -151,7 +143,6 @@ Fleet::add_vehicle( msg.log << "inserting vehicle: " << m_trucks.back().idx() << "\n"; pgassert((m_trucks.back().idx() + 1) == m_trucks.size()); } - } /*! From 50f272db00000a394fbad26457422397ba3912c6 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Tue, 16 May 2017 14:02:35 -0500 Subject: [PATCH 30/40] commenting out probable not use code --- include/vrp/pgr_pickDeliver.h | 23 +++++++++-------------- src/pickDeliver/src/pgr_pickDeliver.cpp | 11 ++++++----- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/include/vrp/pgr_pickDeliver.h b/include/vrp/pgr_pickDeliver.h index b7a61bf2f0f..afb8f93c12f 100644 --- a/include/vrp/pgr_pickDeliver.h +++ b/include/vrp/pgr_pickDeliver.h @@ -31,9 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -#include #include -#include #include #include @@ -42,24 +40,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "c_types/pickDeliver/pickDeliveryOrders_t.h" #include "cpp_common/identifiers.hpp" #include "cpp_common/Dmatrix.h" - -#include "vrp/base_node.h" -#include "vrp/vehicle_node.h" #include "vrp/fleet.h" +#include "vrp/pd_orders.h" #include "vrp/solution.h" namespace pgrouting { namespace vrp { class Order; -class PD_orders; +class Vehicle_node; +class Base_node; class Pgr_pickDeliver : public PD_problem { - friend class Initial_solution; - friend class Optimize; - friend class Dnode; - typedef size_t ID; public: Pgr_pickDeliver( @@ -82,9 +75,9 @@ class Pgr_pickDeliver : public PD_problem { std::vector get_postgres_result() const; - const Order order_of(const Vehicle_node &node) const; - const Vehicle_node& node(ID id) const; #if 0 + const Order& order_of(const Vehicle_node &node) const; + const Vehicle_node& node(size_t id) const; const PD_Orders& orders() const {return m_orders;} #endif @@ -94,6 +87,7 @@ class Pgr_pickDeliver : public PD_problem { //! name orders handling (TODO? in a class? /// @{ +#if 0 /*! \brief I -> {J} * * gets the orders {J} that can be visited after visiting order I @@ -101,8 +95,8 @@ class Pgr_pickDeliver : public PD_problem { inline Identifiers compatibleJ(size_t I) const { return m_orders[I].subsetJ(Identifiers()); } - inline Order orders(size_t o) const {return m_orders[o];} +#endif inline size_t& node_id() {return m_node_id;} @@ -118,8 +112,9 @@ class Pgr_pickDeliver : public PD_problem { // TODO(vicky) delete this function bool nodesOK() const; #endif +#if 1 Fleet trucks() const {return m_trucks;} - +#endif /// @{ private: //! used define the initial solution algorithm to be used diff --git a/src/pickDeliver/src/pgr_pickDeliver.cpp b/src/pickDeliver/src/pgr_pickDeliver.cpp index 0261981399c..7d1d51d2cdb 100644 --- a/src/pickDeliver/src/pgr_pickDeliver.cpp +++ b/src/pickDeliver/src/pgr_pickDeliver.cpp @@ -309,11 +309,12 @@ Pgr_pickDeliver::Pgr_pickDeliver( } // constructor -const Order +#if 0 +const Order& Pgr_pickDeliver::order_of(const Vehicle_node &node) const { pgassert(node.is_pickup() || node.is_delivery()); if (node.is_pickup()) { - for (const auto o : m_orders) { + for (const auto &o : m_orders) { if (o.pickup().idx() == node.idx()) { return o; } @@ -321,7 +322,7 @@ Pgr_pickDeliver::order_of(const Vehicle_node &node) const { } pgassert(node.is_delivery()); - for (const auto o : m_orders) { + for (const auto &o : m_orders) { if (o.delivery().idx() == node.idx()) { return o; } @@ -336,14 +337,14 @@ Pgr_pickDeliver::order_of(const Vehicle_node &node) const { const Vehicle_node& -Pgr_pickDeliver::node(ID id) const { +Pgr_pickDeliver::node(size_t id) const { pgassert(id < m_nodes.size()); msg.log << "id = " << id << "m_nodes[id].idx()" << m_nodes[id].idx() << "\n"; pgassertwm(id == m_nodes[id].idx(), msg.get_log().c_str()); return m_nodes[id]; } - +#endif } // namespace vrp } // namespace pgrouting From d765244203a4f5f6b3c4b4a293a40d72b14cbaf4 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Tue, 16 May 2017 14:15:41 -0500 Subject: [PATCH 31/40] removed the commented code --- include/vrp/pgr_pickDeliver.h | 23 +--------- src/pickDeliver/src/pgr_pickDeliver.cpp | 57 +------------------------ 2 files changed, 2 insertions(+), 78 deletions(-) diff --git a/include/vrp/pgr_pickDeliver.h b/include/vrp/pgr_pickDeliver.h index afb8f93c12f..c1418be4c58 100644 --- a/include/vrp/pgr_pickDeliver.h +++ b/include/vrp/pgr_pickDeliver.h @@ -75,29 +75,10 @@ class Pgr_pickDeliver : public PD_problem { std::vector get_postgres_result() const; -#if 0 - const Order& order_of(const Vehicle_node &node) const; - const Vehicle_node& node(size_t id) const; - const PD_Orders& orders() const {return m_orders;} -#endif Solution optimize(const Solution init_solution); size_t max_cycles() const {return m_max_cycles;} - //! name orders handling (TODO? in a class? - /// @{ - -#if 0 - /*! \brief I -> {J} - * - * gets the orders {J} that can be visited after visiting order I - */ - inline Identifiers compatibleJ(size_t I) const { - return m_orders[I].subsetJ(Identifiers()); - } - inline Order orders(size_t o) const {return m_orders[o];} -#endif - inline size_t& node_id() {return m_node_id;} void add_node(const Vehicle_node &node) { @@ -112,10 +93,8 @@ class Pgr_pickDeliver : public PD_problem { // TODO(vicky) delete this function bool nodesOK() const; #endif -#if 1 Fleet trucks() const {return m_trucks;} -#endif - /// @{ + private: //! used define the initial solution algorithm to be used int m_initial_id; diff --git a/src/pickDeliver/src/pgr_pickDeliver.cpp b/src/pickDeliver/src/pgr_pickDeliver.cpp index 7d1d51d2cdb..63ce19289f1 100644 --- a/src/pickDeliver/src/pgr_pickDeliver.cpp +++ b/src/pickDeliver/src/pgr_pickDeliver.cpp @@ -46,30 +46,13 @@ namespace pgrouting { namespace vrp { -#if 1 - // TODO(vicky) delete this function +// TODO(vicky) delete this function bool Pgr_pickDeliver::nodesOK() const { ENTERING(); if (m_nodes.empty() && m_base_nodes.empty()) return true; -#if 0 - msg.log << " m_nodes: " << m_nodes.size(); - for (const auto n : m_nodes) { - msg.log << n.id() << ","; - } - - msg.log << "\n"; - - msg.log << "m_base_nodes: " << m_base_nodes.size(); - for (auto const &n : m_base_nodes) { - msg.log << n->id() << ","; - } -#endif pgassertwm(m_nodes.size() == m_base_nodes.size(), msg.get_log().c_str()); -#if 0 - msg.log << "\n"; -#endif for (size_t i = 0; i < m_nodes.size() ; ++i) { pgassertwm(m_nodes[i].id() == m_base_nodes[i]->id(), msg.get_log().c_str()); @@ -79,7 +62,6 @@ Pgr_pickDeliver::nodesOK() const { EXITING(); return true; } -#endif Solution Pgr_pickDeliver::optimize(const Solution solution) { @@ -309,42 +291,5 @@ Pgr_pickDeliver::Pgr_pickDeliver( } // constructor -#if 0 -const Order& -Pgr_pickDeliver::order_of(const Vehicle_node &node) const { - pgassert(node.is_pickup() || node.is_delivery()); - if (node.is_pickup()) { - for (const auto &o : m_orders) { - if (o.pickup().idx() == node.idx()) { - return o; - } - } - } - pgassert(node.is_delivery()); - - for (const auto &o : m_orders) { - if (o.delivery().idx() == node.idx()) { - return o; - } - } -#ifndef NDEBUG - std::ostringstream err_log; - err_log << "Order of" << node << " not found"; -#endif - pgassertwm(false, err_log.str()); - return m_orders[0]; -} - - -const Vehicle_node& -Pgr_pickDeliver::node(size_t id) const { - pgassert(id < m_nodes.size()); - msg.log << "id = " << id - << "m_nodes[id].idx()" << m_nodes[id].idx() << "\n"; - pgassertwm(id == m_nodes[id].idx(), msg.get_log().c_str()); - return m_nodes[id]; -} -#endif - } // namespace vrp } // namespace pgrouting From 7ba4631837b9ae940d74bd0f17fe17076d11b91e Mon Sep 17 00:00:00 2001 From: cvvergara Date: Tue, 16 May 2017 21:28:24 -0500 Subject: [PATCH 32/40] starting testing matrix version --- include/cpp_common/Dmatrix.h | 3 + include/vrp/vehicle.h | 2 + src/pickDeliver/src/base_node.cpp | 30 -------- src/pickDeliver/src/fleet.cpp | 5 +- src/pickDeliver/src/order.cpp | 8 ++- src/pickDeliver/src/pd_orders.cpp | 8 ++- src/pickDeliver/src/pgr_pickDeliver.cpp | 24 +++++-- src/pickDeliver/src/pickDeliver.c | 24 +++++++ .../src/pickDeliverEuclidean_driver.cpp | 15 ++-- src/pickDeliver/src/pickDeliver_driver.cpp | 41 +++-------- src/pickDeliver/src/tw_node.cpp | 32 --------- src/pickDeliver/src/vehicle_node.cpp | 10 +-- src/pickDeliver/test/doc-pickDeliver.result | 71 +++++++++++++++++++ src/pickDeliver/test/doc-pickDeliver.test.sql | 17 +++++ src/pickDeliver/test/test.conf | 2 +- tools/testers/pickDeliver_pgtap_data.sql | 2 +- 16 files changed, 175 insertions(+), 119 deletions(-) diff --git a/include/cpp_common/Dmatrix.h b/include/cpp_common/Dmatrix.h index cbe3cba5a37..a2f594b46c5 100644 --- a/include/cpp_common/Dmatrix.h +++ b/include/cpp_common/Dmatrix.h @@ -103,6 +103,9 @@ class Dmatrix { double comparable_distance(size_t i, size_t j) const { return distance(i, j);} + double distance(int64_t i, int64_t j) const { + return distance(get_index(i), get_index(j));} + double distance(size_t i, size_t j) const { return costs[i][j];} diff --git a/include/vrp/vehicle.h b/include/vrp/vehicle.h index e9daf52572c..8afe7e781be 100644 --- a/include/vrp/vehicle.h +++ b/include/vrp/vehicle.h @@ -251,9 +251,11 @@ class Vehicle : public Identifier, public PD_problem { bool has_cv() const { return cvTot() != 0; } + bool is_feasable() const { return !(has_twv() || has_cv()); } + Vehicle_node start_site() const { return m_path.front(); } diff --git a/src/pickDeliver/src/base_node.cpp b/src/pickDeliver/src/base_node.cpp index c422c4cf2a7..3bcdf10a477 100644 --- a/src/pickDeliver/src/base_node.cpp +++ b/src/pickDeliver/src/base_node.cpp @@ -29,23 +29,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. namespace pgrouting { namespace vrp { -#if 0 -bool -Base_node::isSamePos(const Base_node &rhs) const { - return id() == rhs.id(); -} - -int64_t -Base_node::id() const { - return m_id; -} - -size_t -Base_node::idx() const { - return m_idx; -} -#endif - std::ostream& operator << (std::ostream &log, const Base_node &node) { node.print(log); return log; @@ -53,23 +36,10 @@ std::ostream& operator << (std::ostream &log, const Base_node &node) { void Base_node::print(std::ostream& os) const { - os << "USING BASE_NODE\n"; os << id() << "(" << idx() << ")"; } -#if 0 -double -Base_node::distance(const Base_node &node) const { - return 0; -} -double -Base_node::comparable_distance(const Base_node &) const { - return 0; -} -#endif - - Base_node::Base_node(size_t _idx, int64_t _id) : Identifier(_idx, _id) { } diff --git a/src/pickDeliver/src/fleet.cpp b/src/pickDeliver/src/fleet.cpp index e3d94f404f4..0bd1ed3695c 100644 --- a/src/pickDeliver/src/fleet.cpp +++ b/src/pickDeliver/src/fleet.cpp @@ -121,8 +121,6 @@ Fleet::add_vehicle( problem->add_node(starting_site); problem->add_node(ending_site); - pgassert(problem->nodesOK()); - if (!(starting_site.is_start() && ending_site.is_end())) { msg.error << "Illegal values found on vehicle"; @@ -272,6 +270,7 @@ Fleet::is_order_ok(const Order &order) const { if (truck.is_order_feasable(order)) { return true; } +#if 0 msg.log << "checking order " << order.idx() << "on truck " << truck.idx() << "\n"; @@ -287,8 +286,8 @@ Fleet::is_order_ok(const Order &order) const { EXITING(); return true; } +#endif } - EXITING(); return false; } diff --git a/src/pickDeliver/src/order.cpp b/src/pickDeliver/src/order.cpp index cde885da643..f23cac752d7 100644 --- a/src/pickDeliver/src/order.cpp +++ b/src/pickDeliver/src/order.cpp @@ -52,10 +52,12 @@ Order::Order( } std::ostream& -operator << (std::ostream &log, const Order &order) { - log << "\n\nOrder " << order.idx() << ":\n" +operator<< (std::ostream &log, const Order &order) { + log << "\n\nOrder " + << static_cast(order) << ": \n" << "\tPickup: " << order.pickup() << "\n" - << "\tDelivery: " << order.delivery() << "\n\n"; + << "\tDelivery: " << order.delivery() << "\n\n" + << "\tTravel time: " << order.pickup().travel_time_to(order.delivery(),1); log << "\nThere are | {I}| = " << order.m_compatibleI.size() << " -> order(" << order.idx() diff --git a/src/pickDeliver/src/pd_orders.cpp b/src/pickDeliver/src/pd_orders.cpp index bf23d92fb0a..1c6a008de64 100644 --- a/src/pickDeliver/src/pd_orders.cpp +++ b/src/pickDeliver/src/pd_orders.cpp @@ -55,7 +55,6 @@ PD_Orders:: add_order( problem->add_node(pick); problem->add_node(drop); - pgassert(problem->nodesOK()); /* * add into an order */ @@ -101,6 +100,13 @@ PD_Orders::build_orders( /* * matrix version */ + msg.log << "pickup \n" + << "pick_node_id: " << order.pick_node_id + << "\n"; + + msg.log << "pickup \n" + << "deliver_node_id: " << order.deliver_node_id + << "\n"; auto b_pick = create_b_pick(order, problem->node_id()); Vehicle_node pickup( {problem->node_id()++, order, Tw_node::NodeType::kPickup}); diff --git a/src/pickDeliver/src/pgr_pickDeliver.cpp b/src/pickDeliver/src/pgr_pickDeliver.cpp index 63ce19289f1..43707738c60 100644 --- a/src/pickDeliver/src/pgr_pickDeliver.cpp +++ b/src/pickDeliver/src/pgr_pickDeliver.cpp @@ -170,6 +170,7 @@ Pgr_pickDeliver::Pgr_pickDeliver( pgassert(!vehicles.empty()); pgassert(!m_cost_matrix.empty()); pgassert(m_initial_id > 0 && m_initial_id < 7); + pgassert(nodesOK()); if (!msg.get_error().empty()) { return; @@ -191,11 +192,9 @@ Pgr_pickDeliver::Pgr_pickDeliver( msg.log << t << "\n"; } #endif -#if 0 for (const auto &o : m_orders) { msg.log << o << "\n"; } -#endif /* * check the (S, P, D, E) order on all vehicles @@ -203,20 +202,35 @@ Pgr_pickDeliver::Pgr_pickDeliver( */ msg.log << "\n Checking orders"; for (const auto &o : m_orders) { -#if 1 if (!m_trucks.is_order_ok(o)) { msg.error << "The order " - << o.pickup().order() + << o.id() << " is not feasible on any truck"; msg.log << "\n" << o; + double old_speed(0); + for (auto t : m_trucks) { + if (old_speed == t.speed()) continue; + old_speed = t.speed(); + msg.log << "****** With speed: " << t.speed() << "\n"; + msg.log << t.start_site() << "\n"; + msg.log << o.pickup() << "\n"; + msg.log << "travel time to " << t.start_site().travel_time_to(o.pickup(), t.speed()) << "\n"; + msg.log << "yet other" << m_cost_matrix.distance(o.pickup().id(), t.start_site().id()) << "\n"; + + msg.log << o.delivery() << "\n"; + msg.log << t.end_site() << "\n"; + msg.log << "travel time to " << t.start_site().travel_time_to(o.delivery(), t.speed()) << "\n"; + msg.log << "yet other" << m_cost_matrix.distance(o.delivery().id(), t.start_site().id()) << "\n\nn"; + t.push_back(o); + } return; } -#endif } msg.log << "orders OK \n"; #if 0 m_trucks.set_compatibles(m_orders); #endif + msg.error << "constructor OK"; EXITING(); } // constructor diff --git a/src/pickDeliver/src/pickDeliver.c b/src/pickDeliver/src/pickDeliver.c index f418d1c6383..7d57dd0a0c3 100644 --- a/src/pickDeliver/src/pickDeliver.c +++ b/src/pickDeliver/src/pickDeliver.c @@ -92,6 +92,30 @@ process( &vehicles_arr, &total_vehicles); PGR_DBG("total vehicles %ld", total_vehicles); + + for (size_t i = 0; i < total_pd_orders; i++) { + PGR_DBG("%ld %f pick %f %f %ld - " + "%f %f %f deliver %f %f %ld - %f %f %f ", + pd_orders_arr[i].id, + pd_orders_arr[i].demand, + + pd_orders_arr[i].pick_x, + pd_orders_arr[i].pick_y, + pd_orders_arr[i].pick_node_id, + + pd_orders_arr[i].pick_open_t, + pd_orders_arr[i].pick_close_t, + pd_orders_arr[i].pick_service_t, + + pd_orders_arr[i].deliver_x, + pd_orders_arr[i].deliver_y, + pd_orders_arr[i].deliver_node_id, + + pd_orders_arr[i].deliver_open_t, + pd_orders_arr[i].deliver_close_t, + pd_orders_arr[i].deliver_service_t); + } + for (size_t i = 0; i < total_vehicles; i++) { PGR_DBG("%ld %f %f / %ld %f %f %f %f %f / %ld %f %f %f %f %f / %ld ", vehicles_arr[i].id, diff --git a/src/pickDeliver/src/pickDeliverEuclidean_driver.cpp b/src/pickDeliver/src/pickDeliverEuclidean_driver.cpp index e9a0daabb99..3aa5a00c976 100644 --- a/src/pickDeliver/src/pickDeliverEuclidean_driver.cpp +++ b/src/pickDeliver/src/pickDeliverEuclidean_driver.cpp @@ -44,6 +44,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /************************************************************ customers_sql TEXT, max_vehicles INTEGER, + factor FLOAT, capacity FLOAT, max_cycles INTEGER, ***********************************************************/ @@ -81,7 +82,7 @@ do_pgr_pickDeliverEuclidean( std::vector vehicles( vehicles_arr, vehicles_arr + total_vehicles); - log << "Read data\n"; + log << "Initialize problem\n"; pgrouting::vrp::Pgr_pickDeliver pd_problem( orders, vehicles, @@ -117,11 +118,13 @@ do_pgr_pickDeliverEuclidean( log << "solution size: " << solution.size() << "\n"; - (*return_tuples) = pgr_alloc(solution.size(), (*return_tuples)); - int seq = 0; - for (const auto &row : solution) { - (*return_tuples)[seq] = row; - ++seq; + if (!solution.empty()) { + (*return_tuples) = pgr_alloc(solution.size(), (*return_tuples)); + int seq = 0; + for (const auto &row : solution) { + (*return_tuples)[seq] = row; + ++seq; + } } (*return_count) = solution.size(); diff --git a/src/pickDeliver/src/pickDeliver_driver.cpp b/src/pickDeliver/src/pickDeliver_driver.cpp index 363cb78c62f..7d736a8b0fa 100644 --- a/src/pickDeliver/src/pickDeliver_driver.cpp +++ b/src/pickDeliver/src/pickDeliver_driver.cpp @@ -99,7 +99,7 @@ do_pgr_pickDeliver( return; } - log << "Read data\n"; + log << "Initialize problem\n"; pgrouting::vrp::Pgr_pickDeliver pd_problem( orders, vehicles, @@ -118,46 +118,23 @@ do_pgr_pickDeliver( log << pd_problem.msg.get_log(); log << "Finish Reading data\n"; -#if 0 - if (!pd_problem.msg.has_error()) { - log << "ERROR found\n"; - log << pd_problem.msg.get_log(); - err << pd_problem.msg.get_error(); - *log_msg = pgr_msg(log.str().c_str()); - *err_msg = pgr_msg(err.str().c_str()); - return; - } - pgassert(false); - log << pd_problem.msg.get_log(); - log << "Finish Reading data\n"; - pd_problem.msg.clear(); - -#if 0 - log << pd_problem; - log << pd_problem.msg.get_log(); - log << "Finish printing read data\n"; - pd_problem.msg.clear(); -#endif - *log_msg = pgr_msg(log.str().c_str()); - return; try { pd_problem.solve(); - - log << pd_problem.msg.get_log(); - log << "Finish solve\n"; - pd_problem.msg.clear(); - *log_msg = pgr_msg(log.str().c_str()); - return; } catch (AssertFailedException &except) { log << pd_problem.msg.get_log(); throw except; + } catch(...) { + log << "Caught unknown exception!"; + throw; } - auto solution = pd_problem.get_postgres_result(); + log << pd_problem.msg.get_log(); + log << "Finish solve\n"; + auto solution = pd_problem.get_postgres_result(); log << pd_problem.msg.get_log(); log << "solution size: " << solution.size() << "\n"; - pd_problem.msg.clear(); + if (!solution.empty()) { (*return_tuples) = pgr_alloc(solution.size(), (*return_tuples)); @@ -168,7 +145,7 @@ do_pgr_pickDeliver( } } (*return_count) = solution.size(); -#endif + pgassert(*err_msg == NULL); *log_msg = log.str().empty()? nullptr : diff --git a/src/pickDeliver/src/tw_node.cpp b/src/pickDeliver/src/tw_node.cpp index f0d8cafa325..1b30f0f1a61 100644 --- a/src/pickDeliver/src/tw_node.cpp +++ b/src/pickDeliver/src/tw_node.cpp @@ -51,38 +51,6 @@ Tw_node::travel_time_to(const Tw_node &to, double speed) const { } -#if 0 -double -Tw_node::travel_time_to(const pickdeliver::Node &to, double speed) const { - auto from = static_cast( - *problem->m_base_nodes[idx()].get()); - msg.log << "-----------\n"; - msg.log << from << "\n"; - msg.log << to << "\n"; -#if 0 - msg.log << from->distance(&to) << " == " << distance(other) << "\n"; - pgassertwm(from->distance(to) == distance(other), msg.get_log().c_str()); -#endif -#if 0 - pgassert(problem->m_base_nodes[idx()]-> - distance(*(problem->m_base_nodes[idx()])) == distance(other)); - msg.clear(); - msg.log << "idx" << idx() << "," - << "other idx" << other.idx() << "\tdist " - << distance(other); - pgassert(problem->nodesOK()); - msg.log << "from" << from->idx() - << "\tto" << to->idx() << "\tdist " - << from->distance(*to); - pgassertwm(false, msg.get_log().c_str()); -#endif - - pgassert(speed != 0); - /*! @todo TODO evaluate with matrix also*/ - return from.distance(to) / speed; -} -#endif - /* * I -> J = (*this) */ diff --git a/src/pickDeliver/src/vehicle_node.cpp b/src/pickDeliver/src/vehicle_node.cpp index 0b9422faaa5..3eebdc7f0f8 100644 --- a/src/pickDeliver/src/vehicle_node.cpp +++ b/src/pickDeliver/src/vehicle_node.cpp @@ -104,11 +104,11 @@ operator << (std::ostream &log, const Vehicle_node &v) { << ", twvTot = " << v.twvTot() << ", cvTot = " << v.cvTot() << ", cargo = " << v.cargo() - << ", travel _time = " << v.travel_time() - << ", arrival _time = " << v.arrival_time() - << ", wait _time = " << v.wait_time() - << ", service _time = " << v.service_time() - << ", departure _time = " << v.departure_time(); + << ", travel_time = " << v.travel_time() + << ", arrival_time = " << v.arrival_time() + << ", wait_time = " << v.wait_time() + << ", service_time = " << v.service_time() + << ", departure_time = " << v.departure_time(); return log; } diff --git a/src/pickDeliver/test/doc-pickDeliver.result b/src/pickDeliver/test/doc-pickDeliver.result index f1bc20f7d37..02ba7a191ee 100644 --- a/src/pickDeliver/test/doc-pickDeliver.result +++ b/src/pickDeliver/test/doc-pickDeliver.result @@ -2,6 +2,77 @@ BEGIN; BEGIN SET client_min_messages TO NOTICE; SET +SELECT * FROM orders ORDER BY id; + id | demand | p_node_id | p_x | p_y | p_open | p_close | p_service | d_node_id | d_x | d_y | d_open | d_close | d_service +-----+--------+-----------+-----+-----+--------+---------+-----------+-----------+-----+-----+--------+---------+----------- + 3 | 10 | 6 | 42 | 66 | 65 | 146 | 90 | 66 | 45 | 65 | 997 | 1068 | 90 + 5 | 10 | 22 | 42 | 65 | 15 | 67 | 90 | 93 | 40 | 66 | 170 | 225 | 90 + 6 | 20 | 51 | 40 | 69 | 621 | 702 | 90 | 48 | 45 | 70 | 825 | 870 | 90 + 8 | 20 | 65 | 38 | 68 | 255 | 324 | 90 | 45 | 35 | 66 | 357 | 410 | 90 + 9 | 10 | 20 | 38 | 70 | 534 | 605 | 90 | 42 | 42 | 68 | 727 | 782 | 90 + 11 | 10 | 99 | 35 | 69 | 448 | 505 | 90 | 97 | 45 | 68 | 912 | 967 | 90 + 13 | 30 | 47 | 22 | 75 | 30 | 92 | 90 | 63 | 18 | 75 | 99 | 148 | 90 + 16 | 40 | 60 | 20 | 85 | 475 | 528 | 90 | 50 | 22 | 85 | 567 | 620 | 90 + 18 | 20 | 17 | 15 | 75 | 179 | 254 | 90 | 59 | 25 | 85 | 652 | 721 | 90 + 19 | 10 | 64 | 15 | 80 | 278 | 345 | 90 | 1 | 20 | 80 | 384 | 429 | 90 + 20 | 10 | 14 | 30 | 50 | 10 | 73 | 90 | 16 | 25 | 50 | 65 | 144 | 90 + 23 | 10 | 87 | 28 | 55 | 732 | 777 | 0 | 87 | 28 | 55 | 732 | 777 | 90 + 25 | 40 | 56 | 25 | 52 | 169 | 224 | 90 | 40 | 23 | 52 | 261 | 316 | 90 + 28 | 20 | 15 | 23 | 55 | 546 | 593 | 90 | 69 | 28 | 52 | 812 | 883 | 90 + 29 | 10 | 28 | 20 | 50 | 358 | 405 | 90 | 3 | 25 | 55 | 622 | 701 | 90 + 30 | 10 | 12 | 20 | 55 | 449 | 504 | 90 | 30 | 30 | 52 | 914 | 965 | 90 + 32 | 30 | 74 | 10 | 40 | 31 | 100 | 90 | 96 | 10 | 35 | 200 | 237 | 90 + 33 | 40 | 76 | 8 | 40 | 87 | 158 | 90 | 13 | 2 | 40 | 383 | 434 | 90 + 35 | 10 | 26 | 5 | 35 | 283 | 344 | 90 | 94 | 0 | 45 | 567 | 624 | 90 + 36 | 10 | 84 | 5 | 45 | 665 | 716 | 0 | 84 | 5 | 45 | 665 | 716 | 90 + 38 | 30 | 36 | 0 | 40 | 479 | 522 | 90 | 2 | 8 | 45 | 751 | 816 | 90 + 42 | 20 | 57 | 33 | 32 | 68 | 149 | 90 | 7 | 35 | 30 | 264 | 321 | 90 + 43 | 10 | 55 | 33 | 35 | 16 | 80 | 90 | 24 | 35 | 32 | 166 | 235 | 90 + 44 | 10 | 9 | 32 | 30 | 359 | 412 | 90 | 49 | 30 | 32 | 448 | 509 | 90 + 45 | 10 | 33 | 30 | 30 | 541 | 600 | 90 | 75 | 28 | 30 | 632 | 693 | 90 + 49 | 10 | 61 | 28 | 35 | 1001 | 1066 | 90 | 52 | 30 | 35 | 1054 | 1127 | 90 + 50 | 10 | 83 | 26 | 32 | 815 | 880 | 90 | 31 | 25 | 35 | 912 | 969 | 90 + 51 | 10 | 44 | 25 | 30 | 725 | 786 | 0 | 44 | 25 | 30 | 725 | 786 | 90 + 53 | 20 | 90 | 44 | 5 | 286 | 347 | 90 | 62 | 38 | 5 | 471 | 534 | 90 + 54 | 40 | 71 | 42 | 10 | 186 | 257 | 90 | 23 | 35 | 5 | 562 | 629 | 90 + 56 | 30 | 77 | 40 | 5 | 385 | 436 | 90 | 98 | 38 | 15 | 651 | 740 | 90 + 57 | 40 | 89 | 40 | 15 | 35 | 87 | 90 | 25 | 42 | 15 | 95 | 158 | 90 + 62 | 20 | 95 | 50 | 35 | 262 | 317 | 90 | 91 | 45 | 30 | 734 | 777 | 90 + 63 | 50 | 68 | 50 | 40 | 171 | 218 | 90 | 5 | 53 | 35 | 353 | 412 | 90 + 64 | 10 | 21 | 48 | 30 | 632 | 693 | 0 | 21 | 48 | 30 | 632 | 693 | 90 + 65 | 10 | 35 | 48 | 40 | 76 | 129 | 90 | 18 | 53 | 30 | 450 | 505 | 90 + 66 | 10 | 34 | 47 | 35 | 826 | 875 | 90 | 79 | 45 | 35 | 916 | 969 | 90 + 67 | 10 | 8 | 47 | 40 | 12 | 77 | 90 | 81 | 50 | 30 | 531 | 610 | 90 + 71 | 20 | 39 | 95 | 35 | 293 | 360 | 90 | 53 | 88 | 30 | 574 | 643 | 90 + 76 | 10 | 92 | 90 | 35 | 203 | 260 | 90 | 41 | 92 | 30 | 478 | 551 | 90 + 78 | 20 | 37 | 88 | 35 | 109 | 170 | 0 | 37 | 88 | 35 | 109 | 170 | 90 + 79 | 10 | 32 | 87 | 30 | 668 | 731 | 90 | 4 | 85 | 25 | 769 | 820 | 90 + 81 | 30 | 70 | 85 | 35 | 47 | 124 | 90 | 54 | 95 | 30 | 387 | 456 | 90 + 82 | 20 | 80 | 75 | 55 | 369 | 420 | 90 | 88 | 68 | 60 | 555 | 612 | 90 + 84 | 20 | 67 | 70 | 58 | 458 | 523 | 90 | 78 | 63 | 58 | 737 | 802 | 90 + 86 | 10 | 82 | 66 | 55 | 173 | 238 | 90 | 58 | 60 | 60 | 836 | 889 | 90 + 87 | 20 | 72 | 65 | 55 | 85 | 144 | 90 | 19 | 72 | 55 | 265 | 338 | 90 + 90 | 10 | 38 | 60 | 55 | 20 | 84 | 90 | 43 | 65 | 60 | 645 | 708 | 90 + 92 | 20 | 73 | 67 | 85 | 368 | 441 | 90 | 27 | 65 | 85 | 475 | 518 | 90 + 96 | 10 | 29 | 60 | 80 | 95 | 156 | 90 | 85 | 65 | 82 | 285 | 336 | 90 + 97 | 30 | 86 | 60 | 85 | 561 | 622 | 0 | 86 | 60 | 85 | 561 | 622 | 90 + 98 | 20 | 10 | 58 | 75 | 30 | 84 | 90 | 11 | 62 | 80 | 196 | 239 | 90 + 100 | 20 | 46 | 55 | 85 | 647 | 726 | 90 | 100 | 55 | 80 | 743 | 820 | 90 +(53 rows) +SELECT * FROM vehicles ORDER BY id; + id | start_node_id | start_x | start_y | start_open | start_close | number | capacity +----+---------------+---------+---------+------------+-------------+--------+---------- + 1 | 100 | 40 | 50 | 0 | 1236 | 25 | 200 +(1 row) + start_vid | end_vid | agg_cost +-----------+---------+------------------ + 25 | 89 | 2 + 25 | 100 | 66.2872536767062 + 89 | 25 | 2 + 89 | 100 | 35 + 89 | 100 | 66.7083203206317 + 100 | 25 | 66.2872536767062 + 100 | 89 | 35 --q1 SELECT * FROM pgr_pickDeliver( 'SELECT * FROM orders ORDER BY id', diff --git a/src/pickDeliver/test/doc-pickDeliver.test.sql b/src/pickDeliver/test/doc-pickDeliver.test.sql index d06ed5dfed8..d8a7a9fe73b 100644 --- a/src/pickDeliver/test/doc-pickDeliver.test.sql +++ b/src/pickDeliver/test/doc-pickDeliver.test.sql @@ -1,3 +1,20 @@ +SELECT * FROM orders ORDER BY id; +SELECT * FROM vehicles ORDER BY id; + +WITH +A AS ( + SELECT p_node_id AS id, p_x AS x, p_y AS y FROM orders + UNION + SELECT d_node_id AS id, d_x, d_y FROM orders + UNION + SELECT start_node_id, start_x, start_y FROM vehicles +) +SELECT A.id AS start_vid, B.id AS end_vid, sqrt( (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) AS agg_cost +FROM A, A AS B +WHERE A.id != B.id AND A.id in (89, 25, 101) AND B.id in (89, 25, 101) +ORDER BY start_vid, end_vid; + + \echo --q1 -- using the default values SELECT * FROM pgr_pickDeliver( diff --git a/src/pickDeliver/test/test.conf b/src/pickDeliver/test/test.conf index 9b5de78856f..bd0402afe4b 100644 --- a/src/pickDeliver/test/test.conf +++ b/src/pickDeliver/test/test.conf @@ -16,7 +16,7 @@ differentVechiles-cygwin )], 'linux' => [qw( - doc-pickDeliverEuclidean + doc-pickDeliver )], 'documentation' => [qw( doc-pickDeliverEuclidean diff --git a/tools/testers/pickDeliver_pgtap_data.sql b/tools/testers/pickDeliver_pgtap_data.sql index 6589845649c..213799c0123 100644 --- a/tools/testers/pickDeliver_pgtap_data.sql +++ b/tools/testers/pickDeliver_pgtap_data.sql @@ -106,7 +106,7 @@ FROM third WHERE third.id = orders.id; WITH the_ids AS (SELECT p_node_id AS id FROM orders UNION SELECT d_node_id FROM orders), the_max AS (SELECT max(id) FROM the_ids) -UPDATE vehicles SET start_node_id = max FROM the_max; +UPDATE vehicles SET start_node_id = max+1 FROM the_max; /* WITH From 481da06e7c05ce89bec1ccd80f02d1402bae829a Mon Sep 17 00:00:00 2001 From: cvvergara Date: Tue, 16 May 2017 21:45:00 -0500 Subject: [PATCH 33/40] reading data matrix version part 1 --- src/pickDeliver/src/fleet.cpp | 18 -------------- src/pickDeliver/src/pgr_pickDeliver.cpp | 3 +-- src/pickDeliver/src/pickDeliver_driver.cpp | 4 +++ src/pickDeliver/test/doc-pickDeliver.result | 27 ++++++++++++++++----- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/pickDeliver/src/fleet.cpp b/src/pickDeliver/src/fleet.cpp index 0bd1ed3695c..abc6859301b 100644 --- a/src/pickDeliver/src/fleet.cpp +++ b/src/pickDeliver/src/fleet.cpp @@ -264,29 +264,11 @@ Fleet::is_fleet_ok() const { */ bool Fleet::is_order_ok(const Order &order) const { - ENTERING(); for (const auto truck : m_trucks) { if (!order.is_valid(truck.speed())) continue; if (truck.is_order_feasable(order)) { return true; } -#if 0 - msg.log << "checking order " << order.idx() - << "on truck " << truck.idx() << "\n"; - - /* - * The order must be valid given the speed - */ - if (!order.is_valid(truck.speed())) continue; - - /* - * if its feasible, then the one truck is found - */ - if (truck.is_order_feasable(order)) { - EXITING(); - return true; - } -#endif } return false; } diff --git a/src/pickDeliver/src/pgr_pickDeliver.cpp b/src/pickDeliver/src/pgr_pickDeliver.cpp index 43707738c60..113d212c1b0 100644 --- a/src/pickDeliver/src/pgr_pickDeliver.cpp +++ b/src/pickDeliver/src/pgr_pickDeliver.cpp @@ -191,10 +191,10 @@ Pgr_pickDeliver::Pgr_pickDeliver( for (const auto t : m_trucks) { msg.log << t << "\n"; } -#endif for (const auto &o : m_orders) { msg.log << o << "\n"; } +#endif /* * check the (S, P, D, E) order on all vehicles @@ -230,7 +230,6 @@ Pgr_pickDeliver::Pgr_pickDeliver( #if 0 m_trucks.set_compatibles(m_orders); #endif - msg.error << "constructor OK"; EXITING(); } // constructor diff --git a/src/pickDeliver/src/pickDeliver_driver.cpp b/src/pickDeliver/src/pickDeliver_driver.cpp index 7d736a8b0fa..3082c6b020e 100644 --- a/src/pickDeliver/src/pickDeliver_driver.cpp +++ b/src/pickDeliver/src/pickDeliver_driver.cpp @@ -99,6 +99,7 @@ do_pgr_pickDeliver( return; } + // TODO(vicky) wrap with a try and make a throw??? log << "Initialize problem\n"; pgrouting::vrp::Pgr_pickDeliver pd_problem( orders, @@ -118,6 +119,9 @@ do_pgr_pickDeliver( log << pd_problem.msg.get_log(); log << "Finish Reading data\n"; + *log_msg = pgr_msg(log.str().c_str()); + return; + try { pd_problem.solve(); } catch (AssertFailedException &except) { diff --git a/src/pickDeliver/test/doc-pickDeliver.result b/src/pickDeliver/test/doc-pickDeliver.result index 02ba7a191ee..d61081b8c3f 100644 --- a/src/pickDeliver/test/doc-pickDeliver.result +++ b/src/pickDeliver/test/doc-pickDeliver.result @@ -59,20 +59,35 @@ SELECT * FROM orders ORDER BY id; 98 | 20 | 10 | 58 | 75 | 30 | 84 | 90 | 11 | 62 | 80 | 196 | 239 | 90 100 | 20 | 46 | 55 | 85 | 647 | 726 | 90 | 100 | 55 | 80 | 743 | 820 | 90 (53 rows) + SELECT * FROM vehicles ORDER BY id; id | start_node_id | start_x | start_y | start_open | start_close | number | capacity ----+---------------+---------+---------+------------+-------------+--------+---------- - 1 | 100 | 40 | 50 | 0 | 1236 | 25 | 200 + 1 | 101 | 40 | 50 | 0 | 1236 | 25 | 200 (1 row) + +WITH +A AS ( + SELECT p_node_id AS id, p_x AS x, p_y AS y FROM orders + UNION + SELECT d_node_id AS id, d_x, d_y FROM orders + UNION + SELECT start_node_id, start_x, start_y FROM vehicles +) +SELECT A.id AS start_vid, B.id AS end_vid, sqrt( (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) AS agg_cost +FROM A, A AS B +WHERE A.id != B.id AND A.id in (89, 25, 101) AND B.id in (89, 25, 101) +ORDER BY start_vid, end_vid; start_vid | end_vid | agg_cost -----------+---------+------------------ 25 | 89 | 2 - 25 | 100 | 66.2872536767062 + 25 | 101 | 35.0570962859162 89 | 25 | 2 - 89 | 100 | 35 - 89 | 100 | 66.7083203206317 - 100 | 25 | 66.2872536767062 - 100 | 89 | 35 + 89 | 101 | 35 + 101 | 25 | 35.0570962859162 + 101 | 89 | 35 +(6 rows) + --q1 SELECT * FROM pgr_pickDeliver( 'SELECT * FROM orders ORDER BY id', From 8dc8547af18f72660c2dd55b5d93c841eeefca54 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Tue, 16 May 2017 22:08:38 -0500 Subject: [PATCH 34/40] setting expected results part 1 --- src/pickDeliver/src/pgr_pickDeliver.cpp | 7 +- src/pickDeliver/src/pickDeliver_driver.cpp | 3 +- src/pickDeliver/test/doc-pickDeliver.result | 134 +++++++++++++++++++- 3 files changed, 138 insertions(+), 6 deletions(-) diff --git a/src/pickDeliver/src/pgr_pickDeliver.cpp b/src/pickDeliver/src/pgr_pickDeliver.cpp index 113d212c1b0..4db943be900 100644 --- a/src/pickDeliver/src/pgr_pickDeliver.cpp +++ b/src/pickDeliver/src/pgr_pickDeliver.cpp @@ -227,8 +227,13 @@ Pgr_pickDeliver::Pgr_pickDeliver( } } msg.log << "orders OK \n"; -#if 0 + m_trucks.set_compatibles(m_orders); +#if 0 + msg.error << "foo"; + for (const auto t : m_trucks) { + msg.log << t << "\n"; + } #endif EXITING(); } // constructor diff --git a/src/pickDeliver/src/pickDeliver_driver.cpp b/src/pickDeliver/src/pickDeliver_driver.cpp index 3082c6b020e..5889c68b6b6 100644 --- a/src/pickDeliver/src/pickDeliver_driver.cpp +++ b/src/pickDeliver/src/pickDeliver_driver.cpp @@ -119,8 +119,6 @@ do_pgr_pickDeliver( log << pd_problem.msg.get_log(); log << "Finish Reading data\n"; - *log_msg = pgr_msg(log.str().c_str()); - return; try { pd_problem.solve(); @@ -132,6 +130,7 @@ do_pgr_pickDeliver( throw; } + log << pd_problem.msg.get_log(); log << "Finish solve\n"; diff --git a/src/pickDeliver/test/doc-pickDeliver.result b/src/pickDeliver/test/doc-pickDeliver.result index d61081b8c3f..7464b55864b 100644 --- a/src/pickDeliver/test/doc-pickDeliver.result +++ b/src/pickDeliver/test/doc-pickDeliver.result @@ -104,9 +104,137 @@ SELECT * FROM pgr_pickDeliver( SELECT A.id AS start_vid, B.id AS end_vid, sqrt( (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) AS agg_cost FROM A, A AS B WHERE A.id != B.id' ); - seq | vehicle_number | vehicle_id | vehicle_seq | order_id | stop_type | cargo | travel_time | arrival_time | wait_time | service_time | departure_time ------+----------------+------------+-------------+----------+-----------+-------+-------------+--------------+-----------+--------------+---------------- -(0 rows) + seq | vehicle_number | vehicle_id | vehicle_seq | order_id | stop_type | cargo | travel_time | arrival_time | wait_time | service_time | departure_time +-----+----------------+------------+-------------+----------+-----------+-------+------------------+------------------+-----------+--------------+------------------ + 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 + 4 | 1 | 1 | 4 | 5 | 3 | 10 | 2 | 198.132745950422 | 0 | 90 | 288.132745950422 + 5 | 1 | 1 | 5 | 8 | 2 | 30 | 2.82842712474619 | 290.961173075168 | 0 | 90 | 380.961173075168 + 6 | 1 | 1 | 6 | 8 | 3 | 10 | 3.60555127546399 | 384.566724350632 | 0 | 90 | 474.566724350632 + 7 | 1 | 1 | 7 | 11 | 2 | 20 | 3 | 477.566724350632 | 0 | 90 | 567.566724350632 + 8 | 1 | 1 | 8 | 9 | 2 | 30 | 3.16227766016838 | 570.7290020108 | 0 | 90 | 660.7290020108 + 9 | 1 | 1 | 9 | 6 | 2 | 50 | 2.23606797749979 | 662.9650699883 | 0 | 90 | 752.9650699883 + 10 | 1 | 1 | 10 | 9 | 3 | 40 | 2.23606797749979 | 755.2011379658 | 0 | 90 | 845.2011379658 + 11 | 1 | 1 | 11 | 6 | 3 | 20 | 3.60555127546399 | 848.806689241264 | 0 | 90 | 938.806689241264 + 12 | 1 | 1 | 12 | 11 | 3 | 10 | 2 | 940.806689241264 | 0 | 90 | 1030.80668924126 + 13 | 1 | 1 | 13 | 3 | 3 | 0 | 3 | 1033.80668924126 | 0 | 90 | 1123.80668924126 + 14 | 1 | 1 | 14 | -1 | 6 | 0 | 15.8113883008419 | 1139.61807754211 | 0 | 0 | 1139.61807754211 + 15 | 2 | 1 | 1 | -1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 + 16 | 2 | 1 | 2 | 13 | 2 | 30 | 30.8058436014987 | 30.8058436014987 | 0 | 90 | 120.805843601499 + 17 | 2 | 1 | 3 | 13 | 3 | 0 | 4 | 124.805843601499 | 0 | 90 | 214.805843601499 + 18 | 2 | 1 | 4 | 18 | 2 | 20 | 3 | 217.805843601499 | 0 | 90 | 307.805843601499 + 19 | 2 | 1 | 5 | 19 | 2 | 30 | 5 | 312.805843601499 | 0 | 90 | 402.805843601499 + 20 | 2 | 1 | 6 | 19 | 3 | 20 | 5 | 407.805843601499 | 0 | 90 | 497.805843601499 + 21 | 2 | 1 | 7 | 16 | 2 | 60 | 5 | 502.805843601499 | 0 | 90 | 592.805843601499 + 22 | 2 | 1 | 8 | 16 | 3 | 20 | 2 | 594.805843601499 | 0 | 90 | 684.805843601499 + 23 | 2 | 1 | 9 | 18 | 3 | 0 | 3 | 687.805843601499 | 0 | 90 | 777.805843601499 + 24 | 2 | 1 | 10 | 50 | 2 | 10 | 53.0094331227943 | 830.815276724293 | 0 | 90 | 920.815276724293 + 25 | 2 | 1 | 11 | 50 | 3 | 0 | 3.16227766016838 | 923.977554384461 | 0 | 90 | 1013.97755438446 + 26 | 2 | 1 | 12 | 49 | 2 | 10 | 3 | 1016.97755438446 | 0 | 90 | 1106.97755438446 + 27 | 2 | 1 | 13 | 49 | 3 | 0 | 2 | 1108.97755438446 | 0 | 90 | 1198.97755438446 + 28 | 2 | 1 | 14 | -1 | 6 | 0 | 18.0277563773199 | 1217.00531076178 | 0 | 0 | 1217.00531076178 + 29 | 3 | 1 | 1 | -1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 + 30 | 3 | 1 | 2 | 20 | 2 | 10 | 10 | 10 | 0 | 90 | 100 + 31 | 3 | 1 | 3 | 20 | 3 | 0 | 5 | 105 | 0 | 90 | 195 + 32 | 3 | 1 | 4 | 25 | 2 | 40 | 2 | 197 | 0 | 90 | 287 + 33 | 3 | 1 | 5 | 25 | 3 | 0 | 2 | 289 | 0 | 90 | 379 + 34 | 3 | 1 | 6 | 29 | 2 | 10 | 3.60555127546399 | 382.605551275464 | 0 | 90 | 472.605551275464 + 35 | 3 | 1 | 7 | 30 | 2 | 20 | 5 | 477.605551275464 | 0 | 90 | 567.605551275464 + 36 | 3 | 1 | 8 | 28 | 2 | 40 | 3 | 570.605551275464 | 0 | 90 | 660.605551275464 + 37 | 3 | 1 | 9 | 29 | 3 | 30 | 2 | 662.605551275464 | 0 | 90 | 752.605551275464 + 38 | 3 | 1 | 10 | 23 | 2 | 40 | 3 | 755.605551275464 | 0 | 0 | 755.605551275464 + 39 | 3 | 1 | 11 | 23 | 3 | 30 | 0 | 755.605551275464 | 0 | 90 | 845.605551275464 + 40 | 3 | 1 | 12 | 28 | 3 | 10 | 3 | 848.605551275464 | 0 | 90 | 938.605551275464 + 41 | 3 | 1 | 13 | 30 | 3 | 0 | 2 | 940.605551275464 | 0 | 90 | 1030.60555127546 + 41 | 3 | 1 | 13 | 30 | 3 | 0 | 2 | 940.605551275464 | 0 | 90 | 1030.60555127546 + 42 | 3 | 1 | 14 | -1 | 6 | 0 | 10.1980390271856 | 1040.80359030265 | 0 | 0 | 1040.80359030265 + 43 | 4 | 1 | 1 | -1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 + 44 | 4 | 1 | 2 | 32 | 2 | 30 | 31.6227766016838 | 31.6227766016838 | 0 | 90 | 121.622776601684 + 45 | 4 | 1 | 3 | 33 | 2 | 70 | 2 | 123.622776601684 | 0 | 90 | 213.622776601684 + 46 | 4 | 1 | 4 | 32 | 3 | 40 | 5.3851648071345 | 219.007941408818 | 0 | 90 | 309.007941408818 + 47 | 4 | 1 | 5 | 35 | 2 | 50 | 5 | 314.007941408818 | 0 | 90 | 404.007941408818 + 48 | 4 | 1 | 6 | 33 | 3 | 10 | 5.8309518948453 | 409.838893303664 | 0 | 90 | 499.838893303664 + 49 | 4 | 1 | 7 | 38 | 2 | 40 | 2 | 501.838893303664 | 0 | 90 | 591.838893303664 + 50 | 4 | 1 | 8 | 35 | 3 | 30 | 5 | 596.838893303664 | 0 | 90 | 686.838893303664 + 51 | 4 | 1 | 9 | 36 | 2 | 40 | 5 | 691.838893303664 | 0 | 0 | 691.838893303664 + 52 | 4 | 1 | 10 | 36 | 3 | 30 | 0 | 691.838893303664 | 0 | 90 | 781.838893303664 + 53 | 4 | 1 | 11 | 38 | 3 | 0 | 3 | 784.838893303664 | 0 | 90 | 874.838893303664 + 54 | 4 | 1 | 12 | -1 | 6 | 0 | 32.3882694814033 | 907.227162785067 | 0 | 0 | 907.227162785067 + 55 | 5 | 1 | 1 | -1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 + 56 | 5 | 1 | 2 | 43 | 2 | 10 | 16.5529453572468 | 16.5529453572468 | 0 | 90 | 106.552945357247 + 57 | 5 | 1 | 3 | 42 | 2 | 30 | 3 | 109.552945357247 | 0 | 90 | 199.552945357247 + 58 | 5 | 1 | 4 | 43 | 3 | 20 | 2 | 201.552945357247 | 0 | 90 | 291.552945357247 + 59 | 5 | 1 | 5 | 42 | 3 | 0 | 2 | 293.552945357247 | 0 | 90 | 383.552945357247 + 60 | 5 | 1 | 6 | 44 | 2 | 10 | 3 | 386.552945357247 | 0 | 90 | 476.552945357247 + 61 | 5 | 1 | 7 | 44 | 3 | 0 | 2.82842712474619 | 479.381372481993 | 0 | 90 | 569.381372481993 + 62 | 5 | 1 | 8 | 45 | 2 | 10 | 2 | 571.381372481993 | 0 | 90 | 661.381372481993 + 63 | 5 | 1 | 9 | 45 | 3 | 0 | 2 | 663.381372481993 | 0 | 90 | 753.381372481993 + 64 | 5 | 1 | 10 | 51 | 2 | 10 | 3 | 756.381372481993 | 0 | 0 | 756.381372481993 + 65 | 5 | 1 | 11 | 51 | 3 | 0 | 0 | 756.381372481993 | 0 | 90 | 846.381372481993 + 66 | 5 | 1 | 12 | 66 | 2 | 10 | 22.561028345357 | 868.94240082735 | 0 | 90 | 958.94240082735 + 67 | 5 | 1 | 13 | 66 | 3 | 0 | 2 | 960.94240082735 | 0 | 90 | 1050.94240082735 + 68 | 5 | 1 | 14 | -1 | 6 | 0 | 15.8113883008419 | 1066.75378912819 | 0 | 0 | 1066.75378912819 + 69 | 6 | 1 | 1 | -1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 + 70 | 6 | 1 | 2 | 57 | 2 | 40 | 35 | 35 | 0 | 90 | 125 + 71 | 6 | 1 | 3 | 57 | 3 | 0 | 2 | 127 | 0 | 90 | 217 + 72 | 6 | 1 | 4 | 54 | 2 | 40 | 5 | 222 | 0 | 90 | 312 + 73 | 6 | 1 | 5 | 53 | 2 | 60 | 5.3851648071345 | 317.385164807135 | 0 | 90 | 407.385164807135 + 74 | 6 | 1 | 6 | 56 | 2 | 90 | 4 | 411.385164807135 | 0 | 90 | 501.385164807135 + 75 | 6 | 1 | 7 | 53 | 3 | 70 | 2 | 503.385164807135 | 0 | 90 | 593.385164807135 + 76 | 6 | 1 | 8 | 54 | 3 | 30 | 3 | 596.385164807135 | 0 | 90 | 686.385164807135 + 77 | 6 | 1 | 9 | 56 | 3 | 0 | 10.4403065089106 | 696.825471316045 | 0 | 90 | 786.825471316045 + 78 | 6 | 1 | 10 | -1 | 6 | 0 | 35.0570962859162 | 821.882567601961 | 0 | 0 | 821.882567601961 + 79 | 7 | 1 | 1 | -1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 + 80 | 7 | 1 | 2 | 67 | 2 | 10 | 12.2065556157337 | 12.2065556157337 | 0 | 90 | 102.206555615734 + 81 | 7 | 1 | 3 | 65 | 2 | 20 | 1 | 103.206555615734 | 0 | 90 | 193.206555615734 + 82 | 7 | 1 | 4 | 63 | 2 | 70 | 2 | 195.206555615734 | 0 | 90 | 285.206555615734 + 83 | 7 | 1 | 5 | 62 | 2 | 90 | 5 | 290.206555615734 | 0 | 90 | 380.206555615734 + 84 | 7 | 1 | 6 | 63 | 3 | 40 | 3 | 383.206555615734 | 0 | 90 | 473.206555615734 + 85 | 7 | 1 | 7 | 65 | 3 | 30 | 5 | 478.206555615734 | 0 | 90 | 568.206555615734 + 86 | 7 | 1 | 8 | 67 | 3 | 20 | 3 | 571.206555615734 | 0 | 90 | 661.206555615734 + 87 | 7 | 1 | 9 | 64 | 2 | 30 | 2 | 663.206555615734 | 0 | 0 | 663.206555615734 + 88 | 7 | 1 | 10 | 64 | 3 | 20 | 0 | 663.206555615734 | 0 | 90 | 753.206555615734 + 89 | 7 | 1 | 11 | 62 | 3 | 0 | 3 | 756.206555615734 | 0 | 90 | 846.206555615734 + 90 | 7 | 1 | 12 | -1 | 6 | 0 | 20.6155281280883 | 866.822083743822 | 0 | 0 | 866.822083743822 + 91 | 8 | 1 | 1 | -1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 + 92 | 8 | 1 | 2 | 81 | 2 | 30 | 47.4341649025257 | 47.4341649025257 | 0 | 90 | 137.434164902526 + 93 | 8 | 1 | 3 | 78 | 2 | 50 | 3 | 140.434164902526 | 0 | 0 | 140.434164902526 + 94 | 8 | 1 | 4 | 78 | 3 | 30 | 0 | 140.434164902526 | 0 | 90 | 230.434164902526 + 95 | 8 | 1 | 5 | 76 | 2 | 40 | 2 | 232.434164902526 | 0 | 90 | 322.434164902526 + 96 | 8 | 1 | 6 | 71 | 2 | 60 | 5 | 327.434164902526 | 0 | 90 | 417.434164902526 + 97 | 8 | 1 | 7 | 81 | 3 | 30 | 5 | 422.434164902526 | 0 | 90 | 512.434164902526 + 98 | 8 | 1 | 8 | 76 | 3 | 20 | 3 | 515.434164902526 | 0 | 90 | 605.434164902526 + 99 | 8 | 1 | 9 | 71 | 3 | 0 | 4 | 609.434164902526 | 0 | 90 | 699.434164902526 + 100 | 8 | 1 | 10 | 79 | 2 | 10 | 1 | 700.434164902526 | 0 | 90 | 790.434164902526 + 101 | 8 | 1 | 11 | 79 | 3 | 0 | 5.3851648071345 | 795.81932970966 | 0 | 90 | 885.81932970966 + 102 | 8 | 1 | 12 | -1 | 6 | 0 | 51.478150704935 | 937.297480414595 | 0 | 0 | 937.297480414595 + 103 | 9 | 1 | 1 | -1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 + 104 | 9 | 1 | 2 | 90 | 2 | 10 | 20.6155281280883 | 20.6155281280883 | 0 | 90 | 110.615528128088 + 105 | 9 | 1 | 3 | 87 | 2 | 30 | 5 | 115.615528128088 | 0 | 90 | 205.615528128088 + 106 | 9 | 1 | 4 | 86 | 2 | 40 | 1 | 206.615528128088 | 0 | 90 | 296.615528128088 + 107 | 9 | 1 | 5 | 87 | 3 | 20 | 6 | 302.615528128088 | 0 | 90 | 392.615528128088 + 108 | 9 | 1 | 6 | 82 | 2 | 40 | 3 | 395.615528128088 | 0 | 90 | 485.615528128088 + 109 | 9 | 1 | 7 | 84 | 2 | 60 | 5.8309518948453 | 491.446480022934 | 0 | 90 | 581.446480022934 + 110 | 9 | 1 | 8 | 82 | 3 | 40 | 2.82842712474619 | 584.27490714768 | 0 | 90 | 674.27490714768 + 111 | 9 | 1 | 9 | 90 | 3 | 30 | 3 | 677.27490714768 | 0 | 90 | 767.27490714768 + 112 | 9 | 1 | 10 | 84 | 3 | 10 | 2.82842712474619 | 770.103334272426 | 0 | 90 | 860.103334272426 + 113 | 9 | 1 | 11 | 86 | 3 | 0 | 3.60555127546399 | 863.70888554789 | 0 | 90 | 953.70888554789 + 114 | 9 | 1 | 12 | -1 | 6 | 0 | 22.3606797749979 | 976.069565322888 | 0 | 0 | 976.069565322888 + 115 | 10 | 1 | 1 | -1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 + 116 | 10 | 1 | 2 | 98 | 2 | 20 | 30.8058436014987 | 30.8058436014987 | 0 | 90 | 120.805843601499 + 117 | 10 | 1 | 3 | 96 | 2 | 30 | 5.3851648071345 | 126.191008408633 | 0 | 90 | 216.191008408633 + 118 | 10 | 1 | 4 | 98 | 3 | 10 | 2 | 218.191008408633 | 0 | 90 | 308.191008408633 + 119 | 10 | 1 | 5 | 96 | 3 | 0 | 3.60555127546399 | 311.796559684097 | 0 | 90 | 401.796559684097 + 120 | 10 | 1 | 6 | 92 | 2 | 20 | 3.60555127546399 | 405.402110959561 | 0 | 90 | 495.402110959561 + 121 | 10 | 1 | 7 | 92 | 3 | 0 | 2 | 497.402110959561 | 0 | 90 | 587.402110959561 + 122 | 10 | 1 | 8 | 97 | 2 | 30 | 5 | 592.402110959561 | 0 | 0 | 592.402110959561 + 123 | 10 | 1 | 9 | 97 | 3 | 0 | 0 | 592.402110959561 | 0 | 90 | 682.402110959561 + 124 | 10 | 1 | 10 | 100 | 2 | 20 | 5 | 687.402110959561 | 0 | 90 | 777.402110959561 + 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 +(127 rows) --q2 ROLLBACK; From fc82dd74457f82992ca2957db36f8b90428c1a2c Mon Sep 17 00:00:00 2001 From: cvvergara Date: Tue, 16 May 2017 22:18:59 -0500 Subject: [PATCH 35/40] getting the expected results --- src/pickDeliver/src/pickDeliver.c | 2 +- src/pickDeliver/test/doc-pickDeliver.result | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pickDeliver/src/pickDeliver.c b/src/pickDeliver/src/pickDeliver.c index 7d57dd0a0c3..f96562dd8f2 100644 --- a/src/pickDeliver/src/pickDeliver.c +++ b/src/pickDeliver/src/pickDeliver.c @@ -304,7 +304,7 @@ pickDeliver(PG_FUNCTION_ARGS) { values[2] = Int64GetDatum(result_tuples[call_cntr].vehicle_id); values[3] = Int32GetDatum(result_tuples[call_cntr].vehicle_seq); values[4] = Int64GetDatum(result_tuples[call_cntr].order_id); - values[5] = Int32GetDatum(result_tuples[call_cntr].stop_type); + values[5] = Int32GetDatum(result_tuples[call_cntr].stop_type + 1); values[6] = Float8GetDatum(result_tuples[call_cntr].cargo); values[7] = Float8GetDatum(result_tuples[call_cntr].travelTime); values[8] = Float8GetDatum(result_tuples[call_cntr].arrivalTime); diff --git a/src/pickDeliver/test/doc-pickDeliver.result b/src/pickDeliver/test/doc-pickDeliver.result index 7464b55864b..4a7acba6640 100644 --- a/src/pickDeliver/test/doc-pickDeliver.result +++ b/src/pickDeliver/test/doc-pickDeliver.result @@ -147,7 +147,6 @@ SELECT * FROM pgr_pickDeliver( 39 | 3 | 1 | 11 | 23 | 3 | 30 | 0 | 755.605551275464 | 0 | 90 | 845.605551275464 40 | 3 | 1 | 12 | 28 | 3 | 10 | 3 | 848.605551275464 | 0 | 90 | 938.605551275464 41 | 3 | 1 | 13 | 30 | 3 | 0 | 2 | 940.605551275464 | 0 | 90 | 1030.60555127546 - 41 | 3 | 1 | 13 | 30 | 3 | 0 | 2 | 940.605551275464 | 0 | 90 | 1030.60555127546 42 | 3 | 1 | 14 | -1 | 6 | 0 | 10.1980390271856 | 1040.80359030265 | 0 | 0 | 1040.80359030265 43 | 4 | 1 | 1 | -1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 44 | 4 | 1 | 2 | 32 | 2 | 30 | 31.6227766016838 | 31.6227766016838 | 0 | 90 | 121.622776601684 From 709e60c60d02f4c94eeadf600c98f42960a54c73 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Tue, 16 May 2017 22:53:49 -0500 Subject: [PATCH 36/40] testing bothe versions --- src/pickDeliver/doc/doc-pickDeliver.queries | 224 +++++++++++++++++++- src/pickDeliver/test/test.conf | 9 +- 2 files changed, 222 insertions(+), 11 deletions(-) diff --git a/src/pickDeliver/doc/doc-pickDeliver.queries b/src/pickDeliver/doc/doc-pickDeliver.queries index ff12b423bb7..8f30ef50f4d 100644 --- a/src/pickDeliver/doc/doc-pickDeliver.queries +++ b/src/pickDeliver/doc/doc-pickDeliver.queries @@ -2,10 +2,97 @@ BEGIN; BEGIN SET client_min_messages TO NOTICE; SET +SELECT * FROM orders ORDER BY id; + id | demand | p_node_id | p_x | p_y | p_open | p_close | p_service | d_node_id | d_x | d_y | d_open | d_close | d_service +-----+--------+-----------+-----+-----+--------+---------+-----------+-----------+-----+-----+--------+---------+----------- + 3 | 10 | 6 | 42 | 66 | 65 | 146 | 90 | 66 | 45 | 65 | 997 | 1068 | 90 + 5 | 10 | 22 | 42 | 65 | 15 | 67 | 90 | 93 | 40 | 66 | 170 | 225 | 90 + 6 | 20 | 51 | 40 | 69 | 621 | 702 | 90 | 48 | 45 | 70 | 825 | 870 | 90 + 8 | 20 | 65 | 38 | 68 | 255 | 324 | 90 | 45 | 35 | 66 | 357 | 410 | 90 + 9 | 10 | 20 | 38 | 70 | 534 | 605 | 90 | 42 | 42 | 68 | 727 | 782 | 90 + 11 | 10 | 99 | 35 | 69 | 448 | 505 | 90 | 97 | 45 | 68 | 912 | 967 | 90 + 13 | 30 | 47 | 22 | 75 | 30 | 92 | 90 | 63 | 18 | 75 | 99 | 148 | 90 + 16 | 40 | 60 | 20 | 85 | 475 | 528 | 90 | 50 | 22 | 85 | 567 | 620 | 90 + 18 | 20 | 17 | 15 | 75 | 179 | 254 | 90 | 59 | 25 | 85 | 652 | 721 | 90 + 19 | 10 | 64 | 15 | 80 | 278 | 345 | 90 | 1 | 20 | 80 | 384 | 429 | 90 + 20 | 10 | 14 | 30 | 50 | 10 | 73 | 90 | 16 | 25 | 50 | 65 | 144 | 90 + 23 | 10 | 87 | 28 | 55 | 732 | 777 | 0 | 87 | 28 | 55 | 732 | 777 | 90 + 25 | 40 | 56 | 25 | 52 | 169 | 224 | 90 | 40 | 23 | 52 | 261 | 316 | 90 + 28 | 20 | 15 | 23 | 55 | 546 | 593 | 90 | 69 | 28 | 52 | 812 | 883 | 90 + 29 | 10 | 28 | 20 | 50 | 358 | 405 | 90 | 3 | 25 | 55 | 622 | 701 | 90 + 30 | 10 | 12 | 20 | 55 | 449 | 504 | 90 | 30 | 30 | 52 | 914 | 965 | 90 + 32 | 30 | 74 | 10 | 40 | 31 | 100 | 90 | 96 | 10 | 35 | 200 | 237 | 90 + 33 | 40 | 76 | 8 | 40 | 87 | 158 | 90 | 13 | 2 | 40 | 383 | 434 | 90 + 35 | 10 | 26 | 5 | 35 | 283 | 344 | 90 | 94 | 0 | 45 | 567 | 624 | 90 + 36 | 10 | 84 | 5 | 45 | 665 | 716 | 0 | 84 | 5 | 45 | 665 | 716 | 90 + 38 | 30 | 36 | 0 | 40 | 479 | 522 | 90 | 2 | 8 | 45 | 751 | 816 | 90 + 42 | 20 | 57 | 33 | 32 | 68 | 149 | 90 | 7 | 35 | 30 | 264 | 321 | 90 + 43 | 10 | 55 | 33 | 35 | 16 | 80 | 90 | 24 | 35 | 32 | 166 | 235 | 90 + 44 | 10 | 9 | 32 | 30 | 359 | 412 | 90 | 49 | 30 | 32 | 448 | 509 | 90 + 45 | 10 | 33 | 30 | 30 | 541 | 600 | 90 | 75 | 28 | 30 | 632 | 693 | 90 + 49 | 10 | 61 | 28 | 35 | 1001 | 1066 | 90 | 52 | 30 | 35 | 1054 | 1127 | 90 + 50 | 10 | 83 | 26 | 32 | 815 | 880 | 90 | 31 | 25 | 35 | 912 | 969 | 90 + 51 | 10 | 44 | 25 | 30 | 725 | 786 | 0 | 44 | 25 | 30 | 725 | 786 | 90 + 53 | 20 | 90 | 44 | 5 | 286 | 347 | 90 | 62 | 38 | 5 | 471 | 534 | 90 + 54 | 40 | 71 | 42 | 10 | 186 | 257 | 90 | 23 | 35 | 5 | 562 | 629 | 90 + 56 | 30 | 77 | 40 | 5 | 385 | 436 | 90 | 98 | 38 | 15 | 651 | 740 | 90 + 57 | 40 | 89 | 40 | 15 | 35 | 87 | 90 | 25 | 42 | 15 | 95 | 158 | 90 + 62 | 20 | 95 | 50 | 35 | 262 | 317 | 90 | 91 | 45 | 30 | 734 | 777 | 90 + 63 | 50 | 68 | 50 | 40 | 171 | 218 | 90 | 5 | 53 | 35 | 353 | 412 | 90 + 64 | 10 | 21 | 48 | 30 | 632 | 693 | 0 | 21 | 48 | 30 | 632 | 693 | 90 + 65 | 10 | 35 | 48 | 40 | 76 | 129 | 90 | 18 | 53 | 30 | 450 | 505 | 90 + 66 | 10 | 34 | 47 | 35 | 826 | 875 | 90 | 79 | 45 | 35 | 916 | 969 | 90 + 67 | 10 | 8 | 47 | 40 | 12 | 77 | 90 | 81 | 50 | 30 | 531 | 610 | 90 + 71 | 20 | 39 | 95 | 35 | 293 | 360 | 90 | 53 | 88 | 30 | 574 | 643 | 90 + 76 | 10 | 92 | 90 | 35 | 203 | 260 | 90 | 41 | 92 | 30 | 478 | 551 | 90 + 78 | 20 | 37 | 88 | 35 | 109 | 170 | 0 | 37 | 88 | 35 | 109 | 170 | 90 + 79 | 10 | 32 | 87 | 30 | 668 | 731 | 90 | 4 | 85 | 25 | 769 | 820 | 90 + 81 | 30 | 70 | 85 | 35 | 47 | 124 | 90 | 54 | 95 | 30 | 387 | 456 | 90 + 82 | 20 | 80 | 75 | 55 | 369 | 420 | 90 | 88 | 68 | 60 | 555 | 612 | 90 + 84 | 20 | 67 | 70 | 58 | 458 | 523 | 90 | 78 | 63 | 58 | 737 | 802 | 90 + 86 | 10 | 82 | 66 | 55 | 173 | 238 | 90 | 58 | 60 | 60 | 836 | 889 | 90 + 87 | 20 | 72 | 65 | 55 | 85 | 144 | 90 | 19 | 72 | 55 | 265 | 338 | 90 + 90 | 10 | 38 | 60 | 55 | 20 | 84 | 90 | 43 | 65 | 60 | 645 | 708 | 90 + 92 | 20 | 73 | 67 | 85 | 368 | 441 | 90 | 27 | 65 | 85 | 475 | 518 | 90 + 96 | 10 | 29 | 60 | 80 | 95 | 156 | 90 | 85 | 65 | 82 | 285 | 336 | 90 + 97 | 30 | 86 | 60 | 85 | 561 | 622 | 0 | 86 | 60 | 85 | 561 | 622 | 90 + 98 | 20 | 10 | 58 | 75 | 30 | 84 | 90 | 11 | 62 | 80 | 196 | 239 | 90 + 100 | 20 | 46 | 55 | 85 | 647 | 726 | 90 | 100 | 55 | 80 | 743 | 820 | 90 +(53 rows) + +SELECT * FROM vehicles ORDER BY id; + id | start_node_id | start_x | start_y | start_open | start_close | number | capacity +----+---------------+---------+---------+------------+-------------+--------+---------- + 1 | 101 | 40 | 50 | 0 | 1236 | 25 | 200 +(1 row) + +WITH +A AS ( + SELECT p_node_id AS id, p_x AS x, p_y AS y FROM orders + UNION + SELECT d_node_id AS id, d_x, d_y FROM orders + UNION + SELECT start_node_id, start_x, start_y FROM vehicles +) +SELECT A.id AS start_vid, B.id AS end_vid, sqrt( (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) AS agg_cost +FROM A, A AS B +WHERE A.id != B.id AND A.id in (89, 25, 101) AND B.id in (89, 25, 101) +ORDER BY start_vid, end_vid; + start_vid | end_vid | agg_cost +-----------+---------+------------------ + 25 | 89 | 2 + 25 | 101 | 35.0570962859162 + 89 | 25 | 2 + 89 | 101 | 35 + 101 | 25 | 35.0570962859162 + 101 | 89 | 35 +(6 rows) + --q1 SELECT * FROM pgr_pickDeliver( 'SELECT * FROM orders ORDER BY id', 'SELECT * from vehicles', + 'WITH A AS ( SELECT p_node_id AS id, p_x AS x, p_y AS y FROM orders @@ -15,11 +102,138 @@ SELECT * FROM pgr_pickDeliver( SELECT start_node_id, start_x, start_y FROM vehicles ) SELECT A.id AS start_vid, B.id AS end_vid, sqrt( (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) AS agg_cost - FROM A, A AS B WHERE A.id != B.id', - 30); - seq | vehicle_number | vehicle_id | vehicle_seq | order_id | stop_type | cargo | travel_time | arrival_time | wait_time | service_time | departure_time ------+----------------+------------+-------------+----------+-----------+-------+-------------+--------------+-----------+--------------+---------------- -(0 rows) + FROM A, A AS B WHERE A.id != B.id' + ); + seq | vehicle_number | vehicle_id | vehicle_seq | order_id | stop_type | cargo | travel_time | arrival_time | wait_time | service_time | departure_time +-----+----------------+------------+-------------+----------+-----------+-------+------------------+------------------+-----------+--------------+------------------ + 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 + 4 | 1 | 1 | 4 | 5 | 3 | 10 | 2 | 198.132745950422 | 0 | 90 | 288.132745950422 + 5 | 1 | 1 | 5 | 8 | 2 | 30 | 2.82842712474619 | 290.961173075168 | 0 | 90 | 380.961173075168 + 6 | 1 | 1 | 6 | 8 | 3 | 10 | 3.60555127546399 | 384.566724350632 | 0 | 90 | 474.566724350632 + 7 | 1 | 1 | 7 | 11 | 2 | 20 | 3 | 477.566724350632 | 0 | 90 | 567.566724350632 + 8 | 1 | 1 | 8 | 9 | 2 | 30 | 3.16227766016838 | 570.7290020108 | 0 | 90 | 660.7290020108 + 9 | 1 | 1 | 9 | 6 | 2 | 50 | 2.23606797749979 | 662.9650699883 | 0 | 90 | 752.9650699883 + 10 | 1 | 1 | 10 | 9 | 3 | 40 | 2.23606797749979 | 755.2011379658 | 0 | 90 | 845.2011379658 + 11 | 1 | 1 | 11 | 6 | 3 | 20 | 3.60555127546399 | 848.806689241264 | 0 | 90 | 938.806689241264 + 12 | 1 | 1 | 12 | 11 | 3 | 10 | 2 | 940.806689241264 | 0 | 90 | 1030.80668924126 + 13 | 1 | 1 | 13 | 3 | 3 | 0 | 3 | 1033.80668924126 | 0 | 90 | 1123.80668924126 + 14 | 1 | 1 | 14 | -1 | 6 | 0 | 15.8113883008419 | 1139.61807754211 | 0 | 0 | 1139.61807754211 + 15 | 2 | 1 | 1 | -1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 + 16 | 2 | 1 | 2 | 13 | 2 | 30 | 30.8058436014987 | 30.8058436014987 | 0 | 90 | 120.805843601499 + 17 | 2 | 1 | 3 | 13 | 3 | 0 | 4 | 124.805843601499 | 0 | 90 | 214.805843601499 + 18 | 2 | 1 | 4 | 18 | 2 | 20 | 3 | 217.805843601499 | 0 | 90 | 307.805843601499 + 19 | 2 | 1 | 5 | 19 | 2 | 30 | 5 | 312.805843601499 | 0 | 90 | 402.805843601499 + 20 | 2 | 1 | 6 | 19 | 3 | 20 | 5 | 407.805843601499 | 0 | 90 | 497.805843601499 + 21 | 2 | 1 | 7 | 16 | 2 | 60 | 5 | 502.805843601499 | 0 | 90 | 592.805843601499 + 22 | 2 | 1 | 8 | 16 | 3 | 20 | 2 | 594.805843601499 | 0 | 90 | 684.805843601499 + 23 | 2 | 1 | 9 | 18 | 3 | 0 | 3 | 687.805843601499 | 0 | 90 | 777.805843601499 + 24 | 2 | 1 | 10 | 50 | 2 | 10 | 53.0094331227943 | 830.815276724293 | 0 | 90 | 920.815276724293 + 25 | 2 | 1 | 11 | 50 | 3 | 0 | 3.16227766016838 | 923.977554384461 | 0 | 90 | 1013.97755438446 + 26 | 2 | 1 | 12 | 49 | 2 | 10 | 3 | 1016.97755438446 | 0 | 90 | 1106.97755438446 + 27 | 2 | 1 | 13 | 49 | 3 | 0 | 2 | 1108.97755438446 | 0 | 90 | 1198.97755438446 + 28 | 2 | 1 | 14 | -1 | 6 | 0 | 18.0277563773199 | 1217.00531076178 | 0 | 0 | 1217.00531076178 + 29 | 3 | 1 | 1 | -1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 + 30 | 3 | 1 | 2 | 20 | 2 | 10 | 10 | 10 | 0 | 90 | 100 + 31 | 3 | 1 | 3 | 20 | 3 | 0 | 5 | 105 | 0 | 90 | 195 + 32 | 3 | 1 | 4 | 25 | 2 | 40 | 2 | 197 | 0 | 90 | 287 + 33 | 3 | 1 | 5 | 25 | 3 | 0 | 2 | 289 | 0 | 90 | 379 + 34 | 3 | 1 | 6 | 29 | 2 | 10 | 3.60555127546399 | 382.605551275464 | 0 | 90 | 472.605551275464 + 35 | 3 | 1 | 7 | 30 | 2 | 20 | 5 | 477.605551275464 | 0 | 90 | 567.605551275464 + 36 | 3 | 1 | 8 | 28 | 2 | 40 | 3 | 570.605551275464 | 0 | 90 | 660.605551275464 + 37 | 3 | 1 | 9 | 29 | 3 | 30 | 2 | 662.605551275464 | 0 | 90 | 752.605551275464 + 38 | 3 | 1 | 10 | 23 | 2 | 40 | 3 | 755.605551275464 | 0 | 0 | 755.605551275464 + 39 | 3 | 1 | 11 | 23 | 3 | 30 | 0 | 755.605551275464 | 0 | 90 | 845.605551275464 + 40 | 3 | 1 | 12 | 28 | 3 | 10 | 3 | 848.605551275464 | 0 | 90 | 938.605551275464 + 41 | 3 | 1 | 13 | 30 | 3 | 0 | 2 | 940.605551275464 | 0 | 90 | 1030.60555127546 + 42 | 3 | 1 | 14 | -1 | 6 | 0 | 10.1980390271856 | 1040.80359030265 | 0 | 0 | 1040.80359030265 + 43 | 4 | 1 | 1 | -1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 + 44 | 4 | 1 | 2 | 32 | 2 | 30 | 31.6227766016838 | 31.6227766016838 | 0 | 90 | 121.622776601684 + 45 | 4 | 1 | 3 | 33 | 2 | 70 | 2 | 123.622776601684 | 0 | 90 | 213.622776601684 + 46 | 4 | 1 | 4 | 32 | 3 | 40 | 5.3851648071345 | 219.007941408818 | 0 | 90 | 309.007941408818 + 47 | 4 | 1 | 5 | 35 | 2 | 50 | 5 | 314.007941408818 | 0 | 90 | 404.007941408818 + 48 | 4 | 1 | 6 | 33 | 3 | 10 | 5.8309518948453 | 409.838893303664 | 0 | 90 | 499.838893303664 + 49 | 4 | 1 | 7 | 38 | 2 | 40 | 2 | 501.838893303664 | 0 | 90 | 591.838893303664 + 50 | 4 | 1 | 8 | 35 | 3 | 30 | 5 | 596.838893303664 | 0 | 90 | 686.838893303664 + 51 | 4 | 1 | 9 | 36 | 2 | 40 | 5 | 691.838893303664 | 0 | 0 | 691.838893303664 + 52 | 4 | 1 | 10 | 36 | 3 | 30 | 0 | 691.838893303664 | 0 | 90 | 781.838893303664 + 53 | 4 | 1 | 11 | 38 | 3 | 0 | 3 | 784.838893303664 | 0 | 90 | 874.838893303664 + 54 | 4 | 1 | 12 | -1 | 6 | 0 | 32.3882694814033 | 907.227162785067 | 0 | 0 | 907.227162785067 + 55 | 5 | 1 | 1 | -1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 + 56 | 5 | 1 | 2 | 43 | 2 | 10 | 16.5529453572468 | 16.5529453572468 | 0 | 90 | 106.552945357247 + 57 | 5 | 1 | 3 | 42 | 2 | 30 | 3 | 109.552945357247 | 0 | 90 | 199.552945357247 + 58 | 5 | 1 | 4 | 43 | 3 | 20 | 2 | 201.552945357247 | 0 | 90 | 291.552945357247 + 59 | 5 | 1 | 5 | 42 | 3 | 0 | 2 | 293.552945357247 | 0 | 90 | 383.552945357247 + 60 | 5 | 1 | 6 | 44 | 2 | 10 | 3 | 386.552945357247 | 0 | 90 | 476.552945357247 + 61 | 5 | 1 | 7 | 44 | 3 | 0 | 2.82842712474619 | 479.381372481993 | 0 | 90 | 569.381372481993 + 62 | 5 | 1 | 8 | 45 | 2 | 10 | 2 | 571.381372481993 | 0 | 90 | 661.381372481993 + 63 | 5 | 1 | 9 | 45 | 3 | 0 | 2 | 663.381372481993 | 0 | 90 | 753.381372481993 + 64 | 5 | 1 | 10 | 51 | 2 | 10 | 3 | 756.381372481993 | 0 | 0 | 756.381372481993 + 65 | 5 | 1 | 11 | 51 | 3 | 0 | 0 | 756.381372481993 | 0 | 90 | 846.381372481993 + 66 | 5 | 1 | 12 | 66 | 2 | 10 | 22.561028345357 | 868.94240082735 | 0 | 90 | 958.94240082735 + 67 | 5 | 1 | 13 | 66 | 3 | 0 | 2 | 960.94240082735 | 0 | 90 | 1050.94240082735 + 68 | 5 | 1 | 14 | -1 | 6 | 0 | 15.8113883008419 | 1066.75378912819 | 0 | 0 | 1066.75378912819 + 69 | 6 | 1 | 1 | -1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 + 70 | 6 | 1 | 2 | 57 | 2 | 40 | 35 | 35 | 0 | 90 | 125 + 71 | 6 | 1 | 3 | 57 | 3 | 0 | 2 | 127 | 0 | 90 | 217 + 72 | 6 | 1 | 4 | 54 | 2 | 40 | 5 | 222 | 0 | 90 | 312 + 73 | 6 | 1 | 5 | 53 | 2 | 60 | 5.3851648071345 | 317.385164807135 | 0 | 90 | 407.385164807135 + 74 | 6 | 1 | 6 | 56 | 2 | 90 | 4 | 411.385164807135 | 0 | 90 | 501.385164807135 + 75 | 6 | 1 | 7 | 53 | 3 | 70 | 2 | 503.385164807135 | 0 | 90 | 593.385164807135 + 76 | 6 | 1 | 8 | 54 | 3 | 30 | 3 | 596.385164807135 | 0 | 90 | 686.385164807135 + 77 | 6 | 1 | 9 | 56 | 3 | 0 | 10.4403065089106 | 696.825471316045 | 0 | 90 | 786.825471316045 + 78 | 6 | 1 | 10 | -1 | 6 | 0 | 35.0570962859162 | 821.882567601961 | 0 | 0 | 821.882567601961 + 79 | 7 | 1 | 1 | -1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 + 80 | 7 | 1 | 2 | 67 | 2 | 10 | 12.2065556157337 | 12.2065556157337 | 0 | 90 | 102.206555615734 + 81 | 7 | 1 | 3 | 65 | 2 | 20 | 1 | 103.206555615734 | 0 | 90 | 193.206555615734 + 82 | 7 | 1 | 4 | 63 | 2 | 70 | 2 | 195.206555615734 | 0 | 90 | 285.206555615734 + 83 | 7 | 1 | 5 | 62 | 2 | 90 | 5 | 290.206555615734 | 0 | 90 | 380.206555615734 + 84 | 7 | 1 | 6 | 63 | 3 | 40 | 3 | 383.206555615734 | 0 | 90 | 473.206555615734 + 85 | 7 | 1 | 7 | 65 | 3 | 30 | 5 | 478.206555615734 | 0 | 90 | 568.206555615734 + 86 | 7 | 1 | 8 | 67 | 3 | 20 | 3 | 571.206555615734 | 0 | 90 | 661.206555615734 + 87 | 7 | 1 | 9 | 64 | 2 | 30 | 2 | 663.206555615734 | 0 | 0 | 663.206555615734 + 88 | 7 | 1 | 10 | 64 | 3 | 20 | 0 | 663.206555615734 | 0 | 90 | 753.206555615734 + 89 | 7 | 1 | 11 | 62 | 3 | 0 | 3 | 756.206555615734 | 0 | 90 | 846.206555615734 + 90 | 7 | 1 | 12 | -1 | 6 | 0 | 20.6155281280883 | 866.822083743822 | 0 | 0 | 866.822083743822 + 91 | 8 | 1 | 1 | -1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 + 92 | 8 | 1 | 2 | 81 | 2 | 30 | 47.4341649025257 | 47.4341649025257 | 0 | 90 | 137.434164902526 + 93 | 8 | 1 | 3 | 78 | 2 | 50 | 3 | 140.434164902526 | 0 | 0 | 140.434164902526 + 94 | 8 | 1 | 4 | 78 | 3 | 30 | 0 | 140.434164902526 | 0 | 90 | 230.434164902526 + 95 | 8 | 1 | 5 | 76 | 2 | 40 | 2 | 232.434164902526 | 0 | 90 | 322.434164902526 + 96 | 8 | 1 | 6 | 71 | 2 | 60 | 5 | 327.434164902526 | 0 | 90 | 417.434164902526 + 97 | 8 | 1 | 7 | 81 | 3 | 30 | 5 | 422.434164902526 | 0 | 90 | 512.434164902526 + 98 | 8 | 1 | 8 | 76 | 3 | 20 | 3 | 515.434164902526 | 0 | 90 | 605.434164902526 + 99 | 8 | 1 | 9 | 71 | 3 | 0 | 4 | 609.434164902526 | 0 | 90 | 699.434164902526 + 100 | 8 | 1 | 10 | 79 | 2 | 10 | 1 | 700.434164902526 | 0 | 90 | 790.434164902526 + 101 | 8 | 1 | 11 | 79 | 3 | 0 | 5.3851648071345 | 795.81932970966 | 0 | 90 | 885.81932970966 + 102 | 8 | 1 | 12 | -1 | 6 | 0 | 51.478150704935 | 937.297480414595 | 0 | 0 | 937.297480414595 + 103 | 9 | 1 | 1 | -1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 + 104 | 9 | 1 | 2 | 90 | 2 | 10 | 20.6155281280883 | 20.6155281280883 | 0 | 90 | 110.615528128088 + 105 | 9 | 1 | 3 | 87 | 2 | 30 | 5 | 115.615528128088 | 0 | 90 | 205.615528128088 + 106 | 9 | 1 | 4 | 86 | 2 | 40 | 1 | 206.615528128088 | 0 | 90 | 296.615528128088 + 107 | 9 | 1 | 5 | 87 | 3 | 20 | 6 | 302.615528128088 | 0 | 90 | 392.615528128088 + 108 | 9 | 1 | 6 | 82 | 2 | 40 | 3 | 395.615528128088 | 0 | 90 | 485.615528128088 + 109 | 9 | 1 | 7 | 84 | 2 | 60 | 5.8309518948453 | 491.446480022934 | 0 | 90 | 581.446480022934 + 110 | 9 | 1 | 8 | 82 | 3 | 40 | 2.82842712474619 | 584.27490714768 | 0 | 90 | 674.27490714768 + 111 | 9 | 1 | 9 | 90 | 3 | 30 | 3 | 677.27490714768 | 0 | 90 | 767.27490714768 + 112 | 9 | 1 | 10 | 84 | 3 | 10 | 2.82842712474619 | 770.103334272426 | 0 | 90 | 860.103334272426 + 113 | 9 | 1 | 11 | 86 | 3 | 0 | 3.60555127546399 | 863.70888554789 | 0 | 90 | 953.70888554789 + 114 | 9 | 1 | 12 | -1 | 6 | 0 | 22.3606797749979 | 976.069565322888 | 0 | 0 | 976.069565322888 + 115 | 10 | 1 | 1 | -1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 + 116 | 10 | 1 | 2 | 98 | 2 | 20 | 30.8058436014987 | 30.8058436014987 | 0 | 90 | 120.805843601499 + 117 | 10 | 1 | 3 | 96 | 2 | 30 | 5.3851648071345 | 126.191008408633 | 0 | 90 | 216.191008408633 + 118 | 10 | 1 | 4 | 98 | 3 | 10 | 2 | 218.191008408633 | 0 | 90 | 308.191008408633 + 119 | 10 | 1 | 5 | 96 | 3 | 0 | 3.60555127546399 | 311.796559684097 | 0 | 90 | 401.796559684097 + 120 | 10 | 1 | 6 | 92 | 2 | 20 | 3.60555127546399 | 405.402110959561 | 0 | 90 | 495.402110959561 + 121 | 10 | 1 | 7 | 92 | 3 | 0 | 2 | 497.402110959561 | 0 | 90 | 587.402110959561 + 122 | 10 | 1 | 8 | 97 | 2 | 30 | 5 | 592.402110959561 | 0 | 0 | 592.402110959561 + 123 | 10 | 1 | 9 | 97 | 3 | 0 | 0 | 592.402110959561 | 0 | 90 | 682.402110959561 + 124 | 10 | 1 | 10 | 100 | 2 | 20 | 5 | 687.402110959561 | 0 | 90 | 777.402110959561 + 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 +(127 rows) --q2 ROLLBACK; diff --git a/src/pickDeliver/test/test.conf b/src/pickDeliver/test/test.conf index bd0402afe4b..ff1493ca2bb 100644 --- a/src/pickDeliver/test/test.conf +++ b/src/pickDeliver/test/test.conf @@ -17,24 +17,21 @@ )], 'linux' => [qw( doc-pickDeliver + doc-pickDeliverEuclidean + )], 'documentation' => [qw( + doc-pickDeliver doc-pickDeliverEuclidean )], #put here the ones that you are not testing (just a place holder) 'nottesting' => [qw( - doc-pickDeliverEuclidean - doc-pickDeliverEuclidean - jet_customers differentVechiles jet_customers1 - jet_customers - differentVechiles book_from_query - jet_customers1 )] }, ); From 303c15d5b63d2a74ec17aa3a0e8fe32199094d8b Mon Sep 17 00:00:00 2001 From: cvvergara Date: Wed, 17 May 2017 08:21:37 -0500 Subject: [PATCH 37/40] use underscore on the function _pgr_pickDeliver --- sql/pickDeliver/pickDeliver.sql | 2 +- sql/sigs/pgrouting--2.5.0.sig | 2 +- src/pickDeliver/doc/doc-pickDeliver.queries | 2 +- src/pickDeliver/test/doc-pickDeliver.result | 2 +- src/pickDeliver/test/doc-pickDeliver.test.sql | 2 +- tools/sql-update-scripts/pgrouting--2.0.0--2.5.0.sql | 2 +- tools/sql-update-scripts/pgrouting--2.0.1--2.5.0.sql | 2 +- tools/sql-update-scripts/pgrouting--2.1.0--2.5.0.sql | 2 +- tools/sql-update-scripts/pgrouting--2.2.0--2.5.0.sql | 2 +- tools/sql-update-scripts/pgrouting--2.2.1--2.5.0.sql | 2 +- tools/sql-update-scripts/pgrouting--2.2.2--2.5.0.sql | 2 +- tools/sql-update-scripts/pgrouting--2.2.3--2.5.0.sql | 2 +- tools/sql-update-scripts/pgrouting--2.2.4--2.5.0.sql | 2 +- tools/sql-update-scripts/pgrouting--2.3.0--2.5.0.sql | 2 +- tools/sql-update-scripts/pgrouting--2.3.1--2.5.0.sql | 2 +- tools/sql-update-scripts/pgrouting--2.3.2--2.5.0.sql | 2 +- tools/sql-update-scripts/pgrouting--2.4.0--2.5.0.sql | 2 +- tools/sql-update-scripts/pgrouting--2.4.1--2.5.0.sql | 2 +- tools/sql-update-scripts/pgrouting--2.5.0.sql | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) diff --git a/sql/pickDeliver/pickDeliver.sql b/sql/pickDeliver/pickDeliver.sql index 1062ff87de2..4657122db6b 100644 --- a/sql/pickDeliver/pickDeliver.sql +++ b/sql/pickDeliver/pickDeliver.sql @@ -27,7 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -CREATE OR REPLACE FUNCTION pgr_pickDeliver( +CREATE OR REPLACE FUNCTION _pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, diff --git a/sql/sigs/pgrouting--2.5.0.sig b/sql/sigs/pgrouting--2.5.0.sig index d99384d07be..afa06a5aaaa 100644 --- a/sql/sigs/pgrouting--2.5.0.sig +++ b/sql/sigs/pgrouting--2.5.0.sig @@ -130,7 +130,7 @@ _pgr_onerror(boolean,integer,text,text,text,text) _pgr_parameter_check(text,text,boolean) _pgr_pickdelivereuclidean(text,text,double precision,integer,integer) _pgr_pickdeliver(text,integer,double precision,double precision,integer) -pgr_pickdeliver(text,text,text,double precision,integer,integer) +_pgr_pickdeliver(text,text,text,double precision,integer,integer) pgr_pointsaspolygon(character varying,double precision) pgr_pointstodmatrix(geometry[],integer) pgr_pointstovids(geometry[],text,double precision) diff --git a/src/pickDeliver/doc/doc-pickDeliver.queries b/src/pickDeliver/doc/doc-pickDeliver.queries index 8f30ef50f4d..f5a878e4f0c 100644 --- a/src/pickDeliver/doc/doc-pickDeliver.queries +++ b/src/pickDeliver/doc/doc-pickDeliver.queries @@ -89,7 +89,7 @@ ORDER BY start_vid, end_vid; (6 rows) --q1 -SELECT * FROM pgr_pickDeliver( +SELECT * FROM _pgr_pickDeliver( 'SELECT * FROM orders ORDER BY id', 'SELECT * from vehicles', diff --git a/src/pickDeliver/test/doc-pickDeliver.result b/src/pickDeliver/test/doc-pickDeliver.result index 4a7acba6640..4924e30bafa 100644 --- a/src/pickDeliver/test/doc-pickDeliver.result +++ b/src/pickDeliver/test/doc-pickDeliver.result @@ -89,7 +89,7 @@ ORDER BY start_vid, end_vid; (6 rows) --q1 -SELECT * FROM pgr_pickDeliver( +SELECT * FROM _pgr_pickDeliver( 'SELECT * FROM orders ORDER BY id', 'SELECT * from vehicles', diff --git a/src/pickDeliver/test/doc-pickDeliver.test.sql b/src/pickDeliver/test/doc-pickDeliver.test.sql index d8a7a9fe73b..dda640ada7f 100644 --- a/src/pickDeliver/test/doc-pickDeliver.test.sql +++ b/src/pickDeliver/test/doc-pickDeliver.test.sql @@ -17,7 +17,7 @@ ORDER BY start_vid, end_vid; \echo --q1 -- using the default values -SELECT * FROM pgr_pickDeliver( +SELECT * FROM _pgr_pickDeliver( 'SELECT * FROM orders ORDER BY id', 'SELECT * from vehicles', -- matrix query diff --git a/tools/sql-update-scripts/pgrouting--2.0.0--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.0.0--2.5.0.sql index e5a71c69201..34fbfdc7fd9 100644 --- a/tools/sql-update-scripts/pgrouting--2.0.0--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.0.0--2.5.0.sql @@ -3216,7 +3216,7 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( -CREATE OR REPLACE FUNCTION pgr_pickDeliver( +CREATE OR REPLACE FUNCTION _pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, diff --git a/tools/sql-update-scripts/pgrouting--2.0.1--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.0.1--2.5.0.sql index 33585005727..f1222fe9338 100644 --- a/tools/sql-update-scripts/pgrouting--2.0.1--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.0.1--2.5.0.sql @@ -3216,7 +3216,7 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( -CREATE OR REPLACE FUNCTION pgr_pickDeliver( +CREATE OR REPLACE FUNCTION _pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, diff --git a/tools/sql-update-scripts/pgrouting--2.1.0--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.1.0--2.5.0.sql index d277e1971c6..e85b432143e 100644 --- a/tools/sql-update-scripts/pgrouting--2.1.0--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.1.0--2.5.0.sql @@ -3314,7 +3314,7 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( -CREATE OR REPLACE FUNCTION pgr_pickDeliver( +CREATE OR REPLACE FUNCTION _pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, diff --git a/tools/sql-update-scripts/pgrouting--2.2.0--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.2.0--2.5.0.sql index 7a3d53aca0f..f7c298f068a 100644 --- a/tools/sql-update-scripts/pgrouting--2.2.0--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.2.0--2.5.0.sql @@ -3168,7 +3168,7 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( -CREATE OR REPLACE FUNCTION pgr_pickDeliver( +CREATE OR REPLACE FUNCTION _pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, diff --git a/tools/sql-update-scripts/pgrouting--2.2.1--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.2.1--2.5.0.sql index 6013d13fdd9..6c9357e050a 100644 --- a/tools/sql-update-scripts/pgrouting--2.2.1--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.2.1--2.5.0.sql @@ -3168,7 +3168,7 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( -CREATE OR REPLACE FUNCTION pgr_pickDeliver( +CREATE OR REPLACE FUNCTION _pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, diff --git a/tools/sql-update-scripts/pgrouting--2.2.2--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.2.2--2.5.0.sql index f4f70c6d5e9..e62fdffa09c 100644 --- a/tools/sql-update-scripts/pgrouting--2.2.2--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.2.2--2.5.0.sql @@ -3168,7 +3168,7 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( -CREATE OR REPLACE FUNCTION pgr_pickDeliver( +CREATE OR REPLACE FUNCTION _pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, diff --git a/tools/sql-update-scripts/pgrouting--2.2.3--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.2.3--2.5.0.sql index 12f24e92c21..42e0e3b8d09 100644 --- a/tools/sql-update-scripts/pgrouting--2.2.3--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.2.3--2.5.0.sql @@ -3168,7 +3168,7 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( -CREATE OR REPLACE FUNCTION pgr_pickDeliver( +CREATE OR REPLACE FUNCTION _pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, diff --git a/tools/sql-update-scripts/pgrouting--2.2.4--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.2.4--2.5.0.sql index cadc002ea8b..7ab80e0d1f9 100644 --- a/tools/sql-update-scripts/pgrouting--2.2.4--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.2.4--2.5.0.sql @@ -3168,7 +3168,7 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( -CREATE OR REPLACE FUNCTION pgr_pickDeliver( +CREATE OR REPLACE FUNCTION _pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, diff --git a/tools/sql-update-scripts/pgrouting--2.3.0--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.3.0--2.5.0.sql index b463b7f2d1f..db6bdddb005 100644 --- a/tools/sql-update-scripts/pgrouting--2.3.0--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.3.0--2.5.0.sql @@ -3198,7 +3198,7 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( -CREATE OR REPLACE FUNCTION pgr_pickDeliver( +CREATE OR REPLACE FUNCTION _pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, diff --git a/tools/sql-update-scripts/pgrouting--2.3.1--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.3.1--2.5.0.sql index ab2e5ecbcac..c3953ee9555 100644 --- a/tools/sql-update-scripts/pgrouting--2.3.1--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.3.1--2.5.0.sql @@ -3198,7 +3198,7 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( -CREATE OR REPLACE FUNCTION pgr_pickDeliver( +CREATE OR REPLACE FUNCTION _pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, diff --git a/tools/sql-update-scripts/pgrouting--2.3.2--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.3.2--2.5.0.sql index 68f9aa84029..eb8cc61be72 100644 --- a/tools/sql-update-scripts/pgrouting--2.3.2--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.3.2--2.5.0.sql @@ -3198,7 +3198,7 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( -CREATE OR REPLACE FUNCTION pgr_pickDeliver( +CREATE OR REPLACE FUNCTION _pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, diff --git a/tools/sql-update-scripts/pgrouting--2.4.0--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.4.0--2.5.0.sql index d34b936751c..640ae711106 100644 --- a/tools/sql-update-scripts/pgrouting--2.4.0--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.4.0--2.5.0.sql @@ -3159,7 +3159,7 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( -CREATE OR REPLACE FUNCTION pgr_pickDeliver( +CREATE OR REPLACE FUNCTION _pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, diff --git a/tools/sql-update-scripts/pgrouting--2.4.1--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.4.1--2.5.0.sql index 5dbf598cdcd..cf9876df4eb 100644 --- a/tools/sql-update-scripts/pgrouting--2.4.1--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.4.1--2.5.0.sql @@ -3159,7 +3159,7 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( -CREATE OR REPLACE FUNCTION pgr_pickDeliver( +CREATE OR REPLACE FUNCTION _pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, diff --git a/tools/sql-update-scripts/pgrouting--2.5.0.sql b/tools/sql-update-scripts/pgrouting--2.5.0.sql index ade8c0b3104..b5b93270adf 100644 --- a/tools/sql-update-scripts/pgrouting--2.5.0.sql +++ b/tools/sql-update-scripts/pgrouting--2.5.0.sql @@ -3066,7 +3066,7 @@ CREATE OR REPLACE FUNCTION pgr_contractGraph( -CREATE OR REPLACE FUNCTION pgr_pickDeliver( +CREATE OR REPLACE FUNCTION _pgr_pickDeliver( orders_sql TEXT, vehicles_sql TEXT, matrix_cell_sql TEXT, From 0caa19724c78c77d2077746fda2a51bad917988e Mon Sep 17 00:00:00 2001 From: cvvergara Date: Wed, 17 May 2017 09:48:46 -0500 Subject: [PATCH 38/40] adding a category VRP --- doc/conf.py.in | 3 - doc/src/pgRouting-concepts.rst | 18 ++- doc/src/proposed.rst | 17 +-- src/pickDeliver/doc/VRP-category.rst | 120 ++++++++++++++++++ .../doc/pgr_pickDeliverEuclidean.rst | 20 +-- .../pgtap/pickDeliverEuclidean-innerquery.sql | 10 +- 6 files changed, 160 insertions(+), 28 deletions(-) create mode 100644 src/pickDeliver/doc/VRP-category.rst diff --git a/doc/conf.py.in b/doc/conf.py.in index 08d7fee619d..4150b4e09da 100644 --- a/doc/conf.py.in +++ b/doc/conf.py.in @@ -71,9 +71,6 @@ gettext_compact = False exclude_patterns = [ 'doc/build', 'pgr_withPointsVia.rst', - 'pgr_pickDeliver.rst', - 'pgr_pickDeliverEuclidean.rst', - 'src/pickDeliver', 'maxFlowApplications.rst', '*/notUsed', 'tools/template' diff --git a/doc/src/pgRouting-concepts.rst b/doc/src/pgRouting-concepts.rst index 070b061bd2c..0efa13dfeec 100644 --- a/doc/src/pgRouting-concepts.rst +++ b/doc/src/pgRouting-concepts.rst @@ -354,15 +354,21 @@ Where: .. points_sql_end +.. pd_sql_start + +.. note:: TODO: Matrix version orders_sql + +.. pd_sql_end + .. pd_euclidean_sql_start -.. note TODO +.. note:: TODO: Euclidean version orders_sql .. pd_euclidean_sql_end .. pd_vehicle_sql_start -.. note TODO +.. note:: TODO: VRP vehicles_sql .. pd_vehicle_sql_end @@ -435,9 +441,15 @@ Column Type Description .. result_flow_end +.. return_vrp_euclidean_start + +.. note:: TODO: Eucliden version return + +.. return_vrp_euclidean_end + .. return_vrp_start -.. note:: TODO +.. note:: TODO: Matrix version return .. return_vrp_end diff --git a/doc/src/proposed.rst b/doc/src/proposed.rst index 7296273e10a..9799c343049 100644 --- a/doc/src/proposed.rst +++ b/doc/src/proposed.rst @@ -138,12 +138,12 @@ Experimental and Proposed functions - :ref:`pgr_labelGraph` - Analyze / label subgraphs within a network -.. rubric:: Vehicle Routing Problems -- :ref:`pgr_gsocvrppdtw` - VRP Pickup & Delivery (Euclidean) -- :ref:`pgr_vrp_basic` - VRP One Depot +:ref:`VRP` -.. TODO deprecate pgr_gsocvrppdtw +.. include:: VRP-category.rst + :start-after: index from here + :end-before: index to here .. toctree:: :hidden: @@ -151,13 +151,7 @@ Experimental and Proposed functions contraction-family flow-family pgr_labelGraph - pgr_gsoc_vrppdtw - pgr_vrpOneDepot - - - - - + VRP-category @@ -169,6 +163,5 @@ Experimental and Proposed functions :hidden: .. ../src/funnyDijkstra/doc/pgr_funnyDijkstra.rst - - :ref:`pgr_pickDeliverEuclidean` - VRP Pickup & Delivery with Euclidean distances pgr_pickDeliverEuclidean diff --git a/src/pickDeliver/doc/VRP-category.rst b/src/pickDeliver/doc/VRP-category.rst new file mode 100644 index 00000000000..01c88537a1c --- /dev/null +++ b/src/pickDeliver/doc/VRP-category.rst @@ -0,0 +1,120 @@ +.. + **************************************************************************** + pgRouting Manual + Copyright(c) pgRouting Contributors + + This documentation is licensed under a Creative Commons Attribution-Share + Alike 3.0 License: http://creativecommons.org/licenses/by-sa/3.0/ + **************************************************************************** + +.. _VRP: + +Vehicle Routing Functions Category: +=============================================================================== + + +.. include:: proposed.rst + :start-after: begin-warn-expr + :end-before: end-warn-expr + +.. index from here +.. rubric:: Pickup and delivery problem + +- :ref:`pgr_pickDeliver` - Pickup & Delivery using a Cost Matrix +- :ref:`pgr_pickDeliverEuclidean` - Pickup & Delivery with Euclidean distances +- :ref:`pgr_gsocvrppdtw` - VRP Pickup & Delivery (Euclidean) + +.. rubric:: Delivery prolem + +- :ref:`pgr_vrp_basic` - VRP One Depot + +.. index to here + +.. toctree:: + :hidden: + + pgr_pickDeliver + pgr_pickDeliverEuclidean + pgr_gsoc_vrppdtw + pgr_vrpOneDepot + + +Introduction +------------------------------------------------------------------------------- + + +.. note:: TODO + +.. rubric:: The following is a sketch + +Problem: Distribute and optimize the pickup-delivery pairs into a fleet of vehicles. + +- Optimization problem is NP-hard. +- Pickup and Delivery: + + - capacitated + - with time windows. + +- The vehicles + + - have (x, y) start and ending locations. + - have a start and ending service times. + - have opening and closing times for the start and ending locations. + +- An order is for doing a pickup and a a deliver. + + - has (x, y) pickup and delivery locations. + - has opening and closing times for the pickup and delivery locations. + - has a pickup and deliver service times. + +- There is a customer where to deliver a pickup. + + - travel time between customers is distance / speed + - pickup and delivery pair is done with the same vehicle. + - A pickup is done before the delivery. + + + +Characteristics: +---------------- + +- No multiple time windows for a location. +- Less vehicle used is considered better. +- Less total duration is better. +- Less wait time is better. +- Six different optional different initial solutions + + +Description of the parameters of the signatures +............................................................................... + +================= ================== ========= ================================================= +Column Type Default Description +================= ================== ========= ================================================= +**orders_sql** ``TEXT`` Orders SQL query as described above. +**vehicles_sql** ``TEXT`` Vehciles SQL query as described above. +**factor** ``NUMERIC`` 1 multiplier for the travel time +**max_cycles** ``INTEGER`` 10 Array of identifiers of starting vertices. +**initial_sol** ``INTEGER`` 4 Identifier of the ending vertex of the path. + + * ``1`` One order per truck + * ``2`` push front + * ``3`` push back + * ``4`` best insert + * ``5`` order that allows more orders to be inserted at the back + * ``6`` order that allows more orders to be inserted at the front + +================= ================== ========= ================================================= + + +See Also +------------------------------------------------------------------------------- + +* http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm +* The queries use the :ref:`sampledata` network. + +.. rubric:: Indices and tables + +* :ref:`genindex` +* :ref:`search` + diff --git a/src/pickDeliver/doc/pgr_pickDeliverEuclidean.rst b/src/pickDeliver/doc/pgr_pickDeliverEuclidean.rst index cf9324cf194..234236bc972 100644 --- a/src/pickDeliver/doc/pgr_pickDeliverEuclidean.rst +++ b/src/pickDeliver/doc/pgr_pickDeliverEuclidean.rst @@ -9,9 +9,11 @@ .. _pgr_pickDeliverEuclidean: -pgr_pickDeliverEuclidean: +__pgr_pickDeliverEuclidean: =============================================================================== +.. warning:: Under development: Changes in code/documentation are without notice + .. include:: proposed.rst :start-after: begin-warn-expr :end-before: end-warn-expr @@ -25,8 +27,8 @@ Problem: Distribute and optimize the pickup-delivery pairs into a fleet of vehic - Optimization problem is NP-hard. - Pickup and Delivery: - - capacitated - - with time windows. + - capacitated + - with time windows. - The vehicles @@ -65,14 +67,13 @@ Signature Summary .. code-block:: none - _pgr_pickDeliverEuclidean(orders_sql, vehicles_sql, max_cycles, initial) + _pgr_pickDeliverEuclidean(orders_sql, vehicles_sql, [,factor, max_cycles, initial_sol]) RETURNS SET OF (seq, vehicle_number, vehicle_id, stop, order_id, stop_type, cargo, travel_time, arrival_time, wait_time, service_time, departure_time) - Signatures ------------------------------------------------------------------------------- @@ -85,15 +86,15 @@ pgr_pickDeliverEuclidean(Complete Signature) .. code-block:: none - _pgr_pickDeliverEuclidean(orders_sql, vehicles_sql [, max_cycles, initial]) + _pgr_pickDeliverEuclidean(orders_sql, vehicles_sql [,factor , max_cycles, initial_sol]) RETURNS SET OF (seq, vehicle_number, vehicle_id, stop, order_id, stop_type, cargo, travel_time, arrival_time, wait_time, service_time, departure_time) :Example: .. literalinclude:: ./doc-pickDeliverEuclidean.queries - :start-after: --q2 - :end-before: --q3 + :start-after: --q1 + :end-before: --q2 Description of the Signatures @@ -115,8 +116,9 @@ Description of the parameters of the signatures ================= ================== ========= ================================================= Column Type Default Description ================= ================== ========= ================================================= -**orders_sql** ``TEXT`` Orders SQL query as described above. +**orders_sql** ``TEXT`` Orders SQL query as described above. **vehicles_sql** ``TEXT`` Vehciles SQL query as described above. +**factor** ``NUMERIC`` 10 Array of identifiers of starting vertices. **max_cycles** ``INTEGER`` 10 Array of identifiers of starting vertices. **initial** ``INTEGER`` 4 Identifier of the ending vertex of the path. diff --git a/src/pickDeliver/test/pgtap/pickDeliverEuclidean-innerquery.sql b/src/pickDeliver/test/pgtap/pickDeliverEuclidean-innerquery.sql index e1f60a438bb..76ff4a7445d 100644 --- a/src/pickDeliver/test/pgtap/pickDeliverEuclidean-innerquery.sql +++ b/src/pickDeliver/test/pgtap/pickDeliverEuclidean-innerquery.sql @@ -1,6 +1,6 @@ \i setup.sql -SELECT plan(92); +SELECT plan(94); SET client_min_messages TO ERROR; /* A call looks like this @@ -11,6 +11,14 @@ SELECT * INTO pickDeliverResults FROM _pgr_pickdeliverEuclidean( 30); */ +SELECT todo(2); +SELECT has_function('pgr_pickdelivereuclidean', + ARRAY['text', 'text', 'numeric', 'integer', 'integer']); + +SELECT function_returns('pgr_pickdelivereuclidean', + ARRAY['text', 'text', 'numeric', 'integer', 'integer'], + 'setof record'); + SELECT has_function('_pgr_pickdelivereuclidean', ARRAY['text', 'text', 'double precision', 'integer', 'integer']); From 965859e45a5573729b04cf6dfa64d9e97ffd3f30 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Wed, 17 May 2017 10:38:24 -0500 Subject: [PATCH 39/40] generate hidden initial user documentation for pick delivery --- doc/src/pgRouting-concepts.rst | 33 ---- doc/src/proposed.rst | 1 - src/pickDeliver/doc/VRP-category.rst | 157 +++++++++++++++++- src/pickDeliver/doc/pgr_pickDeliver.rst | 80 ++------- .../doc/pgr_pickDeliverEuclidean.rst | 36 +--- 5 files changed, 181 insertions(+), 126 deletions(-) diff --git a/doc/src/pgRouting-concepts.rst b/doc/src/pgRouting-concepts.rst index 0efa13dfeec..3295c1c50da 100644 --- a/doc/src/pgRouting-concepts.rst +++ b/doc/src/pgRouting-concepts.rst @@ -354,26 +354,6 @@ Where: .. points_sql_end -.. pd_sql_start - -.. note:: TODO: Matrix version orders_sql - -.. pd_sql_end - -.. pd_euclidean_sql_start - -.. note:: TODO: Euclidean version orders_sql - -.. pd_euclidean_sql_end - -.. pd_vehicle_sql_start - -.. note:: TODO: VRP vehicles_sql - -.. pd_vehicle_sql_end - - - .. _return_values: Return columns & values @@ -441,19 +421,6 @@ Column Type Description .. result_flow_end -.. return_vrp_euclidean_start - -.. note:: TODO: Eucliden version return - -.. return_vrp_euclidean_end - -.. return_vrp_start - -.. note:: TODO: Matrix version return - -.. return_vrp_end - - .. _advanced_topics: Advanced Topics diff --git a/doc/src/proposed.rst b/doc/src/proposed.rst index 9799c343049..fb9b8dd69ec 100644 --- a/doc/src/proposed.rst +++ b/doc/src/proposed.rst @@ -163,5 +163,4 @@ Experimental and Proposed functions :hidden: .. ../src/funnyDijkstra/doc/pgr_funnyDijkstra.rst - pgr_pickDeliverEuclidean diff --git a/src/pickDeliver/doc/VRP-category.rst b/src/pickDeliver/doc/VRP-category.rst index 01c88537a1c..a56b28b84ea 100644 --- a/src/pickDeliver/doc/VRP-category.rst +++ b/src/pickDeliver/doc/VRP-category.rst @@ -85,6 +85,94 @@ Characteristics: - Six different optional different initial solutions + +Inner Queries +------------- + +.. pd_matrix_sql_start + +.. warning:: TODO: FIX becuase the following is outdated + +Description of the orders_sql query +......................................................................................... + +================ =================== ================================================= +Column Type Description +================ =================== ================================================= +**id** ``ANY-INTEGER`` Identifier of the customer. + + - A value of ``0`` identifies the starting location + +**demand** ``ANY-NUMERICAL`` How much is added / removed from the vehicle. + + - Negative value is a delivery, + - Positive value is a pickup, + +**openTime** ``ANY-NUMERICAL`` The time relative to 0, when the customer opens. +**closeTime** ``ANY-NUMERICAL`` The time relative to 0, when the customer closes. +**serviceTime** ``ANY-NUMERICAL`` The duration of the loading / unloading. +**pickup_id** ``ANY-INTEGER`` Value used when the current customer is a Delivery to find the corresponding Pickup +**deliver_id** ``ANY-INTEGER`` Value used when the current customer is a Pickup to find the corresponding Delivery +================ =================== ================================================= + +Where: + +:ANY-INTEGER: SMALLINT, INTEGER, BIGINT +:ANY-NUMERICAL: SMALLINT, INTEGER, BIGINT, REAL, FLOAT + + +.. pd_matrix_sql_end + +.. pd_euclidean_sql_start + +.. warning:: TODO: FIX becuase the following is outdated + +Description of the orders_sql query +......................................................................................... + +================ =================== ================================================= +Column Type Description +================ =================== ================================================= +**id** ``ANY-INTEGER`` Identifier of the customer. + + - A value of ``0`` identifies the starting location + +**x** ``ANY-NUMERICAL`` ``X`` coordinate of the location. +**y** ``ANY-NUMERICAL`` ``Y`` coordinate of the location. +**demand** ``ANY-NUMERICAL`` How much is added / removed from the vehicle. + + - Negative value is a delivery, + - Positive value is a pickup, + +**openTime** ``ANY-NUMERICAL`` The time relative to 0, when the customer opens. +**closeTime** ``ANY-NUMERICAL`` The time relative to 0, when the customer closes. +**serviceTime** ``ANY-NUMERICAL`` The duration of the loading / unloading. +**pickup_id** ``ANY-INTEGER`` Value used when the current customer is a Delivery to find the corresponding Pickup +**deliver_id** ``ANY-INTEGER`` Value used when the current customer is a Pickup to find the corresponding Delivery +================ =================== ================================================= + +Where: + +:ANY-INTEGER: SMALLINT, INTEGER, BIGINT +:ANY-NUMERICAL: SMALLINT, INTEGER, BIGINT, REAL, FLOAT + + +.. pd_euclidean_sql_end + +.. pd_vehicle_sql_start + +.. warning:: TODO: Write + + +Description of the vehicles_sql query +......................................................................................... + +.. pd_vehicle_sql_end + +.. pd_parameters_start + +.. warning:: TODO: FIX becuase the following is outdated + Description of the parameters of the signatures ............................................................................... @@ -93,9 +181,9 @@ Column Type Default Description ================= ================== ========= ================================================= **orders_sql** ``TEXT`` Orders SQL query as described above. **vehicles_sql** ``TEXT`` Vehciles SQL query as described above. -**factor** ``NUMERIC`` 1 multiplier for the travel time +**factor** ``NUMERIC`` 1 $multiplier for the travel time **max_cycles** ``INTEGER`` 10 Array of identifiers of starting vertices. -**initial_sol** ``INTEGER`` 4 Identifier of the ending vertex of the path. +**initial** ``INTEGER`` 4 Identifier of the ending vertex of the path. * ``1`` One order per truck * ``2`` push front @@ -106,11 +194,74 @@ Column Type Default Description ================= ================== ========= ================================================= +.. pd_parameters_end + + +Results +--------- + +.. return_vrp_euclidean_start + +.. warning:: TODO: FIX becuase the following is outdated + +Description of the result +......................................................................................... + +:RETURNS SET OF: (seq, vehicle_id, vehicle_seq, stop_id, travel_time, arrival_time, wait_time, service_time, departure_time) + +=================== ============= ================================================= +Column Type Description +=================== ============= ================================================= +**seq** INTEGER Sequential value starting from **1**. +**vehicle_id** INTEGER Current vehicle identifier. +**vehicle_seq** INTEGER Sequential value starting from **1** for the current vehicle. +**stop_id** BIGINT Visited customer identifier. +**travel_time** FLOAT Travel time from previous ``stop_id`` to current ``stop_id``. +**arrival_time** FLOAT Previous ``departure_time`` plus current ``travel_time``. +**wait_time** FLOAT Time spent waiting for ``stop_id`` to open. +**service_time** FLOAT Service time at current stop_id. +**departure_time** FLOAT Previous :math:`departure\_time + travel\_time + wait\_time + service\_time`. + - When ``stop_id = 0`` and ``vehicle_seq != 1`` has the total time for the current ``vehicle_id``. + - When ``vehicle_id = -1`` has the aggregate total time +=================== ============= ================================================= + + +.. return_vrp_euclidean_end + +.. return_vrp_matrix_start + +.. warning:: TODO: FIX becuase the following is outdated + +Description of the result +......................................................................................... + +:RETURNS SET OF: (seq, vehicle_id, vehicle_seq, stop_id, travel_time, arrival_time, wait_time, service_time, departure_time) + +=================== ============= ================================================= +Column Type Description +=================== ============= ================================================= +**seq** INTEGER Sequential value starting from **1**. +**vehicle_id** INTEGER Current vehicle identifier. +**vehicle_seq** INTEGER Sequential value starting from **1** for the current vehicle. +**stop_id** BIGINT Visited customer identifier. +**travel_time** FLOAT Travel time from previous ``stop_id`` to current ``stop_id``. +**arrival_time** FLOAT Previous ``departure_time`` plus current ``travel_time``. +**wait_time** FLOAT Time spent waiting for ``stop_id`` to open. +**service_time** FLOAT Service time at current stop_id. +**departure_time** FLOAT Previous :math:`departure\_time + travel\_time + wait\_time + service\_time`. + - When ``stop_id = 0`` and ``vehicle_seq != 1`` has the total time for the current ``vehicle_id``. + - When ``vehicle_id = -1`` has the aggregate total time +=================== ============= ================================================= + +.. return_vrp_matrix_end + + + See Also ------------------------------------------------------------------------------- -* http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm +* https://en.wikipedia.org/wiki/Vehicle_routing_problem * The queries use the :ref:`sampledata` network. .. rubric:: Indices and tables diff --git a/src/pickDeliver/doc/pgr_pickDeliver.rst b/src/pickDeliver/doc/pgr_pickDeliver.rst index 7b455f21ab4..21c5063f8c0 100644 --- a/src/pickDeliver/doc/pgr_pickDeliver.rst +++ b/src/pickDeliver/doc/pgr_pickDeliver.rst @@ -79,9 +79,9 @@ Signature Summary .. code-block:: none _pgr_pickDeliver(customers_sql, max_vehicles, capacity) - _pgr_pickDeliver(customers_sql, max_vehicles, capacity, speed, max_cycles) - RETURNS SET OF (seq, vehicle_id, vehicle_seq, stop_id, - travel_time, arrival_time, wait_time, service_time, departure_time) + _pgr_pickDeliver(customers_sql, max_vehicles, capacity, [factor, max_cycles, initial_sol]) + RETURNS SET OF (seq, vehicle_number, vehicle_id, stop, order_id, stop_type, cargo, + travel_time, arrival_time, wait_time, service_time, departure_time) @@ -146,75 +146,31 @@ Description of the Signatures ------------------------------- -Description of the customers_sql query -......................................................................................... - -================ =================== ================================================= -Column Type Description -================ =================== ================================================= -**id** ``ANY-INTEGER`` Identifier of the customer. - - - A value of ``0`` identifies the starting location - -**x** ``ANY-NUMERICAL`` ``X`` coordinate of the location. -**y** ``ANY-NUMERICAL`` ``Y`` coordinate of the location. -**demand** ``ANY-NUMERICAL`` How much is added / removed from the vehicle. - - - Negative value is a delivery, - - Positive value is a pickup, +.. include:: VRP-category.rst + :start-after: pd_matrix_sql_start + :end-before: pd_matrix_sql_end -**openTime** ``ANY-NUMERICAL`` The time relative to 0, when the customer opens. -**closeTime** ``ANY-NUMERICAL`` The time relative to 0, when the customer closes. -**serviceTime** ``ANY-NUMERICAL`` The duration of the loading / unloading. -**pickup_id** ``ANY-INTEGER`` Value used when the current customer is a Delivery to find the corresponding Pickup -**deliver_id** ``ANY-INTEGER`` Value used when the current customer is a Pickup to find the corresponding Delivery -================ =================== ================================================= -Where: +.. include:: VRP-category.rst + :start-after: pd_vehicle_sql_start + :end-before: pd_vehicle_sql_end -:ANY-INTEGER: SMALLINT, INTEGER, BIGINT -:ANY-NUMERICAL: SMALLINT, INTEGER, BIGINT, REAL, FLOAT +.. include:: VRP-category.rst + :start-after: pd_parameters_start + :end-before: pd_parameters_end -Description of the parameters of the signatures -......................................................................................... - -================== =========== ======== ================================================= -Column Type Default Description -================== =========== ======== ================================================= -**customers_sql** ``TEXT`` SQL query as described above. -**max_vehicles** ``INTEGER`` Maximum number of vehicles in the result. (currently is ignored) -**capacity** ``FLOAT`` Capacity of the vehicle. -**speed** ``FLOAT`` 1 Speed of the vehicle. -**max_cycles** ``INTEGER`` 30 A multiplier for internal cycles (currently is ignored) -================== =========== ======== ================================================= - -Description of the result -......................................................................................... - -:RETURNS SET OF: (seq, vehicle_id, vehicle_seq, stop_id, travel_time, arrival_time, wait_time, service_time, departure_time) - -=================== ============= ================================================= -Column Type Description -=================== ============= ================================================= -**seq** INTEGER Sequential value starting from **1**. -**vehicle_id** INTEGER Current vehicle identifier. -**vehicle_seq** INTEGER Sequential value starting from **1** for the current vehicle. -**stop_id** BIGINT Visited customer identifier. -**travel_time** FLOAT Travel time from previous ``stop_id`` to current ``stop_id``. -**arrival_time** FLOAT Previous ``departure_time`` plus current ``travel_time``. -**wait_time** FLOAT Time spent waiting for ``stop_id`` to open. -**service_time** FLOAT Service time at current stop_id. -**departure_time** FLOAT Previous :math:`departure\_time + travel\_time + wait\_time + service\_time`. - - When ``stop_id = 0`` and ``vehicle_seq != 1`` has the total time for the current ``vehicle_id``. - - When ``vehicle_id = -1`` has the aggregate total time -=================== ============= ================================================= - +.. include:: VRP-category.rst + :start-after: return_vrp_matrix_start + :end-before: return_vrp_matrix_end See Also ------------------------------------------------------------------------------- +* :ref:`VRP` +* The queries use the :ref:`sampledata` network. + .. rubric:: Indices and tables * :ref:`genindex` diff --git a/src/pickDeliver/doc/pgr_pickDeliverEuclidean.rst b/src/pickDeliver/doc/pgr_pickDeliverEuclidean.rst index 234236bc972..1aefe1d81c5 100644 --- a/src/pickDeliver/doc/pgr_pickDeliverEuclidean.rst +++ b/src/pickDeliver/doc/pgr_pickDeliverEuclidean.rst @@ -100,48 +100,30 @@ pgr_pickDeliverEuclidean(Complete Signature) Description of the Signatures ------------------------------------------------------------------------------- -.. include:: pgRouting-concepts.rst +.. include:: VRP-category.rst :start-after: pd_euclidean_sql_start :end-before: pd_euclidean_sql_end -.. include:: pgRouting-concepts.rst +.. include:: VRP-category.rst :start-after: pd_vehicle_sql_start :end-before: pd_vehicle_sql_end -Description of the parameters of the signatures -............................................................................... +.. include:: VRP-category.rst + :start-after: pd_parameters_start + :end-before: pd_parameters_end -================= ================== ========= ================================================= -Column Type Default Description -================= ================== ========= ================================================= -**orders_sql** ``TEXT`` Orders SQL query as described above. -**vehicles_sql** ``TEXT`` Vehciles SQL query as described above. -**factor** ``NUMERIC`` 10 Array of identifiers of starting vertices. -**max_cycles** ``INTEGER`` 10 Array of identifiers of starting vertices. -**initial** ``INTEGER`` 4 Identifier of the ending vertex of the path. - - * ``1`` One order per truck - * ``2`` push front - * ``3`` push back - * ``4`` best insert - * ``5`` order that allows more orders to be inserted at the back - * ``6`` order that allows more orders to be inserted at the front - -================= ================== ========= ================================================= - - -.. include:: pgRouting-concepts.rst - :start-after: return_vrp_start - :end-before: return_vrp_end +.. include:: VRP-category.rst + :start-after: return_vrp_euclidean_start + :end-before: return_vrp_euclidean_end See Also ------------------------------------------------------------------------------- -* http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm +* :ref:`VRP` * The queries use the :ref:`sampledata` network. .. rubric:: Indices and tables From a8d689b76c09828ced9fb83b2a5a55375df261d7 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Wed, 17 May 2017 10:46:01 -0500 Subject: [PATCH 40/40] linted pickDelive --- include/vrp/node.h | 6 +++--- include/vrp/pgr_pickDeliver.h | 2 -- src/pickDeliver/src/order.cpp | 5 +++-- src/pickDeliver/src/pgr_pickDeliver.cpp | 14 ++++++++------ 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/include/vrp/node.h b/include/vrp/node.h index 5132964a081..8521c47a161 100644 --- a/include/vrp/node.h +++ b/include/vrp/node.h @@ -25,8 +25,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. /*! @file */ -#ifndef INCLUDE_PICKDELIVER_NODE_H_ -#define INCLUDE_PICKDELIVER_NODE_H_ +#ifndef INCLUDE_VRP_NODE_H_ +#define INCLUDE_VRP_NODE_H_ #pragma once #include @@ -74,4 +74,4 @@ class Node : public Base_node { } // namespace vrp } // namespace pgrouting -#endif // INCLUDE_PICKDELIVER_NODE_H_ +#endif // INCLUDE_VRP_NODE_H_ diff --git a/include/vrp/pgr_pickDeliver.h b/include/vrp/pgr_pickDeliver.h index c1418be4c58..a8c83792e8d 100644 --- a/include/vrp/pgr_pickDeliver.h +++ b/include/vrp/pgr_pickDeliver.h @@ -52,8 +52,6 @@ class Vehicle_node; class Base_node; class Pgr_pickDeliver : public PD_problem { - - public: Pgr_pickDeliver( const std::vector &pd_orders, diff --git a/src/pickDeliver/src/order.cpp b/src/pickDeliver/src/order.cpp index f23cac752d7..61e32264304 100644 --- a/src/pickDeliver/src/order.cpp +++ b/src/pickDeliver/src/order.cpp @@ -53,11 +53,12 @@ Order::Order( std::ostream& operator<< (std::ostream &log, const Order &order) { - log << "\n\nOrder " + log << "\n\nOrder " << static_cast(order) << ": \n" << "\tPickup: " << order.pickup() << "\n" << "\tDelivery: " << order.delivery() << "\n\n" - << "\tTravel time: " << order.pickup().travel_time_to(order.delivery(),1); + << "\tTravel time: " + << order.pickup().travel_time_to(order.delivery(), 1); log << "\nThere are | {I}| = " << order.m_compatibleI.size() << " -> order(" << order.idx() diff --git a/src/pickDeliver/src/pgr_pickDeliver.cpp b/src/pickDeliver/src/pgr_pickDeliver.cpp index 4db943be900..c9a03ef4e3a 100644 --- a/src/pickDeliver/src/pgr_pickDeliver.cpp +++ b/src/pickDeliver/src/pgr_pickDeliver.cpp @@ -163,8 +163,7 @@ Pgr_pickDeliver::Pgr_pickDeliver( m_base_nodes(), m_cost_matrix(cost_matrix), m_orders(pd_orders), - m_trucks(vehicles, factor) -{ + m_trucks(vehicles, factor) { ENTERING(); pgassert(!pd_orders.empty()); pgassert(!vehicles.empty()); @@ -214,13 +213,16 @@ Pgr_pickDeliver::Pgr_pickDeliver( msg.log << "****** With speed: " << t.speed() << "\n"; msg.log << t.start_site() << "\n"; msg.log << o.pickup() << "\n"; - msg.log << "travel time to " << t.start_site().travel_time_to(o.pickup(), t.speed()) << "\n"; - msg.log << "yet other" << m_cost_matrix.distance(o.pickup().id(), t.start_site().id()) << "\n"; + msg.log << "travel time to " + << t.start_site().travel_time_to( + o.pickup(), t.speed()) << "\n"; msg.log << o.delivery() << "\n"; msg.log << t.end_site() << "\n"; - msg.log << "travel time to " << t.start_site().travel_time_to(o.delivery(), t.speed()) << "\n"; - msg.log << "yet other" << m_cost_matrix.distance(o.delivery().id(), t.start_site().id()) << "\n\nn"; + msg.log << "travel time to " + << t.start_site().travel_time_to( + o.delivery(), t.speed()) + << "\n"; t.push_back(o); } return;