Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,9 @@ assignment = routing.read_assignment_from_routes(routes, true)
The limit is checked cooperatively, so the call can exceed it. Restoration can
return a valid assignment found before the limit. A `nil` result does not
distinguish an invalid route from a limit reached before finding a solution.
Call `routing.check_limit` immediately after restoration to check whether the
native search limit was reached. It returns a boolean, like Python's
`routing.CheckLimit()`.
A subsequent solve uses the time limit in its own search parameters.

Native improvement-rate stopping is available through search parameters:
Expand Down
1 change: 1 addition & 0 deletions ext/or-tools/routing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,7 @@ void init_routing(Rice::Module& m) {
self.CloseModel();
}
})
.define_method("check_limit", [](RoutingModel& self) { return self.CheckLimit(); })
.define_method(
"update_time_limit",
[](RoutingModel& self, double seconds) {
Expand Down
13 changes: 13 additions & 0 deletions test/routing_time_limit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,26 @@ def test_restoration_limit_can_be_reset_after_timeout

assert_nil routing.read_assignment_from_routes([[1, 2]], true)
assert_equal :fail, routing.status
assert_equal true, routing.check_limit

routing.update_time_limit(0.5)
assignment = routing.read_assignment_from_routes([[1, 2]], true)

refute_nil assignment
assert_equal 4, assignment.objective_value
assert_equal :success, routing.status
assert_equal false, routing.check_limit
end

def test_infeasible_restoration_does_not_cross_limit
routing = build_routing
transit = routing.register_transit_matrix([[0, 1, 2], [1, 0, 1], [2, 1, 0]])
routing.add_dimension(transit, 0, 3, true, "Distance")
routing.close_model
routing.update_time_limit(1)

assert_nil routing.read_assignment_from_routes([[1, 2]], true)
assert_equal false, routing.check_limit
end

def test_solve_replaces_restoration_time_limit
Expand Down
Loading