Skip to content

Wrong distance-based optimization with only custom durations #1298

@jcoupey

Description

@jcoupey

Bumped into this while looking at #1281. Let's say we have an instance where:

  • custom durations matrices are provided;
  • no custom distances matrices are provided;
  • distance should be used in optimization objective (one vehicle has a non-zero costs.per_km value).

Then the distance matrix is filled with zeros in the else clause at:

// Custom durations matrix defined.
if (!_distances_matrices.contains(profile)) {
// No custom distances.
if (_geometry) {
// Get distances from routing engine later on since routing
// is explicitly requested.
_distances_matrices.try_emplace(profile);
} else {
// Routing-less optimization with no distances involved,
// fill internal distances matrix with zeros.
_distances_matrices.try_emplace(profile, durations_m->second.size(), 0);
}
}

so the distance component in the cost is basically zero, contrary to the expectation. To make it worse: if costs.per_hour is zero and costs.per_km is non-zero, then basically any route will evaluate to zero (while one expects to optimize on distance only), yielding an arbitrary route ordering.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions