OptlangHelper 0.0.1__tar.gz
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.
- OptlangHelper-0.0.1/OptlangHelper.egg-info/PKG-INFO +171 -0
- OptlangHelper-0.0.1/OptlangHelper.egg-info/SOURCES.txt +7 -0
- OptlangHelper-0.0.1/OptlangHelper.egg-info/dependency_links.txt +1 -0
- OptlangHelper-0.0.1/OptlangHelper.egg-info/requires.txt +1 -0
- OptlangHelper-0.0.1/OptlangHelper.egg-info/top_level.txt +1 -0
- OptlangHelper-0.0.1/PKG-INFO +171 -0
- OptlangHelper-0.0.1/README.rst +148 -0
- OptlangHelper-0.0.1/setup.cfg +4 -0
- OptlangHelper-0.0.1/setup.py +43 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: OptlangHelper
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Python package for building Linear Programming models that are compatible with Optlang
|
|
5
|
+
Home-page: https://github.com/Freiburgermsu/OptlangHelper
|
|
6
|
+
Author: Andrew Freiburger
|
|
7
|
+
Author-email: afreiburger@anl.gov
|
|
8
|
+
License: UNKNOWN
|
|
9
|
+
Project-URL: Issues, https://github.com/Freiburgermsu/OptlangHelper/issues
|
|
10
|
+
Platform: UNKNOWN
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Natural Language :: English
|
|
20
|
+
Description-Content-Type: text/x-rst
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
Efficiently creating optimization models
|
|
25
|
+
________________________________________________________________________
|
|
26
|
+
|
|
27
|
+
|PyPI version| |License|
|
|
28
|
+
|
|
29
|
+
.. |Supported Python Versions| image:: https://img.shields.io/pypi/pyversions/optlanghelper)
|
|
30
|
+
:target: https://pypi.org/project/optlanghelper/
|
|
31
|
+
:alt: Python versions
|
|
32
|
+
|
|
33
|
+
.. |PyPI version| image:: https://img.shields.io/pypi/v/optlanghelper.svg?logo=PyPI&logoColor=brightgreen
|
|
34
|
+
:target: https://pypi.org/project/optlanghelper/
|
|
35
|
+
:alt: PyPI version
|
|
36
|
+
|
|
37
|
+
.. |Actions Status| image:: https://github.com/freiburgermsu/optlanghelper/workflows/Test%20optlanghelper/badge.svg
|
|
38
|
+
:target: https://github.com/freiburgermsu/optlanghelper/actions
|
|
39
|
+
:alt: Actions Status
|
|
40
|
+
|
|
41
|
+
.. |License| image:: https://img.shields.io/badge/License-MIT-blue.svg
|
|
42
|
+
:target: https://opensource.org/licenses/MIT
|
|
43
|
+
:alt: License
|
|
44
|
+
|
|
45
|
+
.. .. |Downloads| image:: https://pepy.tech/badge/modelseedpy
|
|
46
|
+
.. :target: https://pepy.tech/project/modelseedpy
|
|
47
|
+
.. :alt: Downloads
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
.. note::
|
|
51
|
+
|
|
52
|
+
This project is under active development, and may be subject to losing back-compatibility.
|
|
53
|
+
|
|
54
|
+
----------------------
|
|
55
|
+
Installation
|
|
56
|
+
----------------------
|
|
57
|
+
|
|
58
|
+
OptlangHelper can be installed via ``pip`` through the ``PyPI`` channel::
|
|
59
|
+
|
|
60
|
+
pip install optlanghelper
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
----------------------
|
|
64
|
+
Usage
|
|
65
|
+
----------------------
|
|
66
|
+
|
|
67
|
+
The OptlangHelper package is a collection of functions that make it easier to build linear programming models using the Optlang package. This is accomplished through dictionaries of variables, constraints, and an objective that are added to a model at the end of iterating through all conditions. Since each solver -- such as GLPK, CPLEX, and GUROBI -- differently defines variables and constraints, a separate class (although using the same function design and arguments) is provided for each of these solvers. This requires the user to correctly select the proper OptlangHelper class that will construct the appropriate model for their solver.
|
|
68
|
+
|
|
69
|
+
****************
|
|
70
|
+
GLPK
|
|
71
|
+
****************
|
|
72
|
+
|
|
73
|
+
The GLPK class is used to construct an optlang model for the GLPK solver. This is the simplest of the solvers and is employed by default for optlang without specification for CPlex or Gurobi.
|
|
74
|
+
|
|
75
|
+
++++++++++++++++++++++
|
|
76
|
+
Named Tuples
|
|
77
|
+
++++++++++++++++++++++
|
|
78
|
+
|
|
79
|
+
There are several NamedTuples that are defined in OptlangHelper and assist with defining variables, constraints, and the objective.
|
|
80
|
+
|
|
81
|
+
``Bounds`` object has attributes of
|
|
82
|
+
|
|
83
|
+
- ``lb``, the lower bound of the entity associated with this bound: default is 0.
|
|
84
|
+
- ``up``, the upper bound of the associated entity: default is 1000.
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
``tupVariable`` object has attributes of
|
|
88
|
+
|
|
89
|
+
- ``name``, the name of the variable represented by this tuple
|
|
90
|
+
- ``bounds``, the lower and upper limit bounds associated with the tuple: (0,1000) is the default
|
|
91
|
+
- ``type``, the variable type: "integer"; "binary"; "continuous" is the default.
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
``tupConstraint`` object has attributes of
|
|
95
|
+
|
|
96
|
+
- ``name``, the name of the variable represented by this tuple
|
|
97
|
+
- ``bounds``, the lower and upper limit bounds associated with the tuple: (0,0) is the default
|
|
98
|
+
- ``expr``, the constraint expression: ``None`` is the default.
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
``tupObjective`` object has attributes of
|
|
102
|
+
|
|
103
|
+
- ``name``, the name of the variable represented by this tuple
|
|
104
|
+
- ``expr``, the objective expression: ``None`` is the default.
|
|
105
|
+
- ``direction``, the optimization direction: "max" is the default.
|
|
106
|
+
|
|
107
|
+
All of the above objects are fed into the ``define_model`` function
|
|
108
|
+
|
|
109
|
+
- ``model_name``, the name of the model
|
|
110
|
+
- ``variables``, the tupVariable objects for the model.
|
|
111
|
+
- ``constraints``, the tupConstraint objects for the model.
|
|
112
|
+
- ``objective``, the tupObjective object for the model.
|
|
113
|
+
- ``optlang``, specifies whether an optlang model is returned (``True``), or the raw dictionary (``False``) by default.
|
|
114
|
+
|
|
115
|
+
This function calls all of the class functions and returns either the GLPK model as as dictionary or an optlang object.
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
++++++++++++++++++++++
|
|
119
|
+
Example
|
|
120
|
+
++++++++++++++++++++++
|
|
121
|
+
|
|
122
|
+
The following blocks define the intended usage of the GLPK class.
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
.. code-block:: python
|
|
126
|
+
|
|
127
|
+
from optlanghelper import tupVariable, tupConstraint, tupObjective, define_model
|
|
128
|
+
|
|
129
|
+
# define the variables
|
|
130
|
+
variables = {}
|
|
131
|
+
for var in vars:
|
|
132
|
+
variables[var.name] = tupVariable(var.name, Bounds(0, 5), "continuous")
|
|
133
|
+
variables[var.name+"_bin"] = tupVariable(var.name+"_bin", Bounds(0, 1), "binary")
|
|
134
|
+
|
|
135
|
+
# define the constraints
|
|
136
|
+
constraints = {}
|
|
137
|
+
for name, content in constraint_info.items():
|
|
138
|
+
lb, ub = content["low_bound"], content["high_bound"]
|
|
139
|
+
consExpr = {}
|
|
140
|
+
## define the constraint expression
|
|
141
|
+
for varName, coef in var_info.items():
|
|
142
|
+
if varName not in consCoefs: continue
|
|
143
|
+
coef2 = consCoefs[varName]
|
|
144
|
+
consExpr[varName].update({"elements": [varName, coef2], "operation": "Mul"})
|
|
145
|
+
## create the constraint tuple
|
|
146
|
+
constraints[nutrient] = tupConstraint(name=nutrient, bounds=Bounds(lb, ub), expr={"elements": list(consExpr.values()), "operation": "Add"})
|
|
147
|
+
|
|
148
|
+
for varName in var_info.keys():
|
|
149
|
+
constraints[varName+"_bin"] = tupConstraint(varName+"_bin", bounds=Bounds(0,None),
|
|
150
|
+
expr={
|
|
151
|
+
"elements": [
|
|
152
|
+
variables[varName].bounds.ub,
|
|
153
|
+
{"elements": [-1, variables[varName].name,], "operation": "Mul"},
|
|
154
|
+
{"elements": [-variables[varName].bounds.ub, variables[varName+"_bin"].name], "operation": "Mul"}],
|
|
155
|
+
"operation": "Add"})
|
|
156
|
+
|
|
157
|
+
# define the objective
|
|
158
|
+
objective = tupObjective("< optimization name>", [], "min")
|
|
159
|
+
for varName, coef in var_info.items():
|
|
160
|
+
objective.expr.append({
|
|
161
|
+
"elements": [
|
|
162
|
+
{"elements": [variables[varName].name, coef],
|
|
163
|
+
"operation": "Mul"}],
|
|
164
|
+
"operation": "Add"
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
# create an optlang model from all of the variables, constraints, and objective defined above
|
|
168
|
+
model = define_model("< model name>", list(variables.values()), list(constraints.values()), objective, True)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
optlang
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: OptlangHelper
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Python package for building Linear Programming models that are compatible with Optlang
|
|
5
|
+
Home-page: https://github.com/Freiburgermsu/OptlangHelper
|
|
6
|
+
Author: Andrew Freiburger
|
|
7
|
+
Author-email: afreiburger@anl.gov
|
|
8
|
+
License: UNKNOWN
|
|
9
|
+
Project-URL: Issues, https://github.com/Freiburgermsu/OptlangHelper/issues
|
|
10
|
+
Platform: UNKNOWN
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Natural Language :: English
|
|
20
|
+
Description-Content-Type: text/x-rst
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
Efficiently creating optimization models
|
|
25
|
+
________________________________________________________________________
|
|
26
|
+
|
|
27
|
+
|PyPI version| |License|
|
|
28
|
+
|
|
29
|
+
.. |Supported Python Versions| image:: https://img.shields.io/pypi/pyversions/optlanghelper)
|
|
30
|
+
:target: https://pypi.org/project/optlanghelper/
|
|
31
|
+
:alt: Python versions
|
|
32
|
+
|
|
33
|
+
.. |PyPI version| image:: https://img.shields.io/pypi/v/optlanghelper.svg?logo=PyPI&logoColor=brightgreen
|
|
34
|
+
:target: https://pypi.org/project/optlanghelper/
|
|
35
|
+
:alt: PyPI version
|
|
36
|
+
|
|
37
|
+
.. |Actions Status| image:: https://github.com/freiburgermsu/optlanghelper/workflows/Test%20optlanghelper/badge.svg
|
|
38
|
+
:target: https://github.com/freiburgermsu/optlanghelper/actions
|
|
39
|
+
:alt: Actions Status
|
|
40
|
+
|
|
41
|
+
.. |License| image:: https://img.shields.io/badge/License-MIT-blue.svg
|
|
42
|
+
:target: https://opensource.org/licenses/MIT
|
|
43
|
+
:alt: License
|
|
44
|
+
|
|
45
|
+
.. .. |Downloads| image:: https://pepy.tech/badge/modelseedpy
|
|
46
|
+
.. :target: https://pepy.tech/project/modelseedpy
|
|
47
|
+
.. :alt: Downloads
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
.. note::
|
|
51
|
+
|
|
52
|
+
This project is under active development, and may be subject to losing back-compatibility.
|
|
53
|
+
|
|
54
|
+
----------------------
|
|
55
|
+
Installation
|
|
56
|
+
----------------------
|
|
57
|
+
|
|
58
|
+
OptlangHelper can be installed via ``pip`` through the ``PyPI`` channel::
|
|
59
|
+
|
|
60
|
+
pip install optlanghelper
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
----------------------
|
|
64
|
+
Usage
|
|
65
|
+
----------------------
|
|
66
|
+
|
|
67
|
+
The OptlangHelper package is a collection of functions that make it easier to build linear programming models using the Optlang package. This is accomplished through dictionaries of variables, constraints, and an objective that are added to a model at the end of iterating through all conditions. Since each solver -- such as GLPK, CPLEX, and GUROBI -- differently defines variables and constraints, a separate class (although using the same function design and arguments) is provided for each of these solvers. This requires the user to correctly select the proper OptlangHelper class that will construct the appropriate model for their solver.
|
|
68
|
+
|
|
69
|
+
****************
|
|
70
|
+
GLPK
|
|
71
|
+
****************
|
|
72
|
+
|
|
73
|
+
The GLPK class is used to construct an optlang model for the GLPK solver. This is the simplest of the solvers and is employed by default for optlang without specification for CPlex or Gurobi.
|
|
74
|
+
|
|
75
|
+
++++++++++++++++++++++
|
|
76
|
+
Named Tuples
|
|
77
|
+
++++++++++++++++++++++
|
|
78
|
+
|
|
79
|
+
There are several NamedTuples that are defined in OptlangHelper and assist with defining variables, constraints, and the objective.
|
|
80
|
+
|
|
81
|
+
``Bounds`` object has attributes of
|
|
82
|
+
|
|
83
|
+
- ``lb``, the lower bound of the entity associated with this bound: default is 0.
|
|
84
|
+
- ``up``, the upper bound of the associated entity: default is 1000.
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
``tupVariable`` object has attributes of
|
|
88
|
+
|
|
89
|
+
- ``name``, the name of the variable represented by this tuple
|
|
90
|
+
- ``bounds``, the lower and upper limit bounds associated with the tuple: (0,1000) is the default
|
|
91
|
+
- ``type``, the variable type: "integer"; "binary"; "continuous" is the default.
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
``tupConstraint`` object has attributes of
|
|
95
|
+
|
|
96
|
+
- ``name``, the name of the variable represented by this tuple
|
|
97
|
+
- ``bounds``, the lower and upper limit bounds associated with the tuple: (0,0) is the default
|
|
98
|
+
- ``expr``, the constraint expression: ``None`` is the default.
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
``tupObjective`` object has attributes of
|
|
102
|
+
|
|
103
|
+
- ``name``, the name of the variable represented by this tuple
|
|
104
|
+
- ``expr``, the objective expression: ``None`` is the default.
|
|
105
|
+
- ``direction``, the optimization direction: "max" is the default.
|
|
106
|
+
|
|
107
|
+
All of the above objects are fed into the ``define_model`` function
|
|
108
|
+
|
|
109
|
+
- ``model_name``, the name of the model
|
|
110
|
+
- ``variables``, the tupVariable objects for the model.
|
|
111
|
+
- ``constraints``, the tupConstraint objects for the model.
|
|
112
|
+
- ``objective``, the tupObjective object for the model.
|
|
113
|
+
- ``optlang``, specifies whether an optlang model is returned (``True``), or the raw dictionary (``False``) by default.
|
|
114
|
+
|
|
115
|
+
This function calls all of the class functions and returns either the GLPK model as as dictionary or an optlang object.
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
++++++++++++++++++++++
|
|
119
|
+
Example
|
|
120
|
+
++++++++++++++++++++++
|
|
121
|
+
|
|
122
|
+
The following blocks define the intended usage of the GLPK class.
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
.. code-block:: python
|
|
126
|
+
|
|
127
|
+
from optlanghelper import tupVariable, tupConstraint, tupObjective, define_model
|
|
128
|
+
|
|
129
|
+
# define the variables
|
|
130
|
+
variables = {}
|
|
131
|
+
for var in vars:
|
|
132
|
+
variables[var.name] = tupVariable(var.name, Bounds(0, 5), "continuous")
|
|
133
|
+
variables[var.name+"_bin"] = tupVariable(var.name+"_bin", Bounds(0, 1), "binary")
|
|
134
|
+
|
|
135
|
+
# define the constraints
|
|
136
|
+
constraints = {}
|
|
137
|
+
for name, content in constraint_info.items():
|
|
138
|
+
lb, ub = content["low_bound"], content["high_bound"]
|
|
139
|
+
consExpr = {}
|
|
140
|
+
## define the constraint expression
|
|
141
|
+
for varName, coef in var_info.items():
|
|
142
|
+
if varName not in consCoefs: continue
|
|
143
|
+
coef2 = consCoefs[varName]
|
|
144
|
+
consExpr[varName].update({"elements": [varName, coef2], "operation": "Mul"})
|
|
145
|
+
## create the constraint tuple
|
|
146
|
+
constraints[nutrient] = tupConstraint(name=nutrient, bounds=Bounds(lb, ub), expr={"elements": list(consExpr.values()), "operation": "Add"})
|
|
147
|
+
|
|
148
|
+
for varName in var_info.keys():
|
|
149
|
+
constraints[varName+"_bin"] = tupConstraint(varName+"_bin", bounds=Bounds(0,None),
|
|
150
|
+
expr={
|
|
151
|
+
"elements": [
|
|
152
|
+
variables[varName].bounds.ub,
|
|
153
|
+
{"elements": [-1, variables[varName].name,], "operation": "Mul"},
|
|
154
|
+
{"elements": [-variables[varName].bounds.ub, variables[varName+"_bin"].name], "operation": "Mul"}],
|
|
155
|
+
"operation": "Add"})
|
|
156
|
+
|
|
157
|
+
# define the objective
|
|
158
|
+
objective = tupObjective("< optimization name>", [], "min")
|
|
159
|
+
for varName, coef in var_info.items():
|
|
160
|
+
objective.expr.append({
|
|
161
|
+
"elements": [
|
|
162
|
+
{"elements": [variables[varName].name, coef],
|
|
163
|
+
"operation": "Mul"}],
|
|
164
|
+
"operation": "Add"
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
# create an optlang model from all of the variables, constraints, and objective defined above
|
|
168
|
+
model = define_model("< model name>", list(variables.values()), list(constraints.values()), objective, True)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
Efficiently creating optimization models
|
|
4
|
+
________________________________________________________________________
|
|
5
|
+
|
|
6
|
+
|PyPI version| |License|
|
|
7
|
+
|
|
8
|
+
.. |Supported Python Versions| image:: https://img.shields.io/pypi/pyversions/optlanghelper)
|
|
9
|
+
:target: https://pypi.org/project/optlanghelper/
|
|
10
|
+
:alt: Python versions
|
|
11
|
+
|
|
12
|
+
.. |PyPI version| image:: https://img.shields.io/pypi/v/optlanghelper.svg?logo=PyPI&logoColor=brightgreen
|
|
13
|
+
:target: https://pypi.org/project/optlanghelper/
|
|
14
|
+
:alt: PyPI version
|
|
15
|
+
|
|
16
|
+
.. |Actions Status| image:: https://github.com/freiburgermsu/optlanghelper/workflows/Test%20optlanghelper/badge.svg
|
|
17
|
+
:target: https://github.com/freiburgermsu/optlanghelper/actions
|
|
18
|
+
:alt: Actions Status
|
|
19
|
+
|
|
20
|
+
.. |License| image:: https://img.shields.io/badge/License-MIT-blue.svg
|
|
21
|
+
:target: https://opensource.org/licenses/MIT
|
|
22
|
+
:alt: License
|
|
23
|
+
|
|
24
|
+
.. .. |Downloads| image:: https://pepy.tech/badge/modelseedpy
|
|
25
|
+
.. :target: https://pepy.tech/project/modelseedpy
|
|
26
|
+
.. :alt: Downloads
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
.. note::
|
|
30
|
+
|
|
31
|
+
This project is under active development, and may be subject to losing back-compatibility.
|
|
32
|
+
|
|
33
|
+
----------------------
|
|
34
|
+
Installation
|
|
35
|
+
----------------------
|
|
36
|
+
|
|
37
|
+
OptlangHelper can be installed via ``pip`` through the ``PyPI`` channel::
|
|
38
|
+
|
|
39
|
+
pip install optlanghelper
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
----------------------
|
|
43
|
+
Usage
|
|
44
|
+
----------------------
|
|
45
|
+
|
|
46
|
+
The OptlangHelper package is a collection of functions that make it easier to build linear programming models using the Optlang package. This is accomplished through dictionaries of variables, constraints, and an objective that are added to a model at the end of iterating through all conditions. Since each solver -- such as GLPK, CPLEX, and GUROBI -- differently defines variables and constraints, a separate class (although using the same function design and arguments) is provided for each of these solvers. This requires the user to correctly select the proper OptlangHelper class that will construct the appropriate model for their solver.
|
|
47
|
+
|
|
48
|
+
****************
|
|
49
|
+
GLPK
|
|
50
|
+
****************
|
|
51
|
+
|
|
52
|
+
The GLPK class is used to construct an optlang model for the GLPK solver. This is the simplest of the solvers and is employed by default for optlang without specification for CPlex or Gurobi.
|
|
53
|
+
|
|
54
|
+
++++++++++++++++++++++
|
|
55
|
+
Named Tuples
|
|
56
|
+
++++++++++++++++++++++
|
|
57
|
+
|
|
58
|
+
There are several NamedTuples that are defined in OptlangHelper and assist with defining variables, constraints, and the objective.
|
|
59
|
+
|
|
60
|
+
``Bounds`` object has attributes of
|
|
61
|
+
|
|
62
|
+
- ``lb``, the lower bound of the entity associated with this bound: default is 0.
|
|
63
|
+
- ``up``, the upper bound of the associated entity: default is 1000.
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
``tupVariable`` object has attributes of
|
|
67
|
+
|
|
68
|
+
- ``name``, the name of the variable represented by this tuple
|
|
69
|
+
- ``bounds``, the lower and upper limit bounds associated with the tuple: (0,1000) is the default
|
|
70
|
+
- ``type``, the variable type: "integer"; "binary"; "continuous" is the default.
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
``tupConstraint`` object has attributes of
|
|
74
|
+
|
|
75
|
+
- ``name``, the name of the variable represented by this tuple
|
|
76
|
+
- ``bounds``, the lower and upper limit bounds associated with the tuple: (0,0) is the default
|
|
77
|
+
- ``expr``, the constraint expression: ``None`` is the default.
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
``tupObjective`` object has attributes of
|
|
81
|
+
|
|
82
|
+
- ``name``, the name of the variable represented by this tuple
|
|
83
|
+
- ``expr``, the objective expression: ``None`` is the default.
|
|
84
|
+
- ``direction``, the optimization direction: "max" is the default.
|
|
85
|
+
|
|
86
|
+
All of the above objects are fed into the ``define_model`` function
|
|
87
|
+
|
|
88
|
+
- ``model_name``, the name of the model
|
|
89
|
+
- ``variables``, the tupVariable objects for the model.
|
|
90
|
+
- ``constraints``, the tupConstraint objects for the model.
|
|
91
|
+
- ``objective``, the tupObjective object for the model.
|
|
92
|
+
- ``optlang``, specifies whether an optlang model is returned (``True``), or the raw dictionary (``False``) by default.
|
|
93
|
+
|
|
94
|
+
This function calls all of the class functions and returns either the GLPK model as as dictionary or an optlang object.
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
++++++++++++++++++++++
|
|
98
|
+
Example
|
|
99
|
+
++++++++++++++++++++++
|
|
100
|
+
|
|
101
|
+
The following blocks define the intended usage of the GLPK class.
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
.. code-block:: python
|
|
105
|
+
|
|
106
|
+
from optlanghelper import tupVariable, tupConstraint, tupObjective, define_model
|
|
107
|
+
|
|
108
|
+
# define the variables
|
|
109
|
+
variables = {}
|
|
110
|
+
for var in vars:
|
|
111
|
+
variables[var.name] = tupVariable(var.name, Bounds(0, 5), "continuous")
|
|
112
|
+
variables[var.name+"_bin"] = tupVariable(var.name+"_bin", Bounds(0, 1), "binary")
|
|
113
|
+
|
|
114
|
+
# define the constraints
|
|
115
|
+
constraints = {}
|
|
116
|
+
for name, content in constraint_info.items():
|
|
117
|
+
lb, ub = content["low_bound"], content["high_bound"]
|
|
118
|
+
consExpr = {}
|
|
119
|
+
## define the constraint expression
|
|
120
|
+
for varName, coef in var_info.items():
|
|
121
|
+
if varName not in consCoefs: continue
|
|
122
|
+
coef2 = consCoefs[varName]
|
|
123
|
+
consExpr[varName].update({"elements": [varName, coef2], "operation": "Mul"})
|
|
124
|
+
## create the constraint tuple
|
|
125
|
+
constraints[nutrient] = tupConstraint(name=nutrient, bounds=Bounds(lb, ub), expr={"elements": list(consExpr.values()), "operation": "Add"})
|
|
126
|
+
|
|
127
|
+
for varName in var_info.keys():
|
|
128
|
+
constraints[varName+"_bin"] = tupConstraint(varName+"_bin", bounds=Bounds(0,None),
|
|
129
|
+
expr={
|
|
130
|
+
"elements": [
|
|
131
|
+
variables[varName].bounds.ub,
|
|
132
|
+
{"elements": [-1, variables[varName].name,], "operation": "Mul"},
|
|
133
|
+
{"elements": [-variables[varName].bounds.ub, variables[varName+"_bin"].name], "operation": "Mul"}],
|
|
134
|
+
"operation": "Add"})
|
|
135
|
+
|
|
136
|
+
# define the objective
|
|
137
|
+
objective = tupObjective("< optimization name>", [], "min")
|
|
138
|
+
for varName, coef in var_info.items():
|
|
139
|
+
objective.expr.append({
|
|
140
|
+
"elements": [
|
|
141
|
+
{"elements": [variables[varName].name, coef],
|
|
142
|
+
"operation": "Mul"}],
|
|
143
|
+
"operation": "Add"
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
# create an optlang model from all of the variables, constraints, and objective defined above
|
|
147
|
+
model = define_model("< model name>", list(variables.values()), list(constraints.values()), objective, True)
|
|
148
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
from setuptools import setup, find_packages
|
|
4
|
+
|
|
5
|
+
with open("README.rst") as f:
|
|
6
|
+
readme = f.read()
|
|
7
|
+
|
|
8
|
+
setup(
|
|
9
|
+
name="OptlangHelper",
|
|
10
|
+
version="0.0.1",
|
|
11
|
+
description="Python package for building Linear Programming models that are compatible with Optlang",
|
|
12
|
+
long_description_content_type="text/x-rst",
|
|
13
|
+
long_description=readme,
|
|
14
|
+
author="Andrew Freiburger",
|
|
15
|
+
author_email="afreiburger@anl.gov",
|
|
16
|
+
url="https://github.com/Freiburgermsu/OptlangHelper",
|
|
17
|
+
packages=find_packages(exclude=("docs")),
|
|
18
|
+
classifiers=[
|
|
19
|
+
"Development Status :: 3 - Alpha",
|
|
20
|
+
"Topic :: Scientific/Engineering :: Bio-Informatics",
|
|
21
|
+
"Intended Audience :: Science/Research",
|
|
22
|
+
"Operating System :: OS Independent",
|
|
23
|
+
"Programming Language :: Python :: 3.8",
|
|
24
|
+
"Programming Language :: Python :: 3.9",
|
|
25
|
+
"Programming Language :: Python :: 3.10",
|
|
26
|
+
"Programming Language :: Python :: 3.11",
|
|
27
|
+
"Natural Language :: English",
|
|
28
|
+
],
|
|
29
|
+
include_package_data =True,
|
|
30
|
+
install_requires=[
|
|
31
|
+
"optlang",
|
|
32
|
+
# "glpk",
|
|
33
|
+
# "cplex",
|
|
34
|
+
# "gurobipy"
|
|
35
|
+
],
|
|
36
|
+
# tests_require=[
|
|
37
|
+
# "pytest",
|
|
38
|
+
# ],
|
|
39
|
+
project_urls={
|
|
40
|
+
# "Documentation": "https://modelseedpy.readthedocs.io/en/latest/",
|
|
41
|
+
"Issues": "https://github.com/Freiburgermsu/OptlangHelper/issues",
|
|
42
|
+
},
|
|
43
|
+
)
|