Skip to content

Refactor CostWrapper #828

@jcoupey

Description

@jcoupey

We've introduced CostWrapper to be able to scale travel times on the fly based on vehicles speed_factor values. The current implementation is that we compute a scaling factor in the ctor:

: discrete_duration_factor(std::round(1 / speed_factor * DIVISOR)),

Then when a duration value is requested, we scale the original matrix value (DIVISOR is 100 to keep a fair amount of precision since speed_factor is a double):

Duration duration(Index i, Index j) const {
Duration c = duration_data[i * duration_matrix_size + j];
return (c * discrete_duration_factor) / DIVISOR;
}

The advantage of this approach is that even if speed_factor is a double, it keeps all our computations in the integer world (see #491). The current implementation have drawbacks though:

  • we're still doing an integer division for each call to duration or cost (heavily used!);
  • we still have rounding issues when getting back to seconds by dividing: depending on the speed_factor value, this can lead to different matrix durations being scaled to the same value.

I'd like to try to get rid of the division and simply use scaled values all over internally. This would amount to describing all durations as hundredth of second internally. We'd have to apply that change to all time-related values and round back to seconds upon solution formatting. This would add some code boilerplate but could improve precision while reducing computing time.

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