Skip to content

Commit

Permalink
Fix issue with skills
Browse files Browse the repository at this point in the history
  • Loading branch information
reinterpretcat committed Oct 2, 2023
1 parent c4d9491 commit 8666736
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ All notable changes to this project will be documented in this file.
* double reload assignment when initial solution is used (#126)
* unexpected total_order behavior in dynamic heuristic (#128)
* improve validation rule for break with time offset (#129)
* fix issue with skills (#133)


## [v1.22.1]- 2023-08-26
Expand Down
10 changes: 10 additions & 0 deletions vrp-pragmatic/src/construction/features/skills.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ pub struct JobSkills {
pub none_of: Option<HashSet<String>>,
}

impl JobSkills {
/// Creates a new instance of [`JobSkills`].
pub fn new(all_of: Option<Vec<String>>, one_of: Option<Vec<String>>, none_of: Option<Vec<String>>) -> Self {
let map: fn(Option<Vec<_>>) -> Option<HashSet<_>> =
|skills| skills.and_then(|v| if v.is_empty() { None } else { Some(v.into_iter().collect()) });

Self { all_of: map(all_of), one_of: map(one_of), none_of: map(none_of) }
}
}

/// Creates a skills feature as hard constraint.
pub fn create_skills_feature(name: &str, code: ViolationCode) -> Result<Feature, GenericError> {
FeatureBuilder::default().with_name(name).with_constraint(SkillsConstraint { code }).build()
Expand Down
8 changes: 3 additions & 5 deletions vrp-pragmatic/src/format/problem/job_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,11 +506,9 @@ fn create_condition(vehicle_id: String, shift_index: usize) -> Arc<dyn Fn(&Actor
}

fn get_skills(skills: &Option<ApiJobSkills>) -> Option<FeatureJobSkills> {
skills.as_ref().map(|skills| FeatureJobSkills {
all_of: skills.all_of.as_ref().map(|all_of| all_of.iter().cloned().collect()),
one_of: skills.one_of.as_ref().map(|any_of| any_of.iter().cloned().collect()),
none_of: skills.none_of.as_ref().map(|none_of| none_of.iter().cloned().collect()),
})
skills
.as_ref()
.map(|skills| FeatureJobSkills::new(skills.all_of.clone(), skills.one_of.clone(), skills.none_of.clone()))
}

fn empty() -> MultiDimLoad {
Expand Down
9 changes: 9 additions & 0 deletions vrp-pragmatic/tests/unit/construction/features/skills_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,12 @@ fn can_merge_skills_impl(source: Job, candidate: Job, expected: Result<(), i32>)

assert_eq!(result, expected);
}

#[test]
fn can_create_empty_skills_as_none() {
let skills = JobSkills::new(Some(vec![]), Some(vec![]), Some(vec![]));

assert!(skills.all_of.is_none());
assert!(skills.one_of.is_none());
assert!(skills.none_of.is_none());
}

0 comments on commit 8666736

Please sign in to comment.