68 std::vector<Short_vehicle>
71 Vehicle_t *vehicles_arr,
size_t total_vehicles,
72 std::vector<Short_vehicle> new_stops,
75 int64_t execution_date) {
81 shipments_arr, total_shipments,
82 vehicles_arr, total_vehicles,
98 auto sol =
static_cast<Solution
>(Initial_solution(execution_date,
true, &pd_problem));
106 sol = Optimize(sol,
static_cast<size_t>(max_cycles),
false,
true);
108 return sol.get_stops();
127 for (
size_t i = 0; i < total_shipments; ++i) {
133 return processing_times;
145 Vehicle_t *vehicles_arr,
size_t total_vehicles
148 for (
size_t i = 0; i < total_vehicles; ++i) {
151 processing_times += vehicles_arr[i].
end_open_t;
154 return processing_times;
164 std::vector<Short_vehicle>
166 Vehicle_t *vehicles_arr,
size_t total_vehicles
168 std::vector<Short_vehicle> the_stops;
169 for (
size_t i = 0; i < total_vehicles; ++i) {
170 std::vector<Id> stops;
171 for (
size_t j = 0; j < vehicles_arr[i].
stops_size; ++j) {
172 stops.push_back(vehicles_arr[i].stops[j]);
174 the_stops.push_back({vehicles_arr[i].
id, stops});
176 std::sort(the_stops.begin(), the_stops.end(), []
188 const std::vector<Short_vehicle> new_values) {
189 for (
const auto &v : new_values) {
191 auto v_to_modify = std::find_if(
192 the_stops.begin(), the_stops.end(), [v_id]
194 pgassert(v_to_modify != the_stops.end());
195 v_to_modify->stops = v.
stops;
212 std::vector<Short_vehicle>
215 Vehicle_t *vehicles_arr,
size_t total_vehicles,
218 int64_t execution_date,
219 bool subdivide_by_vehicle,
220 std::ostringstream &log) {
224 auto processing_times = subdivide_by_vehicle?
229 for (
const auto &t : processing_times) {
234 auto vehicles_to_process =
static_cast<size_t>(std::distance(vehicles_arr,
236 vehicles_arr, vehicles_arr + total_vehicles,
242 for (
size_t i = 0; i < vehicles_to_process; ++i) {
243 auto v_id = vehicles_arr[i].
id;
244 auto v_to_modify = std::find_if(
245 the_stops.begin(), the_stops.end(), [&]
248 for (
const auto &s : v_to_modify->stops) {
249 shipments_in_stops += s;
258 if ((shipments_in_stops.
size() == 0)
259 || (prev_shipments_in_stops == shipments_in_stops))
continue;
260 log <<
"\nOptimizing at time: " << t;
262 prev_shipments_in_stops = shipments_in_stops;
264 auto shipments_to_process =
static_cast<size_t>(std::distance(shipments_arr,
265 std::partition(shipments_arr, shipments_arr + total_shipments,
269 pgassert(shipments_in_stops.
size() ==
static_cast<size_t>(shipments_to_process));
272 shipments_arr, shipments_to_process,
273 vehicles_arr, vehicles_to_process, the_stops,
275 max_cycles, execution_date);
352 Vehicle_t *vehicles_arr,
size_t total_vehicles,
359 int64_t execution_date,
361 bool check_triangle_inequality,
363 bool subdivide_by_vehicle,
366 size_t *return_count,
371 std::ostringstream log;
372 std::ostringstream notice;
373 std::ostringstream err;
387 *return_tuples =
nullptr;
400 std::sort(vehicles_arr, vehicles_arr + total_vehicles,
403 total_vehicles =
static_cast<size_t>(std::distance(vehicles_arr,
404 std::unique(vehicles_arr, vehicles_arr + total_vehicles,
407 total_vehicles =
static_cast<size_t>(std::distance(vehicles_arr,
408 std::remove_if(vehicles_arr, vehicles_arr + total_vehicles,
418 for (
size_t i = 0; i < total_vehicles; ++i) {
421 for (
size_t j = 0; j < vehicles_arr[i].
stops_size; ++j) {
422 shipments_in_stops += vehicles_arr[i].
stops[j];
426 std::sort(shipments_arr, shipments_arr + total_shipments,
429 total_shipments =
static_cast<size_t>(std::distance(shipments_arr,
430 std::unique(shipments_arr, shipments_arr + total_shipments,
433 total_shipments =
static_cast<size_t>(std::distance(shipments_arr,
434 std::remove_if(shipments_arr, shipments_arr + total_shipments,
440 if (shipments_in_stops.
size() != total_shipments) {
441 for (
size_t i = 0; i < total_shipments; ++i) {
442 shipments_in_stops -= shipments_arr[i].
id;
444 std::ostringstream hint;
445 err <<
"Missing shipments for processing ";
446 hint <<
"Shipments missing: " << shipments_in_stops << log.str();
447 *log_msg =
pgr_msg(hint.str());
455 for (
size_t i = 0; i < total_shipments; ++i) {
467 matrix_cells_arr, total_cells,
468 multipliers_arr, total_multipliers,
472 log <<
"\nFixing Matrix that does not obey triangle inequality "
476 log <<
"\nMatrix Still does not obey triangle inequality ";
481 err <<
"\nAn Infinity value was found on the Matrix";
490 auto solution = subdivide?
492 shipments_arr, total_shipments,
493 vehicles_arr, total_vehicles,
495 max_cycles, execution_date,
496 subdivide_by_vehicle,
499 shipments_arr, total_shipments,
500 vehicles_arr, total_vehicles, {},
502 max_cycles, execution_date);
507 if (!solution.empty()) {
508 (*return_tuples) =
pgr_alloc(total_shipments * 2, (*return_tuples));
511 for (
const auto &row : solution) {
512 for (
const auto &o_id : row.stops) {
513 (*return_tuples)[seq].vehicle_id = row.id;
514 (*return_tuples)[seq].order_id = o_id;
520 (*return_count) = total_shipments * 2;
523 *log_msg = log.str().empty()?
526 *notice_msg = notice.str().empty()?
530 err << except.
what() << log.str();
532 }
catch (std::exception& except) {
533 err << except.what() << log.str();
535 }
catch (
const std::pair<std::string, std::string>& ex) {
540 *err_msg =
pgr_msg(err.str().c_str());
541 *log_msg =
pgr_msg(log.str().c_str());
543 err <<
"Caught unknown exception!" << log.str();