Skip to content

Commit

Permalink
Merge pull request #7 from cvvergara/macos-action
Browse files Browse the repository at this point in the history
[vrp_pgr_pickDeliverEuclidean] fixing code for macos pgtap test
  • Loading branch information
cvvergara committed Jul 1, 2021
2 parents 1482e08 + ec152cc commit 3d93b94
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 53 deletions.
6 changes: 3 additions & 3 deletions docqueries/version/doc-full_version.result
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ SET client_min_messages TO NOTICE;
SET
-- q1
SELECT version, library FROM vrp_full_version();
version | library
---------+------------------
0.2.0 | vrprouting-0.2.0
version | library
-----------+------------------
0.2.0-dev | vrprouting-0.2.0
(1 row)

-- q2
Expand Down
2 changes: 1 addition & 1 deletion docqueries/version/doc-version.result
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SET
SELECT vrp_version();
vrp_version
-------------
0.2.0
0.2.0-dev
(1 row)

-- q2
Expand Down
58 changes: 22 additions & 36 deletions pgtap/pgr_pickDeliver/wrong_data_pickDeliverEuclidean.sql
Original file line number Diff line number Diff line change
Expand Up @@ -257,62 +257,48 @@ SELECT throws_ok('vehicles10',
-- testing wrong data on orders
--------------------------------------

---------------------
-- d_open > d_close
---------------------
UPDATE orders_1 SET d_close = 5 WHERE id = 1;

PREPARE orders1 AS
SELECT * FROM _vrp_pgr_pickDeliverEuclidean(
$$SELECT * FROM orders_1$$,
$$SELECT * FROM vehicles_1$$);

SELECT todo_start('thorws text changed');
---------------------
-- amount <= 0
---------------------

UPDATE orders_1 SET amount= -20 WHERE id =1;

SELECT CASE WHEN (pgr_full_version()).system LIKE 'Darwin%'
THEN skip('test crashing server', 1 )
ELSE collect_tap(
throws_ok('orders1',
SELECT throws_ok('orders1',
'XX000',
'Order not feasible on any truck was found',
'orders1, Should throw: d_open > d_close')
) END;
'Unexpected Negative value in column amount',
'Should throw: pickup.demand < 0');

UPDATE orders_1 SET d_close = 15 WHERE id = 1;
UPDATE orders_1 SET amount= 10 WHERE id =1;

---------------------
-- p_open > p_close
-- d_open > d_close
---------------------
UPDATE orders_1 SET p_close = 1 WHERE id = 1;
UPDATE orders_1 SET d_close = 5 WHERE id = 1;

SELECT CASE WHEN (pgr_full_version()).system LIKE 'Darwin%'
THEN skip('test crashing server', 1 )
ELSE collect_tap(
throws_ok('orders1',
SELECT throws_ok('orders1',
'XX000',
'Order not feasible on any truck was found',
'orders1, Should throw: p_open > p_close')
) END;
'Unexpected delivery time windows found on shipments',
'orders1, Should throw: d_open > d_close');

UPDATE orders_1 SET p_close = 10 WHERE id = 1;
UPDATE orders_1 SET d_close = 15 WHERE id = 1;

SELECT todo_end();
---------------------
-- amount <= 0
-- p_open > p_close
---------------------
UPDATE orders_1 SET p_close = 1 WHERE id = 1;

UPDATE orders_1 SET amount= -20 WHERE id =1;

SELECT CASE WHEN (pgr_full_version()).system LIKE 'Darwin%'
THEN skip('test crashing server', 1 )
ELSE collect_tap(
throws_ok('orders1',
SELECT throws_ok('orders1',
'XX000',
'Unexpected Negative value in column amount',
'Should throw: amount(PICKUP) < 0')
) END;
'Unexpected pickup time windows found on shipments',
'orders1, Should throw: p_open > p_close');

UPDATE orders_1 SET p_close = 10 WHERE id = 1;

UPDATE orders_1 SET amount= 10 WHERE id =11;

SELECT finish();
ROLLBACK;
2 changes: 1 addition & 1 deletion src/common/get_check_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ check_any_integer_type(Column_info_t info) {
|| info.type == INT8OID)) {
ereport(ERROR,
(errmsg_internal("Unexpected type in column '%s'.", info.name),
errhint("Found %lu", info.type)));
errhint("Expected ANY-INTEGER")));
}
}

