Skip to content

Wrong internal durations matrix with different location_index on same location #909

@jcoupey

Description

@jcoupey

Say I have a simple instance like:

{
  "jobs": [
    {
      "id": 1,
      "location": [
        2.38403,
        48.88413
      ],
      "location_index": 1
    },
    {
      "id": 2,
      "location": [
        2.35862,
        48.84212
      ],
      "location_index": 2
    }
  ],
  "vehicles": [
    {
      "id": 1,
      "start": [
        2.29822,
        48.85116
      ],
      "start_index": 0
    }
  ],
  "matrices": {
    "car": {
      "costs": [
        [
          0,
          2,
          1
        ],
        [
          2,
          0,
          1
        ],
        [
          1,
          1,
          0
        ]
      ]
    }
  }
}

If I log the content of the durations matrix from Input::set_matrices, I get an expected:

0	2027	1291	
2087	0	1386	
1257	1343	0

Now if I add another job that has the same location as job 2 but a different location_index, such as:

    {
      "id": 3,
      "location": [
        2.35862,
        48.84212
      ],
      "location_index": 3
    }

then the durations matrix becomes:

0	2027	1291	0	
2087	0	1386	0	
1257	1343	0	0	
0	0	0	0

In other words, the size is correct in term of the number of total location_index values, but the additional row/column does not get filled. This is due to the fact that the matrix is computed based on Input::_locations (we use an indirection to go back to user-defined index values). But in case of custom location_index values, additional locations are only store here if they have a new coordinate.

A work-around to avoid hitting this problem is to make sure to re-use the same location_index value in case coordinates are identical. Which sounds like a good practice anyway.

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