From 249957176e5ccdb568f8e7e4c5d83aa3d61ec8c1 Mon Sep 17 00:00:00 2001 From: cvvergara Date: Sun, 25 Aug 2024 11:57:25 -0600 Subject: [PATCH] (vroom) consting some functions and using a typedef --- include/vroom/vroom.hpp | 16 +++++++++------- src/problem/vroom.cpp | 10 +++++----- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/include/vroom/vroom.hpp b/include/vroom/vroom.hpp index 54d1cf76f..0569f248c 100644 --- a/include/vroom/vroom.hpp +++ b/include/vroom/vroom.hpp @@ -49,24 +49,26 @@ namespace vrprouting { namespace problem { class Vroom : public vrprouting::Messages { + using MapTW = std::vector; + public: /** @brief sets m_jobs by adding the Vroom_job_t */ void add_jobs( const std::vector&, - const std::vector&); + const MapTW&); void add_jobs(const Vroom_job_t*, size_t, const Vroom_time_window_t*, size_t); /** @brief sets m_shipments by adding the Vroom_shipment_t */ void add_shipments( const std::vector&, - const std::vector&); + const MapTW&); void add_shipments(const Vroom_shipment_t*, size_t, const Vroom_time_window_t*, size_t); /** @brief sets m_vehicles by adding the Vroom_vehicle_t */ void add_vehicles( const std::vector&, const std::vector&, - const std::vector&); + const MapTW&); void add_vehicles(const Vroom_vehicle_t*, size_t, const Vroom_break_t*, size_t, const Vroom_time_window_t*, size_t); /** @brief sets m_matrix */ @@ -94,10 +96,10 @@ class Vroom : public vrprouting::Messages { const Vroom_vehicle_t&, const std::vector&, const std::vector&) const; - void get_amount(::vroom::Amount, Amount**); - StepType get_job_step_type(::vroom::JOB_TYPE); - StepType get_step_type(::vroom::Step); - std::vector get_results(::vroom::Solution); + void get_amount(const ::vroom::Amount&, Amount**); + StepType get_job_step_type(const ::vroom::JOB_TYPE&); + StepType get_step_type(const ::vroom::Step&); + std::vector get_results(const ::vroom::Solution&); private: std::vector<::vroom::Job> m_jobs; diff --git a/src/problem/vroom.cpp b/src/problem/vroom.cpp index ba7d301ff..1389d8c85 100644 --- a/src/problem/vroom.cpp +++ b/src/problem/vroom.cpp @@ -297,7 +297,7 @@ Vroom::add_matrix(const vrprouting::vroom::Matrix &matrix) { } void -Vroom::get_amount(::vroom::Amount vroom_amount, Amount **amount) { +Vroom::get_amount(const ::vroom::Amount &vroom_amount, Amount **amount) { size_t amount_size = vroom_amount.size(); for (size_t i = 0; i < amount_size; i++) { *((*amount) + i) = vroom_amount[i]; @@ -305,7 +305,7 @@ Vroom::get_amount(::vroom::Amount vroom_amount, Amount **amount) { } StepType -Vroom::get_job_step_type(::vroom::JOB_TYPE vroom_job_type) { +Vroom::get_job_step_type(const ::vroom::JOB_TYPE &vroom_job_type) { StepType step_type; switch (vroom_job_type) { case ::vroom::JOB_TYPE::SINGLE: @@ -322,7 +322,7 @@ Vroom::get_job_step_type(::vroom::JOB_TYPE vroom_job_type) { } StepType -Vroom::get_step_type(::vroom::Step step) { +Vroom::get_step_type(const ::vroom::Step &step) { StepType step_type = 0; switch (step.step_type) { case ::vroom::STEP_TYPE::START: @@ -342,7 +342,7 @@ Vroom::get_step_type(::vroom::Step step) { } std::vector -Vroom::get_results(::vroom::Solution solution) { +Vroom::get_results(const ::vroom::Solution &solution) { std::vector results; auto routes = solution.routes; Idx vehicle_seq = 1; @@ -508,7 +508,7 @@ Vroom::solve( static_cast(exploration_level), threads); results = get_results(solution); } else { - int timeout_ms = (loading_time <= timeout * 1000) ? (timeout * 1000 - loading_time) : 0; + auto timeout_ms = (loading_time <= timeout * 1000) ? (timeout * 1000 - loading_time) : 0; auto solution = problem_instance.solve( static_cast(exploration_level), threads, timeout_ms); results = get_results(solution);