jump-dev / gurobi.jl Goto Github PK
View Code? Open in Web Editor NEWA Julia interface to the Gurobi Optimizer
Home Page: http://www.gurobi.com/
License: MIT License
A Julia interface to the Gurobi Optimizer
Home Page: http://www.gurobi.com/
License: MIT License
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
I am trying to use the Gurobi.jl interface to solve an LP (min c'x s.t. Ax == b
) with parameters c
, A
, and b
all of type SparseMatrixCSC{Float64,Int64}
. I simulate them as follows:
m = 5000 # nrows
n = 10000 # ncols
s = 0.01 # sparsity level
A = sprandn(m,n,s)
c = sprand(m,1,s)
y = sprandn(n,1,s)
x = sparsevec(y.rowval,max(y.nzval,0.0),y.m)
b = A*x + sprand(m,1,s)
I match the Gurobi variable names: f == c
, Aeq == A
, and beq == b
.
addvars!
throws an error if I feed it a sparse vector f
. Does the Gurobi solver not admit sparse parameters for solving big LPs?
Note that I may not be simulating my LP parameters intelligently; having a sparse f
may not make sense in the real world (and if it is not, please correct me!)
using JuMP
using Gurobi
m = Model(solver=GurobiSolver())
@defVar(m, x)
@defVar(m, u[1:3])
@defVar(m, y[1:2], Bin)
u_samps = [0.0 0.0 0.0;
1.0 1.0 1.0]
x_samps = [5.0, 20.0]
@addConstraint(m, x == x_samps[1]*y[1] + x_samps[2]*y[2])
addConstraint(m, sum([(u_samps[1,k]^2 - u_samps[1,k]*u[k] + u[k]^2) for k=1:3]) + y[1] >= 1)
addConstraint(m, sum([(u_samps[2,k]^2 - u_samps[2,k]*u[k] + u[k]^2) for k=1:3]) + y[2] >= 1)
solve(m)
println(getValue(x))
gives
ERROR: BoundsError()
in get_status at /home/idunning/.julia/v0.3/Gurobi/src/grb_solve.jl:61
because get_status_code(model) actually returns an error code, Q_NOT_PSD (10022) which is of course not a solve code... strange logic.
@lindahua, do you mind if lp_model
is removed in favor of linprog
in MathProgBase? Although the interfaces are not identical, supporting both matlab-type interfaces seems redundant, and any convenience versions (like providing a separate Aeq and Aineq) should be build on top of linprog
so that they are solver independent.
qp_model
should stay for now, since we don't yet have QP support in MathProgBase.
On master, Gurobi 7.0.1:
Unbounded model
Passed
ERROR: LoadError: LoadError: You have encountered a known bug in Gurobi. Any information you query from the model may be incorrect.
This bug has existed since the first version of Gurobi but is fixed in Gurobi v7.0.
For more information go to https://github.com/JuliaOpt/Gurobi.jl/issues/60.
Please leave a comment stating that you encountered this bug! We would like to know how prevalent it is.
in updatemodel!(::Gurobi.GurobiMathProgModel) at /home/mlubin/.julia/v0.5/Gurobi/src/GurobiSolverInterface.jl:251
in optimize!(::Gurobi.GurobiMathProgModel) at /home/mlubin/.julia/v0.5/Gurobi/src/GurobiSolverInterface.jl:326
in linprogsolvertest(::Gurobi.GurobiSolver, ::Float64) at /home/mlubin/.julia/v0.5/MathProgBase/test/linproginterface.jl:274
in linprogsolvertest(::Gurobi.GurobiSolver) at /home/mlubin/.julia/v0.5/MathProgBase/test/linproginterface.jl:7
in include_from_node1(::String) at ./loading.jl:488
in evalfile(::String, ::Array{String,1}) at ./loading.jl:504
in macro expansion; at /home/mlubin/.julia/v0.5/Gurobi/test/runtests.jl:20 [inlined]
in anonymous at ./<missing>:?
in include_from_node1(::String) at ./loading.jl:488
in process_options(::Base.JLOptions) at ./client.jl:265
in _start() at ./client.jl:321
while loading /home/mlubin/.julia/v0.5/Gurobi/test/mathprog.jl, in expression starting on line 10
while loading /home/mlubin/.julia/v0.5/Gurobi/test/runtests.jl, in expression starting on line 17
Hi All,
I believe I have set the correct environment variables to point toward my Gurobi installation, yet the installation of Gurobi.jl is still failing. See here:
[msl33@percent bin]$ echo $GUROBI_HOME
/home/grad/msl33/gurobi751/linux64
[msl33@percent bin]$ ./julia
_
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: https://docs.julialang.org
_ _ _| |_ __ _ | Type "?help" for help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.6.0 (2017-06-19 13:05 UTC)
_/ |\__'_|_|_|\__'_| | Official http://julialang.org/ release
|__/ | x86_64-pc-linux-gnu
julia> Pkg.add("Gurobi")
INFO: Installing Gurobi v0.3.2
INFO: Building Gurobi
============================================[ ERROR: Gurobi ]============================================
LoadError: Unable to locate Gurobi installation. Note that this must be downloaded separately from gurobi.com
while loading /home/grad/msl33/.julia/v0.6/Gurobi/deps/build.jl, in expression starting on line 42
=========================================================================================================
============================================[ BUILD ERRORS ]=============================================
WARNING: Gurobi had build errors.
- packages with build errors remain installed in /home/grad/msl33/.julia/v0.6
- build the package(s) and all dependencies with `Pkg.build("Gurobi")`
- build a single package by running its `deps/build.jl` script
=========================================================================================================
INFO: Package database updated
INFO: METADATA is out-of-date \u2014 you may not have the latest version of Gurobi
INFO: Use `Pkg.update()` to get the latest versions of your packages
julia>
[msl33@percent bin]$ gurobi.sh
Python 2.7.13 (default, Jun 8 2017, 07:12:38)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Academic license - for non-commercial use only
Gurobi Interactive Shell (linux64), Version 7.5.1
Copyright (c) 2017, Gurobi Optimization, Inc.
Type "help()" for help
gurobi>
As far as I can tell the GUROBI_HOME environment variable is set correctly. Please help.
I'm fairly new to the whole JuMP/MathProgBase modelling environment and I, therefore, might have misunderstood the whole architecture which might be the main problem.
My problem is:
When I add constraints it seems like they are only added in the Gurobi Solver and not in the GurobiMathProgModel.
How can I update my GurobiMathProgModel after I added the constraints?
My process is the following:
I put some example code below that reflects my problem.
I hope you can help me or explain how I should actually use the architecture.
m = Model(solver = GurobiSolver())
#Add binary variables to JuMP model
@variable(m, 0 <= z[1:nCols] <= 1, Bin )
#Define objective function
@objective(m, Max, sum(z[i] for i=1:length(z)))
#Build model
JuMP.build(m)
#Convert to GurobiMathProgModel
m2 = internalmodel(m)
#Try to add constraint
Gurobi.addconstr!(m2, [1], [1], -Inf, 2)
#Updating model
Gurobi.updatemodel!(m2)
#Output GurobiMathProgModel to check number of constraints in the model
m2 #Output 0 constraints
#Get raw solver to check number of constraints
Gurobi.getrawsolver(m2) #Output 1 constraint
I'm unable to install Gurobi with:
Pkg.add("Gurobi")
I get the following output:
===============================[ ERROR: Gurobi ]================================
Unable to locate Gurobi installation. Note that this must be downloaded separately from gurobi.com
while loading /home/jtheurer/.julia/v0.3/Gurobi/deps/build.jl, in expression starting on line 36
================================================================================
================================[ BUILD ERRORS ]================================
WARNING: Gurobi had build errors.
- packages with build errors remain installed in /home/jtheurer/.julia/v0.3
- build the package(s) and all dependencies with `Pkg.build("Gurobi")`
- build a single package by running its `deps/build.jl` script
================================================================================
I'm running 0.3.7 of julia
$ dpkg -s julia|grep "Version"
Version: 0.3.7-trusty1
I've been using your wonderful Gurobi wrapper with JuMP and MathProgBase for a few months now and it's been an absolute joy, and today I think I found a small bug in getconstrsolution. When a constraint is not tight, getconstrsolution returns a value that is not within constraint bounds.
For instance, the first half of the following code fails, while the second does not:
# getconstrsolutionTest.jl
using JuMP, MathProgBase, Gurobi
# Slack GEQ constraint
m = Model(solver=GurobiSolver())
@defVar(m, x)
@addConstraint(m, x >= 0)
@addConstraint(m, x >= 3)
@setObjective(m, Min, x)
buildInternalModel(m)
im = getInternalModel(m)
MathProgBase.optimize!(im)
for i = 1:length(MathProgBase.getconstrLB(im))
println("Checking constraint $i")
@assert MathProgBase.getconstrLB(im)[i] <= MathProgBase.getconstrsolution(im)[i] <= MathProgBase.getconstrUB(im)[i]
end
# Slack LEQ constraint
m = Model(solver=GurobiSolver())
@defVar(m, x)
@addConstraint(m, x <= 3)
@addConstraint(m, x <= 0)
@setObjective(m, Max, x)
buildInternalModel(m)
im = getInternalModel(m)
MathProgBase.optimize!(im)
for i = 1:length(MathProgBase.getconstrLB(im))
println("Checking constraint $i")
@assert MathProgBase.getconstrLB(im)[i] <= MathProgBase.getconstrsolution(im)[i] <= MathProgBase.getconstrUB(im)[i]
end
I think this is because the variables that represent slackness of a constraint might have an overall sign, which leads to a sign error on line 264 of GurobiSolverInterface.jl. Is this correct ?
Thanks for your help !
Opening this to keep track of adopting the new API changes in MathProgBase
The gurobi function addrangeconstrs
introduces an additional slack variable to the problem for each constraint added. To properly support this, we need to transform user-facing variable indices to Gurobi variable indices at the mathprog interface layer (or convince Gurobi to make this transparent at the C-interface level). Until then, I'm printing a appropriate warning when range constraints are used.
grb_common::getlibversion crashes on win32.
Localized here:
julia> ccall( (:GRBversion, "gurobi51"), Void, (Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), _major,_minor, _tech)
(crashes). Observed on two different computers during @mlubin presentation today.
We are facing problem with Gurobi callback, which throws - ErrorException("optimizing: Gurobi.GurobiError(10017,\"Unable to retrieve attribute 'NumVars'\")"
. We commented grb_callback.jl:145 and rebuild the package, which makes it work.
We tried to execute the example, which is also throwing the same error.
Please find below the code.
using JuMP
using MathProgBase
using Gurobi
m = Model(solver = GurobiSolver(MIPGap=0.1, Cuts=0, VarBranch=1, TimeLimit=3600, OutputFlag=1))
@variable(m, 0 <= x <= 2, Int)
@variable(m, 0 <= y <= 2, Int)
@objective(m, Max, x + 2y)
@constraint(m, y + x <= 3.5)
type NodeData
time::Float64 # in seconds since the epoch
node::Int
obj::Float64
bestbound::Float64
end
bbdata = NodeData[]
function infocallback(cb)
node = MathProgBase.cbgetexplorednodes(cb)
obj = MathProgBase.cbgetobj(cb)
bestbound = MathProgBase.cbgetbestbound(cb)
push!(bbdata, NodeData(time(),node,obj,bestbound))
end
addinfocallback(m, infocallback, when = :Intermediate)
solve(m)
Library Used: Julia, JuMP
JuMP.jl Version: 0.17.1
Gurobi.jl Version: 0.3.3
Language and Solver
Julia Version: 0.5.1
Gurobi Version: 7.0.2
Will try to make test case, but any ideas why?
I sometimes want to remove a constraint to replace it by a different constraint not on the same variable. Here's a toy example that works:
using JuMP
using Gurobi
m = Model(solver=GurobiSolver(MIPFocus = 3))
x = @variable(m)
y = @variable(m)
con = @constraint(m, x<=1)
@constraint(m, x>=0)
@constraint(m, y>=2)
@objective(m, Min, (y-x)^2)
solve(m)
JuMP.setRHS(con, 100) # effectively deleting constraint
solve(m)
Unfortunately, this only works because I can choose a large number for JuMP.setRHS
where I do not expect the constraint to be binding. Attempting JuMP.setRHS(con, Inf)
leads to the following error message:
ERROR: LoadError: Internal error.
Stacktrace:
[1] updatemodel!(::Gurobi.GurobiMathProgModel) at /home/vtjeng/.julia/v0.6/Gurobi/src/GurobiSolverInterface.jl:310
[2] setvartype!(::Gurobi.GurobiMathProgModel, ::Array{Symbol,1}) at /home/vtjeng/.julia/v0.6/Gurobi/src/GurobiSolverInterface.jl:459
[3] #build#119(::Bool, ::Bool, ::JuMP.ProblemTraits, ::Function, ::JuMP.Model) at /home/vtjeng/.julia/v0.6/JuMP/src/solvers.jl:391
[4] (::JuMP.#kw##build)(::Array{Any,1}, ::JuMP.#build, ::JuMP.Model) at ./<missing>:0
[5] #solve#116(::Bool, ::Bool, ::Bool, ::Array{Any,1}, ::Function, ::JuMP.Model) at /home/vtjeng/.julia/v0.6/JuMP/src/solvers.jl:168
[6] solve(::JuMP.Model) at /home/vtjeng/.julia/v0.6/JuMP/src/solvers.jl:150
[7] include_from_node1(::String) at ./loading.jl:569
[8] include(::String) at ./sysimg.jl:14
[9] process_options(::Base.JLOptions) at ./client.jl:305
[10] _start() at ./client.jl:371
Is there any way I can work around this?
If I create the model and then optimize it, Then I copy it with function copy(model::Model)
, I cannot get solution or basis from the copy of model but I can get from the original model.
With JuMP/Gurobi.jl master on OSX, Gurobi 6.5 is segfaulting in the callback.jl
tests of JuMP.
Relevant test code:
using JuMP, Gurobi, FactCheck
entered = [false,false]
mod = Model(solver=GurobiSolver(Presolve=0))
@defVar(mod, 0 <= x <= 2, Int)
@defVar(mod, 0 <= y <= 2, Int)
@setObjective(mod, Max, y + 0.5x)
function corners(cb)
x_val = getValue(x)
y_val = getValue(y)
TOL = 1e-6
# Check top right
if y_val + x_val > 3 + TOL
@addLazyConstraint(cb, y + 0.5x + 0.5x <= 3)
end
entered[1] = true
@fact_throws ErrorException @defVar(cb, z)
@fact_throws ErrorException @addLazyConstraint(cb, x^2 <= 1)
end
addLazyCallback(mod, corners)
addLazyCallback(mod, cb -> (entered[2] = true))
@fact solve(mod) --> :Optimal
gives
Optimize a model with 0 rows, 2 columns and 0 nonzeros
Coefficient statistics:
Matrix range [0e+00, 0e+00]
Objective range [5e-01, 1e+00]
Bounds range [2e+00, 2e+00]
RHS range [0e+00, 0e+00]
Variable types: 0 continuous, 2 integer (0 binary)
[1] 899 segmentation fault julia --color=yes
It works using Gurobi 6.0.5. @yeesian can reproduce it as well, something funny going on with callbacks?
There's a deprecation warning, but then it stops building, but it still works (sorry for my impatience.)
julia> Pkg.status("Gurobi")
- Gurobi 0.2.4
julia> Pkg.build("Gurobi")
INFO: Building Gurobi
WARNING: `@unix_only` is deprecated, use `@static if is_unix()` instead
in depwarn(::String, ::Symbol) at ./deprecated.jl:64
in @unix_only(::Any) at ./deprecated.jl:492
in include_from_node1(::String) at ./loading.jl:488
in evalfile(::String, ::Array{String,1}) at ./loading.jl:504 (repeats 2 times)
in cd(::##2#4, ::String) at ./file.jl:59
in (::##1#3)(::IOStream) at ./none:13
in open(::##1#3, ::String, ::String) at ./iostream.jl:113
in eval(::Module, ::Any) at ./boot.jl:234
in process_options(::Base.JLOptions) at ./client.jl:239
in _start() at ./client.jl:318
while loading /home/bzfschwa/.julia/v0.5/Gurobi/deps/build.jl, in expression starting on line 16
julia> versioninfo()
Julia Version 0.5.0
Commit 3c9d753 (2016-09-19 18:14 UTC)
Platform Info:
System: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
LAPACK: libopenblas64_
LIBM: libopenlibm
LLVM: libLLVM-3.7.1 (ORCJIT, ivybridge)
Hi Gurobi,
I'm new to Julia and trying to install Gurobi.jl. I can add it and Pkg.build("Gurobi") completes successfully, but when I try to use it, it tells me to run Pkg.build again.
julia> Pkg.add("Gurobi")
INFO: Installing Gurobi v0.1.25
INFO: Building Gurobi
INFO: Package database updated
julia> Pkg.build("Gurobi")
INFO: Building Gurobi
julia> using Gurobi
ERROR: Gurobi not properly installed. Please run Pkg.build("Gurobi")
in error at error.jl:21
in include at /Applications/Julia-0.3.6.app/Contents/Resources/julia/lib/julia/sys.dylib
in include_from_node1 at /Applications/Julia-0.3.6.app/Contents/Resources/julia/lib/julia/sys.dylib
in reload_path at loading.jl:152
in _require at loading.jl:67
in require at loading.jl:51
while loading /Users/ryangiordanonon-admin/.julia/v0.3/Gurobi/src/Gurobi.jl, in expression starting on line 6
julia> Pkg.build("Gurobi")
INFO: Building Gurobi
julia>
Pkg.test("Gurobi") also fails:
julia> Pkg.test("Gurobi")
INFO: Testing Gurobi
running lp_01a.jl ...
ERROR: Gurobi not properly installed. Please run Pkg.build("Gurobi")
in error at error.jl:21
in include at /Applications/Julia-0.3.6.app/Contents/Resources/julia/lib/julia/sys.dylib
Thanks in advance for your help,
Ryan
We are using Gurobi.jl with JuMP.jl to run calculations. In a given script, we will run ~100 models. Rather than run the calculations locally, the Gurobi model connects to a Gurobi computation server. (If you're unfamiliar - the only change locally is that the license file says "instead of a license key, I actually point to a server". Everything else is basically the same).
When running the script, calculations are blocked until they complete on the server. However, when the calculation appears to have completed locally (because it receives a convergent result) - the computation server still shows it as a running calculation. The calculation is not consuming any resources, but it blocks additional calculations and causes the next calculation to block. So, if we limit the computation server to 2 simultaneous calculations - then two begin processing, finish, but continue to block, and all subsequent calculations enter a queued state. They do not get calculated until the original calculations time out.
Can we explicitly free the Gurobi environment after a calculation completes? Is there a way to explicitely do this using the JuMP interface?
If you need a computation server for testing, I can spin one up - ping me (philip at staffjoy.com)
We have different APIs from which you can call Gurobi (C, C++, Java, Python,...). In some of these APIs there are explicit methods for freeing a Gurobi environment, in some of them you just delete the GRBEnv object. If you are not using one of our APIs there is no way to free the environment except for killing the complete process.
As you are using Julia JuMP for calling Gurobi, I don't see a way for you do free the environment, except for changing the JuMP code. If this is what you want to do, just tell me which API they use (I guess C or C++, for C there is a function called GRBfreeEnv: http://www.gurobi.com/documentation/6.0/refman/c_grbfreeenv.html).
Our complete documentation can be found here: http://www.gurobi.com/documentation/
There are also reference manuals for the different programming languages.
Is it possible to give Gurobi the same magic as jump-dev/CPLEX.jl#45 so that it doesn't segfault on ctrl-c? I'm happy to have a go if needed, but it might be easier for someone that understands the internals better than I do.
Related, I've been working with a model given to me that uses gurobipy, and on that, ctrl-c interrupts the solve and returns the current incumbent. I'm not sure if that would fall out here as a consequence, but it would be pretty cool if it worked!
I think there is a bug with function get_basis(model::Model)
. It is not accounting for slack variables, the limit shouldn't be num_vars(model)
but the number of lines of A matrix. After, it has to use GRBgetBasisHead
to know the corresponding variables and known which variables are slacks. I will try to submit pull request soon.
Hi all,
I tried to solve an IP with JuMP using Gurobi. Yet I get an error:
julia> status=solve(m)
ERROR: error compiling #GurobiMathProgModel#10: error compiling Type: could not
load library "gurobi75"
The specified module could not be found.
Stacktrace:
[1] (::Core.#kw#Type)(::Array{Any,1}, ::Type{Gurobi.GurobiMathProgModel}, ::Voi
d) at .<missing>:0
[2] LinearQuadraticModel(::Gurobi.GurobiSolver) at C:\Users\Steffie.julia\v0.6
\Gurobi\src\GurobiSolverInterface.jl:68
[3] #build#119(::Bool, ::Bool, ::JuMP.ProblemTraits, ::Function, ::JuMP.Model)
at C:\Users\Steffie.julia\v0.6\JuMP\src\solvers.jl:356
[4] (::JuMP.#kw##build)(::Array{Any,1}, ::JuMP.#build, ::JuMP.Model) at .<miss
ing>:0
[5] #solve#116(::Bool, ::Bool, ::Bool, ::Array{Any,1}, ::Function, ::JuMP.Model
) at C:\Users\Steffie.julia\v0.6\JuMP\src\solvers.jl:168
[6] solve(::JuMP.Model) at C:\Users\Steffie.julia\v0.6\JuMP\src\solvers.jl:150
julia> ENV["GUROBI_HOME"]
"C:\gurobi751\win64"
My Gurobi version is 0.3.3 and in the following line is stated in the /deps/build.jl file:
aliases = ["gurobi75","gurobi70","gurobi65","gurobi60","gurobi56","gurobi55"]
Do you have any suggestions/ tips?
Thanks!
Steffie
As raised here, when setting the objective Gurobi silently rounds numbers greater than 1e100 down to 1e100.
using JuMP, Gurobi
m = Model(solver=GurobiSolver())
@variable(m, x >= 1)
@objective(m, Min, 1.1e100 * x)
solve(m) # :Optimal
getobjectivevalue(m) # 1.0e100 not 1.1e100
This also happens when setting other values such as the RHS. This is probably because Gurobi just rounds inputs to GRB_INFINITY (1e100).
Things also get weird around variable bounds. It ignores variable bounds larger than or equal to 1e20 (when +ve and upper, or -ve and lower)
using JuMP, Gurobi
m = Model(solver=GurobiSolver())
@variable(m, x <= 1e20)
@objective(m, Min, x)
solve(m) # unbounded
# ... or ...
# @variable(m, x >= -1e20)
# @objective(m, Max, x)
But when -ve and upper or +ve and lower, it allows up to 1e30
using JuMP, Gurobi
m = Model(solver=GurobiSolver())
@variable(m, x >= 1e30)
@objective(m, Min, x)
solve(m) # infeasible (default upper bound is 1e30)
# ... or
@variable(m, x <= -1e30)
@objective(m, Max x)
These "features" are also present in the Python interface.
Not really sure what we should do about it.
See https://groups.google.com/forum/#!topic/gurobi/R9SuKdb8YHc for the discussion.
Files demonstrating this (in both Julia and Python) are here
https://gist.github.com/odow/5255c34daef85a752da76b3836f20be3
Briefly:
After solving some LP, we add a new constraint
https://gist.github.com/odow/5255c34daef85a752da76b3836f20be3#file-main-jl-L25-L26
During the subsequent resolve (https://gist.github.com/odow/5255c34daef85a752da76b3836f20be3#file-main-jl-L30), Gurobi reformulates the model
The LP (and MPS) file of the model at this stage leaks this reformulation (minor bug).
https://gist.github.com/odow/5255c34daef85a752da76b3836f20be3#file-3_julia-jl-L1-L16
However, this leak does not occur through the other API's. Therefore, when we get the objective coefficients, we query the original coefficients.
https://gist.github.com/odow/5255c34daef85a752da76b3836f20be3#file-main-jl-L34
When we set the objective coefficients (which on resolve, JuMP always does using the original JuMP model coefficients https://github.com/JuliaOpt/JuMP.jl/blob/master/src/solvers.jl#L356 ), we trigger a bug, overriding the reformulated coefficients with this original coefficients.
https://gist.github.com/odow/5255c34daef85a752da76b3836f20be3#file-main-jl-L35
In the next solve, Gurobi "undoes" the formulation, but doesn't account for us resetting the correct (but incorrect for that formulation) coefficients (major bug).
This creates the unboundedness.
https://gist.github.com/odow/5255c34daef85a752da76b3836f20be3#file-julia-log-L39
This is pretty worrying for any model solved with JuMP and Gurobi as JuMP always performs this supposed no-op of getting and setting the objective coefficients. If Gurobi has ever reformulated a model in a way that is not unbounded, there would be no way of knowing (short of manually recalculating the objective) that the objective coefficients were switched, leading to an incorrect solution.
Running the following:
using Gurobi, JuMP
while true
env = Gurobi.Env()
m = Model(solver=GurobiSolver(env, OutputFlag=0))
@variable m x
@objective m Min x^2
solve(m)
Gurobi.free_env(env)
end
causes Julia to segfault after a few seconds with:
*** Error in `julia': corrupted double-linked list: 0x0000000003735d20 ***
gdb shows the following:
*** Error in `/usr/local/bin/julia': corrupted double-linked list: 0x0000000002f025f0 ***
Program received signal SIGABRT, Aborted.
0x00007ffff6d24c37 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
56 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0 0x00007ffff6d24c37 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1 0x00007ffff6d28028 in __GI_abort () at abort.c:89
#2 0x00007ffff6d612a4 in __libc_message (do_abort=do_abort@entry=1,
fmt=fmt@entry=0x7ffff6e6f6b0 "*** Error in `%s': %s: 0x%s ***\n") at ../sysdeps/posix/libc_fatal.c:175
#3 0x00007ffff6d6cb02 in malloc_printerr (ptr=0x2f025f0, str=0x7ffff6e6b7e4 "corrupted double-linked list",
action=1) at malloc.c:4996
#4 malloc_consolidate (av=av@entry=0x7ffff70ac760 <main_arena>) at malloc.c:4157
#5 0x00007ffff6d6d45d in _int_free (av=0x7ffff70ac760 <main_arena>, p=<optimized out>, have_lock=0)
at malloc.c:4057
#6 0x00007fffcda0c1be in PRIVATE00000000000620d1 ()
from /home/rdeits/Applications/gurobi750/linux64/lib/libgurobi75.so
#7 0x00007fffcda0addc in GRBfreemodel () from /home/rdeits/Applications/gurobi750/linux64/lib/libgurobi75.so
I'm running the following Julia version:
julia> versioninfo()
Julia Version 0.6.0
Commit 9036443 (2017-06-19 13:05 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i7-3920XM CPU @ 2.90GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
LAPACK: libopenblas64_
LIBM: libopenlibm
LLVM: libLLVM-3.9.1 (ORCJIT, ivybridge)
and the following Gurobi version:
julia> Gurobi.version
v"7.5.0"
julia> Pkg.installed("Gurobi")
v"0.3.3+"
I'm not entirely sure that this is a Gurobi.jl issue, but I have noticed that just constructing and freeing environments seems to work fine. That is, the following does not crash:
while true
env = Gurobi.Env()
Gurobi.free_env(env)
end
Hello
I could not get the gap out of a Gurobi model, I don't see the function implemented in the code.
regards
We already support a lot of the interface, so lets push for 100%. This was taken from the 5.6 Reference Manual: http://www.gurobi.com/documentation/5.6/reference-manual/refman
Suppose I create a Gurobi.Model
, called m
. Then I do this:
Gurobi.set_intattr!(model, "NumObj", 10)
Gurobi.get_intattr(model, "NumObj")
Interestingly, the last line returns 1
, instead of 10
. Why is NumObj
not being modified here?
I'm getting the error below when I try to call Gurobi through JuMP. I am able to call Gurobi from Python. Do I need to set GUROBI_HOME environment variable? My Gurobi license is set up to run Gurobi on a remote server.
Capacity available on '10.60.129.38' - connecting...
Established 256-bit AES encrypted connection
ERROR: LoadError: Invalid Gurobi license
Stacktrace:
[1] Gurobi.Env() at /Users/a598124/.julia/v0.6/Gurobi/src/grb_env.jl:13
[2] include_from_node1(::String) at ./loading.jl:576
[3] include(::String) at ./sysimg.jl:14
[4] process_options(::Base.JLOptions) at ./client.jl:305
[5] _start() at ./client.jl:371
while loading /Users/a598124/juliaCode/boxPacking1/monroe.jl, in expression starting on line 3
Hello,
I had Gurobi.jl installed and it worked fine until I did a Package update yesterday.
Now, with Gurobi.jl v0.2.8 I get the error "unable to locate Gurobi installation" even though GUROBI_HOME is set to the right path in terminal (If I type 'gurobi.sh' in terminal it works just fine). I use julia v0.5.0 on Ubuntu 16.04.
Hierarchical linear programming is when you have more than one objective, and you optimize them hierarchically. For example, if z1 is the optimal result from the first objective, you then optimize the second objective, but adding the contstrain that the first objective function is fixed at z1, and so on.
Gurobi has an interface for this, as I gather from the manual. It would be nice if this were ported to Gurobi.jl.
Note that simply doing the two optimizations by hand seems to have numerical issues in my experience. I have found that frequently the secondary optimization is seen as infeasible.
On Windows_7_x64 installed julia-0.6.2-win64.exe
File gurobi75.dll in D:\Julia\Solvers\bin
julia> ENV["GUROBI_HOME"]
"D:\\Julia\\Solvers"
julia> Pkg.add("Gurobi")
INFO: Installing Gurobi v0.3.3
INFO: Building Gurobi
INFO: Package database updated
julia> include("C:\\Users\\User\\.julia\\v0.6\\Gurobi\\test\\mip_01.jl")
INFO: Precompiling module Gurobi.
ERROR: LoadError: LoadError: error compiling getlibversion: could not load libra
ry "D:JuliaSolveringurobi75.dll"
The specified module could not be found.
Stacktrace:
[1] include_from_node1(::String) at .\loading.jl:576
[2] include(::String) at .\sysimg.jl:14
[3] include_from_node1(::String) at .\loading.jl:576
[4] include(::String) at .\sysimg.jl:14
[5] anonymous at .\<missing>:2
while loading C:\Users\User\.julia\v0.6\Gurobi\src\grb_common.jl, in expression
starting on line 72
while loading C:\Users\User\.julia\v0.6\Gurobi\src\Gurobi.jl, in expression star
ting on line 66
ERROR: LoadError: Failed to precompile Gurobi to C:\Users\User\.julia\lib\v0.6\G
urobi.ji.
Stacktrace:
[1] compilecache(::String) at .\loading.jl:710
[2] _require(::Symbol) at .\loading.jl:497
[3] require(::Symbol) at .\loading.jl:405
[4] include_from_node1(::String) at .\loading.jl:576
[5] include(::String) at .\sysimg.jl:14
while loading C:\Users\User\.julia\v0.6\Gurobi\test\mip_01.jl, in expression sta
rting on line 13
It'd be good if attributes were supported so objectives, bounds, etc. could be updated
C: GRBsetdblattrelement(model, "Obj", j, cost[j]);
Julia: setAttrElement!(model, "Obj", j, cost[j])
EDIT: I see these are actually there, but not exported - is something broken with them?
I have a JuMP (mixed-integer) model where I'm trying to determine the upper and lower bounds on many variables. Each individual solve is very quick, but since I have many variables (~1,000), the overall solve time is slow (~5s).
One thing that I observed is that julia
often seems to be using only one core at a time, and I was hoping that parallelization might be able to reduce solve times significantly. However, I'm running into an issue that seems to have to do with there being only a single Gurobi environment created.
Here's an example of a snippet of code that doesn't work. (map
runs fine, but pmap
does not).
addprocs(2)
using JuMP
using Gurobi
@everywhere begin
env = Gurobi.Env()
m = JuMP.Model(solver = Gurobi.GurobiSolver(env, OutputFlag=0))
@JuMP.variable(m, 0 <= x[i=1:100] <= i)
function upperbound_mip(x)
@JuMP.objective(x.m, Max, x)
JuMP.solve(x.m)
return JuMP.getobjectivevalue(x.m)
end
end
@time map(upperbound_mip, x)
@time pmap(upperbound_mip, x)
Output
Academic license - for non-commercial use only
From worker 3: Academic license - for non-commercial use only
From worker 2: Academic license - for non-commercial use only
2.317813 seconds (1.72 M allocations: 90.407 MiB, 1.04% gc time)
ERROR: LoadError: On worker 2:
AssertionError: env.ptr_env != C_NULL
get_error_msg at /home/vtjeng/.julia/v0.6/Gurobi/src/grb_env.jl:38
Type at /home/vtjeng/.julia/v0.6/Gurobi/src/grb_env.jl:50 [inlined]
get_intattr at /home/vtjeng/.julia/v0.6/Gurobi/src/grb_attrs.jl:16
setvarLB! at /home/vtjeng/.julia/v0.6/Gurobi/src/GurobiSolverInterface.jl:187
#build#119 at /home/vtjeng/.julia/v0.6/JuMP/src/solvers.jl:338
#build at ./<missing>:0
#solve#116 at /home/vtjeng/.julia/v0.6/JuMP/src/solvers.jl:168
upperbound_mip at /home/vtjeng/Dropbox/Documents/MIT/UROP/adversarial_examples/pset/6_using_MIPVerify/debug/feature-parallel-solves.jl:14
#106 at ./distributed/process_messages.jl:268 [inlined]
run_work_thunk at ./distributed/process_messages.jl:56
macro expansion at ./distributed/process_messages.jl:268 [inlined]
#105 at ./event.jl:73
Stacktrace:
[1] #571 at ./asyncmap.jl:178 [inlined]
[2] foreach(::Base.##571#573, ::Array{Any,1}) at ./abstractarray.jl:1733
[3] maptwice(::Function, ::Channel{Any}, ::Array{Any,1}, ::Array{JuMP.Variable,1}, ::Vararg{Array{JuMP.Variable,1},N} where N) at ./asyncmap.jl:178
[4] wrap_n_exec_twice(::Channel{Any}, ::Array{Any,1}, ::Base.Distributed.##204#207{WorkerPool}, ::Function, ::Array{JuMP.Variable,1}, ::Vararg{Array{JuMP.Variable,1},N} where N) at ./asyncmap.jl:154
[5] #async_usemap#556(::Function, ::Void, ::Function, ::Base.Distributed.##188#190, ::Array{JuMP.Variable,1}, ::Vararg{Array{JuMP.Variable,1},N} where N) at ./asyncmap.jl:103
[6] (::Base.#kw##async_usemap)(::Array{Any,1}, ::Base.#async_usemap, ::Function, ::Array{JuMP.Variable,1}, ::Vararg{Array{JuMP.Variable,1},N} where N) at ./<missing>:0
[7] (::Base.#kw##asyncmap)(::Array{Any,1}, ::Base.#asyncmap, ::Function, ::Array{JuMP.Variable,1}) at ./<missing>:0
[8] #pmap#203(::Bool, ::Int64, ::Void, ::Array{Any,1}, ::Void, ::Function, ::WorkerPool, ::Function, ::Array{JuMP.Variable,1}) at ./distributed/pmap.jl:126
[9] pmap(::WorkerPool, ::Function, ::Array{JuMP.Variable,1}) at ./distributed/pmap.jl:101
[10] #pmap#213(::Array{Any,1}, ::Function, ::Function, ::Array{JuMP.Variable,1}) at ./distributed/pmap.jl:156
[11] pmap(::Function, ::Array{JuMP.Variable,1}) at ./distributed/pmap.jl:156
[12] include_from_node1(::String) at ./loading.jl:576
[13] include(::String) at ./sysimg.jl:14
[14] process_options(::Base.JLOptions) at ./client.jl:305
[15] _start() at ./client.jl:371
One thing I've thought about trying to do is to generate one environment per worker thread, but 1) I don't know whether that would help and 2) I don't know how to do that.
On this problem,
Min y
s.t. x >= 1
loadproblem!(m, [1. 0.], [-Inf, -Inf], [Inf, Inf], [0., 1.], [1.], [Inf], :Min)
calling optimize!
returns :Unbounded
and then getsolution
gives [6.93747e-310,0.0]
which is not feasible since x = 6.93747e-310 < 1
(I am using Gurobi 6.51).
However, it seems that in Gurobi getsolution
gives a feasible solution even for unbounded problem since for the following problem
Max x
s.t. x >= 1
x unbounded
y <= -1
loadproblem!(m, [1. 0.], [-Inf, -Inf], [Inf, -1], [1., 0.], [1], [Inf], :Max)
optimize!
returns :Unbounded
and then getsolution
returns a feasible solution.
We finally have some unit tests for LinprogSolver.
using Gurobi
include(joinpath(Pkg.dir("MathProgBase"),"test","linproginterface.jl"))
m = Gurobi.model()
linprogsolvertest(m)
ERROR: test error during :((getvarLB(m)==[0.0,0.0]))
Not Implemented
in anonymous at test.jl:63
in do_test at test.jl:36
in linprogsolvertest at /home/mlubin/.julia/MathProgBase/test/linproginterface.jl:13
On commit JuliaLang/julia@4e84913
julia> using Gurobi
ERROR: no method Set{ASCIIString}(ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString, ASCIIString)
you may have intended to import Base.Set
in reload_path at loading.jl:144
in _require at loading.jl:59
in require at loading.jl:43
while loading /Users/huchette/.julia/v0.3/Gurobi/src/grb_params.jl, in expression starting on line 9
while loading /Users/huchette/.julia/v0.3/Gurobi/src/Gurobi.jl, in expression starting on line 63
Seems sets should be specified Set(["a", "b"])
now; this will probably break on 0.2 though
I'm new to using Gurobi in Julia, so I was following your README, looking at the examples. In particular, I was looking at Example 1.4. I could run the code and solve the optimization problem, but I noticed that any parameters I attempted to manipulate through a combination of
env = Gurobi.Env()
and
setparam!(env, name, v)
had no effect on the results.
After more time than I care to admit, I realized that the problem was the following line in Example 1.4:
m = Model(solver=GurobiSolver())
As soon as I updated this to read
m = Model(solver=GurobiSolver(env))
My parameter manipulations had the expected effect.
For the seasoned Gurobi users out there, it is perhaps obvious that we somehow need to inform Gurobi of the changes made to the environment. However, this was not obvious to a noob like me. You might consider updating the troublesome line in Example 1.4 to spare future noobs the same confusion.
Hey all,
One of my colleagues (Ramandeep) said he recently tried to pull down JuMP and Gurobi and get it working and it would not work with Gurobi 6, but does work with Gurobi 5.6...
Granted, this is not exactly a reproducible use case, and it may have been something else entirely, but I thought I'd flag it with all of you just in case.
Vishal
It appears that GurobiSolver
ignores any constant terms in the JuMP model's cost function. For example:
using JuMP, Gurobi
model = Model(solver=GurobiSolver(OutputFlag=1))
@variable model x
@objective model Min x^2 - 1
solve(model)
The gurobi output shows:
Optimize a model with 0 rows, 1 columns and 0 nonzeros
Model has 1 quadratic objective term
Coefficient statistics:
Matrix range [0e+00, 0e+00]
Objective range [0e+00, 0e+00]
QObjective range [2e+00, 2e+00]
Bounds range [0e+00, 0e+00]
RHS range [0e+00, 0e+00]
Presolve removed 0 rows and 1 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Barrier solved model in 0 iterations and 0.00 seconds
Optimal objective 0.00000000e+00
but the optimal objective value is actually -1
, as confirmed by JuMP:
getvalue(getobjective(model))
# -1.0
Of course, for most optimization problems this is fine. Any constant term in the objective doesn't affect the minimizer, and JuMP still reports the correct final objective with getvalue()
.
However, there is one case in which this absolutely does matter: mixed-integer programming. When solving an MIP, Gurobi checks optimality by measuring (among other things), the relative gap between the best incumbent and the best bound. Since this gap is relative to the actual cost value, adding an arbitrary constant offset (or failing to add one) will affect whether the MIP gap is considered small enough.
This is causing some trouble for me, since I see very different solve times depending on how the particular initial state of my system affects the (eliminated) constant term in the cost.
Is there any way to turn this on in Gurobi.jl? I'd be happy to do the work myself, but I'd appreciate some pointers on where to look, since I haven't used the internal Gurobi interface at all.
I'm trying to use Convex.jl with Gurobi
using Convex, Gurobi
x = Variable()
y = Variable(Positive())
p = minimize(x+y,x==1)
solve!(p, GurobiSolver())
and I get
ERROR: `add_cvars!` has no method matching add_cvars!(::Model, ::Array{Float64,2}, ::Array{Float64,1}, ::Array{Float64,1})
in loadproblem! at /Users/karanveer/.julia/v0.3/Gurobi/src/GurobiSolverInterface.jl:35
in loadconicproblem! at /Users/karanveer/.julia/v0.3/MathProgBase/src/SolverInterface/conic.jl:105
in solve! at /Users/karanveer/.julia/v0.3/Convex/src/solution.jl:31
in solve! at /Users/karanveer/.julia/v0.3/Convex/src/solution.jl:66
I can change line 35 of GurobiSolverInterface.jl to:
add_cvars!(m.inner, float(vec(obj)), float(collb), float(colub))
and the relevant Convex.jl tests all pass, but is that the best place for that change to be made, or should something differently be done in MPB?
Hi, I am trying to solve a MIQP problem and feel confused about some of your arguments... Could you please tell me what is the meaning of "rowinds", "colinds", "coeffs" in Example 2.2? Thank you very much in advance. :)
# add quadratic terms: x^2, x * y, y^2
# add_qpterms!(model, rowinds, colinds, coeffs)
add_qpterms!(model, [1, 1, 2], [1, 2, 2], [1., 1., 1.])
The gurobi library on OS X is a .so
file instead of a .dylib
file, so BinDeps can't find it.
Gurobi expects the callbacks to follow the stdcall convention.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.