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

Go to the source code of this file.

Typedefs

typedef struct PickDeliveryOrders_t PickDeliveryOrders_t
 
typedef struct Solution_rt Solution_rt
 

Functions

void do_pgr_pickDeliverEuclidean (PickDeliveryOrders_t *pd_orders_arr, size_t total_pd_orders, Vehicle_t *vehicles_arr, size_t total_vehicles, double factor, int max_cycles, int initial_solution_id, Solution_rt **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
 

Typedef Documentation

◆ PickDeliveryOrders_t

Definition at line 43 of file pickDeliverEuclidean_driver.h.

◆ Solution_rt

typedef struct Solution_rt Solution_rt

Definition at line 44 of file pickDeliverEuclidean_driver.h.

Function Documentation

◆ do_pgr_pickDeliverEuclidean()

void do_pgr_pickDeliverEuclidean ( PickDeliveryOrders_t pd_orders_arr,
size_t  total_pd_orders,
Vehicle_t vehicles_arr,
size_t  total_vehicles,
double  factor,
int  max_cycles,
int  initial_solution_id,
Solution_rt **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Definition at line 121 of file pickDeliverEuclidean_driver.cpp.

137  {
138  std::ostringstream log;
139  std::ostringstream notice;
140  std::ostringstream err;
141  try {
142  *return_tuples = nullptr;
143  *return_count = 0;
144  std::string err_string;
145  std::string hint_string;
146  if (!are_shipments_ok(customers_arr, total_customers, &err_string, &hint_string)) {
147  *err_msg = pgr_msg(err_string.c_str());
148  *log_msg = pgr_msg(hint_string.c_str());
149  return;
150  }
151 
152  /*
153  * transform to C++ containers
154  */
155  std::vector<PickDeliveryOrders_t> orders(
156  customers_arr, customers_arr + total_customers);
157  std::vector<Vehicle_t> vehicles(
158  vehicles_arr, vehicles_arr + total_vehicles);
159 
160  std::map<std::pair<Coordinate, Coordinate>, Id> matrix_data;
161 
162  for (const auto &o : orders) {
163  pgassert(o.pick_node_id == 0);
164  pgassert(o.deliver_node_id == 0);
165  matrix_data[std::pair<Coordinate, Coordinate>(o.pick_x, o.pick_y)] = 0;
166  matrix_data[std::pair<Coordinate, Coordinate>(o.deliver_x, o.deliver_y)] = 0;
167  }
168 
169  for (const auto &v : vehicles) {
170  matrix_data[std::pair<Coordinate, Coordinate>(v.start_x, v.start_y)] = 0;
171  matrix_data[std::pair<Coordinate, Coordinate>(v.end_x, v.end_y)] = 0;
172  }
173 
174  Identifiers<int64_t> unique_ids;
175  /*
176  * Data does not have ids for the locations'
177  */
178  Id id(0);
179  for (auto &e : matrix_data) {
180  e.second = id++;
181  }
182 
183  for (const auto &e : matrix_data) {
184  unique_ids += e.second;
185  log << e.second << "(" << e.first.first << "," << e.first.second << ")\n";
186  }
187 
188  for (size_t i = 0; i < total_customers; ++i) {
189  customers_arr[i].pick_node_id =
190  matrix_data[std::pair<Coordinate, Coordinate>(customers_arr[i].pick_x, customers_arr[i].pick_y)];
191 
192  customers_arr[i].deliver_node_id =
193  matrix_data[std::pair<Coordinate, Coordinate>(customers_arr[i].deliver_x, customers_arr[i].deliver_y)];
194  }
195  for (auto &v : vehicles) {
196  v.start_node_id = matrix_data[std::pair<Coordinate, Coordinate>(v.start_x, v.start_y)];
197  v.end_node_id = matrix_data[std::pair<Coordinate, Coordinate>(v.end_x, v.end_y)];
198  }
199 
200  vrprouting::problem::Matrix cost_matrix(matrix_data, static_cast<Multiplier>(factor));
201 
202  log << "Initialize problem\n";
204  customers_arr, total_customers,
205  vehicles_arr, total_vehicles,
206  cost_matrix);
207 
208  err << pd_problem.msg.get_error();
209  if (!err.str().empty()) {
210  log.str("");
211  log.clear();
212  log << pd_problem.msg.get_error();
213  log << pd_problem.msg.get_log();
214  *log_msg = pgr_msg(log.str().c_str());
215  *err_msg = pgr_msg(err.str().c_str());
216  return;
217  }
218  log << pd_problem.msg.get_log();
219  log << "Finish Reading data\n";
220 
221 #if 0
222  try {
223 #endif
224  auto sol = get_initial_solution(&pd_problem, initial_solution_id);
227  sol = Optimize(sol, static_cast<size_t>(max_cycles), (Initials_code)initial_solution_id);
228 #if 0
229  } catch (AssertFailedException &except) {
230  log << pd_problem.msg.get_log();
231  throw;
232  } catch(...) {
233  log << "Caught unknown exception!";
234  throw;
235  }
236 #endif
237  log << pd_problem.msg.get_log();
238  log << "Finish solve\n";
239 
240  auto solution = sol.get_postgres_result();
241  log << pd_problem.msg.get_log();
242  log << "solution size: " << solution.size() << "\n";
243 
244 
245  if (!solution.empty()) {
246  (*return_tuples) = pgr_alloc(solution.size(), (*return_tuples));
247  int seq = 0;
248  for (const auto &row : solution) {
249  (*return_tuples)[seq] = row;
250  ++seq;
251  }
252  }
253  (*return_count) = solution.size();
254 
255  log << pd_problem.msg.get_log();
256 
257  pgassert(*err_msg == NULL);
258  *log_msg = log.str().empty()?
259  nullptr :
260  pgr_msg(log.str().c_str());
261  *notice_msg = notice.str().empty()?
262  nullptr :
263  pgr_msg(notice.str().c_str());
264  } catch (AssertFailedException &except) {
265  if (*return_tuples) free(*return_tuples);
266  (*return_count) = 0;
267  err << except.what();
268  *err_msg = pgr_msg(err.str().c_str());
269  *log_msg = pgr_msg(log.str().c_str());
270  } catch (std::exception& except) {
271  if (*return_tuples) free(*return_tuples);
272  (*return_count) = 0;
273  err << except.what();
274  *err_msg = pgr_msg(err.str().c_str());
275  *log_msg = pgr_msg(log.str().c_str());
276  } catch (const std::pair<std::string, std::string>& ex) {
277  (*return_count) = 0;
278  err << ex.first;
279  log.str("");
280  log.clear();
281  log << ex.second;
282  *err_msg = pgr_msg(err.str().c_str());
283  *log_msg = pgr_msg(log.str().c_str());
284  } catch(...) {
285  if (*return_tuples) free(*return_tuples);
286  (*return_count) = 0;
287  err << "Caught unknown exception!";
288  *err_msg = pgr_msg(err.str().c_str());
289  *log_msg = pgr_msg(log.str().c_str());
290  }
291 }

References anonymous_namespace{pickDeliverEuclidean_driver.cpp}::are_shipments_ok(), PickDeliveryOrders_t::deliver_node_id, vrprouting::Pgr_messages::get_error(), anonymous_namespace{pickDeliverEuclidean_driver.cpp}::get_initial_solution(), vrprouting::Pgr_messages::get_log(), vrprouting::problem::PickDeliver::msg, pgassert, pgr_alloc(), pgr_msg(), PickDeliveryOrders_t::pick_node_id, and AssertFailedException::what().

Referenced by process().

PickDeliveryOrders_t::deliver_x
Coordinate deliver_x
Pickup service duration.
Definition: pickDeliveryOrders_t.h:70
PickDeliveryOrders_t::pick_x
Coordinate pick_x
Number of demand.
Definition: pickDeliveryOrders_t.h:62
pgr_alloc
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:66
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::initialsol::simple::Initials_code
Initials_code
Different kinds to insert an order into the vehicle.
Definition: initialsol/initials_code.h:37
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::id
Id id
Definition: pickDeliveryOrders_t.h:59
Id
int64_t Id
Definition: typedefs.h:78
anonymous_namespace{pickDeliverEuclidean_driver.cpp}::are_shipments_ok
bool are_shipments_ok(PickDeliveryOrders_t *customers_arr, size_t total_customers, std::string *err_string, std::string *hint_string)
Definition: pickDeliverEuclidean_driver.cpp:72
PickDeliveryOrders_t::pick_y
Coordinate pick_y
Pick x coordinate: used in stand alone program for benchmarks.
Definition: pickDeliveryOrders_t.h:63
Multiplier
double Multiplier
Definition: typedefs.h:77
vrprouting::optimizers::simple::Optimize
Definition: optimizers/simple.h:40
anonymous_namespace{pickDeliverEuclidean_driver.cpp}::get_initial_solution
vrprouting::problem::Solution get_initial_solution(vrprouting::problem::PickDeliver *problem_ptr, int m_initial_id)
Definition: pickDeliverEuclidean_driver.cpp:50
PickDeliveryOrders_t::deliver_y
Coordinate deliver_y
Deliver x coordinate: used in stand alone program for benchmarks.
Definition: pickDeliveryOrders_t.h:71
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