vrpRouting  0.3
compatibleVehicles_driver.h File Reference
#include <stddef.h>
Include dependency graph for compatibleVehicles_driver.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct CompatibleVehicles_rt CompatibleVehicles_rt
 
typedef struct Matrix_cell_t Matrix_cell_t
 
typedef struct PickDeliveryOrders_t PickDeliveryOrders_t
 
typedef struct Time_multipliers_t Time_multipliers_t
 
typedef struct Vehicle_t Vehicle_t
 

Functions

void do_compatibleVehicles (PickDeliveryOrders_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, CompatibleVehicles_rt **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
 Driver for processing a "compatible vehicles" problem. More...
 

Typedef Documentation

◆ CompatibleVehicles_rt

Definition at line 46 of file compatibleVehicles_driver.h.

◆ Matrix_cell_t

typedef struct Matrix_cell_t Matrix_cell_t

Definition at line 45 of file compatibleVehicles_driver.h.

◆ PickDeliveryOrders_t

Definition at line 42 of file compatibleVehicles_driver.h.

◆ Time_multipliers_t

Definition at line 43 of file compatibleVehicles_driver.h.

◆ Vehicle_t

typedef struct Vehicle_t Vehicle_t

Definition at line 44 of file compatibleVehicles_driver.h.

Function Documentation

◆ do_compatibleVehicles()

void do_compatibleVehicles ( PickDeliveryOrders_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,
CompatibleVehicles_rt **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Driver for processing a "compatible vehicles" problem.

Parameters
[in]customers_arrA C Array of pickup and dropoff orders
[in]total_customerssize of the customers_arr
[in]vehicles_arrA C Array of vehicles
[in]total_vehiclessize of the vehicles_arr
[in]matrix_cells_arrA C Array of the (time) matrix cells
[in]total_cellssize of the matrix_cells_arr
[in]multipliers_arrA C Array of the multipliers
[in]total_multiplierssize of the multipliers_arr
[in]factorA global multiplier for the (time) matrix cells
[out]return_tuplesC array of contents to be returned to postgres
[out]return_countnumber of tuples returned
[out]log_msgspecial log message pointer
[out]notice_msgspecial message pointer to be returned as NOTICE
[out]err_msgspecial message pointer to be returned as ERROR
Precondition
The messages: log_msg, notice_msg, err_msg must be empty (=nullptr)
The C arrays: customers_arr, vehicles_arr, matrix_cells_arr must not be empty
The C array: return_tuples must be empty
Only matrix cells (i, i) can be missing and are considered as 0 (time units)
Postcondition
The C arrays: customers_arr, vehicles_arr, matrix_cells_arr Do not change
The C array: return_tuples contains the result for the problem given
The return_tuples array size is return_count
The return_tuples array size is return_count
err_msg is empty if no throw from the process is catched
log_msg contains some logging
notice_msg is empty
dot_inline_dotgraph_2.png

Definition at line 98 of file compatibleVehicles_driver.cpp.

118  {
119  std::ostringstream log;
120  std::ostringstream notice;
121  std::ostringstream err;
122  try {
123  /*
124  * verify preconditions
125  */
126  pgassert(!(*log_msg));
127  pgassert(!(*notice_msg));
128  pgassert(!(*err_msg));
129  pgassert(total_customers);
130  pgassert(total_vehicles);
131  pgassert(total_vehicles);
132  pgassert(*return_count == 0);
133  pgassert(!(*return_tuples));
134  log << "do_compatibleVehicles\n";
135 
136 
137  Identifiers<Id> node_ids;
138 
139  for (size_t i = 0; i < total_customers; ++i) {
140  node_ids += customers_arr[i].pick_node_id;
141  node_ids += customers_arr[i].deliver_node_id;
142  }
143 
144  for (size_t i = 0; i < total_vehicles; ++i) {
145  node_ids += vehicles_arr[i].start_node_id;
146  node_ids += vehicles_arr[i].end_node_id;
147  }
148 
149  /*
150  * Verify matrix cells preconditions
151  */
152  vrprouting::problem::Matrix cost_matrix(
153  matrix_cells_arr, total_cells,
154  multipliers_arr, total_multipliers,
155  node_ids, static_cast<Multiplier>(factor));
156 #if 0
157  /*
158  * Verify matrix triangle inequality
159  */
160  if (!cost_matrix.obeys_triangle_inequality()) {
161  log << "[Compatible Vehicles] Fixing Matrix that does not obey triangle inequality ";
162  log << cost_matrix.fix_triangle_inequality() << " cycles used";
163 
164  if (!cost_matrix.obeys_triangle_inequality()) {
165  log << "[Compatible Vehicles] Matrix Still does not obey triangle inequality";
166  }
167  }
168 #endif
169  if (!cost_matrix.has_no_infinity()) {
170  err << "An Infinity value was found on the Matrix";
171  *err_msg = pgr_msg(err.str());
172  return;
173  }
174 
175  /*
176  * Construct problem
177  */
178  log << "Initialize problem\n";
180  customers_arr, total_customers,
181  vehicles_arr, total_vehicles,
182  cost_matrix);
183 
184  err << pd_problem.msg.get_error();
185  if (!err.str().empty()) {
186  log << pd_problem.msg.get_log();
187  *log_msg = pgr_msg(log.str());
188  *err_msg = pgr_msg(err.str());
189  return;
190  }
191  log << pd_problem.msg.get_log();
192  log << "Finish Reading data\n";
193  pd_problem.msg.clear();
194 
195  /*
196  * Prepare results
197  */
198  auto solution = pd_problem.get_pg_compatibleVehicles();
199  log << "solution size: " << solution.size() << "\n";
200  log << "solution empty: " << solution.empty() << "\n";
201 
202  if (!solution.empty()) {
203  log << "solution empty " << "\n";
204  (*return_tuples) = pgr_alloc(solution.size(), (*return_tuples));
205  int seq = 0;
206  for (const auto &row : solution) {
207  (*return_tuples)[seq] = row;
208  ++seq;
209  }
210  }
211  (*return_count) = solution.size();
212 
213 
214  pgassert(*err_msg == nullptr);
215  *log_msg = log.str().empty()?
216  nullptr :
217  pgr_msg(log.str());
218  *notice_msg = notice.str().empty()?
219  nullptr :
220  pgr_msg(notice.str());
221  } catch (AssertFailedException &except) {
222  if (*return_tuples) free(*return_tuples);
223  (*return_count) = 0;
224  err << except.what();
225  *err_msg = pgr_msg(err.str());
226  *log_msg = pgr_msg(log.str());
227  } catch (std::exception& except) {
228  if (*return_tuples) free(*return_tuples);
229  (*return_count) = 0;
230  err << except.what();
231  *err_msg = pgr_msg(err.str());
232  *log_msg = pgr_msg(log.str());
233  } catch(...) {
234  if (*return_tuples) free(*return_tuples);
235  (*return_count) = 0;
236  err << "Caught unknown exception!";
237  *err_msg = pgr_msg(err.str());
238  *log_msg = pgr_msg(log.str());
239  }
240 }

References vrprouting::Pgr_messages::clear(), PickDeliveryOrders_t::deliver_node_id, Vehicle_t::end_node_id, vrprouting::base::Base_Matrix::fix_triangle_inequality(), vrprouting::Pgr_messages::get_error(), vrprouting::Pgr_messages::get_log(), vrprouting::problem::PickDeliver::get_pg_compatibleVehicles(), vrprouting::base::Base_Matrix::has_no_infinity(), vrprouting::problem::PickDeliver::msg, vrprouting::base::Base_Matrix::obeys_triangle_inequality(), pgassert, pgr_alloc(), pgr_msg(), PickDeliveryOrders_t::pick_node_id, Vehicle_t::start_node_id, and AssertFailedException::what().

Referenced by process().

PickDeliveryOrders_t::deliver_node_id
Id deliver_node_id
Deliver y coordinate: used in stand alone program for benchmarks.
Definition: pickDeliveryOrders_t.h:72
pgr_alloc
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:66
Vehicle_t::start_node_id
Id start_node_id
Stops size.
Definition: vehicle_t.h:58
Vehicle_t::end_node_id
Id end_node_id
Definition: vehicle_t.h:65
pgr_msg
char * pgr_msg(const std::string &msg)
Definition: pgr_alloc.cpp:33
AssertFailedException::what
virtual const char * what() const
Definition: pgr_assert.cpp:67
vrprouting::problem::PickDeliver
the pick deliver problem
Definition: pickDeliver.h:50
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:95
vrprouting::problem::Matrix
Definition: matrix.h:46
PickDeliveryOrders_t::pick_node_id
Id pick_node_id
Pick y coordinate: used in stand alone program for benchmarks.
Definition: pickDeliveryOrders_t.h:64
Multiplier
double Multiplier
Definition: typedefs.h:77
Identifiers
Definition: identifiers.hpp:51
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:140