Skip to content

Commit

Permalink
Clarify Env module constants in README
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Oct 17, 2023
1 parent 5f32366 commit 33f87cb
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,29 @@ model_2 = direct_model(Gurobi.Optimizer(GRB_ENV))
set_attribute(model_2, "OutputFlag", 0)
```

If you create a module with a `Gurobi.Env` as a module-level constant, use an
`__init__` function to ensure that a new environment is created each time the
module is loaded:

```julia
module MyModule

import Gurobi

const GRB_ENV_REF = Ref{Gurobi.Env}()

function __init__()
global GRB_ENV
GRB_ENV[] = Gurobi.Env()
return
end

# Note the need for GRB_ENV_REF[] not GRB_ENV_REF
create_optimizer() = Gurobi.Optimizer(GRB_ENV_REF[])

end # module
```

## Accessing Gurobi-specific attributes

Get and set Gurobi-specific variable, constraint, and model attributes as
Expand Down

0 comments on commit 33f87cb

Please sign in to comment.