Statistics Module¶
This section documents the statistics components of the Nextmv Gurobi Python SDK.
statistics
¶
Defines gurobipy statistics interoperability.
This module provides utilities to convert Gurobi optimization results into Nextmv statistics objects for consistency across the Nextmv platform.
FUNCTION | DESCRIPTION |
---|---|
ModelStatistics |
Creates a Nextmv statistics object from a Gurobi model. |
Variables
STATUS Mapping between Gurobi status codes and their string representations.
ModelStatistics
¶
ModelStatistics(
model: Model, run_duration_start: Optional[float] = None
) -> Statistics
Creates a Nextmv statistics object from a Gurobi model, once it has been optimized.
You can import the ModelStatistics
function directly from nextmv_gurobipy
:
The statistics returned are quite basic, and should be extended
according to the custom metrics that the user wants to track. The optional
run_duration_start
parameter can be used to set the start time of the
whole run. This is useful to separate the run time from the solve time.
PARAMETER | DESCRIPTION |
---|---|
|
The Gurobi model after optimization.
TYPE:
|
|
The start time of the run in seconds since the epoch, as returned by
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Statistics
|
The Nextmv statistics object containing run information, result statistics, and series data. |
Examples:
>>> import time
>>> from nextmv_gurobipy import Model, Options, ModelStatistics
>>>
>>> start_time = time.time()
>>> options = Options()
>>> model = Model(options, ".")
>>> # Create and configure your model
>>> model.optimize()
>>> stats = ModelStatistics(model, start_time)
>>> # Add additional information to the statistics object if needed
Source code in nextmv-gurobipy/nextmv_gurobipy/statistics.py
STATUS
module-attribute
¶
STATUS = {
LOADED: "LOADED",
OPTIMAL: "OPTIMAL",
INFEASIBLE: "INFEASIBLE",
INF_OR_UNBD: "INF_OR_UNBD",
UNBOUNDED: "UNBOUNDED",
CUTOFF: "CUTOFF",
ITERATION_LIMIT: "ITERATION_LIMIT",
NODE_LIMIT: "NODE_LIMIT",
TIME_LIMIT: "TIME_LIMIT",
SOLUTION_LIMIT: "SOLUTION_LIMIT",
INTERRUPTED: "INTERRUPTED",
NUMERIC: "NUMERIC",
SUBOPTIMAL: "SUBOPTIMAL",
INPROGRESS: "INPROGRESS",
USER_OBJ_LIMIT: "USER_OBJ_LIMIT",
WORK_LIMIT: "WORK_LIMIT",
MEM_LIMIT: "MEM_LIMIT",
}
dict: Mapping between Gurobi status codes and their string representations.
You can import the STATUS
dictionary directly from nextmv_gurobipy
:
This dictionary converts numerical Gurobi status codes to human-readable string representations for use in statistics reporting. The status codes indicate the outcome of the optimization process (e.g., whether an optimal solution was found, or the solver hit a limit).
Examples: