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

Unable to set Integer options to infinity #25

Closed
joeltay opened this issue Oct 29, 2014 · 11 comments · Fixed by #346
Closed

Unable to set Integer options to infinity #25

joeltay opened this issue Oct 29, 2014 · 11 comments · Fixed by #346
Labels
Wrapper: C API Issue is specific to low-level C API

Comments

@joeltay
Copy link

joeltay commented Oct 29, 2014

Because Inf is floating point, this code in grb_params.jl fails when trying to set something in GRB_INT_PARAMS to infinity.

function set_int_param!(env::Env, name::ASCIIString, v::Integer)
ret = @grb_ccall(setintparam, Cint, (Ptr{Void}, Ptr{Cchar}, Cint),
env, name, v)
if ret != 0
throw(GurobiError(env, ret))
end
end
@IainNZ
Copy link
Contributor

IainNZ commented Oct 29, 2014

What parameter are you trying to set to Inf?

@joeltay
Copy link
Author

joeltay commented Oct 29, 2014

SolutionLimit using JuMP.

@joeltay
Copy link
Author

joeltay commented Oct 29, 2014

E.g.

using JuMP, Gurobi
m = Model(solver=GurobiSolver(SolutionLimit=Inf))
solve(m)

fails with

ERROR: `set_int_param!` has no method matching set_int_param!(::Env, ::ASCIIString, ::Float64)
 in setparam! at /home/joel/.julia/Gurobi/src/grb_params.jl:208
 in GurobiMathProgModel at /home/joel/.julia/Gurobi/src/GurobiSolverInterface.jl:18
 in model at /home/joel/.julia/Gurobi/src/GurobiSolverInterface.jl:29
 in solveLP at /home/joel/.julia/JuMP/src/solvers.jl:210
 in solve at /home/joel/.julia/JuMP/src/solvers.jl:46

@joeltay
Copy link
Author

joeltay commented Oct 29, 2014

Just to note that there do exist integer parameters which are not set to Infinity by default but which should be able to, e.g. CutPasses.

@IainNZ
Copy link
Contributor

IainNZ commented Oct 29, 2014

Ah I see, OK.
So, its interesting, because it says at http://www.gurobi.com/documentation/5.6/reference-manual/solutionlimit that Infinity is a valid value, but no such concept exists in C (for integers) nor Julia. What does exist is GRB_INFINITY, which I thought was the floating point value 1e100, so thats not good...

@IainNZ
Copy link
Contributor

IainNZ commented Oct 29, 2014

Ahah, gurobi_c.h has #define GRB_MAXINT 2000000000

@IainNZ
Copy link
Contributor

IainNZ commented Oct 29, 2014

So that is fairly easy to fix, we can just create another method that takes floating point arguments, checks for a number bigger than GRB_MAXINT and calls the int version with GRB_MAXINT, otherwise error.

@mlubin
Copy link
Member

mlubin commented Oct 29, 2014

That seems a bit messy on our side. Maybe just export GRB_MAXINT?

IainNZ added a commit that referenced this issue Oct 29, 2014
@IainNZ IainNZ mentioned this issue Oct 29, 2014
@pajalevi
Copy link

pajalevi commented Aug 7, 2018

Hello from the future!
I'm getting this same error message noted here, when implementing the code for benders cuts found here in the JuliaOpt teaching notebooks

I've copy-pasted the code in the notebook above for the lazy constraints version, including test data. The only changes I've made are to update it to use current JuMP conventions around setting constraints etc (@constraint instead of @addConstraint etc) and current notation for sums (sum( for ) instead of sum{ , }), and to use Gurobi as the solver.

solve(masterProblemModel) returns the following error message:

ERROR: MethodError: no method matching set_int_param!(::Gurobi.Model, ::String, ::Float64)
Closest candidates are:
  set_int_param!(::Gurobi.Model, ::String, ::Integer) at /Users/patricia/.julia/v0.6/Gurobi/src/grb_params.jl:266
  set_int_param!(::Gurobi.Env, ::String, ::Integer) at /Users/patricia/.julia/v0.6/Gurobi/src/grb_params.jl:192
