# Error building \`Gurobi\`

**URL:** <https://discourse.julialang.org/t/error-building-gurobi/59852>\
**Category:** Optimization (Mathematical)\
**Tags:** package, gurobi\
**Created:** [April 23, 2021, 8:49am UTC](https://discourse.julialang.org/t/error-building-gurobi/59852 "2021-04-23T08:49:01Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![zlq178](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zlq178/32/17952_2.png) [@zlq178](https://discourse.julialang.org/u/zlq178)\
**Post date:** [April 23, 2021, 12:01pm UTC](https://discourse.julialang.org/t/error-building-gurobi/59852/3 "2021-04-23T12:01:32Z")

</div>

The above problem has been solved according to your suggestion. But when I run the code, a new error has occurred.

```julia
using JuMP,JuMPeR,Gurobi

# Define problem parameters
I = 3 # Number of factories
T = 24 # Number of time periods
d_nom = 1000*[1 + 0.5*sin(π*(t-1)/12) for t in 1:T] # Nominal demand
θ = 0.20 # Uncertainty level
α = [1.0, 1.5, 2.0] # Production costs
c = [α[i] * (1 + 0.5*sin(π*(t-1)/12)) for i in 1:I, t in 1:T]
P = 567 # Maximimum production per period
Q = 13600 # Maximumum production over all
Vmin = 500 # Minimum inventory at warehouse
Vmax = 2000 # Maximum inventory at warehouse
v1 = Vmin # Initial inventory (not provided in paper)

# Setup robust model
invmgmt = RobustModel(solver=GurobiSolver(OutputFlag=0))

# Uncertain parameter: demand at each time stage lies in a interval
@uncertain(invmgmt, d_nom[t]*(1-θ) <= d[t=1:T] <= d_nom[t]*(1+θ))

# Decision: how much to produce at each factory at each time
# As this decision can be updated as demand is realized, we will use adaptive
# policy - in particular, an affine policy where production at time t is an
# affine function of the demand realized previously.
@adaptive(invmgmt, p[i=1:I,t=1:T], policy=Affine, depends_on=d[1:t-1])

# Objective: minimize total cost of production
@variable(invmgmt, F) # Overall cost
@objective(invmgmt, Min, F)
@constraint(invmgmt, F >= sum{c[i,t] * p[i,t], i=1:I, t=1:T})

# Constraint: cannot exceed production limits
for i in 1:I, t in 1:T
    @constraint(invmgmt, p[i,t] >= 0)
    @constraint(invmgmt, p[i,t] <= P)
end
for i in 1:I
    @constraint(invmgmt, sum{p[i,t], t=1:T} <= Q)
end

# Constraint: cannot exceed inventory limits
for t in 1:T
    @constraint(invmgmt,
        v1 + sum{p[i,s], i=1:I, s=1:t} - sum{d[s],s=1:t} >= Vmin)
    @constraint(invmgmt,
        v1 + sum{p[i,s], i=1:I, s=1:t} - sum{d[s],s=1:t} <= Vmax)
end

# Solve
status = solve(invmgmt)

println(getobjectivevalue(invmgmt))

```

- ERROR  
LoadError: The C API of Gurobi.jl has been rewritten to expose the complete C API, and  
all old functions have been removed. For more information, see the Discourse  
announcement: [https://discourse.julialang.org/t/ann-upcoming-breaking-changes-to-cplex-jl-and-gurobi-jl](https://discourse.julialang.org/t/ann-upcoming-breaking-changes-to-cplex-jl-and-gurobi-jl)  
Here is a brief summary of the changes.
- Constants have changed. For example `CB_MIPNODE` is now `GRB_CB_MIPNODE`  
to match the C API.
- Function names have changed. For example `free_env(env)` is now  
`GRBfreeenv(env)`.
- For users of `Gurobi.Optimizer()`, `model.inner` is now a pointer to the C  
model, instead of a `Gurobi.Model` object. However, conversion means that  
you should always pass `model` instead of `model.inner` to the low-level  
functions. For example:

```julia
model = direct_model(Gurobi.Optimizer())
grb_model = backend(model) # grb_model is Gurobi.Optimizer
# Old
Gurobi.tune_model(grb_model.inner)
# New
GRBtunemodel(grb_model)

```

- Some functions have been removed entirely. For example:

```julia
using JuMP, Gurobi
model = direct_model(Gurobi.Optimizer())
optimize!(model)
grb_model = backend(model)
stat = Gurobi.get_status_code(grb_model.inner)

```

is now:

```julia
using JuMP, Gurobi
model = direct_model(Gurobi.Optimizer())
optimize!(model)
valueP = Ref{Cint}()
grb_model = backend(model)
ret = GRBgetintattr(grb_model, "Status", valueP)
if ret != 0
    # Do something because the call failed
end
stat = valueP[]

```

The new API is more verbose, but the names and function arguments are now  
identical to the C API, documentation for which is available at:

> **[C API Details - Gurobi Optimization](https://www.gurobi.com/documentation/9.0/refman/c_api_details.html)**
>
> C API Details

To revert to the old API, use:  
import Pkg  
Pkg.add(Pkg.PackageSpec(name = “Gurobi”, version = v"0.8.1"))  
Then restart Julia for the change to take effect.  
in expression starting at untitled-254185b6f7c55e2fdb6293d5d74fc246:17  
error(::String) at error.jl:33  
GurobiSolver(; kwargs::Base.Iterators.Pairs{Symbol,Int64,Tuple{Symbol},NamedTuple{(:OutputFlag,),Tuple{Int64}}}) at deprecated\_functions.jl:548  
(::Gurobi.var"#GurobiSolver##kw")(::NamedTuple{(:OutputFlag,),Tuple{Int64}}, ::typeof(GurobiSolver)) at deprecated\_functions.jl:548  
top-level scope at untitled-254185b6f7c55e2fdb6293d5d74fc246:17  
include\_string(::Function, ::Module, ::String, ::String) at loading.jl:1088

---

_[View the full topic](https://discourse.julialang.org/t/error-building-gurobi/59852)._
