Skip to content

Commit

Permalink
Update README.md (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored May 18, 2020
1 parent 5d67530 commit c0b69a6
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,41 @@ The [Gurobi](http://www.gurobi.com) Optimizer is a commercial optimization solve

You need to set the NonConvex parameter:
```julia
model = Model(with_optimizer(Gurobi.Optimizer, NonConvex = 2))
model = Model(Gurobi.Optimizer)
set_optimizer_attribute(model, "NonConvex", 2)
```

## Use with JuMP

We highly recommend that you use the *Gurobi.jl* package with higher level packages such as [JuMP.jl](https://github.com/JuliaOpt/JuMP.jl).

This can be done using the ``Gurobi.Optimizer`` object. Here is how to create a *JuMP* model that uses Gurobi as the solver. Parameters are passed as keyword arguments:
This can be done using the ``Gurobi.Optimizer`` object. Here is how to create a *JuMP* model that uses Gurobi as the solver.
```julia
using JuMP, Gurobi

model = Model(Gurobi.Optimizer)
set_optimizer_attribute(model,"TimeLimit",100)
set_optimizer_attribute(model,"Presolve",0)
set_optimizer_attribute(model, "TimeLimit", 100)
set_optimizer_attribute(model, "Presolve", 0)
```
See the [Gurobi Documentation](https://www.gurobi.com/documentation/current/refman/parameters.html) for a list and description of allowable parameters.

## Reusing the same Gurobi environment for multiple solves

When using this package via other packages such as [JuMP.jl](https://github.com/JuliaOpt/JuMP.jl), the default behavior is to obtain a new Gurobi license token every time a model is created and solved. If you are using Gurobi in a setting where the number of concurrent Gurobi uses is limited (e.g. ["Single-Use" or "Floating-Use" licenses](http://www.gurobi.com/products/licensing-pricing/licensing-overview)), you might instead prefer to obtain a single license token that is shared by all models that your program solves. You can do this by passing a Gurobi Environment object as the first parameter to `Gurobi.Optimizer`. For example, the follow code snippet solves multiple problems with JuMP using the same license token:

```julia
using JuMP, Gurobi

const GRB_ENV = Gurobi.Env()

model1 = Model(() -> Gurobi.Optimizer(GRB_ENV))
...

# The solvers can have different options too
model2 = Model(optimizer_with_attributes(() -> Gurobi.Optimizer(GRB_ENV), "OutputFlag" => 0))
...
```

### Common Performance Pitfall with JuMP

Gurobi API works differently than most solvers. Any changes to the model are not applied immediately, but instead go sit in a internal buffer (making any modifications appear to be instantaneous) waiting for a call to `update_model!` (where the work is done). If Gurobi.jl is used directly, it is the user responsability to call `update_model!` when necessary (for example, before solving the model), as it would be if the user was using the official C interface. However, if Gurobi.jl is used with JuMP, it becomes Gurobi.jl responsibility to call `update_model!` when necessary, as a valid JuMP program should work for solvers with and without such lazy update semantics (i.e., with and without a `update_model!`-like method).
Expand Down Expand Up @@ -98,23 +116,6 @@ julia> import Pkg; Pkg.build("Gurobi")
```
The Gurobi library (`gurobiXX.dll` on Windows, `gurobiXX.so` on Unix, and `gurobiXX.dylib` in OSX where `XX` is a version) will be searched for in ``GUROBI_HOME/lib`` on unix platforms and ``GUROBI_HOME\bin`` on Windows.

## Reusing the same Gurobi environment for multiple solves

When using this package via other packages such as [JuMP.jl](https://github.com/JuliaOpt/JuMP.jl), the default behavior is to obtain a new Gurobi license token every time a model is created and solved. If you are using Gurobi in a setting where the number of concurrent Gurobi uses is limited (e.g. ["Single-Use" or "Floating-Use" licenses](http://www.gurobi.com/products/licensing-pricing/licensing-overview)), you might instead prefer to obtain a single license token that is shared by all models that your program solves. You can do this by passing a Gurobi Environment object as the first parameter to `Gurobi.Optimizer`. For example, the follow code snippet solves multiple problems with JuMP using the same license token:

```julia
using JuMP, Gurobi

const GRB_ENV = Gurobi.Env()

model1 = Model(with_optimizer(Gurobi.Optimizer, GRB_ENV))
...

# The solvers can have different options too
model2 = Model(with_optimizer(Gurobi.Optimizer, GRB_ENV, OutputFlag=0))
...
```

## Accessing Gurobi-specific attributes via JuMP

You can get and set Gurobi-specific variable, constraint, and model attributes via JuMP as follows:
Expand Down

2 comments on commit c0b69a6

@odow
Copy link
Member Author

@odow odow commented on c0b69a6 May 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/15355

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.8.1 -m "<description of version>" c0b69a690aa73e8dd3a8b6980ab1a5de10569573
git push origin v0.8.1

Please sign in to comment.