110 Vehicle_t *vehicles_arr,
size_t total_vehicles,
118 bool stop_on_all_served,
119 int64_t execution_date,
122 size_t *return_count,
127 std::ostringstream log;
128 std::ostringstream notice;
129 std::ostringstream err;
142 log <<
"do_pickDeliver\n";
144 *return_tuples =
nullptr;
150 for (
size_t i = 0; i < total_customers; ++i) {
153 order_ids += customers_arr[i].
id;
156 bool missing =
false;
157 for (
size_t i = 0; i < total_vehicles; ++i) {
158 auto vehicle = vehicles_arr[i];
159 node_ids += vehicle.start_node_id;
160 node_ids += vehicle.end_node_id;
161 for (
size_t j = 0; j < vehicle.stops_size; ++j) {
162 if (!order_ids.
has(vehicle.stops[j])) {
163 if (!missing) err <<
"Order in 'stops' information missing";
165 err <<
"Missing information of order " << vehicle.stops[j] <<
"\n";
175 matrix_cells_arr, total_cells,
176 multipliers_arr, total_multipliers,
183 log <<
"[PickDeliver] Fixing Matrix that does not obey triangle inequality ";
187 log <<
"[pickDeliver] Matrix Still does not obey triangle inequality ";
195 err <<
"An Infinity value was found on the Matrix";
201 log <<
"stop_on_all_served" << stop_on_all_served <<
"\n";
202 log <<
"execution_date" << execution_date <<
"\n";
203 log <<
"Initialize problem\n";
208 customers_arr, total_customers,
209 vehicles_arr, total_vehicles,
213 if (!err.str().empty()) {
223 log <<
"Finish Initialize problem\n";
233 auto sol =
static_cast<Solution
>(Initial_solution(execution_date, optimize, &pd_problem));
238 sol = Optimize(sol,
static_cast<size_t>(max_cycles), stop_on_all_served, optimize);
244 log <<
"Caught unknown exception!";
251 log <<
"Finish solve\n";
256 auto solution = sol.get_postgres_result();
259 log <<
"solution size: " << solution.size() <<
"\n";
262 if (!solution.empty()) {
263 (*return_tuples) =
pgr_alloc(solution.size(), (*return_tuples));
265 for (
const auto &row : solution) {
266 (*return_tuples)[seq] = row;
270 (*return_count) = solution.size();
275 *log_msg = log.str().empty()?
278 *notice_msg = notice.str().empty()?
282 if (*return_tuples) free(*return_tuples);
284 err << except.
what() << log.str();
286 }
catch (std::exception& except) {
287 if (*return_tuples) free(*return_tuples);
289 err << except.what() << log.str();
292 if (*return_tuples) free(*return_tuples);
294 err <<
"Caught unknown exception!" << log.str();