Skip to content

Commit

Permalink
Merge branch 'enhancement/chrono-timeout'
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoupey committed Jun 30, 2022
2 parents 6b609fc + 9a2f799 commit 596b69f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

### Changed

- Use `std::chrono::milliseconds` for `Timeout` value (#728)
- Use `struct` for storing `Coordinates` instead of an `std::array` (#730)

### Fixed
Expand Down
4 changes: 3 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ int main(int argc, char** argv) {
try {
if (!limit_arg.empty()) {
// Internally timeout is in milliseconds.
cl_args.timeout = 1000 * std::stof(limit_arg);
cl_args.timeout =
std::chrono::milliseconds(static_cast<std::chrono::milliseconds::rep>(
1000 * std::stof(limit_arg)));
}
} catch (const std::exception& e) {
throw cxxopts::OptionException("Argument '" + limit_arg +
Expand Down
2 changes: 1 addition & 1 deletion src/structures/typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct Coordinates {
using OptionalCoordinates = std::optional<Coordinates>;
using Skills = std::unordered_set<Skill>;
using TimePoint = std::chrono::high_resolution_clock::time_point;
using Timeout = std::optional<unsigned>;
using Timeout = std::optional<std::chrono::milliseconds>;
using Deadline = std::optional<TimePoint>;

// Setting max value would cause trouble with further additions.
Expand Down
8 changes: 4 additions & 4 deletions src/structures/vroom/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,14 +928,14 @@ Solution Input::solve(unsigned exploration_level,
_end_loading = std::chrono::high_resolution_clock::now();

auto loading = std::chrono::duration_cast<std::chrono::milliseconds>(
_end_loading - _start_loading)
.count();
_end_loading - _start_loading);

// Decide time allocated for solving, 0 means only heuristics will
// be applied.
Timeout solve_time;
if (timeout.has_value()) {
solve_time = (loading <= timeout.value()) ? (timeout.value() - loading) : 0;
solve_time = (loading <= timeout.value()) ? (timeout.value() - loading)
: std::chrono::milliseconds(0);
}

// Solve.
Expand All @@ -947,7 +947,7 @@ Solution Input::solve(unsigned exploration_level,
(_has_initial_routes) ? h_init_routes : h_param);

// Update timing info.
sol.summary.computing_times.loading = loading;
sol.summary.computing_times.loading = loading.count();

_end_solving = std::chrono::high_resolution_clock::now();
sol.summary.computing_times.solving =
Expand Down

0 comments on commit 596b69f

Please sign in to comment.