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

[Needs MOI 0.9.21] AffExpr in ZeroOne does not work #1943

Closed
blegat opened this issue Apr 17, 2019 · 9 comments · Fixed by jump-dev/MathOptInterface.jl#1237 or #2705
Closed

[Needs MOI 0.9.21] AffExpr in ZeroOne does not work #1943

blegat opened this issue Apr 17, 2019 · 9 comments · Fixed by jump-dev/MathOptInterface.jl#1237 or #2705
Milestone

Comments

@blegat
Copy link
Member

blegat commented Apr 17, 2019

julia> using JuMP

julia> model = Model()
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.

julia> @variable(model, x)
x

julia> @constraint(model, x + 1 in MOI.Integer())
ERROR: MethodError: no method matching shift_constant(::MathOptInterface.Integer, ::Float64)
Closest candidates are:
  shift_constant(::Union{EqualTo{T}, GreaterThan{T}, LessThan{T}}, ::T) where T at /home/blegat/.julia/packages/MathOptInterface/C3lip/src/Utilities/sets.jl:39
  shift_constant(::MathOptInterface.Interval, ::Any) at /home/blegat/.julia/packages/MathOptInterface/C3lip/src/Utilities/sets.jl:42
Stacktrace:
 [1] build_constraint(::Function, ::GenericAffExpr{Float64,VariableRef}, ::MathOptInterface.Integer) at /home/blegat/.julia/packages/JuMP/jnmGG/src/macros.jl:491
 [2] top-level scope at /home/blegat/.julia/packages/JuMP/jnmGG/src/macros.jl:621

julia> @constraint(model, x + 1 in MOI.ZeroOne())
ERROR: MethodError: no method matching shift_constant(::MathOptInterface.ZeroOne, ::Float64)
Closest candidates are:
  shift_constant(::Union{EqualTo{T}, GreaterThan{T}, LessThan{T}}, ::T) where T at /home/blegat/.julia/packages/MathOptInterface/C3lip/src/Utilities/sets.jl:39
  shift_constant(::MathOptInterface.Interval, ::Any) at /home/blegat/.julia/packages/MathOptInterface/C3lip/src/Utilities/sets.jl:42
Stacktrace:
 [1] build_constraint(::Function, ::GenericAffExpr{Float64,VariableRef}, ::MathOptInterface.ZeroOne) at /home/blegat/.julia/packages/JuMP/jnmGG/src/macros.jl:491
 [2] top-level scope at /home/blegat/.julia/packages/JuMP/jnmGG/src/macros.jl:621

We should probably leave the constant in the function for these sets.

Reported by @jebouchat

@blegat blegat added this to the 1.0 milestone Apr 17, 2019
@1ozturkbe
Copy link

1ozturkbe commented Jul 7, 2020

This issue has been a real difficulty in JuMP/MOI for me, using the latest versions (0.21.3 and 0.9.14). I would like to be able to constrain variables to integer or binary post-declaration, eg:

using JuMP, MathOptInterface
m = Model()
@variable(m, x[1:3])
@constraint(m, x[1] in MathOptInterface.Integer())

I get an error in constructconstraint!.

ERROR: MethodError: no method matching constructconstraint!(::JuMP.GenericAffExpr{Float64,Variable}, ::MathOptInterface.Integer)
Closest candidates are:
  constructconstraint!(::JuMP.GenericAffExpr{Float64,Variable}, ::Any, ::Any) at 
...

I'm assuming these issues are related, since I tried the above example and got the same result. I work around right now as such, but I'd prefer not doubling up on variables.

    aux = @variable(m, [1:length(int_idxs)], Int);
    @constraint(m, x[int_idxs] .== aux);

Thanks for the help.

@mlubin
Copy link
Member

mlubin commented Jul 7, 2020

@1ozturkbe

I would like to be able to constrain variables to integer or binary post-declaration

Use set_integer or set_binary.

@odow
Copy link
Member

odow commented Feb 14, 2021

I have a plan for this, but it requires: jump-dev/MathOptInterface.jl#1237. It has the added benefit of making it much more explicit when JuMP will push the function into the set.

@odow
Copy link
Member

odow commented Mar 2, 2021

Accidentally closed by the MOI PR.

@odow odow changed the title AffExpr in ZeroOne does not work [Needs MOI 0.9.21] AffExpr in ZeroOne does not work Mar 31, 2021
@odow
Copy link
Member

odow commented Apr 23, 2021

MOI now has supports_shift_constant.

@blegat
Copy link
Member Author

blegat commented Sep 24, 2021

Wy don't we leave the constant in the functio' instead or returning an error? Then it can be bridged with a slack bridge

@odow
Copy link
Member

odow commented Sep 24, 2021

That's what we do

@blegat
Copy link
Member Author

blegat commented Sep 24, 2021

I missread the PR diff

@blegat blegat closed this as completed Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants