From b42b4c4da299648e8b05fd177b5328158de6ad2c Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Tue, 17 Oct 2023 17:55:31 -0700 Subject: [PATCH] Clarify Env module constants in README (#521) --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index ee0bb02..29eb37c 100644 --- a/README.md +++ b/README.md @@ -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