Skip to content

solvers

Code to interface with various solvers

GurobiSolver(*args, **kwargs)

Bases: FileBasedSolver

Source code in pyoframe/solvers.py
def __init__(self, *args, **kwargs):
    super().__init__(*args, **kwargs)
    if not self.log_to_console:
        self.params["LogToConsole"] = 0
    self.env = None

create_solver_model_from_lp()

Solve a linear problem using the gurobi solver.

This function communicates with gurobi using the gurubipy package.

Source code in pyoframe/solvers.py
def create_solver_model_from_lp(self) -> Any:
    """
    Solve a linear problem using the gurobi solver.

    This function communicates with gurobi using the gurubipy package.
    """
    assert self.problem_file is not None
    self.env = gurobipy.Env(params=self.params)

    m = gurobipy.read(_path_to_str(self.problem_file), env=self.env)
    if not self.keep_files:
        self.problem_file.unlink()

    return m

Solver(model, log_to_console, params, directory)

Bases: ABC

Source code in pyoframe/solvers.py
def __init__(self, model: "Model", log_to_console, params, directory):
    self._model = model
    self.solver_model: Optional[Any] = None
    self.log_to_console: bool = log_to_console
    self.params = params
    self.directory = directory

dispose()

Clean up any resources that wouldn't be cleaned up by the garbage collector.

For now, this is only used by the Gurobi solver to call .dispose() on the solver model and Gurobi environment which helps close a connection to the Gurobi Computer Server. Note that this effectively disables commands that need access to the solver model (like .slack and .RC)

Source code in pyoframe/solvers.py
def dispose(self):
    """
    Clean up any resources that wouldn't be cleaned up by the garbage collector.

    For now, this is only used by the Gurobi solver to call .dispose() on the solver model and Gurobi environment
    which helps close a connection to the Gurobi Computer Server. Note that this effectively disables commands that
    need access to the solver model (like .slack and .RC)
    """