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

WIP: prep for v1.0 #451

Merged
merged 3 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
name = "Gurobi"
uuid = "2e9cd046-0924-5485-92f1-d5272153d98b"
repo = "https://github.com/jump-dev/Gurobi.jl"
version = "0.10.3"
version = "1.0.0"

[deps]
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

[compat]
CEnum = "0.3, 0.4"
MathOptInterface = "~0.10"
julia = "1.3"
MathOptInterface = "1"
julia = "1.6"

[extras]
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand Down
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
**Gurobi.jl underwent a major rewrite between versions 0.8.1 and 0.9.0. Users of
JuMP should see no breaking changes, but if you used the lower-level C API
(e.g., for callbacks), you will need to update your code accordingly. For a full
description of the changes, read [this discourse post](https://discourse.julialang.org/t/ann-upcoming-breaking-changes-to-cplex-jl-and-gurobi-jl/47814).**

**To revert to the old API, use:**
```julia
import Pkg
Pkg.add(Pkg.PackageSpec(name = "Gurobi", version = v"0.8"))
```
**Then restart Julia for the change to take effect.**

# Gurobi.jl

[![Build Status](https://github.com/jump-dev/Gurobi.jl/workflows/CI/badge.svg?branch=master)](https://github.com/jump-dev/Gurobi.jl/actions?query=workflow%3ACI)
Expand Down
54 changes: 0 additions & 54 deletions scripts/deprecate.jl

This file was deleted.

14 changes: 2 additions & 12 deletions src/Gurobi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ else
""")
end

using CEnum

const _GUROBI_VERSION = if libgurobi == "julia_registryci_automerge"
VersionNumber(9, 5, 1)
else
Expand All @@ -44,15 +42,12 @@ function _is_patch(x::VersionNumber, reference::VersionNumber)
end

if _is_patch(_GUROBI_VERSION, v"9.0")
include("gen90/ctypes.jl")
include("gen90/libgrb_common.jl")
include("gen90/libgrb_api.jl")
elseif _is_patch(_GUROBI_VERSION, v"9.1")
include("gen91/ctypes.jl")
include("gen91/libgrb_common.jl")
include("gen91/libgrb_api.jl")
elseif _is_patch(_GUROBI_VERSION, v"9.5")
include("gen95/ctypes.jl")
include("gen95/libgrb_common.jl")
include("gen95/libgrb_api.jl")
else
Expand Down Expand Up @@ -84,13 +79,8 @@ include("MOI_wrapper/MOI_indicator_constraint.jl")
# Gurobi exports all `GRBXXX` symbols. If you don't want all of these symbols in
# your environment, then use `import Gurobi` instead of `using Gurobi`.

for sym in names(@__MODULE__, all=true)
sym_string = string(sym)
if startswith(sym_string, "GRB")
@eval export $sym
end
for sym in filter(s -> startswith("$s", "GRB"), names(@__MODULE__, all = true))
@eval export $sym
end

include("deprecated_functions.jl")

end
68 changes: 28 additions & 40 deletions src/MOI_wrapper/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,34 @@ Base.unsafe_convert(::Type{Ptr{Cvoid}}, env::Env) = env.ptr_env::Ptr{Cvoid}
const _HASH = CleverDicts.key_to_index
const _INVERSE_HASH = x -> CleverDicts.index_to_key(MOI.VariableIndex, x)

"""
Optimizer(
env::Union{Nothing,Env} = nothing;
enable_interrupts::Bool = true,
)

Create a new Optimizer object.

You can share Gurobi `Env`s between models by passing an instance of `Env`
as the first argument.

In order to enable interrupts via `CTRL+C`, a no-op callback is added to the
model by default. In most cases, this has negligible effect on solution
times. However, you can disable it (at the cost of not being able to
interrupt a solve) by passing `enable_interrupts = false`.

Set optimizer attributes using `MOI.RawOptimizerAttribute` or
`JuMP.set_optimizer_atttribute`.

## Example

```julia
using JuMP, Gurobi
const env = Gurobi.Env()
model = JuMP.Model(() -> Gurobi.Optimizer(env; enable_interrupts=false))
set_optimizer_attribute(model, "OutputFlag", 0)
```
"""
mutable struct Optimizer <: MOI.AbstractOptimizer
# The low-level Gurobi model.
inner::Ptr{Cvoid}
Expand Down Expand Up @@ -232,54 +260,15 @@ mutable struct Optimizer <: MOI.AbstractOptimizer

conflict::Cint

"""
Optimizer(
env::Union{Nothing,Env} = nothing;
enable_interrupts::Bool = true,
)

Create a new Optimizer object.

You can share Gurobi `Env`s between models by passing an instance of `Env`
as the first argument.

In order to enable interrupts via `CTRL+C`, a no-op callback is added to the
model by default. In most cases, this has negligible effect on solution
times. However, you can disable it (at the cost of not being able to
interrupt a solve) by passing `enable_interrupts = false`.

Set optimizer attributes using `MOI.RawOptimizerAttribute` or
`JuMP.set_optimizer_atttribute`.

## Example

using JuMP, Gurobi
const env = Gurobi.Env()
model = JuMP.Model(() -> Gurobi.Optimizer(env; enable_interrupts=false))
set_optimizer_attribute(model, "OutputFlag", 0)
"""
function Optimizer(
env::Union{Nothing,Env} = nothing;
enable_interrupts::Bool = true,
kwargs...,
)
model = new()
model.inner = C_NULL
model.env = env === nothing ? Env() : env
model.enable_interrupts = enable_interrupts
model.params = Dict{String,Any}()
if length(kwargs) > 0
@warn("""Passing optimizer attributes as keyword arguments to
Gurobi.Optimizer is deprecated. Use
MOI.set(model, MOI.RawOptimizerAttribute("key"), value)
or
JuMP.set_optimizer_attribute(model, "key", value)
instead.
""")
end
for (name, value) in kwargs
model.params[string(name)] = value
end
model.silent = false
model.variable_info =
CleverDicts.CleverDict{MOI.VariableIndex,_VariableInfo}(
Expand All @@ -293,7 +282,6 @@ mutable struct Optimizer <: MOI.AbstractOptimizer
model.quadratic_constraint_info = Dict{Int,_ConstraintInfo}()
model.sos_constraint_info = Dict{Int,_ConstraintInfo}()
model.indicator_constraint_info = Dict{Int,_ConstraintInfo}()

model.callback_variable_primal = Float64[]
MOI.empty!(model)
finalizer(model) do m
Expand Down
Loading