Expand Down
84 changes: 72 additions & 12 deletions src/pgr_pickDeliver/pickDeliverEuclidean_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,60 @@ get_initial_solution(vrprouting::problem::PickDeliver* problem_ptr, int m_initia

return m_solutions;
}

bool
are_shipments_ok(
PickDeliveryOrders_t *customers_arr,
size_t total_customers,
std::string &err_string,
std::string &hint_string) {
/**
* - demand > 0 (the type is unsigned so no need to check for negative values, only for it to be non 0
* - pick_service_t >=0
* - drop_service_t >=0
* - p_open <= p_close
* - d_open <= d_close
*/
for (size_t i = 0; i < total_customers; ++i) {
if (customers_arr[i].demand == 0) {
err_string = "Unexpected zero value found on column 'demand' of shipments";
hint_string = "Check shipment id #:" + std::to_string(customers_arr[i].id);
return false;
}

if (customers_arr[i].pick_service_t < 0) {
err_string = "Unexpected negative value found on column 'p_service_t' of shipments";
hint_string = "Check shipment id #:" + std::to_string(customers_arr[i].id);
return false;
}

if (customers_arr[i].deliver_service_t < 0) {
err_string = "Unexpected negative value found on column 'd_service_t' of shipments";
hint_string = "Check shipment id #:" + std::to_string(customers_arr[i].id);
return false;
}

if (customers_arr[i].pick_open_t > customers_arr[i].pick_close_t) {
err_string = "Unexpected pickup time windows found on shipments";
hint_string = "Check shipment id #:" + std::to_string(customers_arr[i].id);
return false;
}

if (customers_arr[i].deliver_open_t > customers_arr[i].deliver_close_t) {
err_string = "Unexpected delivery time windows found on shipments";
hint_string = "Check shipment id #:" + std::to_string(customers_arr[i].id);
return false;
}

}
return true;
}

} // namespace

void
do_pgr_pickDeliverEuclidean(
struct PickDeliveryOrders_t *customers_arr,
PickDeliveryOrders_t *customers_arr,
size_t total_customers,

Vehicle_t *vehicles_arr,
Expand All @@ -93,6 +142,13 @@ do_pgr_pickDeliverEuclidean(
try {
*return_tuples = nullptr;
*return_count = 0;
std::string err_string;
std::string hint_string;
if (!are_shipments_ok(customers_arr, total_customers, err_string, hint_string)) {
*err_msg = pgr_msg(err_string.c_str());
*log_msg = pgr_msg(hint_string.c_str());
return;
}

/*
* transform to C++ containers
Expand All @@ -105,25 +161,29 @@ do_pgr_pickDeliverEuclidean(
std::map<std::pair<Coordinate, Coordinate>, Id> matrix_data;

for (const auto &o : orders) {
matrix_data[std::pair<Coordinate, Coordinate>(o.pick_x, o.pick_y)] = o.pick_node_id;
matrix_data[std::pair<Coordinate, Coordinate>(o.deliver_x, o.deliver_y)] = o.deliver_node_id;
pgassert(o.pick_node_id==0);
pgassert(o.deliver_node_id==0);
matrix_data[std::pair<Coordinate, Coordinate>(o.pick_x, o.pick_y)] = 0;
matrix_data[std::pair<Coordinate, Coordinate>(o.deliver_x, o.deliver_y)] = 0;
}

for (const auto &v : vehicles) {
matrix_data[std::pair<Coordinate, Coordinate>(v.start_x, v.start_y)] = v.start_node_id;
matrix_data[std::pair<Coordinate, Coordinate>(v.end_x, v.end_y)] = v.end_node_id;
matrix_data[std::pair<Coordinate, Coordinate>(v.start_x, v.start_y)] = 0;
matrix_data[std::pair<Coordinate, Coordinate>(v.end_x, v.end_y)] = 0;
}

Identifiers<int64_t> unique_ids;
/*
* Data does not have ids for the locations'
*/
Id id(0);
for (auto &e : matrix_data) {
e.second = id++;
}

for (const auto &e : matrix_data) {
unique_ids += e.second;
}
if (unique_ids.size() != matrix_data.size()) {
// ignoring ids given by the user
Id id(0);
for (auto &e : matrix_data) {
e.second = id++;
}
log << e.second << "(" << e.first.first << "," << e.first.second << ")\n";
}

for (size_t i = 0; i < total_customers; ++i) {
Expand Down

0 comments on commit 3d93b94

Please sign in to comment.