jump-dev / MiniZinc.jl

A Julia interface to the MiniZinc constraint modeling language
https://www.minizinc.org/
MIT License
17 stars 4 forks source link

Support nonlinear constraints with Boolean operators #21

Closed odow closed 1 year ago

odow commented 1 year ago

x-ref: https://github.com/jump-dev/JuMP.jl/issues/2227#issuecomment-1404491375

The demo is

julia> using JuMP

julia> import MiniZinc

julia> model = Model(() -> MiniZinc.Optimizer{Int}(MiniZinc.Chuffed()))
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: MiniZinc

julia> set_optimizer_attribute(model, "model_filename", "test.mzn")

julia> @variable(model, x, Bin)
x

julia> @variable(model, y, Bin)
y

julia> @constraint(model, [x, y] in MOI.AllDifferent(2))
[x, y] ∈ MathOptInterface.AllDifferent(2)

julia> @NLconstraint(model, (x || y) == true)
(x || y) - 1.0 = 0

julia> @NLconstraint(model, (x && y) == false)
(x && y) - 0.0 = 0

julia> optimize!(model)
Warning: included file "count.mzn" overrides a global constraint file from the standard library. This is deprecated. For a solver-specific redefinition of a global constraint, override "fzn_<global>.mzn" instead.

Warning: included file "global_cardinality_low_up.mzn" overrides a global constraint file from the standard library. This is deprecated. For a solver-specific redefinition of a global constraint, override "fzn_<global>.mzn" instead.

julia> value(x), value(y)
(0.0, 1.0)

julia> print(read("test.mzn", String))
include "alldifferent.mzn";
var bool: x;
var bool: y;
constraint alldifferent([x, y]);
constraint ((x \/ y) - 1) == false;
constraint ((x /\ y) - 0) == false;
solve satisfy;
codecov[bot] commented 1 year ago

Codecov Report

Base: 95.07% // Head: 95.15% // Increases project coverage by +0.07% :tada:

Coverage data is based on head (ca90a3a) compared to base (e31983b). Patch coverage: 95.58% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #21 +/- ## ========================================== + Coverage 95.07% 95.15% +0.07% ========================================== Files 3 3 Lines 386 454 +68 ========================================== + Hits 367 432 +65 - Misses 19 22 +3 ``` | [Impacted Files](https://codecov.io/gh/jump-dev/MiniZinc.jl/pull/21?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jump-dev) | Coverage Δ | | |---|---|---| | [src/write.jl](https://codecov.io/gh/jump-dev/MiniZinc.jl/pull/21?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jump-dev#diff-c3JjL3dyaXRlLmps) | `98.59% <95.16%> (-0.73%)` | :arrow_down: | | [src/MiniZinc.jl](https://codecov.io/gh/jump-dev/MiniZinc.jl/pull/21?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jump-dev#diff-c3JjL01pbmlaaW5jLmps) | `100.00% <100.00%> (ø)` | | | [src/optimize.jl](https://codecov.io/gh/jump-dev/MiniZinc.jl/pull/21?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jump-dev#diff-c3JjL29wdGltaXplLmps) | `81.31% <100.00%> (+0.41%)` | :arrow_up: | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jump-dev). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jump-dev)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.