-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
return MOI.TIME_LIMIT when time_limit_sec is set
- Loading branch information
1 parent
a71268a
commit 379db9a
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright (c) 2022 MiniZinc.jl contributors | ||
# | ||
# Use of this source code is governed by an MIT-style license that can be found | ||
# in the LICENSE.md file or at https://opensource.org/licenses/MIT. | ||
|
||
# N-queens example | ||
# based on MiniZinc example nqueens.mzn | ||
# queen in column i is in row q[i] | ||
|
||
# Test solver time out | ||
function test_nqueens_timeout() | ||
n = 100 # can't finish in 1s | ||
model = MOI.instantiate( | ||
() -> MiniZinc.Optimizer{Int}("chuffed"); | ||
with_cache_type = Int, | ||
with_bridge_type = Int, | ||
) | ||
MOI.set(model, MOI.RawOptimizerAttribute("model_filename"), "test.mzn") | ||
q = MOI.add_variables(model, n) | ||
MOI.add_constraint.(model, q, MOI.Interval(1, n)) | ||
MOI.add_constraint(model, MOI.VectorOfVariables(q), MOI.AllDifferent(n)) | ||
for op in (+, -) | ||
f = MOI.Utilities.vectorize([op(q[i], i) for i in eachindex(q)]) | ||
MOI.add_constraint(model, f, MOI.AllDifferent(n)) | ||
end | ||
|
||
# test timeout in 1s | ||
MOI.set(model, MOI.TimeLimitSec(), 1.0) | ||
# solve | ||
MOI.optimize!(model) | ||
@test MOI.get(model, MOI.TerminationStatus()) === MOI.TIME_LIMIT | ||
@test MOI.get(model, MOI.ResultCount()) == 0 | ||
rm("test.mzn") | ||
return | ||
end |