Stacktrace:
 [1] setparam!(::Gurobi.Model, ::String, ::Float64) at /Users/patricia/.julia/v0.6/Gurobi/src/grb_params.jl:319
 [2] setparams!(::Gurobi.GurobiMathProgModel) at /Users/patricia/.julia/v0.6/Gurobi/src/GurobiSolverInterface.jl:58
 [3] #GurobiMathProgModel#14(::Array{Any,1}, ::Type{T} where T, ::Void) at /Users/patricia/.julia/v0.6/Gurobi/src/GurobiSolverInterface.jl:27
 [4] (::Core.#kw#Type)(::Array{Any,1}, ::Type{Gurobi.GurobiMathProgModel}, ::Void) at ./<missing>:0
 [5] LinearQuadraticModel(::Gurobi.GurobiSolver) at /Users/patricia/.julia/v0.6/Gurobi/src/GurobiSolverInterface.jl:68
 [6] #build#119(::Bool, ::Bool, ::JuMP.ProblemTraits, ::Function, ::JuMP.Model) at /Users/patricia/.julia/v0.6/JuMP/src/solvers.jl:353
 [7] (::JuMP.#kw##build)(::Array{Any,1}, ::JuMP.#build, ::JuMP.Model) at ./<missing>:0
 [8] #solve#116(::Bool, ::Bool, ::Bool, ::Array{Any,1}, ::Function, ::JuMP.Model) at /Users/patricia/.julia/v0.6/JuMP/src/solvers.jl:168
 [9] addBendersCut(::Gurobi.GurobiCallbackData) at /Users/patricia/Documents/Google Drive/stanford/second yearpaper/Tutorial II/Julia_scripts/testbenders_lazy.jl:100
 [10] lazycallback(::Gurobi.GurobiCallbackData, ::JuMP.Model, ::Array{JuMP.LazyCallback,1}) at /Users/patricia/.julia/v0.6/JuMP/src/callbacks.jl:78
 [11] (::JuMP.##140#141{JuMP.Model,Array{JuMP.LazyCallback,1}})(::Gurobi.GurobiCallbackData) at /Users/patricia/.julia/v0.6/JuMP/src/callbacks.jl:96
 [12] mastercallback(::Ptr{Void}, ::Ptr{Void}, ::Int32, ::Ptr{Void}) at /Users/patricia/.julia/v0.6/Gurobi/src/GurobiSolverInterface.jl:695
 [13] optimize(::Gurobi.Model) at /Users/patricia/.julia/v0.6/Gurobi/src/grb_solve.jl:5
 [14] optimize!(::Gurobi.GurobiMathProgModel) at /Users/patricia/.julia/v0.6/Gurobi/src/GurobiSolverInterface.jl:417
 [15] #solve#116(::Bool, ::Bool, ::Bool, ::Array{Any,1}, ::Function, ::JuMP.Model) at /Users/patricia/.julia/v0.6/JuMP/src/solvers.jl:175
 [16] solve(::JuMP.Model) at /Users/patricia/.julia/v0.6/JuMP/src/solvers.jl:150
 [17] macro expansion at /Users/patricia/.julia/v0.6/Atom/src/repl.jl:118 [inlined]
 [18] anonymous at ./<missing>:?

I'm having trouble identifying the place where set_int_param! is called with a Float argument instead of an Integer, so I'm not quite sure why this is happening but it seems that it should not be an available option within the Gurobi wrapper.

It looks like the commit referencing this issue was never merged into the master file, which might be why it is still a problem. Any advice for how to work around this problem or fix it would be greatly appreciated!

thanks
Patricia

@joeltay
Copy link
Author

joeltay commented Aug 7, 2018

This error occurs because the Gurobi model is being initialized with some parameter that only takes integers, but is being set to a float.

In my case, it sufficed to set it to a sufficiently large integer; I don't think there is a solution in Julia for if you really need Inf.

In your case, there are only two cases where the Model() function is called, so it was easy to check. Try changing this line:

subProblemModel = Model(solver=GurobiSolver(Presolve=0.0))

to Presolve=0

http://www.gurobi.com/documentation/8.0/refman/presolve.html#parameter:Presolve

@pajalevi
Copy link

pajalevi commented Aug 7, 2018

Ah, such a simple solution - Thanks so much for your speedy help. It didn't occur to me that the 'int_param' in question was one that I had set in my own code.

I changed it per your suggestion and everything ran perfectly. Excellent!

@odow odow added the Wrapper: C API Issue is specific to low-level C API label Dec 14, 2018
@odow odow closed this as completed in #346 Sep 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Wrapper: C API Issue is specific to low-level C API
Development

Successfully merging a pull request may close this issue.

5 participants