pyoframe 0.2.0__py3-none-any.whl → 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyoframe/__init__.py +21 -14
- pyoframe/_arithmetic.py +346 -238
- pyoframe/_constants.py +463 -0
- pyoframe/_core.py +2652 -0
- pyoframe/_model.py +598 -0
- pyoframe/_model_element.py +189 -0
- pyoframe/_monkey_patch.py +82 -0
- pyoframe/{objective.py → _objective.py} +50 -17
- pyoframe/{util.py → _utils.py} +108 -129
- pyoframe/_version.py +16 -3
- {pyoframe-0.2.0.dist-info → pyoframe-1.0.0.dist-info}/METADATA +37 -31
- pyoframe-1.0.0.dist-info/RECORD +15 -0
- pyoframe/constants.py +0 -140
- pyoframe/core.py +0 -1794
- pyoframe/model.py +0 -408
- pyoframe/model_element.py +0 -184
- pyoframe/monkey_patch.py +0 -54
- pyoframe-0.2.0.dist-info/RECORD +0 -15
- {pyoframe-0.2.0.dist-info → pyoframe-1.0.0.dist-info}/WHEEL +0 -0
- {pyoframe-0.2.0.dist-info → pyoframe-1.0.0.dist-info}/licenses/LICENSE +0 -0
- {pyoframe-0.2.0.dist-info → pyoframe-1.0.0.dist-info}/top_level.txt +0 -0
pyoframe/constants.py
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
File containing shared constants used across the package.
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
import typing
|
|
6
|
-
from enum import Enum
|
|
7
|
-
from typing import Literal, Optional
|
|
8
|
-
|
|
9
|
-
import polars as pl
|
|
10
|
-
import pyoptinterface as poi
|
|
11
|
-
|
|
12
|
-
COEF_KEY = "__coeff"
|
|
13
|
-
VAR_KEY = "__variable_id"
|
|
14
|
-
QUAD_VAR_KEY = "__quadratic_variable_id"
|
|
15
|
-
CONSTRAINT_KEY = "__constraint_id"
|
|
16
|
-
SOLUTION_KEY = "solution"
|
|
17
|
-
DUAL_KEY = "dual"
|
|
18
|
-
SUPPORTED_SOLVERS = ["gurobi", "highs"]
|
|
19
|
-
SUPPORTED_SOLVER_TYPES = Literal["gurobi", "highs"]
|
|
20
|
-
KEY_TYPE = pl.UInt32
|
|
21
|
-
|
|
22
|
-
# Variable ID for constant terms. This variable ID is reserved.
|
|
23
|
-
CONST_TERM = 0
|
|
24
|
-
|
|
25
|
-
RESERVED_COL_KEYS = (
|
|
26
|
-
COEF_KEY,
|
|
27
|
-
VAR_KEY,
|
|
28
|
-
QUAD_VAR_KEY,
|
|
29
|
-
CONSTRAINT_KEY,
|
|
30
|
-
SOLUTION_KEY,
|
|
31
|
-
DUAL_KEY,
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
class _ConfigMeta(type):
|
|
36
|
-
"""Metaclass for Config that stores the default values of all configuration options."""
|
|
37
|
-
|
|
38
|
-
def __init__(cls, name, bases, dct):
|
|
39
|
-
super().__init__(name, bases, dct)
|
|
40
|
-
cls._defaults = {
|
|
41
|
-
k: v
|
|
42
|
-
for k, v in dct.items()
|
|
43
|
-
if not k.startswith("_") and type(v) != classmethod # noqa: E721 (didn't want to mess with it since it works)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
class Config(metaclass=_ConfigMeta):
|
|
48
|
-
"""
|
|
49
|
-
Configuration options that apply to the entire library.
|
|
50
|
-
"""
|
|
51
|
-
|
|
52
|
-
default_solver: Optional[SUPPORTED_SOLVER_TYPES] = None
|
|
53
|
-
disable_unmatched_checks: bool = False
|
|
54
|
-
float_to_str_precision: Optional[int] = 5
|
|
55
|
-
print_uses_variable_names: bool = True
|
|
56
|
-
print_max_line_length: int = 80
|
|
57
|
-
print_max_lines: int = 15
|
|
58
|
-
print_max_set_elements: int = 50
|
|
59
|
-
"Number of elements to show when printing a set to the console (additional elements are replaced with ...)"
|
|
60
|
-
|
|
61
|
-
enable_is_duplicated_expression_safety_check: bool = False
|
|
62
|
-
|
|
63
|
-
integer_tolerance: float = 1e-8
|
|
64
|
-
"""
|
|
65
|
-
For convenience, Pyoframe returns the solution of integer and binary variables as integers not floating point values.
|
|
66
|
-
To do so, Pyoframe must convert the solver-provided floating point values to integers. To avoid unexpected rounding errors,
|
|
67
|
-
Pyoframe uses this tolerance to check that the floating point result is an integer as expected. Overly tight tolerances can trigger
|
|
68
|
-
unexpected errors. Setting the tolerance to zero disables the check.
|
|
69
|
-
"""
|
|
70
|
-
|
|
71
|
-
@classmethod
|
|
72
|
-
def reset_defaults(cls):
|
|
73
|
-
"""
|
|
74
|
-
Resets all configuration options to their default values.
|
|
75
|
-
"""
|
|
76
|
-
for key, value in cls._defaults.items():
|
|
77
|
-
setattr(cls, key, value)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
class ConstraintSense(Enum):
|
|
81
|
-
LE = "<="
|
|
82
|
-
GE = ">="
|
|
83
|
-
EQ = "="
|
|
84
|
-
|
|
85
|
-
def to_poi(self):
|
|
86
|
-
if self == ConstraintSense.LE:
|
|
87
|
-
return poi.ConstraintSense.LessEqual
|
|
88
|
-
elif self == ConstraintSense.EQ:
|
|
89
|
-
return poi.ConstraintSense.Equal
|
|
90
|
-
elif self == ConstraintSense.GE:
|
|
91
|
-
return poi.ConstraintSense.GreaterEqual
|
|
92
|
-
else:
|
|
93
|
-
raise ValueError(f"Invalid constraint type: {self}") # pragma: no cover
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
class ObjSense(Enum):
|
|
97
|
-
MIN = "min"
|
|
98
|
-
MAX = "max"
|
|
99
|
-
|
|
100
|
-
def to_poi(self):
|
|
101
|
-
if self == ObjSense.MIN:
|
|
102
|
-
return poi.ObjectiveSense.Minimize
|
|
103
|
-
elif self == ObjSense.MAX:
|
|
104
|
-
return poi.ObjectiveSense.Maximize
|
|
105
|
-
else:
|
|
106
|
-
raise ValueError(f"Invalid objective sense: {self}") # pragma: no cover
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
class VType(Enum):
|
|
110
|
-
CONTINUOUS = "continuous"
|
|
111
|
-
BINARY = "binary"
|
|
112
|
-
INTEGER = "integer"
|
|
113
|
-
|
|
114
|
-
def to_poi(self):
|
|
115
|
-
if self == VType.CONTINUOUS:
|
|
116
|
-
return poi.VariableDomain.Continuous
|
|
117
|
-
elif self == VType.BINARY:
|
|
118
|
-
return poi.VariableDomain.Binary
|
|
119
|
-
elif self == VType.INTEGER:
|
|
120
|
-
return poi.VariableDomain.Integer
|
|
121
|
-
else:
|
|
122
|
-
raise ValueError(f"Invalid variable type: {self}") # pragma: no cover
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
class UnmatchedStrategy(Enum):
|
|
126
|
-
UNSET = "not_set"
|
|
127
|
-
DROP = "drop"
|
|
128
|
-
KEEP = "keep"
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
# This is a hack to get the Literal type for VType
|
|
132
|
-
# See: https://stackoverflow.com/questions/67292470/type-hinting-enum-member-value-in-python
|
|
133
|
-
ObjSenseValue = Literal["min", "max"]
|
|
134
|
-
VTypeValue = Literal["continuous", "binary", "integer"]
|
|
135
|
-
for enum, type in [(ObjSense, ObjSenseValue), (VType, VTypeValue)]:
|
|
136
|
-
assert set(typing.get_args(type)) == {vtype.value for vtype in enum}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
class PyoframeError(Exception):
|
|
140
|
-
pass
|