Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Standardize drivers #59

Merged
merged 14 commits into from
Aug 25, 2024
2 changes: 1 addition & 1 deletion doxygen/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ WARN_FORMAT = "$file:$line: $text"
# messages should be written. If left blank the output is written to standard
# error (stderr).

WARN_LOGFILE = @CMAKE_CURRENT_BIN_DIR@/LOG
WARN_LOGFILE = @CMAKE_CURRENT_BINARY_DIR@/LOG

#---------------------------------------------------------------------------
# Configuration options related to the input files
Expand Down
96 changes: 50 additions & 46 deletions src/compatibleVehicles/compatibleVehicles_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,23 @@ 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*/
/** @file */


#include "drivers/compatibleVehicles_driver.h"

#include <cstring>
#include <deque>
#include <sstream>
#include <string>
#include <deque>
#include <utility>

#include "problem/pickDeliver.hpp"
#include "problem/matrix.hpp"
#include "cpp_common/orders_t.hpp"
#include "c_types/compatibleVehicles_rt.h"
#include "cpp_common/vehicle_t.hpp"

#include "cpp_common/assert.hpp"
#include "cpp_common/alloc.hpp"
#include "cpp_common/assert.hpp"

#include "cpp_common/orders_t.hpp"
#include "cpp_common/vehicle_t.hpp"
#include "problem/pickDeliver.hpp"
#include "problem/matrix.hpp"

/**
*
Expand All @@ -54,6 +53,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* @param[in] multipliers_arr A C Array of the multipliers
* @param[in] total_multipliers size of the multipliers_arr
* @param[in] factor A global multiplier for the (time) matrix cells
*
* @param[out] return_tuples C array of contents to be returned to postgres
* @param[out] return_count number of tuples returned
* @param[out] log_msg special log message pointer
Expand All @@ -65,48 +65,37 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* @pre The C array: return_tuples must be empty
* @pre Only matrix cells (i, i) can be missing and are considered as 0 (time units)
*
* @post The C arrays: customers_arr, vehicles_arr, matrix_cells_arr Do not change
* @post The C array: return_tuples contains the result for the problem given
* @post The return_tuples array size is return_count
* @post The return_tuples array size is return_count
* @post err_msg is empty if no throw from the process is catched
* @post log_msg contains some logging
* @post notice_msg is empty
*
*
@dot
digraph G {
node[fontsize=11, nodesep=0.75,ranksep=0.75];

start [shape=Mdiamond];
n1 [label="Verify preconditions",shape=rect];
n3 [label="Verify matrix cells preconditions",shape=rect];
n3 [label="Verify matrix preconditions",shape=rect];
n4 [label="Construct problem",shape=cds,color=blue];
n7 [label="Prepare results",shape=rect];
end [shape=Mdiamond];
error [shape=Mdiamond,color=red]
start -> n1 -> n3 -> n4 -> n7 -> end;
n1 -> error [ label="Caller error",color=red];
n3 -> error [ label="User error",color=red];

n1 -> error [ label="throw",color=red];
n3 -> error [ label="throw",color=red];
}
@enddot

*
*/
void
vrp_do_compatibleVehicles(
Orders_t customers_arr[],
size_t total_customers,

Vehicle_t *vehicles_arr,
size_t total_vehicles,

Matrix_cell_t *matrix_cells_arr,
size_t total_cells,

Time_multipliers_t *multipliers_arr,
size_t total_multipliers,
Orders_t customers_arr[], size_t total_customers,
Vehicle_t *vehicles_arr, size_t total_vehicles,
Matrix_cell_t *matrix_cells_arr, size_t total_cells,
Time_multipliers_t *multipliers_arr, size_t total_multipliers,

double factor,

Expand All @@ -117,8 +106,11 @@ vrp_do_compatibleVehicles(
char **notice_msg,
char **err_msg) {
using vrprouting::alloc;
using vrprouting::free;
using vrprouting::to_pg_msg;

char* hint = nullptr;

std::ostringstream log;
std::ostringstream notice;
std::ostringstream err;
Expand All @@ -140,13 +132,15 @@ vrp_do_compatibleVehicles(
Identifiers<Id> node_ids;

for (size_t i = 0; i < total_customers; ++i) {
node_ids += customers_arr[i].pick_node_id;
node_ids += customers_arr[i].deliver_node_id;
auto o = customers_arr[i];
node_ids += o.pick_node_id;
node_ids += o.deliver_node_id;
}

for (size_t i = 0; i < total_vehicles; ++i) {
node_ids += vehicles_arr[i].start_node_id;
node_ids += vehicles_arr[i].end_node_id;
auto v = vehicles_arr[i];
node_ids += v.start_node_id;
node_ids += v.end_node_id;
}

/*
Expand All @@ -156,7 +150,8 @@ vrp_do_compatibleVehicles(
matrix_cells_arr, total_cells,
multipliers_arr, total_multipliers,
node_ids, static_cast<Multiplier>(factor));
#if 0

#ifdef TODO
/*
* Verify matrix triangle inequality
*/
Expand All @@ -169,6 +164,7 @@ vrp_do_compatibleVehicles(
}
}
#endif

if (!cost_matrix.has_no_infinity()) {
err << "An Infinity value was found on the Matrix";
*err_msg = to_pg_msg(err.str());
Expand All @@ -186,9 +182,8 @@ vrp_do_compatibleVehicles(

err << pd_problem.msg.get_error();
if (!err.str().empty()) {
log << pd_problem.msg.get_log();
*log_msg = to_pg_msg(log.str());
*err_msg = to_pg_msg(err.str());
*log_msg = to_pg_msg(pd_problem.msg.get_log());
*err_msg = to_pg_msg(pd_problem.msg.get_error());
return;
}
log << pd_problem.msg.get_log();
Expand All @@ -213,25 +208,34 @@ vrp_do_compatibleVehicles(
}
(*return_count) = solution.size();


pgassert(*err_msg == nullptr);
*log_msg = log.str().empty()?
nullptr :
to_pg_msg(log.str());
*notice_msg = notice.str().empty()?
nullptr :
to_pg_msg(notice.str());
*log_msg = log.str().empty()? nullptr : to_pg_msg(log.str());
*notice_msg = notice.str().empty()? nullptr : to_pg_msg(notice.str());
} catch (AssertFailedException &except) {
if (*return_tuples) free(*return_tuples);
(*return_count) = 0;
err << except.what();
*err_msg = to_pg_msg(err.str());
*err_msg = to_pg_msg(except.what());
*log_msg = to_pg_msg(log.str());
} catch (std::exception& except) {
if (*return_tuples) free(*return_tuples);
(*return_count) = 0;
err << except.what();
*err_msg = to_pg_msg(err.str());
*err_msg = to_pg_msg(except.what());
*log_msg = to_pg_msg(log.str());
} catch (const std::string &except) {
if (*return_tuples) free(*return_tuples);
(*return_count) = 0;
*err_msg = to_pg_msg(except);
*log_msg = hint? to_pg_msg(hint) : to_pg_msg(log.str());
} catch (const std::pair<std::string, std::string>& ex) {
if (*return_tuples) free(*return_tuples);
(*return_count) = 0;
*err_msg = to_pg_msg(ex.first);
*log_msg = to_pg_msg(ex.second);
} catch (const std::pair<std::string, int64_t>& except) {
if (*return_tuples) free(*return_tuples);
(*return_count) = 0;
log << "id = " << except.second;
*err_msg = to_pg_msg(except.first);
*log_msg = to_pg_msg(log.str());
} catch(...) {
if (*return_tuples) free(*return_tuples);
Expand Down
Loading