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

Clarify Env module constants in README #521

Merged
merged 2 commits into from
Oct 18, 2023
Merged
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
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_REF
GRB_ENV_REF[] = Gurobi.Env()
return
end

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

end
```

## Accessing Gurobi-specific attributes

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