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.
We've introduced
CostWrapperto be able to scale travel times on the fly based on vehiclesspeed_factorvalues. The current implementation is that we compute a scaling factor in the ctor:vroom/src/structures/vroom/cost_wrapper.cpp
Line 17 in 4b898ec
Then when a duration value is requested, we scale the original matrix value (
DIVISORis 100 to keep a fair amount of precision sincespeed_factoris a double):vroom/src/structures/vroom/cost_wrapper.h
Lines 36 to 39 in 4b898ec
The advantage of this approach is that even if
speed_factoris a double, it keeps all our computations in the integer world (see #491). The current implementation have drawbacks though:durationorcost(heavily used!);speed_factorvalue, 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.