54 Solution m_solutions(problem_ptr);
55 if (m_initial_id == 0) {
56 for (
int i = 1; i < 7; ++i) {
58 m_solutions = Initial_solution((
Initials_code)i, problem_ptr);
60 auto new_sol = Initial_solution((
Initials_code)i, problem_ptr);
61 m_solutions = (new_sol < m_solutions)? new_sol : m_solutions;
65 m_solutions = Initial_solution((
Initials_code)m_initial_id, problem_ptr);
74 size_t total_customers,
75 std::string *err_string,
76 std::string *hint_string) {
84 for (
size_t i = 0; i < total_customers; ++i) {
85 if (customers_arr[i].
demand == 0) {
86 *err_string =
"Unexpected zero value found on column 'demand' of shipments";
87 *hint_string =
"Check shipment id #:" + std::to_string(customers_arr[i].
id);
92 *err_string =
"Unexpected negative value found on column 'p_service_t' of shipments";
93 *hint_string =
"Check shipment id #:" + std::to_string(customers_arr[i].
id);
98 *err_string =
"Unexpected negative value found on column 'd_service_t' of shipments";
99 *hint_string =
"Check shipment id #:" + std::to_string(customers_arr[i].
id);
104 *err_string =
"Unexpected pickup time windows found on shipments";
105 *hint_string =
"Check shipment id #:" + std::to_string(customers_arr[i].
id);
110 *err_string =
"Unexpected delivery time windows found on shipments";
111 *hint_string =
"Check shipment id #:" + std::to_string(customers_arr[i].
id);
123 size_t total_customers,
126 size_t total_vehicles,
130 int initial_solution_id,
133 size_t *return_count,
138 std::ostringstream log;
139 std::ostringstream notice;
140 std::ostringstream err;
142 *return_tuples =
nullptr;
144 std::string err_string;
145 std::string hint_string;
146 if (!
are_shipments_ok(customers_arr, total_customers, &err_string, &hint_string)) {
147 *err_msg =
pgr_msg(err_string.c_str());
148 *log_msg =
pgr_msg(hint_string.c_str());
155 std::vector<PickDeliveryOrders_t> orders(
156 customers_arr, customers_arr + total_customers);
157 std::vector<Vehicle_t> vehicles(
158 vehicles_arr, vehicles_arr + total_vehicles);
160 std::map<std::pair<Coordinate, Coordinate>,
Id> matrix_data;
162 for (
const auto &o : orders) {
165 matrix_data[std::pair<Coordinate, Coordinate>(o.pick_x, o.pick_y)] = 0;
166 matrix_data[std::pair<Coordinate, Coordinate>(o.deliver_x, o.deliver_y)] = 0;
169 for (
const auto &v : vehicles) {
170 matrix_data[std::pair<Coordinate, Coordinate>(v.start_x, v.start_y)] = 0;
171 matrix_data[std::pair<Coordinate, Coordinate>(v.end_x, v.end_y)] = 0;
179 for (
auto &e : matrix_data) {
183 for (
const auto &e : matrix_data) {
184 unique_ids += e.second;
185 log << e.second <<
"(" << e.first.first <<
"," << e.first.second <<
")\n";
188 for (
size_t i = 0; i < total_customers; ++i) {
190 matrix_data[std::pair<Coordinate, Coordinate>(customers_arr[i].pick_x, customers_arr[i].pick_y)];
193 matrix_data[std::pair<Coordinate, Coordinate>(customers_arr[i].deliver_x, customers_arr[i].deliver_y)];
195 for (
auto &v : vehicles) {
196 v.start_node_id = matrix_data[std::pair<Coordinate, Coordinate>(v.start_x, v.start_y)];
197 v.end_node_id = matrix_data[std::pair<Coordinate, Coordinate>(v.end_x, v.end_y)];
202 log <<
"Initialize problem\n";
204 customers_arr, total_customers,
205 vehicles_arr, total_vehicles,
209 if (!err.str().empty()) {
214 *log_msg =
pgr_msg(log.str().c_str());
215 *err_msg =
pgr_msg(err.str().c_str());
219 log <<
"Finish Reading data\n";
227 sol = Optimize(sol,
static_cast<size_t>(max_cycles), (
Initials_code)initial_solution_id);
233 log <<
"Caught unknown exception!";
238 log <<
"Finish solve\n";
240 auto solution = sol.get_postgres_result();
242 log <<
"solution size: " << solution.size() <<
"\n";
245 if (!solution.empty()) {
246 (*return_tuples) =
pgr_alloc(solution.size(), (*return_tuples));
248 for (
const auto &row : solution) {
249 (*return_tuples)[seq] = row;
253 (*return_count) = solution.size();
258 *log_msg = log.str().empty()?
261 *notice_msg = notice.str().empty()?
265 if (*return_tuples) free(*return_tuples);
267 err << except.
what();
268 *err_msg =
pgr_msg(err.str().c_str());
269 *log_msg =
pgr_msg(log.str().c_str());
270 }
catch (std::exception& except) {
271 if (*return_tuples) free(*return_tuples);
273 err << except.what();
274 *err_msg =
pgr_msg(err.str().c_str());
275 *log_msg =
pgr_msg(log.str().c_str());
276 }
catch (
const std::pair<std::string, std::string>& ex) {
282 *err_msg =
pgr_msg(err.str().c_str());
283 *log_msg =
pgr_msg(log.str().c_str());
285 if (*return_tuples) free(*return_tuples);
287 err <<
"Caught unknown exception!";
288 *err_msg =
pgr_msg(err.str().c_str());
289 *log_msg =
pgr_msg(log.str().c_str());