Skip to content

Commit

Permalink
Add support for MOI.EqualTo{Bool}
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Jan 31, 2024
1 parent 01bc0f7 commit 637e4c2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/MiniZinc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const ReifiedTable{T} = MOI.Reified{MOI.Table{T}}

MOI.Utilities.@model(
Model,
(MOI.ZeroOne, MOI.Integer),
(MOI.ZeroOne, MOI.Integer, MOI.EqualTo{Bool}),
(MOI.EqualTo, MOI.GreaterThan, MOI.LessThan, MOI.Interval),
(
MOI.AllDifferent,
Expand Down
36 changes: 36 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,42 @@ function test_write_circuit()
return
end

function test_write_bool_true()
model = MiniZinc.Model{Bool}()
x = MOI.add_variables(model, 2)
MOI.set(model, MOI.VariableName(), x, ["x1", "x2"])
MOI.add_constraint(
model,
MOI.ScalarNonlinearFunction(:||, Any[x[1], x[2]]),
MOI.EqualTo{Bool}(true),
)
@test sprint(write, model) == """
var bool: x1;
var bool: x2;
constraint (x1 \\/ x2) = true;
solve satisfy;
"""
return
end

function test_write_bool_false()
model = MiniZinc.Model{Bool}()
x = MOI.add_variables(model, 2)
MOI.set(model, MOI.VariableName(), x, ["x1", "x2"])
MOI.add_constraint(
model,
MOI.ScalarNonlinearFunction(:&&, Any[x[1], x[2]]),
MOI.EqualTo{Bool}(false),
)
@test sprint(write, model) == """
var bool: x1;
var bool: x2;
constraint (x1 /\\ x2) = false;
solve satisfy;
"""
return
end

function _test_chuffed_asset(file, args...)
filename = joinpath(@__DIR__, "assets", file)
ret = MiniZinc.run_flatzinc(Chuffed_jll.fznchuffed, filename, args...)
Expand Down

0 comments on commit 637e4c2

Please sign in to comment.