Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Convert c array to cpp containers #62

Merged
merged 16 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docqueries/pgr_pickDeliver/pgr_pickDeliverEuclidean.result
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ SELECT * FROM vrp_pgr_pickDeliverEuclidean(
3 | 1 | 1 | 3 | 3 | 3 | 0 | 1 | 6 | 0 | 3 | 9
4 | 1 | 1 | 4 | 2 | 2 | 20 | 1 | 10 | 0 | 2 | 12
5 | 1 | 1 | 5 | 3 | 2 | 0 | 1 | 13 | 0 | 3 | 16
6 | 1 | 1 | 6 | 6 | -1 | 0 | 3 | 19 | 0 | 0 | 19
7 | 2 | 2 | 1 | 1 | -1 | 0 | 0 | 0 | 0 | 0 | 0
8 | 2 | 2 | 2 | 2 | 1 | 10 | 2 | 2 | 0 | 3 | 5
6 | 1 | 1 | 6 | 6 | -1 | 0 | 1 | 17 | 0 | 0 | 17
7 | 2 | 2 | 1 | 1 | -1 | 0 | 0 | 0 | 1 | 0 | 1
8 | 2 | 2 | 2 | 2 | 1 | 10 | 1 | 2 | 0 | 3 | 5
9 | 2 | 2 | 3 | 3 | 1 | 0 | 2 | 7 | 0 | 3 | 10
10 | 2 | 2 | 4 | 6 | -1 | 0 | 0 | 10 | 0 | 0 | 10
11 | -2 | 0 | 0 | -1 | -1 | -1 | 11 | -1 | 1 | 17 | 29
10 | 2 | 2 | 4 | 6 | -1 | 0 | 2 | 12 | 0 | 0 | 12
11 | -2 | 0 | 0 | -1 | -1 | -1 | 10 | -1 | 2 | 17 | 29
(11 rows)

/* --q2 */
Expand Down
4 changes: 2 additions & 2 deletions include/cpp_common/base_matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include "c_types/typedefs.h"
#include "cpp_common/identifiers.hpp"

typedef struct Matrix_cell_t Matrix_cell_t;
using Matrix_cell_t = struct Matrix_cell_t;

namespace vrprouting {
namespace base {
Expand All @@ -57,7 +57,7 @@ class Base_Matrix {
/** @brief Constructs an emtpy matrix */
Base_Matrix() = default;
/** @brief Constructs a matrix for only specific identifiers */
Base_Matrix(Matrix_cell_t*, size_t, const Identifiers<Id>&, Multiplier);
Base_Matrix(const std::vector<Matrix_cell_t>&, const Identifiers<Id>&, Multiplier);
/** @brief Constructs a matrix for the euclidean */
Base_Matrix(const std::map<std::pair<Coordinate, Coordinate>, Id>&, Multiplier);

Expand Down
2 changes: 1 addition & 1 deletion include/cpp_common/vroom_matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Matrix {
public:
/** @brief Constructs an emtpy matrix */
Matrix() = default;
Matrix(Vroom_matrix_t *, size_t, const Identifiers<Id> &, double);
Matrix(const std::vector<Vroom_matrix_t>&, const Identifiers<Id>&, double);

::vroom::Matrix<::vroom::Duration> get_vroom_duration_matrix() const;
::vroom::Matrix<::vroom::Cost> get_vroom_cost_matrix() const;
Expand Down
6 changes: 3 additions & 3 deletions include/problem/fleet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ class Fleet: protected std::vector<Vehicle_pickDeliver> {

/** @brief Create a fleet based on the Vehicles of the problem */
Fleet(
Vehicle_t* , size_t,
const std::vector<Vehicle_t>&,
const Orders&,
std::vector<Vehicle_node>&, size_t&);

/** @brief Create a fleet based on the Vehicles of the problem */
Fleet(
Vehicle_t*, size_t,
const std::vector<Vehicle_t>&,
const std::vector<Short_vehicle>&,
const Orders&,
std::vector<Vehicle_node>&,
Expand Down Expand Up @@ -121,7 +121,7 @@ class Fleet: protected std::vector<Vehicle_pickDeliver> {

/** @brief build the fleet */
void build_fleet(
Vehicle_t*, size_t,
std::vector<Vehicle_t>,
const std::vector<Short_vehicle>&,
const Orders&,
std::vector<Vehicle_node>&, size_t&);
Expand Down
7 changes: 5 additions & 2 deletions include/problem/matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ class Matrix : public base::Base_Matrix {
Matrix() = default;

/** brief constructor for matrix version with time dependant multipliers */
Matrix(Matrix_cell_t *, size_t, Time_multipliers_t*, size_t, const Identifiers<Id>&, Multiplier = 1.0);
Matrix(
const std::vector<Matrix_cell_t>&,
const std::vector<Time_multipliers_t>&,
const Identifiers<Id>&, Multiplier = 1.0);

/** brief constructor for matrix version default multipliers */
Matrix(Matrix_cell_t *, size_t, const Identifiers<Id>&, Multiplier = 1.0);
Matrix(const std::vector<Matrix_cell_t>&, const Identifiers<Id>&, Multiplier = 1.0);

/** brief constructor for euclidean version default multipliers */
explicit Matrix(const std::map<std::pair<Coordinate, Coordinate>, Id>&, Multiplier = 1.0);
Expand Down
23 changes: 6 additions & 17 deletions include/problem/orders.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,24 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <algorithm>

#include "problem/order.hpp"
#include "cpp_common/orders_t.hpp"
#include "cpp_common/assert.hpp"
#include "cpp_common/identifiers.hpp"
#include "problem/tw_node.hpp"
#include "problem/vehicle_node.hpp"
#include "problem/node_types.hpp"


using Orders_t = struct Orders_t;

namespace vrprouting {
namespace problem {

class Vehicle_node;
class PickDeliver;

class Orders : public std::vector<Order> {
public:
using std::vector<Order>::size;
Orders() = default;

Orders(Orders_t* , size_t, PickDeliver&);
Orders(const std::vector<Orders_t>&, PickDeliver&);

/** @brief find the best order -> @b this */
size_t find_best_I(const Identifiers<size_t> &within_this_set) const;
Expand All @@ -69,22 +67,13 @@ class Orders : public std::vector<Order> {
/** @brief is the order valid? */
bool is_valid(Speed = 1.0) const;

friend std::ostream& operator<<(std::ostream &log, const Orders &p_orders) {
log << "Orders\n";
for (const auto &o : p_orders) log << o << "\n";
log << "end Orders\n";
return log;
}
friend std::ostream& operator<<(std::ostream &log, const Orders &p_orders);

private:
void build_orders(Orders_t *, size_t, PickDeliver&);
void build_orders(std::vector<Orders_t>, PickDeliver&);

/** @brief add in an order */
void add_order(const Orders_t &order,
const Vehicle_node &pick,
const Vehicle_node &drop) {
push_back(Order(size(), order.id, pick, drop));
}
void add_order(const Orders_t&, const Vehicle_node&, const Vehicle_node&);
};

} // namespace problem
Expand Down
10 changes: 5 additions & 5 deletions include/problem/pickDeliver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ class PickDeliver {
public:
/** @brief General Constructor */
PickDeliver(
Orders_t* p_orders, size_t p_orders_size,
Vehicle_t* p_vehicles, size_t p_vehicles_size,
const std::vector<Orders_t>&,
const std::vector<Vehicle_t>&,
const Matrix &);

/** @brief Override stops constructor */
PickDeliver(
Orders_t* p_orders, size_t p_orders_size,
Vehicle_t* p_vehicles, size_t p_vehicles_size,
const std::vector<Orders_t>&,
const std::vector<Vehicle_t>&,
std::vector<Short_vehicle>,
const Matrix &);
const Matrix&);

virtual ~PickDeliver() = default;

Expand Down
3 changes: 0 additions & 3 deletions include/vroom/vroom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,17 @@ class Vroom : public vrprouting::Messages {
void add_jobs(
const std::vector<Vroom_job_t>&,
const MapTW&);
void add_jobs(const Vroom_job_t*, size_t, const Vroom_time_window_t*, size_t);

/** @brief sets m_shipments by adding the Vroom_shipment_t */
void add_shipments(
const std::vector<Vroom_shipment_t>&,
const MapTW&);
void add_shipments(const Vroom_shipment_t*, size_t, const Vroom_time_window_t*, size_t);

/** @brief sets m_vehicles by adding the Vroom_vehicle_t */
void add_vehicles(
const std::vector<Vroom_vehicle_t>&,
const std::vector<Vroom_break_t>&,
const MapTW&);
void add_vehicles(const Vroom_vehicle_t*, size_t, const Vroom_break_t*, size_t, const Vroom_time_window_t*, size_t);

/** @brief sets m_matrix */
void add_matrix(const vrprouting::vroom::Matrix&);
Expand Down
2 changes: 1 addition & 1 deletion pgtap/pgr_pickDeliver/pickDeliver/issue-1725.pg
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SELECT * FROM vrp_pgr_pickDeliver(
$$ SELECT * FROM edges_matrix WHERE start_vid IN (3, 4, 5, 8, 9, 11) AND end_vid IN (3, 4, 5, 8, 9, 11) $$
);

SELECT throws_ok('missing_id_on_matrix', 'XX000', 'An Infinity value was found on the Matrix. Might be missing information of a node', 'Should throw: matrix is missing node 6');
SELECT throws_ok('missing_id_on_matrix', 'XX000', 'An Infinity value was found on the Matrix', 'Should throw: matrix is missing node 6');


SELECT finish();
Expand Down
30 changes: 7 additions & 23 deletions src/compatibleVehicles/compatibleVehicles.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,19 @@ process(

CompatibleVehicles_rt **result_tuples,
size_t *result_count) {
char *log_msg = NULL;
char *notice_msg = NULL;
char *err_msg = NULL;

vrp_SPI_connect();

if (factor <= 0) {
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
errmsg("Illegal value in parameter: factor"),
errhint("Value found: %f <= 0", factor)));
}

vrp_SPI_connect();

Orders_t *pd_orders_arr = NULL;
size_t total_pd_orders = 0;

Expand Down Expand Up @@ -172,13 +176,7 @@ process(
PGR_DBG("Total %ld matrix cells in query:", total_cells);
PGR_DBG("Total %ld multipliers in query:", total_cells);

#ifdef PROFILE
clock_t start_t = clock();
#endif
char *log_msg = NULL;
char *notice_msg = NULL;
char *err_msg = NULL;

vrp_do_compatibleVehicles(
pd_orders_arr, total_pd_orders,
vehicles_arr, total_vehicles,
Expand All @@ -193,10 +191,8 @@ process(
&log_msg,
&notice_msg,
&err_msg);

#ifdef PROFILE
time_msg("vrp_compatibleVehicles", start_t, clock());
#endif

if (err_msg && (*result_tuples)) {
pfree(*result_tuples);
(*result_count) = 0;
Expand Down Expand Up @@ -286,20 +282,8 @@ _vrp_compatiblevehicles(PG_FUNCTION_ARGS) {

tuple = heap_form_tuple(tuple_desc, values, nulls);
result = HeapTupleGetDatum(tuple);

tuple = heap_form_tuple(tuple_desc, values, nulls);
result = HeapTupleGetDatum(tuple);


pfree(values); values = NULL;
pfree(nulls); nulls = NULL;

SRF_RETURN_NEXT(funcctx, result);
} else {
if (result_tuples) {
pfree(result_tuples); result_tuples = NULL;
}
funcctx->user_fctx = NULL;
SRF_RETURN_DONE(funcctx);
}
}
Loading