mathoptmodel 0.1.0__cp312-abi3-win_amd64.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.
- mathoptmodel/__init__.py +103 -0
- mathoptmodel/_core.pyd +0 -0
- mathoptmodel/_version.py +1 -0
- mathoptmodel-0.1.0.dist-info/DELVEWHEEL +2 -0
- mathoptmodel-0.1.0.dist-info/METADATA +63 -0
- mathoptmodel-0.1.0.dist-info/RECORD +9 -0
- mathoptmodel-0.1.0.dist-info/WHEEL +5 -0
- mathoptmodel-0.1.0.dist-info/licenses/LICENSE +21 -0
- mathoptmodel.libs/msvcp140-a4c2229bdc2a2a630acdc095b4d86008.dll +0 -0
mathoptmodel/__init__.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"""Python bindings for MathOptSolversCMake's solver-independent part: the
|
|
2
|
+
MathOptModel structure and its MPS / LP / JSON / AMPL .nl readers and
|
|
3
|
+
writers.
|
|
4
|
+
|
|
5
|
+
>>> import mathoptmodel as mom
|
|
6
|
+
>>> model = mom.read("p0033.mps.gz")
|
|
7
|
+
>>> model.number_of_variables, model.number_of_constraints
|
|
8
|
+
(33, 16)
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# start delvewheel patch
|
|
13
|
+
def _delvewheel_patch_1_13_2():
|
|
14
|
+
import os
|
|
15
|
+
if os.path.isdir(libs_dir := os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, 'mathoptmodel.libs'))):
|
|
16
|
+
os.add_dll_directory(libs_dir)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
_delvewheel_patch_1_13_2()
|
|
20
|
+
del _delvewheel_patch_1_13_2
|
|
21
|
+
# end delvewheel patch
|
|
22
|
+
|
|
23
|
+
import bz2
|
|
24
|
+
import gzip
|
|
25
|
+
import os
|
|
26
|
+
|
|
27
|
+
from mathoptmodel._version import __version__
|
|
28
|
+
from mathoptmodel._core import (
|
|
29
|
+
ConstraintClass,
|
|
30
|
+
ConstraintSense,
|
|
31
|
+
Model,
|
|
32
|
+
ObjectiveDirection,
|
|
33
|
+
VariableType,
|
|
34
|
+
dual,
|
|
35
|
+
expand_defined_variables,
|
|
36
|
+
read_json_bytes,
|
|
37
|
+
read_lp_bytes,
|
|
38
|
+
read_mps_bytes,
|
|
39
|
+
read_nl_bytes,
|
|
40
|
+
write_json_string,
|
|
41
|
+
write_lp_string,
|
|
42
|
+
write_mps_string,
|
|
43
|
+
write_nl_string,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
__all__ = [
|
|
47
|
+
"__version__",
|
|
48
|
+
"ConstraintClass", "ConstraintSense", "Model", "ObjectiveDirection", "VariableType",
|
|
49
|
+
"FORMATS", "detect_format", "dual", "expand_defined_variables", "read", "write",
|
|
50
|
+
"read_json_bytes", "read_lp_bytes", "read_mps_bytes", "read_nl_bytes",
|
|
51
|
+
"write_json_string", "write_lp_string", "write_mps_string", "write_nl_string",
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
_READERS = {
|
|
55
|
+
"mps": read_mps_bytes,
|
|
56
|
+
"lp": read_lp_bytes,
|
|
57
|
+
"json": read_json_bytes,
|
|
58
|
+
"nl": read_nl_bytes,
|
|
59
|
+
}
|
|
60
|
+
_WRITERS = {
|
|
61
|
+
"mps": write_mps_string,
|
|
62
|
+
"lp": write_lp_string,
|
|
63
|
+
"json": write_json_string,
|
|
64
|
+
"nl": write_nl_string,
|
|
65
|
+
}
|
|
66
|
+
_OPENERS = {".gz": gzip.open, ".bz2": bz2.open}
|
|
67
|
+
|
|
68
|
+
FORMATS = tuple(_READERS)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def detect_format(path):
|
|
72
|
+
"""The format of `path` ("mps", "lp", "json" or "nl") from its extension,
|
|
73
|
+
ignoring a trailing .gz/.bz2, or None if it isn't recognized."""
|
|
74
|
+
base, ext = os.path.splitext(path.lower())
|
|
75
|
+
if ext in _OPENERS:
|
|
76
|
+
base, ext = os.path.splitext(base)
|
|
77
|
+
ext = ext.lstrip(".")
|
|
78
|
+
return ext if ext in _READERS else None
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def read(path, format=None):
|
|
82
|
+
"""Read a model file, optionally .gz/.bz2 compressed. The format is
|
|
83
|
+
guessed from the extension unless given ("mps", "lp", "json" or "nl")."""
|
|
84
|
+
path = os.fspath(path)
|
|
85
|
+
format = format or detect_format(path)
|
|
86
|
+
if format not in _READERS:
|
|
87
|
+
raise ValueError(f"Unrecognized model file format: {path}")
|
|
88
|
+
opener = _OPENERS.get(os.path.splitext(path.lower())[1], open)
|
|
89
|
+
with opener(path, "rb") as f:
|
|
90
|
+
data = f.read()
|
|
91
|
+
return _READERS[format](data)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def write(model, path, format=None):
|
|
95
|
+
"""Write a model file, .gz/.bz2 compressed if its name says so. The format
|
|
96
|
+
is guessed from the extension unless given ("mps", "lp", "json" or "nl")."""
|
|
97
|
+
path = os.fspath(path)
|
|
98
|
+
format = format or detect_format(path)
|
|
99
|
+
if format not in _WRITERS:
|
|
100
|
+
raise ValueError(f"Unrecognized model file format: {path}")
|
|
101
|
+
opener = _OPENERS.get(os.path.splitext(path.lower())[1], open)
|
|
102
|
+
with opener(path, "wt") as f:
|
|
103
|
+
f.write(_WRITERS[format](model))
|
mathoptmodel/_core.pyd
ADDED
|
Binary file
|
mathoptmodel/_version.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Version: 1.13.2
|
|
2
|
+
Arguments: ['C:\\Users\\runneradmin\\AppData\\Local\\Temp\\cibw-run-3u2_6_46\\cp312-win_amd64\\build\\venv\\Scripts\\delvewheel', 'repair', '-w', 'C:\\Users\\runneradmin\\AppData\\Local\\Temp\\cibw-run-3u2_6_46\\cp312-win_amd64\\repaired_wheel', '-v', 'C:\\Users\\runneradmin\\AppData\\Local\\Temp\\cibw-run-3u2_6_46\\cp312-win_amd64\\built_wheel\\mathoptmodel-0.1.0-cp312-abi3-win_amd64.whl']
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mathoptmodel
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MathOptSolversCMake's optimization model and its MPS, LP, JSON and AMPL .nl readers/writers
|
|
5
|
+
Author-Email: Florian Fontan <dev@florian-fontan.fr>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Classifier: Programming Language :: C++
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
11
|
+
Classifier: Operating System :: MacOS
|
|
12
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
13
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
14
|
+
Project-URL: Homepage, https://github.com/fontanf/mathoptsolverscmake
|
|
15
|
+
Requires-Python: >=3.12
|
|
16
|
+
Requires-Dist: numpy
|
|
17
|
+
Provides-Extra: test
|
|
18
|
+
Requires-Dist: pytest; extra == "test"
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# mathoptmodel
|
|
22
|
+
|
|
23
|
+
`mathoptmodel` is the Python package of
|
|
24
|
+
[MathOptSolversCMake](https://github.com/fontanf/mathoptsolverscmake): Python
|
|
25
|
+
bindings for the solver-independent part of the library, its
|
|
26
|
+
`MathOptModel` optimization-model structure and its MPS, LP, JSON and AMPL
|
|
27
|
+
`.nl` readers and writers. No solver is bundled. Requires Python 3.12 or
|
|
28
|
+
newer (a single stable-ABI wheel per platform).
|
|
29
|
+
|
|
30
|
+
```shell
|
|
31
|
+
pip install mathoptmodel
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
import mathoptmodel as mom
|
|
36
|
+
|
|
37
|
+
model = mom.read("p0033.mps.gz") # format from the extension; .gz/.bz2 handled
|
|
38
|
+
print(model.number_of_variables, model.number_of_constraints)
|
|
39
|
+
|
|
40
|
+
# Arrays are read-only NumPy views onto the C++ model (no copy).
|
|
41
|
+
starts = model.constraints_starts
|
|
42
|
+
for i in range(model.number_of_constraints):
|
|
43
|
+
begin, end = starts[i], model.constraint_end(i)
|
|
44
|
+
variables = model.elements_variables[begin:end]
|
|
45
|
+
coefficients = model.elements_coefficients[begin:end]
|
|
46
|
+
print(model.constraint_name(i), model.constraint_class(i), dict(zip(variables, coefficients)))
|
|
47
|
+
|
|
48
|
+
mom.write(model, "p0033.lp")
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The fields mirror `MathOptModel` in
|
|
52
|
+
[`mathopt.hpp`](https://github.com/fontanf/mathoptsolverscmake/blob/main/include/mathoptsolverscmake/mathopt.hpp),
|
|
53
|
+
which documents each of them, including the expression-tree layout of
|
|
54
|
+
nonlinear objectives and constraints. `variables_types` and
|
|
55
|
+
`constraints_classes` are int8 arrays of `VariableType` / `ConstraintClass`
|
|
56
|
+
values.
|
|
57
|
+
|
|
58
|
+
## Building from source
|
|
59
|
+
|
|
60
|
+
```shell
|
|
61
|
+
pip install .
|
|
62
|
+
pytest python/tests
|
|
63
|
+
```
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
mathoptmodel/_core.pyd,sha256=iZaMfbKk5ljM4azlMG2YleufZK9t-L1WScmp-ue2DmM,450560
|
|
2
|
+
mathoptmodel/_version.py,sha256=QTYqXqSTHFRkM9TEgpDFcHvwLbvqHDqvqfQ9EiXkcAM,23
|
|
3
|
+
mathoptmodel/__init__.py,sha256=omxtQUV-zXkNi9PoLrHMg3qmt8-2mBMNb2ZW80T_L0g,3216
|
|
4
|
+
mathoptmodel-0.1.0.dist-info/DELVEWHEEL,sha256=diYekxej_-3pIONII3nCXpf9mBtQqYWua1LcbVL6o-c,410
|
|
5
|
+
mathoptmodel-0.1.0.dist-info/METADATA,sha256=Z5zbpwPfJfk7DEHTo92MlAjBnVaFCuzxzRNWaSLH-TU,2247
|
|
6
|
+
mathoptmodel-0.1.0.dist-info/RECORD,,
|
|
7
|
+
mathoptmodel-0.1.0.dist-info/WHEEL,sha256=8_VRiNQbKO5y5eAOf8e1j64w5TmsZcQyvXjqQfIKHN4,104
|
|
8
|
+
mathoptmodel-0.1.0.dist-info/licenses/LICENSE,sha256=UDCdYhUkr4tUFqjqsnG7vCn1JU1dmTL63mmze180fQo,1092
|
|
9
|
+
mathoptmodel.libs/msvcp140-a4c2229bdc2a2a630acdc095b4d86008.dll,sha256=pMIim9wqKmMKzcCVtNhgCOXD47x3cxdDVPPaT1vrnN4,575056
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Florian Fontan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
Binary file
|