Skip to content

Bug with distances matrices #1281

@StrangeGirlMurph

Description

@StrangeGirlMurph

Hey, I think I may have found a bug. I've been racking my brain trying to figure this out...

I think there is a bug here:

if ((!_durations_matrices.empty() || !_distances_matrices.empty() ||
!_costs_matrices.empty()) &&
!_has_custom_location_index) {
throw InputException("Missing location index.");
}
if ((_durations_matrices.empty() && _costs_matrices.empty()) &&
_has_custom_location_index) {
throw InputException(
"Unexpected location index while no custom matrices provided.");
}

This is probably missing an && _distances_matrices.empty() in the second if right?

if ((_durations_matrices.empty() && _distances_matrices.empty() &&  _costs_matrices.empty()) && 
     _has_custom_location_index) { 
   throw InputException( 
     "Unexpected location index while no custom matrices provided."); 
 } 

How I found this:

const optimizationResponse = await Optimization.optimize({
  vehicles: [
    { id: 0, profile: "cycling-regular", start_index: 0, end_index: 0 }
  ],
  jobs: [
    { id: 1, location_index: 1 },
    { id: 2, location_index: 2 },
    { id: 3, location_index: 3 },
    { id: 4, location_index: 4 },
    { id: 5, location_index: 5 },
    { id: 6, location_index: 6 },
    { id: 7, location_index: 7 },
    { id: 8, location_index: 8 },
    { id: 9, location_index: 9 },
    { id: 10, location_index: 10 }
  ],
  matrices: {
    "cycling-regular": {
      distances: [
        [
             0,  1405, 3906,
          9318,  5717, 6837,
          4392,  9271, 7374,
          5073, 16503
        ],
        [
          1408,     0, 4184,
          8387,  4786, 5686,
          3978,  8341, 7343,
          5041, 15572
        ],
        [
          3713,  4056,    0,
          8303,  8527, 6316,
          7333, 10461, 4807,
          2679, 17693
        ],
        [
           9041, 8706, 8216,
              0, 8453, 2414,
          10700, 2707, 4492,
           5893, 9428
        ],
        [
          5250,  4451,  8583,
          8418,     0,  7452,
          3875,  7920, 10285,
          9249, 15151
        ],
        [
          6738,  6089, 6191,
          2389,  7384,    0,
          8537,  3865, 3404,
          3868, 11584
        ],
        [
           4434,  3586,  7375,
          11014,  4128,  8786,
              0, 10967, 11486,
           9184, 18199
        ],
        [
           9360, 8692, 10428,
           2861, 7768,  4005,
          10687,    0,  6959,
           7741, 7779
        ],
        [
           7388,  7396, 4947,
           4469,  9240, 3290,
          11128,  6796,    0,
           2910, 13834
        ],
        [
          5117,  5125, 2677,
          5943,  8663, 4110,
          8858,  7687, 2896,
             0, 15406
        ],
        [
          16133, 15465, 17201,
           8766, 14540, 10406,
          17459,  7399, 13359,
          14142,     0
        ]
      ]
    }
  }
});

Always gave me the error: "Unexpected location index while no custom matrices provided."
I am using the openrouteservice-js module.

Hope this helps. Also would be happy to hear if someone has an idea for a workaround. I need this till tomorrow. When I use durations: instead of distances: everything works. Is that a valid work around? I explicitly need the shortest path. Don't know what the difference in the optimizer are behind the scenes for those two cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions