56 Solution m_solutions(problem_ptr);
57 if (m_initial_id == 0) {
58 for (
int i = 1; i < 7; ++i) {
60 m_solutions = Initial_solution((
Initials_code)i, problem_ptr);
62 auto new_sol = Initial_solution((
Initials_code)i, problem_ptr);
63 m_solutions = (new_sol < m_solutions)? new_sol : m_solutions;
67 m_solutions = Initial_solution((
Initials_code)m_initial_id, problem_ptr);
77 size_t total_customers,
80 size_t total_vehicles,
87 int initial_solution_id,
95 std::ostringstream log;
96 std::ostringstream notice;
97 std::ostringstream err;
107 log <<
"do_pgr_pickDeliver\n";
110 *return_tuples =
nullptr;
116 for (
size_t i = 0; i < total_customers; ++i) {
119 order_ids += customers_arr[i].
id;
122 for (
size_t i = 0; i < total_vehicles; ++i) {
123 auto vehicle = vehicles_arr[i];
124 node_ids += vehicle.start_node_id;
125 node_ids += vehicle.end_node_id;
133 std::vector<Vehicle_t> vehicles(
134 vehicles_arr, vehicles_arr + total_vehicles);
143 auto depot_node = vehicles[0].start_node_id;
152 for (
const auto &v : vehicles) {
153 if (v.start_node_id != depot_node && v.end_node_id != depot_node) {
154 err <<
"All vehicles must depart & arrive to same node";
155 *err_msg =
pgr_msg(err.str().c_str());
163 for (
size_t i = 0; i < total_customers; ++i) {
164 if (customers_arr[i].pick_node_id != depot_node) {
165 err <<
"All orders must be picked at depot";
166 *err_msg =
pgr_msg(err.str().c_str());
174 err <<
"An Infinity value was found on the Matrix. Might be missing information of a node";
175 *err_msg =
pgr_msg(err.str().c_str());
181 log <<
"Initialize problem\n";
183 customers_arr, total_customers,
184 vehicles_arr, total_vehicles,
188 if (!err.str().empty()) {
190 *log_msg =
pgr_msg(log.str().c_str());
191 *err_msg =
pgr_msg(err.str().c_str());
195 log <<
"Finish Reading data\n";
204 sol = Optimize(sol,
static_cast<size_t>(max_cycles), (
Initials_code)initial_solution_id);
211 log <<
"Caught unknown exception!";
217 log <<
"Finish solve\n";
220 auto solution = sol.get_postgres_result();
223 log <<
"solution size: " << solution.size() <<
"\n";
226 if (!solution.empty()) {
227 (*return_tuples) =
pgr_alloc(solution.size(), (*return_tuples));
229 for (
const auto &row : solution) {
230 (*return_tuples)[seq] = row;
234 (*return_count) = solution.size();
237 *log_msg = log.str().empty()?
240 *notice_msg = notice.str().empty()?
244 if (*return_tuples) free(*return_tuples);
246 err << except.
what();
247 *err_msg =
pgr_msg(err.str().c_str());
248 *log_msg =
pgr_msg(log.str().c_str());
249 }
catch (std::exception& except) {
250 if (*return_tuples) free(*return_tuples);
252 err << except.what();
253 *err_msg =
pgr_msg(err.str().c_str());
254 *log_msg =
pgr_msg(log.str().c_str());
255 }
catch (
const std::pair<std::string, std::string>& ex) {
259 *err_msg =
pgr_msg(err.str().c_str());
260 *log_msg =
pgr_msg(log.str().c_str());
261 }
catch (
const std::pair<std::string, int64_t>& ex) {
264 log <<
"FOOOO missing on matrix: id = " << ex.second;
265 *err_msg =
pgr_msg(err.str().c_str());
266 *log_msg =
pgr_msg(log.str().c_str());
268 if (*return_tuples) free(*return_tuples);
270 err <<
"Caught unknown exception!";
271 *err_msg =
pgr_msg(err.str().c_str());
272 *log_msg =
pgr_msg(log.str().c_str());