PGROUTING  2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pickDeliver_driver.cpp File Reference
#include "drivers/pickDeliver/pickDeliver_driver.h"
#include <string.h>
#include <sstream>
#include <string>
#include <deque>
#include <vector>
#include "vrp/pgr_pickDeliver.h"
#include "cpp_common/Dmatrix.h"
#include "cpp_common/pgr_assert.h"
#include "cpp_common/pgr_alloc.hpp"
Include dependency graph for pickDeliver_driver.cpp:

Go to the source code of this file.

Functions

void do_pgr_pickDeliver (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, double factor, int max_cycles, int initial_solution_id, General_vehicle_orders_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
 

Function Documentation

void do_pgr_pickDeliver ( 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,
double  factor,
int  max_cycles,
int  initial_solution_id,
General_vehicle_orders_t **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Definition at line 46 of file pickDeliver_driver.cpp.

References pgrouting::Pgr_messages::clear(), pgrouting::Pgr_messages::get_error(), pgrouting::Pgr_messages::get_log(), pgrouting::vrp::Pgr_pickDeliver::get_postgres_result(), pgrouting::tsp::Dmatrix::has_no_infinity(), pgrouting::vrp::PD_problem::msg, pgassert, pgr_alloc(), pgr_msg(), pgrouting::vrp::Pgr_pickDeliver::solve(), and AssertFailedException::what().

Referenced by process().

65  {
66  std::ostringstream log;
67  std::ostringstream notice;
68  std::ostringstream err;
69  try {
70  pgassert(!(*log_msg));
71  pgassert(!(*notice_msg));
72  pgassert(!(*err_msg));
73  pgassert(total_customers);
74  pgassert(total_vehicles);
75  pgassert(total_vehicles);
76  pgassert(*return_count == 0);
77  pgassert(!(*return_tuples));
78  log << "do_pgr_pickDeliver\n";
79 
80 
81  /*
82  * transform to C++ containers
83  */
84  std::vector<PickDeliveryOrders_t> orders(
85  customers_arr, customers_arr + total_customers);
86 
87  std::vector<Vehicle_t> vehicles(
88  vehicles_arr, vehicles_arr + total_vehicles);
89 
90  std::vector <Matrix_cell_t> data_costs(
91  matrix_cells_arr,
92  matrix_cells_arr + total_cells);
93 
94  pgrouting::tsp::Dmatrix cost_matrix(data_costs);
95 
96  if (!cost_matrix.has_no_infinity()) {
97  err << "An Infinity value was found on the Matrix";
98  *err_msg = pgr_msg(err.str().c_str());
99  return;
100  }
101 
102  // TODO(vicky) wrap with a try and make a throw???
103  log << "Initialize problem\n";
105  orders,
106  vehicles,
107  cost_matrix,
108  factor,
109  max_cycles,
110  initial_solution_id);
111 
112  err << pd_problem.msg.get_error();
113  if (!err.str().empty()) {
114  log << pd_problem.msg.get_log();
115  *log_msg = pgr_msg(log.str().c_str());
116  *err_msg = pgr_msg(err.str().c_str());
117  return;
118  }
119  log << pd_problem.msg.get_log();
120  log << "Finish Reading data\n";
121  pd_problem.msg.clear();
122 
123 
124  try {
125  pd_problem.solve();
126  } catch (AssertFailedException &except) {
127  log << pd_problem.msg.get_log();
128  pd_problem.msg.clear();
129  throw except;
130  } catch(...) {
131  log << "Caught unknown exception!";
132  throw;
133  }
134 
135 
136  log << pd_problem.msg.get_log();
137  log << "Finish solve\n";
138  pd_problem.msg.clear();
139 
140  auto solution = pd_problem.get_postgres_result();
141  log << pd_problem.msg.get_log();
142  pd_problem.msg.clear();
143  log << "solution size: " << solution.size() << "\n";
144 
145 
146  if (!solution.empty()) {
147  (*return_tuples) = pgr_alloc(solution.size(), (*return_tuples));
148  int seq = 0;
149  for (const auto &row : solution) {
150  (*return_tuples)[seq] = row;
151  ++seq;
152  }
153  }
154  (*return_count) = solution.size();
155 
156  pgassert(*err_msg == NULL);
157  *log_msg = log.str().empty()?
158  nullptr :
159  pgr_msg(log.str().c_str());
160  *notice_msg = notice.str().empty()?
161  nullptr :
162  pgr_msg(notice.str().c_str());
163  } catch (AssertFailedException &except) {
164  if (*return_tuples) free(*return_tuples);
165  (*return_count) = 0;
166  err << except.what();
167  *err_msg = pgr_msg(err.str().c_str());
168  *log_msg = pgr_msg(log.str().c_str());
169  } catch (std::exception& except) {
170  if (*return_tuples) free(*return_tuples);
171  (*return_count) = 0;
172  err << except.what();
173  *err_msg = pgr_msg(err.str().c_str());
174  *log_msg = pgr_msg(log.str().c_str());
175  } catch(...) {
176  if (*return_tuples) free(*return_tuples);
177  (*return_count) = 0;
178  err << "Caught unknown exception!";
179  *err_msg = pgr_msg(err.str().c_str());
180  *log_msg = pgr_msg(log.str().c_str());
181  }
182 }
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:126
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
char * pgr_msg(const std::string &msg)
Definition: pgr_alloc.cpp:29
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:64
virtual const char * what() const
Definition: pgr_assert.cpp:53

Here is the call graph for this function:

Here is the caller graph for this function: