Skip to content

constants

File containing shared constants used across the package.

Classes:

Name Description
Config

Configuration options that apply to the entire library.

ConstraintSense
ObjSense
PyoframeError
Solver
UnmatchedStrategy
VType

Attributes:

Name Type Description
COEF_KEY
CONSTRAINT_KEY
CONST_TERM
DUAL_KEY
KEY_TYPE
ObjSenseValue
QUAD_VAR_KEY
RESERVED_COL_KEYS
SOLUTION_KEY
SUPPORTED_SOLVERS
SUPPORTED_SOLVER_TYPES
VAR_KEY
VTypeValue

COEF_KEY = '__coeff' module-attribute

CONSTRAINT_KEY = '__constraint_id' module-attribute

CONST_TERM = 0 module-attribute

DUAL_KEY = 'dual' module-attribute

KEY_TYPE = pl.UInt32 module-attribute

ObjSenseValue = Literal['min', 'max'] module-attribute

QUAD_VAR_KEY = '__quadratic_variable_id' module-attribute

RESERVED_COL_KEYS = (COEF_KEY, VAR_KEY, QUAD_VAR_KEY, CONSTRAINT_KEY, SOLUTION_KEY, DUAL_KEY) module-attribute

SOLUTION_KEY = 'solution' module-attribute

SUPPORTED_SOLVERS = [Solver('gurobi'), Solver('highs', supports_quadratics=False, supports_duals=False), Solver('ipopt', supports_integer_variables=False, supports_objective_sense=False, supports_write=False)] module-attribute

SUPPORTED_SOLVER_TYPES = Literal['gurobi', 'highs', 'ipopt'] module-attribute

VAR_KEY = '__variable_id' module-attribute

VTypeValue = Literal['continuous', 'binary', 'integer'] module-attribute

Config

Configuration options that apply to the entire library.

Methods:

Name Description
reset_defaults

Resets all configuration options to their default values.

Attributes:

Name Type Description
default_solver SUPPORTED_SOLVER_TYPES | Solver | None

The solver to use when pf.Model() is called without specifying a solver.

disable_unmatched_checks bool
enable_is_duplicated_expression_safety_check bool
float_to_str_precision Optional[int]
integer_tolerance float

For convenience, Pyoframe returns the solution of integer and binary variables as integers not floating point values.

print_max_line_length int
print_max_lines int
print_max_set_elements int

Number of elements to show when printing a set to the console (additional elements are replaced with ...)

print_uses_variable_names bool

default_solver = None class-attribute instance-attribute

The solver to use when pf.Model() is called without specifying a solver. If default_solver is not set (None), Pyoframe will choose the first solver in SUPPORTED_SOLVERS that doesn't produce an error.

There is no reason why you set the solver here instead of passing it to the Model constructor. This is mainly used for testing purposes.

disable_unmatched_checks = False class-attribute instance-attribute

enable_is_duplicated_expression_safety_check = False class-attribute instance-attribute

float_to_str_precision = 5 class-attribute instance-attribute

integer_tolerance = 1e-08 class-attribute instance-attribute

For convenience, Pyoframe returns the solution of integer and binary variables as integers not floating point values. To do so, Pyoframe must convert the solver-provided floating point values to integers. To avoid unexpected rounding errors, Pyoframe uses this tolerance to check that the floating point result is an integer as expected. Overly tight tolerances can trigger unexpected errors. Setting the tolerance to zero disables the check.

print_max_line_length = 80 class-attribute instance-attribute

print_max_lines = 15 class-attribute instance-attribute

print_max_set_elements = 50 class-attribute instance-attribute

Number of elements to show when printing a set to the console (additional elements are replaced with ...)

print_uses_variable_names = True class-attribute instance-attribute

reset_defaults() classmethod

Resets all configuration options to their default values.

Source code in pyoframe/constants.py
@classmethod
def reset_defaults(cls):
    """
    Resets all configuration options to their default values.
    """
    for key, value in cls._defaults.items():
        setattr(cls, key, value)

ConstraintSense

Bases: Enum

Methods:

Name Description
to_poi

Attributes:

Name Type Description
EQ
GE
LE

EQ = '=' class-attribute instance-attribute

GE = '>=' class-attribute instance-attribute

LE = '<=' class-attribute instance-attribute

to_poi()

Source code in pyoframe/constants.py
def to_poi(self):
    if self == ConstraintSense.LE:
        return poi.ConstraintSense.LessEqual
    elif self == ConstraintSense.EQ:
        return poi.ConstraintSense.Equal
    elif self == ConstraintSense.GE:
        return poi.ConstraintSense.GreaterEqual
    else:
        raise ValueError(f"Invalid constraint type: {self}")  # pragma: no cover

ObjSense

Bases: Enum

Methods:

Name Description
to_poi

Attributes:

Name Type Description
MAX
MIN

MAX = 'max' class-attribute instance-attribute

MIN = 'min' class-attribute instance-attribute

to_poi()

Source code in pyoframe/constants.py
def to_poi(self):
    if self == ObjSense.MIN:
        return poi.ObjectiveSense.Minimize
    elif self == ObjSense.MAX:
        return poi.ObjectiveSense.Maximize
    else:
        raise ValueError(f"Invalid objective sense: {self}")  # pragma: no cover

PyoframeError

Bases: Exception

Solver(name, supports_integer_variables=True, supports_quadratics=True, supports_duals=True, supports_objective_sense=True, supports_write=True) dataclass

Methods:

Name Description
__repr__
check_supports_integer_variables
check_supports_write

Attributes:

Name Type Description
name SUPPORTED_SOLVER_TYPES
supports_duals bool
supports_integer_variables bool
supports_objective_sense bool
supports_quadratics bool
supports_write bool

name instance-attribute

supports_duals = True class-attribute instance-attribute

supports_integer_variables = True class-attribute instance-attribute

supports_objective_sense = True class-attribute instance-attribute

supports_quadratics = True class-attribute instance-attribute

supports_write = True class-attribute instance-attribute

__repr__()

Source code in pyoframe/constants.py
def __repr__(self):
    return self.name

check_supports_integer_variables()

Source code in pyoframe/constants.py
def check_supports_integer_variables(self):
    if not self.supports_integer_variables:
        raise ValueError(
            f"Solver {self.name} does not support integer or binary variables."
        )

check_supports_write()

Source code in pyoframe/constants.py
def check_supports_write(self):
    if not self.supports_write:
        raise ValueError(f"Solver {self.name} does not support .write()")

UnmatchedStrategy

Bases: Enum

Attributes:

Name Type Description
DROP
KEEP
UNSET

DROP = 'drop' class-attribute instance-attribute

KEEP = 'keep' class-attribute instance-attribute

UNSET = 'not_set' class-attribute instance-attribute

VType

Bases: Enum

Methods:

Name Description
to_poi

Attributes:

Name Type Description
BINARY
CONTINUOUS
INTEGER

BINARY = 'binary' class-attribute instance-attribute

CONTINUOUS = 'continuous' class-attribute instance-attribute

INTEGER = 'integer' class-attribute instance-attribute

to_poi()

Source code in pyoframe/constants.py
def to_poi(self):
    if self == VType.CONTINUOUS:
        return poi.VariableDomain.Continuous
    elif self == VType.BINARY:
        return poi.VariableDomain.Binary
    elif self == VType.INTEGER:
        return poi.VariableDomain.Integer
    else:
        raise ValueError(f"Invalid variable type: {self}")  # pragma: no cover