49 size_t total_customers,
52 size_t total_vehicles,
59 int initial_solution_id,
67 std::ostringstream log;
68 std::ostringstream notice;
69 std::ostringstream err;
79 log <<
"do_pgr_pickDeliver\n";
85 std::vector<PickDeliveryOrders_t> orders(
86 customers_arr, customers_arr + total_customers);
88 std::vector<Vehicle_t> vehicles(
89 vehicles_arr, vehicles_arr + total_vehicles);
91 std::vector <Matrix_cell_t> data_costs(
93 matrix_cells_arr + total_cells);
97 auto depot_node = vehicles[0].start_node_id;
106 for (
const auto &v : vehicles) {
107 if (v.start_node_id != depot_node && v.end_node_id != depot_node) {
108 err <<
"All vehicles must depart & arrive to same node";
109 *err_msg =
pgr_msg(err.str().c_str());
117 for (
const auto &o : orders) {
118 if (o.pick_node_id != depot_node) {
119 err <<
"All orders must be picked at depot";
120 *err_msg =
pgr_msg(err.str().c_str());
127 err <<
"An Infinity value was found on the Matrix";
128 *err_msg =
pgr_msg(err.str().c_str());
132 log <<
"Initialize problem\n";
138 static_cast<size_t>(max_cycles),
139 initial_solution_id);
142 if (!err.str().empty()) {
144 *log_msg =
pgr_msg(log.str().c_str());
145 *err_msg =
pgr_msg(err.str().c_str());
149 log <<
"Finish Reading data\n";
160 log <<
"Caught unknown exception!";
166 log <<
"Finish solve\n";
172 log <<
"solution size: " << solution.size() <<
"\n";
175 if (!solution.empty()) {
176 (*return_tuples) =
pgr_alloc(solution.size(), (*return_tuples));
178 for (
const auto &row : solution) {
179 (*return_tuples)[seq] = row;
183 (*return_count) = solution.size();
186 *log_msg = log.str().empty()?
189 *notice_msg = notice.str().empty()?
193 if (*return_tuples) free(*return_tuples);
195 err << except.
what();
196 *err_msg =
pgr_msg(err.str().c_str());
197 *log_msg =
pgr_msg(log.str().c_str());
198 }
catch (std::exception& except) {
199 if (*return_tuples) free(*return_tuples);
201 err << except.what();
202 *err_msg =
pgr_msg(err.str().c_str());
203 *log_msg =
pgr_msg(log.str().c_str());
204 }
catch (
const std::pair<std::string, std::string>& ex) {
210 *err_msg =
pgr_msg(err.str().c_str());
211 *log_msg =
pgr_msg(log.str().c_str());
212 }
catch (
const std::pair<std::string, int64_t>& ex) {
217 log <<
"Node missing on matrix: id = " << ex.second;
218 *err_msg =
pgr_msg(err.str().c_str());
219 *log_msg =
pgr_msg(log.str().c_str());
221 if (*return_tuples) free(*return_tuples);
223 err <<
"Caught unknown exception!";
224 *err_msg =
pgr_msg(err.str().c_str());
225 *log_msg =
pgr_msg(log.str().c_str());