55 size_t total_customers,
58 size_t total_vehicles,
62 int initial_solution_id,
70 std::ostringstream log;
71 std::ostringstream notice;
72 std::ostringstream err;
74 *return_tuples =
nullptr;
80 std::vector<PickDeliveryOrders_t> orders(
81 customers_arr, customers_arr + total_customers);
82 std::vector<Vehicle_t> vehicles(
83 vehicles_arr, vehicles_arr + total_vehicles);
85 std::map<std::pair<double, double>, int64_t> matrix_data;
87 for (
const auto &o : orders) {
88 matrix_data[std::pair<double, double>(o.pick_x, o.pick_y)] = o.pick_node_id;
89 matrix_data[std::pair<double, double>(o.deliver_x, o.deliver_y)] = o.deliver_node_id;
92 for (
const auto &v : vehicles) {
93 matrix_data[std::pair<double, double>(v.start_x, v.start_y)] = v.start_node_id;
94 matrix_data[std::pair<double, double>(v.end_x, v.end_y)] = v.end_node_id;
98 for (
const auto &e: matrix_data) {
99 unique_ids += e.second;
101 if (unique_ids.
size() != matrix_data.size()) {
104 for (
auto &e: matrix_data) {
109 for (
auto &o : orders) {
110 o.pick_node_id = matrix_data[std::pair<double, double>(o.pick_x, o.pick_y)];
111 o.deliver_node_id = matrix_data[std::pair<double, double>(o.deliver_x, o.deliver_y)];
113 for (
auto &v : vehicles) {
114 v.start_node_id = matrix_data[std::pair<double, double>(v.start_x, v.start_y)];
115 v.end_node_id = matrix_data[std::pair<double, double>(v.end_x, v.end_y)];
120 log <<
"Initialize problem\n";
126 static_cast<size_t>(max_cycles),
127 initial_solution_id);
130 if (!err.str().empty()) {
135 *log_msg =
pgr_msg(log.str().c_str());
136 *err_msg =
pgr_msg(err.str().c_str());
140 log <<
"Finish Reading data\n";
148 log <<
"Caught unknown exception!";
153 log <<
"Finish solve\n";
157 log <<
"solution size: " << solution.size() <<
"\n";
160 if (!solution.empty()) {
161 (*return_tuples) =
pgr_alloc(solution.size(), (*return_tuples));
163 for (
const auto &row : solution) {
164 (*return_tuples)[seq] = row;
168 (*return_count) = solution.size();
173 *log_msg = log.str().empty()?
176 *notice_msg = notice.str().empty()?
180 if (*return_tuples) free(*return_tuples);
182 err << except.
what();
183 *err_msg =
pgr_msg(err.str().c_str());
184 *log_msg =
pgr_msg(log.str().c_str());
185 }
catch (std::exception& except) {
186 if (*return_tuples) free(*return_tuples);
188 err << except.what();
189 *err_msg =
pgr_msg(err.str().c_str());
190 *log_msg =
pgr_msg(log.str().c_str());
191 }
catch (
const std::pair<std::string, std::string>& ex) {
197 *err_msg =
pgr_msg(err.str().c_str());
198 *log_msg =
pgr_msg(log.str().c_str());
200 if (*return_tuples) free(*return_tuples);
202 err <<
"Caught unknown exception!";
203 *err_msg =
pgr_msg(err.str().c_str());
204 *log_msg =
pgr_msg(log.str().c_str());