From f4bda1cf16453392b20d2cf4b1dfe5760678b707 Mon Sep 17 00:00:00 2001 From: reinterpretcat Date: Tue, 12 Dec 2023 21:53:47 +0100 Subject: [PATCH] Apply refactoring on objectives definition --- .../src/format/problem/goal_reader.rs | 4 ++-- vrp-pragmatic/src/format/problem/model.rs | 22 +++---------------- vrp-pragmatic/src/validation/objectives.rs | 2 +- .../features/breaks/interval_break_test.rs | 4 ++-- .../tests/features/fleet/basic_multi_shift.rs | 2 +- .../tests/features/priorities/basic_order.rs | 4 ++-- .../tests/features/priorities/basic_value.rs | 2 +- .../tour_shape/basic_tour_compactness.rs | 2 +- .../work_balance/balance_activities.rs | 2 +- .../features/work_balance/balance_max_load.rs | 2 +- .../work_balance/balance_transport.rs | 2 +- vrp-pragmatic/tests/helpers/problem.rs | 4 ++-- .../tests/unit/validation/objectives_test.rs | 8 +++---- 13 files changed, 22 insertions(+), 38 deletions(-) diff --git a/vrp-pragmatic/src/format/problem/goal_reader.rs b/vrp-pragmatic/src/format/problem/goal_reader.rs index e5ee8e42b..5f5a81f14 100644 --- a/vrp-pragmatic/src/format/problem/goal_reader.rs +++ b/vrp-pragmatic/src/format/problem/goal_reader.rs @@ -91,7 +91,7 @@ fn get_objective_features( objectives } else { let mut objectives = vec![ - vec![Objective::MinimizeUnassignedJobs { breaks: Some(1.) }], + vec![Objective::MinimizeUnassigned { breaks: Some(1.) }], vec![Objective::MinimizeTours], vec![Objective::MinimizeCost], ]; @@ -155,7 +155,7 @@ fn get_objective_features( }), -1, ), - Objective::MinimizeUnassignedJobs { breaks } => create_minimize_unassigned_jobs_feature( + Objective::MinimizeUnassigned { breaks } => create_minimize_unassigned_jobs_feature( "min_unassigned", Arc::new({ let break_value = *breaks; diff --git a/vrp-pragmatic/src/format/problem/model.rs b/vrp-pragmatic/src/format/problem/model.rs index 81514260d..7d10c9303 100644 --- a/vrp-pragmatic/src/format/problem/model.rs +++ b/vrp-pragmatic/src/format/problem/model.rs @@ -436,12 +436,11 @@ pub struct VehicleOptionalBreakPlace { /// Vehicle break policy. #[derive(Clone, Deserialize, Debug, Serialize)] +#[serde(rename_all = "kebab-case")] pub enum VehicleOptionalBreakPolicy { /// Allows to skip break if actual tour schedule doesn't intersect with vehicle time window. - #[serde(rename(deserialize = "skip-if-no-intersection", serialize = "skip-if-no-intersection"))] SkipIfNoIntersection, /// Allows to skip break if vehicle arrives before break's time window end. - #[serde(rename(deserialize = "skip-if-arrival-before-end", serialize = "skip-if-arrival-before-end"))] SkipIfArrivalBeforeEnd, } @@ -557,30 +556,24 @@ pub struct Fleet { /// Specifies objective function types. #[derive(Clone, Deserialize, Debug, Serialize)] -#[serde(tag = "type")] +#[serde(tag = "type", rename_all = "kebab-case")] pub enum Objective { /// An objective to minimize total cost as linear combination of total time and distance. - #[serde(rename(deserialize = "minimize-cost", serialize = "minimize-cost"))] MinimizeCost, /// An objective to minimize total distance. - #[serde(rename(deserialize = "minimize-distance", serialize = "minimize-distance"))] MinimizeDistance, /// An objective to minimize total duration. - #[serde(rename(deserialize = "minimize-duration", serialize = "minimize-duration"))] MinimizeDuration, /// An objective to minimize total tour amount. - #[serde(rename(deserialize = "minimize-tours", serialize = "minimize-tours"))] MinimizeTours, /// An objective to maximize total tour amount. - #[serde(rename(deserialize = "maximize-tours", serialize = "maximize-tours"))] MaximizeTours, /// An objective to maximize value of served jobs. - #[serde(rename(deserialize = "maximize-value", serialize = "maximize-value"))] MaximizeValue { /// Specifies a weight of skipped breaks. #[serde(skip_serializing_if = "Option::is_none")] @@ -588,8 +581,7 @@ pub enum Objective { }, /// An objective to minimize amount of unassigned jobs. - #[serde(rename(deserialize = "minimize-unassigned", serialize = "minimize-unassigned"))] - MinimizeUnassignedJobs { + MinimizeUnassigned { /// A skipped break weight to increase/decrease break is importance. /// Default is 1. #[serde(skip_serializing_if = "Option::is_none")] @@ -597,11 +589,9 @@ pub enum Objective { }, /// An objective to minimize sum of arrival times from all routes. - #[serde(rename(deserialize = "minimize-arrival-time", serialize = "minimize-arrival-time"))] MinimizeArrivalTime, /// An objective to balance max load across all tours. - #[serde(rename(deserialize = "balance-max-load", serialize = "balance-max-load"))] BalanceMaxLoad { /// A relative load in single tour before balancing takes place. #[serde(skip_serializing_if = "Option::is_none")] @@ -609,7 +599,6 @@ pub enum Objective { }, /// An objective to balance activities across all tours. - #[serde(rename(deserialize = "balance-activities", serialize = "balance-activities"))] BalanceActivities { /// An options which can be used to specify minimum activity amount in a tour before /// it considered for balancing. @@ -618,7 +607,6 @@ pub enum Objective { }, /// An objective to balance distance across all tours. - #[serde(rename(deserialize = "balance-distance", serialize = "balance-distance"))] BalanceDistance { /// An options which can be used to specify minimum distance of a tour before /// it considered for balancing. @@ -627,7 +615,6 @@ pub enum Objective { }, /// An objective to balance duration across all tours. - #[serde(rename(deserialize = "balance-duration", serialize = "balance-duration"))] BalanceDuration { /// An options which can be used to specify minimum duration of a tour before /// it considered for balancing. @@ -636,18 +623,15 @@ pub enum Objective { }, /// An objective to control how tours are built. - #[serde(rename(deserialize = "compact-tour", serialize = "compact-tour"))] CompactTour { /// Options used to relax objective's impact. options: CompactOptions, }, /// An objective to control order of job activities in the tour. - #[serde(rename(deserialize = "tour-order", serialize = "tour-order"))] TourOrder, /// An objective to prefer jobs to be served as soon as possible. - #[serde(rename(deserialize = "fast-service", serialize = "fast-service"))] FastService { /// An objective tolerance specifies how different objective values have to be /// to consider them different. Relative distance metric is used. diff --git a/vrp-pragmatic/src/validation/objectives.rs b/vrp-pragmatic/src/validation/objectives.rs index ff7e13606..6c5661c15 100644 --- a/vrp-pragmatic/src/validation/objectives.rs +++ b/vrp-pragmatic/src/validation/objectives.rs @@ -31,7 +31,7 @@ fn check_e1601_duplicate_objectives(objectives: &[&Objective]) -> Result<(), For MinimizeTours => acc.entry("minimize-tours"), MaximizeTours => acc.entry("maximize-tours"), MaximizeValue { .. } => acc.entry("maximize-value"), - MinimizeUnassignedJobs { .. } => acc.entry("minimize-unassigned"), + MinimizeUnassigned { .. } => acc.entry("minimize-unassigned"), MinimizeArrivalTime => acc.entry("minimize-arrival-time"), BalanceMaxLoad { .. } => acc.entry("balance-max-load"), BalanceActivities { .. } => acc.entry("balance-activities"), diff --git a/vrp-pragmatic/tests/features/breaks/interval_break_test.rs b/vrp-pragmatic/tests/features/breaks/interval_break_test.rs index 4a0bc2e5b..0a8ad2543 100644 --- a/vrp-pragmatic/tests/features/breaks/interval_break_test.rs +++ b/vrp-pragmatic/tests/features/breaks/interval_break_test.rs @@ -1,10 +1,10 @@ -use crate::format::problem::Objective::{MinimizeCost, MinimizeUnassignedJobs}; +use crate::format::problem::Objective::{MinimizeCost, MinimizeUnassigned}; use crate::format::problem::*; use crate::format_time; use crate::helpers::*; fn create_test_objectives() -> Option>> { - Some(vec![vec![MinimizeUnassignedJobs { breaks: Some(10.) }], vec![MinimizeCost]]) + Some(vec![vec![MinimizeUnassigned { breaks: Some(10.) }], vec![MinimizeCost]]) } #[test] diff --git a/vrp-pragmatic/tests/features/fleet/basic_multi_shift.rs b/vrp-pragmatic/tests/features/fleet/basic_multi_shift.rs index 4783a01a9..2e0f0e43e 100644 --- a/vrp-pragmatic/tests/features/fleet/basic_multi_shift.rs +++ b/vrp-pragmatic/tests/features/fleet/basic_multi_shift.rs @@ -102,7 +102,7 @@ fn can_prefer_first_days_with_minimize_arrival_time_objective() { ..create_empty_plan() }, objectives: Some(vec![ - vec![Objective::MinimizeUnassignedJobs { breaks: None }], + vec![Objective::MinimizeUnassigned { breaks: None }], vec![Objective::MinimizeArrivalTime], vec![Objective::MinimizeCost], ]), diff --git a/vrp-pragmatic/tests/features/priorities/basic_order.rs b/vrp-pragmatic/tests/features/priorities/basic_order.rs index d3e3e03f4..719bf31aa 100644 --- a/vrp-pragmatic/tests/features/priorities/basic_order.rs +++ b/vrp-pragmatic/tests/features/priorities/basic_order.rs @@ -21,13 +21,13 @@ fn create_test_limit() -> Option { fn create_order_objective(is_constrained: bool) -> Vec> { if is_constrained { vec![ - vec![Objective::MinimizeUnassignedJobs { breaks: None }], + vec![Objective::MinimizeUnassigned { breaks: None }], vec![Objective::MinimizeTours], vec![Objective::MinimizeCost], ] } else { vec![ - vec![Objective::MinimizeUnassignedJobs { breaks: None }], + vec![Objective::MinimizeUnassigned { breaks: None }], vec![Objective::MinimizeTours], vec![Objective::TourOrder], vec![Objective::MinimizeCost], diff --git a/vrp-pragmatic/tests/features/priorities/basic_value.rs b/vrp-pragmatic/tests/features/priorities/basic_value.rs index 215c453a0..b2a66dd77 100644 --- a/vrp-pragmatic/tests/features/priorities/basic_value.rs +++ b/vrp-pragmatic/tests/features/priorities/basic_value.rs @@ -9,7 +9,7 @@ parameterized_test! {can_prefer_jobs_with_more_value, objectives, { can_prefer_jobs_with_more_value! { case01: Some(vec![ - vec![MinimizeUnassignedJobs { breaks: None }], + vec![MinimizeUnassigned { breaks: None }], vec![MaximizeValue { breaks: None }], vec![MinimizeCost], ]), diff --git a/vrp-pragmatic/tests/features/tour_shape/basic_tour_compactness.rs b/vrp-pragmatic/tests/features/tour_shape/basic_tour_compactness.rs index 336e2959e..f1dcd55df 100644 --- a/vrp-pragmatic/tests/features/tour_shape/basic_tour_compactness.rs +++ b/vrp-pragmatic/tests/features/tour_shape/basic_tour_compactness.rs @@ -37,7 +37,7 @@ fn can_compact_tour() { ..create_default_fleet() }, objectives: Some(vec![ - vec![MinimizeUnassignedJobs { breaks: None }], + vec![MinimizeUnassigned { breaks: None }], vec![MinimizeTours], vec![CompactTour { options: CompactOptions { job_radius: 2, threshold: 2, distance: 0. } }], vec![MinimizeCost], diff --git a/vrp-pragmatic/tests/features/work_balance/balance_activities.rs b/vrp-pragmatic/tests/features/work_balance/balance_activities.rs index 9b4f2a0b0..228bd6b8e 100644 --- a/vrp-pragmatic/tests/features/work_balance/balance_activities.rs +++ b/vrp-pragmatic/tests/features/work_balance/balance_activities.rs @@ -52,7 +52,7 @@ fn can_balance_activities_with_threshold_impl(threshold: Option, expected_l ..create_default_fleet() }, objectives: Some(vec![ - vec![MinimizeUnassignedJobs { breaks: None }], + vec![MinimizeUnassigned { breaks: None }], vec![BalanceActivities { options: Some(BalanceOptions { threshold }) }], vec![MinimizeCost], ]), diff --git a/vrp-pragmatic/tests/features/work_balance/balance_max_load.rs b/vrp-pragmatic/tests/features/work_balance/balance_max_load.rs index e19742f32..e6440805a 100644 --- a/vrp-pragmatic/tests/features/work_balance/balance_max_load.rs +++ b/vrp-pragmatic/tests/features/work_balance/balance_max_load.rs @@ -26,7 +26,7 @@ fn can_balance_max_load() { ..create_default_fleet() }, objectives: Some(vec![ - vec![MinimizeUnassignedJobs { breaks: None }], + vec![MinimizeUnassigned { breaks: None }], vec![BalanceMaxLoad { options: None }], vec![MinimizeCost], ]), diff --git a/vrp-pragmatic/tests/features/work_balance/balance_transport.rs b/vrp-pragmatic/tests/features/work_balance/balance_transport.rs index c77b502f5..5d300c83d 100644 --- a/vrp-pragmatic/tests/features/work_balance/balance_transport.rs +++ b/vrp-pragmatic/tests/features/work_balance/balance_transport.rs @@ -24,7 +24,7 @@ fn can_balance_duration() { ..create_default_fleet() }, objectives: Some(vec![ - vec![MinimizeUnassignedJobs { breaks: None }], + vec![MinimizeUnassigned { breaks: None }], vec![BalanceDuration { options: None }], vec![MinimizeCost], ]), diff --git a/vrp-pragmatic/tests/helpers/problem.rs b/vrp-pragmatic/tests/helpers/problem.rs index 37313d69a..033b2ebde 100644 --- a/vrp-pragmatic/tests/helpers/problem.rs +++ b/vrp-pragmatic/tests/helpers/problem.rs @@ -1,4 +1,4 @@ -use crate::format::problem::Objective::{MinimizeCost, MinimizeUnassignedJobs}; +use crate::format::problem::Objective::{MinimizeCost, MinimizeUnassigned}; use crate::format::problem::*; use crate::format::{CoordIndex, Location}; use crate::format_time; @@ -269,7 +269,7 @@ pub fn create_default_matrix_profiles() -> Vec { } pub fn create_min_jobs_cost_objective() -> Option>> { - Some(vec![vec![MinimizeUnassignedJobs { breaks: None }], vec![MinimizeCost]]) + Some(vec![vec![MinimizeUnassigned { breaks: None }], vec![MinimizeCost]]) } pub fn create_empty_plan() -> Plan { diff --git a/vrp-pragmatic/tests/unit/validation/objectives_test.rs b/vrp-pragmatic/tests/unit/validation/objectives_test.rs index 505c89ede..eb6004bd6 100644 --- a/vrp-pragmatic/tests/unit/validation/objectives_test.rs +++ b/vrp-pragmatic/tests/unit/validation/objectives_test.rs @@ -96,7 +96,7 @@ fn can_detect_missing_cost_objective_impl(objectives: Option> fn can_detect_missing_value_jobs() { let problem = Problem { objectives: Some(vec![ - vec![MinimizeUnassignedJobs { breaks: None }], + vec![MinimizeUnassigned { breaks: None }], vec![MaximizeValue { breaks: None }], vec![MinimizeCost], ]), @@ -114,7 +114,7 @@ fn can_detect_missing_value_jobs() { #[test] fn can_detect_missing_order_jobs() { let problem = Problem { - objectives: Some(vec![vec![MinimizeUnassignedJobs { breaks: None }], vec![TourOrder], vec![MinimizeCost]]), + objectives: Some(vec![vec![MinimizeUnassigned { breaks: None }], vec![TourOrder], vec![MinimizeCost]]), ..create_empty_problem() }; let coord_index = CoordIndex::new(&problem); @@ -186,11 +186,11 @@ parameterized_test! {can_detect_missing_value_objective, (objectives, expected), can_detect_missing_value_objective! { case01: (Some(vec![ - vec![MinimizeUnassignedJobs { breaks: None }], + vec![MinimizeUnassigned { breaks: None }], vec![MinimizeCost], ]), Some("E1607".to_string())), case02: (Some(vec![ - vec![MinimizeUnassignedJobs { breaks: None }], + vec![MinimizeUnassigned { breaks: None }], vec![MaximizeValue { breaks: None }], vec![MinimizeCost], ]), None),