Model Module¶
This section documents the model components of the Nextmv Gurobi Python SDK.
model
¶
Defines gurobipy model interoperability.
This module provides functions for integrating Nextmv with Gurobi optimization.
FUNCTION | DESCRIPTION |
---|---|
Model |
Creates a Gurobi model that can be used to solve optimization problems. |
Model
¶
Model(
options: Options, license_path: Optional[str] = ""
) -> Model
Creates a Gurobi model, using Nextmv options.
You can import the Model
function directly from nextmv_gurobipy
:
The returned type is a gurobipy.Model
class. This means that once the Gurobi
model is created, it can be used as any other Gurobi model. This loader will
look for the gurobi.lic
file in the provided license_path
. If the file
is not found, it will not be read. This means that by default, you will be
working with Gurobi's community license.
Only the parameters that are available in the Gurobi API are set. If a parameter is not available, it will be skipped.
This function has some side effects that you should be aware of: - It redirects the solver chatter to stderr. - It sets the provider to "gurobi" in the options.
PARAMETER | DESCRIPTION |
---|---|
|
The options for the Gurobi model. Any option that matches a Gurobi parameter name will be set in the model.
TYPE:
|
|
Path to the directory containing the Gurobi license file. Default is "" (empty string).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Model
|
The Gurobi model instance that can be used to define and solve optimization problems. |
Examples:
>>> import nextmv
>>> from nextmv_gurobipy import Model
>>>
>>> # Create options
>>> options = nextmv.Options()
>>> options.threads = 4
>>> options.time_limit = 60
>>>
>>> # Create Gurobi model with Nextmv options
>>> model = Model(options, license_path="/path/to/license/directory")
>>>
>>> # Use model as any other Gurobi model
>>> x = model.addVar(name="x")
>>> y = model.addVar(name="y")
>>> model.addConstr(x + y <= 1)
>>> model.setObjective(x + y, sense=gp.GRB.MAXIMIZE)
>>> model.optimize()