Skip to content

Commit

Permalink
Merge branch 'enhancement/allow-empty-skills'
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoupey committed Apr 12, 2021
2 parents 59e79ae + c3ad681 commit 1e32124
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

### Changed

- A mix of empty and non-empty `skills` arrays is allowed in input (#460)
- Formatting script updated to use version 10 of clang-format (#452)
- vroom will now read json input from stdin if no other input is specified (#457)
- Clearer error message with invalid json response from http routing request (#471)
Expand Down
11 changes: 8 additions & 3 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,14 @@ served by a vehicle that has **all** its required skills. In other
words: job `j` is eligible to vehicle `v` iff `j.skills` is included
in `v.skills`.

In order to ease modeling problems with no skills required, it is
assumed that there is no restriction at all if no `skills` keys are
provided.
This definition implies in particular that:

- a task without skills can be served by any vehicle;
- a vehicle without skills can only serve tasks with no particular
need (i.e. without skills as well).

In order to ease modeling problems with no skills required, not
providing a `skills` key default to providing an empty array.

### Task priorities

Expand Down
17 changes: 6 additions & 11 deletions src/structures/vroom/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,20 @@ void Input::check_job(Job& job) {
std::to_string(_amount_size) + '.');
}

// Ensure that skills or location index are either always or never
// provided.
// Ensure that location index are either always or never provided.
bool has_location_index = job.location.user_index();
if (_no_addition_yet) {
_has_skills = !job.skills.empty();
_no_addition_yet = false;
_has_custom_location_index = has_location_index;
} else {
if (_has_skills != !job.skills.empty()) {
throw Exception(ERROR::INPUT, "Missing skills.");
}
if (_has_custom_location_index != has_location_index) {
throw Exception(ERROR::INPUT, "Missing location index.");
}
}

// Check for time-windows.
_has_TW |= (!(job.tws.size() == 1) or !job.tws[0].is_default());
// Check for time-windows and skills.
_has_TW = _has_TW || (!(job.tws.size() == 1) or !job.tws[0].is_default());
_has_skills = _has_skills || !job.skills.empty();

if (!job.location.user_index()) {
// Index of job in the matrices is not specified in input, check
Expand Down Expand Up @@ -237,8 +233,9 @@ void Input::add_vehicle(const Vehicle& vehicle) {
std::to_string(_amount_size) + '.');
}

// Check for time-windows.
// Check for time-windows and skills.
_has_TW = _has_TW || !vehicle.tw.is_default();
_has_skills = _has_skills || !current_v.skills.empty();

bool has_location_index = false;
if (current_v.has_start()) {
Expand Down Expand Up @@ -436,11 +433,9 @@ void Input::set_skills_compatibility() {
if (_has_skills) {
for (std::size_t v = 0; v < vehicles.size(); ++v) {
const auto& v_skills = vehicles[v].skills;
assert(!v_skills.empty());

for (std::size_t j = 0; j < jobs.size(); ++j) {
bool is_compatible = true;
assert(!jobs[j].skills.empty());
for (const auto& s : jobs[j].skills) {
if (v_skills.find(s) == v_skills.end()) {
is_compatible = false;
Expand Down

0 comments on commit 1e32124

Please # to comment.