Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MiniZinc example in the docs does not work. #77

Closed
mbataillou opened this issue Jul 19, 2024 · 1 comment · Fixed by #78
Closed

MiniZinc example in the docs does not work. #77

mbataillou opened this issue Jul 19, 2024 · 1 comment · Fixed by #78

Comments

@mbataillou
Copy link

mbataillou commented Jul 19, 2024

Hello!

Looking at the JuMP docs for MiniZinc, we find a toy problem to be solved:

using JuMP
import MiniZinc
model = Model(() -> MiniZinc.Optimizer{Float64}("highs"))
@variable(model, 1 <= x[1:3] <= 3, Int)
@constraint(model, x in MOI.AllDifferent(3))
@objective(model, Max, sum(i * x[i] for i in 1:3))
optimize!(model)
@show value.(x)

However this returns no solution:

ERROR: Result index of attribute MathOptInterface.VariablePrimal(1) out of bounds. There are currently 0 solution(s) in the model.

Also not sure if it helps but the previous example (not using JuMP) works:

julia> import MiniZinc

julia> import MathOptInterface as MOI

julia> function main()
           model = MOI.Utilities.CachingOptimizer(
               MiniZinc.Model{Int}(),
               MiniZinc.Optimizer{Int}("chuffed"),
           )
           # xᵢ ∈ {1, 2, 3} ∀i=1,2,3
           x = MOI.add_variables(model, 3)
           MOI.add_constraint.(model, x, MOI.Interval(1, 3))
           MOI.add_constraint.(model, x, MOI.Integer())
           # zⱼ ∈ {0, 1}    ∀j=1,2
           z = MOI.add_variables(model, 2)
           MOI.add_constraint.(model, z, MOI.ZeroOne())
           # z₁ <-> x₁ != x₂
           MOI.add_constraint(
               model,
               MOI.VectorOfVariables([z[1], x[1], x[2]]),
               MOI.Reified(MOI.AllDifferent(2)),
           )
           # z₂ <-> x₂ != x₃
           MOI.add_constraint(
               model,
               MOI.VectorOfVariables([z[2], x[2], x[3]]),
               MOI.Reified(MOI.AllDifferent(2)),
           )
           # z₁ + z₂ = 1
           MOI.add_constraint(model, 1 * z[1] + x[2], MOI.EqualTo(1))
           MOI.optimize!(model)
           x_star = MOI.get(model, MOI.VariablePrimal(), x)
           z_star = MOI.get(model, MOI.VariablePrimal(), z)
           return x_star, z_star
       end
main (generic function with 1 method)

julia> main()
@odow odow transferred this issue from jump-dev/JuMP.jl Jul 21, 2024
@odow
Copy link
Member

odow commented Jul 21, 2024

Thanks for finding this. I've transferred this issue to MiniZinc.jl.

I can reproduce, with more information:

julia> solution_summary(model)
* Solver : MiniZinc

* Status
  Result count       : 0
  Termination status : OTHER_ERROR
  Message from the solver:
  "=====ERROR=====
Error: type error: no function or predicate with this signature found: `alldifferent(array[int] of var float)'
Cannot use the following functions or predicates with the same identifier:
predicate alldifferent(array [$X] of var set of int: x);
    (argument 1 expects type array[$_] of var set of int, but type array[int] of var float given)
predicate alldifferent(array [$X] of var int: x);
    (argument 1 expects type array[$_] of var int, but type array[int] of var float given)
predicate alldifferent(array [$X] of var opt int: x);
    (argument 1 expects type array[$_] of var opt int, but type array[int] of var float given)

/private/var/folders/bg/dzq_hhvx1dxgy6gb5510pxj80000gn/T/jl_fPnuhi/model.mzn:4.12-43
"

* Candidate solution (result #1)
  Primal status      : NO_SOLUTION
  Dual status        : NO_SOLUTION

* Work counters
  Solve time (sec)   : 1.20307e+00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants