Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with inconsistent vehicle capacity arrays #1086

Open
jcoupey opened this issue Apr 12, 2024 · 1 comment
Open

Error with inconsistent vehicle capacity arrays #1086

jcoupey opened this issue Apr 12, 2024 · 1 comment
Labels
Milestone

Comments

@jcoupey
Copy link
Collaborator

jcoupey commented Apr 12, 2024

My intent when parsing json what to ensure all vehicles either have no capacity key, or have all the same length for the capacity array. In particular I expect a missing capacity array to trigger an error. This happens for example when using:

{
  "vehicles": [
    {
      "id":0,
      ...
    },
    {
      "id":1,
      "capacity": [1],
      ...
    ],
    ...

resulting in an error with the message "Inconsistent capacity length: 1 and 0."

So far so good, but I just found out that reversing the order of vehicles above changes the behavior: we no longer get an error, instead the capacity for vehicle with id 0 is considered as zero and we move on with solving.
In this situation the vehicle won't get a route assigned if all tasks have a non-zero demand, so this is not such a big problem if considering that no capacity key means zero capacity.

Yet I think we should change this because:

  • it would be more consistent to enforce always explicitly providing a capacity array as initially intended;
  • it is clearer to get an error in the first place than to have to debug why those vehicles do not get routes (the reason I stumbled upon this);
  • getting either a "usual" solution or an error just by changing vehicle order in input is not really acceptable.
@jcoupey jcoupey added the bug label Apr 12, 2024
@jcoupey jcoupey added this to the v1.15.0 milestone Apr 12, 2024
@jcoupey
Copy link
Collaborator Author

jcoupey commented Apr 12, 2024

In practice, this happens because we use the length of the capacity for the first vehicle as the reference for amount lengths, assuming consistency but not enforcing it if the key is absent.

All amounts are parsed using the same function:

inline Amount get_amount(const rapidjson::Value& object,
const char* key,
unsigned amount_size) {
// Default to zero amount with provided size.
Amount amount(amount_size);

We default to an empty amount because it makes sense for shipment.amount, job.pickup or job.delivery keys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant