gurobipy 10.0.1__cp311-cp311-macosx_10_9_universal2.whl → 13.0.0__cp311-cp311-macosx_10_9_universal2.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.
- gurobipy/.libs/gurobi.lic +4 -4
- gurobipy/.libs/libgurobi130.dylib +0 -0
- gurobipy/__init__.py +139 -1
- gurobipy/__init__.pyi +3399 -0
- gurobipy/_attrconst.py +477 -0
- gurobipy/_attrutil.cpython-311-darwin.so +0 -0
- gurobipy/_batch.cpython-311-darwin.so +0 -0
- gurobipy/_callbackconst.py +206 -0
- gurobipy/_core.cpython-311-darwin.so +0 -0
- gurobipy/_errorconst.py +80 -0
- gurobipy/_exception.cpython-311-darwin.so +0 -0
- gurobipy/_grb.py +298 -0
- gurobipy/_helpers.cpython-311-darwin.so +0 -0
- gurobipy/_load_model.py +248 -0
- gurobipy/_lowlevel.cpython-311-darwin.so +0 -0
- gurobipy/_matrixapi.cpython-311-darwin.so +0 -0
- gurobipy/_model.cpython-311-darwin.so +0 -0
- gurobipy/_modelutil.cpython-311-darwin.so +0 -0
- gurobipy/_paramconst.py +493 -0
- gurobipy/_paramdetails.py +2078 -0
- gurobipy/_statusconst.py +47 -0
- gurobipy/_util.cpython-311-darwin.so +0 -0
- gurobipy/nlfunc.py +34 -0
- gurobipy/nlfunc.pyi +52 -0
- gurobipy/py.typed +0 -0
- {gurobipy-10.0.1.dist-info → gurobipy-13.0.0.dist-info}/METADATA +71 -52
- gurobipy-13.0.0.dist-info/RECORD +30 -0
- {gurobipy-10.0.1.dist-info → gurobipy-13.0.0.dist-info}/WHEEL +1 -1
- gurobipy-13.0.0.dist-info/licenses/LICENSE.txt +5168 -0
- gurobipy/.libs/libgurobi100.dylib +0 -0
- gurobipy/gurobipy.cpython-311-darwin.so +0 -0
- gurobipy-10.0.1.dist-info/RECORD +0 -8
- {gurobipy-10.0.1.dist-info → gurobipy-13.0.0.dist-info}/top_level.txt +0 -0
gurobipy/_errorconst.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Wrapper for 'GRB.Error' object
|
|
2
|
+
|
|
3
|
+
class ErrorConstClass(object):
|
|
4
|
+
'''
|
|
5
|
+
Gurobi error codes (e.g., exception.errno == GRB.ERROR_OUT_OF_MEMORY):
|
|
6
|
+
|
|
7
|
+
OUT_OF_MEMORY: Exhausted available memory
|
|
8
|
+
NULL_ARGUMENT: NULL argument value
|
|
9
|
+
INVALID_ARGUMENT: Invalid argument value
|
|
10
|
+
UNKNOWN_ATTRIBUTE: Unknown attribute name
|
|
11
|
+
DATA_NOT_AVAILABLE: Requested data not available
|
|
12
|
+
INDEX_OUT_OF_RANGE: Constr/var index out of range
|
|
13
|
+
UNKNOWN_PARAMETER: Unknown parameter name
|
|
14
|
+
VALUE_OUT_OF_RANGE: Parameter value outside of valid range
|
|
15
|
+
NO_LICENSE: No Gurobi license found
|
|
16
|
+
SIZE_LIMIT_EXCEEDED: Exceeded licensed model size limit
|
|
17
|
+
CALLBACK: Error in callback
|
|
18
|
+
FILE_READ: Error reading file
|
|
19
|
+
FILE_WRITE: Error writing file
|
|
20
|
+
NUMERIC: Numeric error encountered
|
|
21
|
+
IIS_NOT_INFEASIBLE: Can't compute an IIS on a feasible model
|
|
22
|
+
NOT_FOR_MIP: Method not valid for MIP models
|
|
23
|
+
OPTIMIZATION_IN_PROGRESS: Must stop optimization to query results
|
|
24
|
+
DUPLICATES: Duplicate entries in list
|
|
25
|
+
NODEFILE: Problem reading or writing node file
|
|
26
|
+
Q_NOT_PSD: Q matrix isn't Positive Semi-Definite
|
|
27
|
+
QCP_EQUALITY_CONSTRAINT: Quadratic constraints must be inequalities
|
|
28
|
+
NETWORK: Network error
|
|
29
|
+
JOB_REJECTED: Job rejected by Compute Server
|
|
30
|
+
NOT_SUPPORTED: Requested operation is not supported
|
|
31
|
+
EXCEED_2B_NONZEROS: Result too large for query routine
|
|
32
|
+
INVALID_PIECEWISE_OBJ: Problem with specified piecewise-linear objective
|
|
33
|
+
JOB_REJECTED: Job rejected by Compute Server
|
|
34
|
+
NOT_SUPPORTED: Operation is not supported
|
|
35
|
+
NOT_IN_MODEL: Variable/constraint not in model
|
|
36
|
+
FAILED_TO_CREATE_MODEL: Failed to create the requested model
|
|
37
|
+
CLOUD: Instant Cloud error
|
|
38
|
+
MODEL_MODIFICATION: An error occurred during model modification or update
|
|
39
|
+
CSWORKER: An error occurred with the client-server application
|
|
40
|
+
TUNE_MODEL_TYPES: Tried multi-model tuning on models of different types
|
|
41
|
+
INTERNAL: Internal Gurobi error
|
|
42
|
+
'''
|
|
43
|
+
|
|
44
|
+
def __setattr__(self, name, value):
|
|
45
|
+
raise AttributeError("Gurobi error code constants are not modifiable")
|
|
46
|
+
|
|
47
|
+
OUT_OF_MEMORY = 10001
|
|
48
|
+
NULL_ARGUMENT = 10002
|
|
49
|
+
INVALID_ARGUMENT = 10003
|
|
50
|
+
UNKNOWN_ATTRIBUTE = 10004
|
|
51
|
+
DATA_NOT_AVAILABLE = 10005
|
|
52
|
+
INDEX_OUT_OF_RANGE = 10006
|
|
53
|
+
UNKNOWN_PARAMETER = 10007
|
|
54
|
+
VALUE_OUT_OF_RANGE = 10008
|
|
55
|
+
NO_LICENSE = 10009
|
|
56
|
+
SIZE_LIMIT_EXCEEDED = 10010
|
|
57
|
+
CALLBACK = 10011
|
|
58
|
+
FILE_READ = 10012
|
|
59
|
+
FILE_WRITE = 10013
|
|
60
|
+
NUMERIC = 10014
|
|
61
|
+
IIS_NOT_INFEASIBLE = 10015
|
|
62
|
+
NOT_FOR_MIP = 10016
|
|
63
|
+
OPTIMIZATION_IN_PROGRESS = 10017
|
|
64
|
+
DUPLICATES = 10018
|
|
65
|
+
NODEFILE = 10019
|
|
66
|
+
Q_NOT_PSD = 10020
|
|
67
|
+
QCP_EQUALITY_CONSTRAINT = 10021
|
|
68
|
+
NETWORK = 10022
|
|
69
|
+
JOB_REJECTED = 10023
|
|
70
|
+
NOT_SUPPORTED = 10024
|
|
71
|
+
EXCEED_2B_NONZEROS = 10025
|
|
72
|
+
INVALID_PIECEWISE_OBJ = 10026
|
|
73
|
+
UPDATEMODE_CHANGE = 10027
|
|
74
|
+
CLOUD = 10028
|
|
75
|
+
MODEL_MODIFICATION = 10029
|
|
76
|
+
CSWORKER = 10030
|
|
77
|
+
TUNE_MODEL_TYPES = 10031
|
|
78
|
+
NOT_IN_MODEL = 20001
|
|
79
|
+
FAILED_TO_CREATE_MODEL = 20002
|
|
80
|
+
INTERNAL = 20003
|
|
Binary file
|
gurobipy/_grb.py
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
# GRB class - constants
|
|
2
|
+
|
|
3
|
+
from gurobipy._attrconst import AttrConstClass
|
|
4
|
+
from gurobipy._callbackconst import CallbackConstClass
|
|
5
|
+
from gurobipy._errorconst import ErrorConstClass
|
|
6
|
+
from gurobipy._paramconst import ParamConstClass
|
|
7
|
+
from gurobipy._statusconst import StatusConstClass
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class GRB(object):
|
|
11
|
+
'''
|
|
12
|
+
Gurobi constants. Constants defined in this class are as follows:
|
|
13
|
+
|
|
14
|
+
Basis status (e.g., var.vBasis == GRB.BASIC):
|
|
15
|
+
|
|
16
|
+
BASIC: Variable is basic
|
|
17
|
+
NONBASIC_LOWER: Variable is non-basic at lower bound
|
|
18
|
+
NONBASIC_UPPER: Variable is non-basic at upper bound
|
|
19
|
+
SUPERBASIC: Variable is superbasic
|
|
20
|
+
|
|
21
|
+
Constraint sense (e.g., constr.sense = GRB.LESS_EQUAL):
|
|
22
|
+
|
|
23
|
+
LESS_EQUAL, GREATER_EQUAL, EQUAL
|
|
24
|
+
|
|
25
|
+
Variable types (e.g., var.vType = GRB.INTEGER):
|
|
26
|
+
|
|
27
|
+
CONTINUOUS, BINARY, INTEGER, SEMICONT, SEMIINT
|
|
28
|
+
|
|
29
|
+
SOS types:
|
|
30
|
+
|
|
31
|
+
SOS_TYPE1, SOS_TYPE2
|
|
32
|
+
|
|
33
|
+
General constraint types:
|
|
34
|
+
|
|
35
|
+
GENCONSTR_MAX, GENCONSTR_MIN, GENCONSTR_ABS, GENCONSTR_AND, GENCONSTR_OR,
|
|
36
|
+
GENCONSTR_NORM, GENCONSTR_NL, GENCONSTR_INDICATOR, GENCONSTR_PWL,
|
|
37
|
+
GENCONSTR_POLY, GENCONSTR_EXP, GENCONSTR_EXPA, GENCONSTR_LOG,
|
|
38
|
+
GENCONSTR_LOGA, GENCONSTR_POW, GENCONSTR_SIN, GENCONSTR_COS, GENCONSTR_TAN
|
|
39
|
+
|
|
40
|
+
The GRB class also includes definitions for attributes (GRB.attr),
|
|
41
|
+
errors (GRB.error), parameters (GRB.param), status codes (GRB.status),
|
|
42
|
+
and callbacks (GRB.callback). You can ask for help on any of these
|
|
43
|
+
(e.g., "help(GRB.attr)").
|
|
44
|
+
'''
|
|
45
|
+
|
|
46
|
+
attr = Attr = AttrConstClass()
|
|
47
|
+
param = Param = ParamConstClass()
|
|
48
|
+
callback = Callback = CallbackConstClass()
|
|
49
|
+
error = Error = ErrorConstClass()
|
|
50
|
+
status = Status = StatusConstClass()
|
|
51
|
+
|
|
52
|
+
# Status codes
|
|
53
|
+
|
|
54
|
+
LOADED = 1
|
|
55
|
+
OPTIMAL = 2
|
|
56
|
+
INFEASIBLE = 3
|
|
57
|
+
INF_OR_UNBD = 4
|
|
58
|
+
UNBOUNDED = 5
|
|
59
|
+
CUTOFF = 6
|
|
60
|
+
ITERATION_LIMIT = 7
|
|
61
|
+
NODE_LIMIT = 8
|
|
62
|
+
TIME_LIMIT = 9
|
|
63
|
+
SOLUTION_LIMIT = 10
|
|
64
|
+
INTERRUPTED = 11
|
|
65
|
+
NUMERIC = 12
|
|
66
|
+
SUBOPTIMAL = 13
|
|
67
|
+
INPROGRESS = 14
|
|
68
|
+
USER_OBJ_LIMIT = 15
|
|
69
|
+
WORK_LIMIT = 16
|
|
70
|
+
MEM_LIMIT = 17
|
|
71
|
+
LOCALLY_OPTIMAL = 18
|
|
72
|
+
LOCALLY_INFEASIBLE = 19
|
|
73
|
+
|
|
74
|
+
# Batch status codes
|
|
75
|
+
|
|
76
|
+
BATCH_CREATED = 1
|
|
77
|
+
BATCH_SUBMITTED = 2
|
|
78
|
+
BATCH_ABORTED = 3
|
|
79
|
+
BATCH_FAILED = 4
|
|
80
|
+
BATCH_COMPLETED = 5
|
|
81
|
+
|
|
82
|
+
# Constraint senses
|
|
83
|
+
|
|
84
|
+
LESS_EQUAL = '<'
|
|
85
|
+
GREATER_EQUAL = '>'
|
|
86
|
+
EQUAL = '='
|
|
87
|
+
|
|
88
|
+
# Variable types
|
|
89
|
+
|
|
90
|
+
CONTINUOUS = 'C'
|
|
91
|
+
BINARY = 'B'
|
|
92
|
+
INTEGER = 'I'
|
|
93
|
+
SEMICONT = 'S'
|
|
94
|
+
SEMIINT = 'N'
|
|
95
|
+
|
|
96
|
+
# Objective sense
|
|
97
|
+
|
|
98
|
+
MINIMIZE = 1
|
|
99
|
+
MAXIMIZE = -1
|
|
100
|
+
|
|
101
|
+
# SOS types
|
|
102
|
+
|
|
103
|
+
SOS_TYPE1 = 1
|
|
104
|
+
SOS_TYPE2 = 2
|
|
105
|
+
|
|
106
|
+
# General constraint types
|
|
107
|
+
|
|
108
|
+
GENCONSTR_MAX = 0
|
|
109
|
+
GENCONSTR_MIN = 1
|
|
110
|
+
GENCONSTR_ABS = 2
|
|
111
|
+
GENCONSTR_AND = 3
|
|
112
|
+
GENCONSTR_OR = 4
|
|
113
|
+
GENCONSTR_NORM = 5
|
|
114
|
+
GENCONSTR_NL = 6
|
|
115
|
+
GENCONSTR_INDICATOR = 7
|
|
116
|
+
GENCONSTR_PWL = 8
|
|
117
|
+
GENCONSTR_POLY = 9
|
|
118
|
+
GENCONSTR_EXP = 10
|
|
119
|
+
GENCONSTR_EXPA = 11
|
|
120
|
+
GENCONSTR_LOG = 12
|
|
121
|
+
GENCONSTR_LOGA = 13
|
|
122
|
+
GENCONSTR_POW = 14
|
|
123
|
+
GENCONSTR_SIN = 15
|
|
124
|
+
GENCONSTR_COS = 16
|
|
125
|
+
GENCONSTR_TAN = 17
|
|
126
|
+
GENCONSTR_LOGISTIC = 18
|
|
127
|
+
|
|
128
|
+
# Operation codes
|
|
129
|
+
OPCODE_CONSTANT = 0
|
|
130
|
+
OPCODE_VARIABLE = 1
|
|
131
|
+
OPCODE_PLUS = 2
|
|
132
|
+
OPCODE_MINUS = 3
|
|
133
|
+
OPCODE_MULTIPLY = 4
|
|
134
|
+
OPCODE_DIVIDE = 5
|
|
135
|
+
OPCODE_UMINUS = 6
|
|
136
|
+
OPCODE_SQUARE = 7
|
|
137
|
+
OPCODE_SQRT = 8
|
|
138
|
+
OPCODE_SIN = 9
|
|
139
|
+
OPCODE_COS = 10
|
|
140
|
+
OPCODE_TAN = 11
|
|
141
|
+
OPCODE_POW = 12
|
|
142
|
+
OPCODE_EXP = 13
|
|
143
|
+
OPCODE_LOG = 14
|
|
144
|
+
OPCODE_LOG2 = 15
|
|
145
|
+
OPCODE_LOG10 = 16
|
|
146
|
+
OPCODE_LOGISTIC = 17
|
|
147
|
+
OPCODE_TANH = 18
|
|
148
|
+
OPCODE_SIGNPOW = 19
|
|
149
|
+
|
|
150
|
+
# Basis status
|
|
151
|
+
|
|
152
|
+
BASIC = 0
|
|
153
|
+
NONBASIC_LOWER = -1
|
|
154
|
+
NONBASIC_UPPER = -2
|
|
155
|
+
SUPERBASIC = -3
|
|
156
|
+
|
|
157
|
+
# Numeric constants
|
|
158
|
+
|
|
159
|
+
INFINITY = 1e100
|
|
160
|
+
UNDEFINED = 1e101
|
|
161
|
+
MAXINT = 2000000000
|
|
162
|
+
|
|
163
|
+
# Limits
|
|
164
|
+
|
|
165
|
+
MAX_NAMELEN = 255
|
|
166
|
+
MAX_STRLEN = 512
|
|
167
|
+
MAX_TAGLEN = 10240
|
|
168
|
+
MAX_CONCURRENT = 64
|
|
169
|
+
|
|
170
|
+
# Other constants
|
|
171
|
+
|
|
172
|
+
DEFAULT_CS_PORT = 61000
|
|
173
|
+
|
|
174
|
+
# Version number
|
|
175
|
+
|
|
176
|
+
VERSION_MAJOR = 13
|
|
177
|
+
VERSION_MINOR = 0
|
|
178
|
+
VERSION_TECHNICAL = 0
|
|
179
|
+
|
|
180
|
+
# Errors
|
|
181
|
+
|
|
182
|
+
ERROR_OUT_OF_MEMORY = 10001
|
|
183
|
+
ERROR_NULL_ARGUMENT = 10002
|
|
184
|
+
ERROR_INVALID_ARGUMENT = 10003
|
|
185
|
+
ERROR_UNKNOWN_ATTRIBUTE = 10004
|
|
186
|
+
ERROR_DATA_NOT_AVAILABLE = 10005
|
|
187
|
+
ERROR_INDEX_OUT_OF_RANGE = 10006
|
|
188
|
+
ERROR_UNKNOWN_PARAMETER = 10007
|
|
189
|
+
ERROR_VALUE_OUT_OF_RANGE = 10008
|
|
190
|
+
ERROR_NO_LICENSE = 10009
|
|
191
|
+
ERROR_SIZE_LIMIT_EXCEEDED = 10010
|
|
192
|
+
ERROR_CALLBACK = 10011
|
|
193
|
+
ERROR_FILE_READ = 10012
|
|
194
|
+
ERROR_FILE_WRITE = 10013
|
|
195
|
+
ERROR_NUMERIC = 10014
|
|
196
|
+
ERROR_IIS_NOT_INFEASIBLE = 10015
|
|
197
|
+
ERROR_NOT_FOR_MIP = 10016
|
|
198
|
+
ERROR_OPTIMIZATION_IN_PROGRESS = 10017
|
|
199
|
+
ERROR_DUPLICATES = 10018
|
|
200
|
+
ERROR_NODEFILE = 10019
|
|
201
|
+
ERROR_Q_NOT_PSD = 10020
|
|
202
|
+
ERROR_QCP_EQUALITY_CONSTRAINT = 10021
|
|
203
|
+
ERROR_NETWORK = 10022
|
|
204
|
+
ERROR_JOB_REJECTED = 10023
|
|
205
|
+
ERROR_NOT_SUPPORTED = 10024
|
|
206
|
+
ERROR_EXCEED_2B_NONZEROS = 10025
|
|
207
|
+
ERROR_INVALID_PIECEWISE_OBJ = 10026
|
|
208
|
+
ERROR_UPDATEMODE_CHANGE = 10027
|
|
209
|
+
ERROR_CLOUD = 10028
|
|
210
|
+
ERROR_MODEL_MODIFICATION = 10029
|
|
211
|
+
ERROR_CSWORKER = 10030
|
|
212
|
+
ERROR_TUNE_MODEL_TYPES = 10031
|
|
213
|
+
ERROR_SECURITY = 10032
|
|
214
|
+
ERROR_NOT_IN_MODEL = 20001
|
|
215
|
+
ERROR_FAILED_TO_CREATE_MODEL = 20002
|
|
216
|
+
ERROR_INTERNAL = 20003
|
|
217
|
+
|
|
218
|
+
# Cuts parameter values
|
|
219
|
+
|
|
220
|
+
CUTS_AUTO = -1
|
|
221
|
+
CUTS_OFF = 0
|
|
222
|
+
CUTS_CONSERVATIVE = 1
|
|
223
|
+
CUTS_AGGRESSIVE = 2
|
|
224
|
+
CUTS_VERYAGGRESSIVE = 3
|
|
225
|
+
|
|
226
|
+
# Presolve parameter values
|
|
227
|
+
|
|
228
|
+
PRESOLVE_AUTO = -1
|
|
229
|
+
PRESOLVE_OFF = 0
|
|
230
|
+
PRESOLVE_CONSERVATIVE = 1
|
|
231
|
+
PRESOLVE_AGGRESSIVE = 2
|
|
232
|
+
|
|
233
|
+
# Method parameter values
|
|
234
|
+
|
|
235
|
+
METHOD_NONE = -1
|
|
236
|
+
METHOD_AUTO = -1
|
|
237
|
+
METHOD_PRIMAL = 0
|
|
238
|
+
METHOD_DUAL = 1
|
|
239
|
+
METHOD_BARRIER = 2
|
|
240
|
+
METHOD_CONCURRENT = 3
|
|
241
|
+
METHOD_DETERMINISTIC_CONCURRENT = 4
|
|
242
|
+
METHOD_DETERMINISTIC_CONCURRENT_SIMPLEX = 5
|
|
243
|
+
METHOD_PDHG = 6
|
|
244
|
+
|
|
245
|
+
# BarHomogeneous parameter values
|
|
246
|
+
|
|
247
|
+
BARHOMOGENEOUS_AUTO = -1
|
|
248
|
+
BARHOMOGENEOUS_OFF = 0
|
|
249
|
+
BARHOMOGENEOUS_ON = 1
|
|
250
|
+
|
|
251
|
+
# BarOrder parameter values
|
|
252
|
+
|
|
253
|
+
BARORDER_AUTOMATIC = -1
|
|
254
|
+
BARORDER_AMD = 0
|
|
255
|
+
BARORDER_NESTEDDISSECTION = 1
|
|
256
|
+
|
|
257
|
+
# MIPFocus parameter values
|
|
258
|
+
|
|
259
|
+
MIPFOCUS_BALANCED = 0
|
|
260
|
+
MIPFOCUS_FEASIBILITY = 1
|
|
261
|
+
MIPFOCUS_OPTIMALITY = 2
|
|
262
|
+
MIPFOCUS_BESTBOUND = 3
|
|
263
|
+
|
|
264
|
+
# SimplexPricing parameter values
|
|
265
|
+
|
|
266
|
+
SIMPLEXPRICING_AUTO = -1
|
|
267
|
+
SIMPLEXPRICING_PARTIAL = 0
|
|
268
|
+
SIMPLEXPRICING_STEEPEST_EDGE = 1
|
|
269
|
+
SIMPLEXPRICING_DEVEX = 2
|
|
270
|
+
SIMPLEXPRICING_STEEPEST_QUICK = 3
|
|
271
|
+
|
|
272
|
+
# VarBranch parameter values
|
|
273
|
+
|
|
274
|
+
VARBRANCH_AUTO = -1
|
|
275
|
+
VARBRANCH_PSEUDO_REDUCED = 0
|
|
276
|
+
VARBRANCH_PSEUDO_SHADOW = 1
|
|
277
|
+
VARBRANCH_MAX_INFEAS = 2
|
|
278
|
+
VARBRANCH_STRONG = 3
|
|
279
|
+
|
|
280
|
+
# Partition parameter values
|
|
281
|
+
|
|
282
|
+
PARTITION_EARLY = 16
|
|
283
|
+
PARTITION_ROOTSTART = 8
|
|
284
|
+
PARTITION_ROOTEND = 4
|
|
285
|
+
PARTITION_NODES = 2
|
|
286
|
+
PARTITION_CLEANUP = 1
|
|
287
|
+
|
|
288
|
+
# Callback phase values
|
|
289
|
+
|
|
290
|
+
PHASE_MIP_NOREL = 0
|
|
291
|
+
PHASE_MIP_SEARCH = 1
|
|
292
|
+
PHASE_MIP_IMPROVE = 2
|
|
293
|
+
|
|
294
|
+
# FeasRelax method parameter values
|
|
295
|
+
|
|
296
|
+
FEASRELAX_LINEAR = 0
|
|
297
|
+
FEASRELAX_QUADRATIC = 1
|
|
298
|
+
FEASRELAX_CARDINALITY = 2
|
|
Binary file
|
gurobipy/_load_model.py
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
from gurobipy._grb import GRB
|
|
2
|
+
from gurobipy._lowlevel import _load_model_memoryview, _add_qp_terms_memoryview
|
|
3
|
+
from gurobipy._util import _isscalar
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def _double_array_argument(arg, size):
|
|
7
|
+
"""If arg is a single value, build a repeating array. Otherwise,
|
|
8
|
+
let numpy handle conversion from an arbitrary iterator."""
|
|
9
|
+
import numpy as np
|
|
10
|
+
|
|
11
|
+
if _isscalar(arg):
|
|
12
|
+
arg = float(arg)
|
|
13
|
+
repeat = np.empty(size, dtype="float64")
|
|
14
|
+
repeat.fill(arg)
|
|
15
|
+
return repeat
|
|
16
|
+
|
|
17
|
+
else:
|
|
18
|
+
return np.require(arg, dtype="float64", requirements=["C"])
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _char_array_argument(arg, size):
|
|
22
|
+
"""Convert str or bytearray to bytes. If a single value is given and
|
|
23
|
+
size is not None, build a repeating byte array. Otherwise, let numpy
|
|
24
|
+
handle conversion from an arbitrary iterator."""
|
|
25
|
+
|
|
26
|
+
import numpy as np
|
|
27
|
+
|
|
28
|
+
# Convert to bytes first if possible. Single character case still
|
|
29
|
+
# needs to be handled after conversion.
|
|
30
|
+
if isinstance(arg, str):
|
|
31
|
+
arg = arg.encode()
|
|
32
|
+
|
|
33
|
+
if isinstance(arg, (bytes, bytearray)):
|
|
34
|
+
if size is not None and len(arg) == 1:
|
|
35
|
+
return arg * size
|
|
36
|
+
else:
|
|
37
|
+
return arg
|
|
38
|
+
else:
|
|
39
|
+
return np.require(arg, dtype="S1", requirements=["C"]).tobytes()
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def loadModel(
|
|
43
|
+
*,
|
|
44
|
+
env,
|
|
45
|
+
numvars,
|
|
46
|
+
numconstrs,
|
|
47
|
+
modelsense=GRB.MINIMIZE,
|
|
48
|
+
objcon=0.0,
|
|
49
|
+
obj=None,
|
|
50
|
+
lb=None,
|
|
51
|
+
ub=None,
|
|
52
|
+
vtype=None,
|
|
53
|
+
constr_csc=None,
|
|
54
|
+
sense=None,
|
|
55
|
+
rhs=None,
|
|
56
|
+
qobj_coo=None,
|
|
57
|
+
name=None,
|
|
58
|
+
):
|
|
59
|
+
"""
|
|
60
|
+
ROUTINE:
|
|
61
|
+
loadModel(
|
|
62
|
+
*, env, numvars, numconstrs, modelsense=GRB.MINIMIZE, objcon=0.0,
|
|
63
|
+
obj=None, lb=None, ub=None, vtype=None, constr_csc=None, sense=None,
|
|
64
|
+
rhs=None, qobj_coo=None, name=None
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
PURPOSE:
|
|
68
|
+
Create a new optimization model, using the provided arguments to
|
|
69
|
+
initialize the model data (objective function, variable bounds,
|
|
70
|
+
constraint matrix, etc.). The model is then ready for optimization.
|
|
71
|
+
|
|
72
|
+
This function allows you to build models with only linear constraints,
|
|
73
|
+
and linear or quadratic objectives.
|
|
74
|
+
|
|
75
|
+
You’ll need "numpy" installed to use this function. All arguments to
|
|
76
|
+
this function are keyword-only.
|
|
77
|
+
|
|
78
|
+
ARGUMENTS:
|
|
79
|
+
env – The environment in which the new model should be created.
|
|
80
|
+
numvars – The number of variables in the model.
|
|
81
|
+
numconstrs – The number of constraints in the model.
|
|
82
|
+
modelsense – The sense of the objective function. Allowed
|
|
83
|
+
values are "GRB.MINIMIZE" or "GRB.MAXIMIZE". Defaults to
|
|
84
|
+
"GRB.MINIMIZE".
|
|
85
|
+
objcon – Constant objective offset (defaults to "0.0").
|
|
86
|
+
obj – (optional) Objective coefficients for the model
|
|
87
|
+
variables, as a list or 1-D array of length "numvars". If not
|
|
88
|
+
provided, all linear objective coefficients in the model are set
|
|
89
|
+
to "0.0".
|
|
90
|
+
lb – (optional) Lower bounds for the model variables, as a
|
|
91
|
+
list or 1-D array of length "numvars". If not provided, all
|
|
92
|
+
variables will have lower bounds of "0.0".
|
|
93
|
+
ub – (optional) Upper bounds for the model variables, as a
|
|
94
|
+
list or 1-D array of length "numvars". If not provided, all
|
|
95
|
+
variables will have infinite upper bounds.
|
|
96
|
+
vtype – (optional) Types for the variables, as a list or 1-D
|
|
97
|
+
array of length "numvars". Options are "GRB.CONTINUOUS",
|
|
98
|
+
"GRB.BINARY", "GRB.INTEGER", "GRB.SEMICONT", or "GRB.SEMIINT". If
|
|
99
|
+
not provided, all variables will be continuous.
|
|
100
|
+
constr_csc – (optional) Linear constraint data in Compressed
|
|
101
|
+
Sparse Column format (CSC) as a tuple "(data, indices, indptr)".
|
|
102
|
+
In this format the constraint indices for variable i are stored
|
|
103
|
+
in "indices[indptr[i]:indptr[i+1]]" and their corresponding
|
|
104
|
+
coefficients are stored in "data[indptr[i]:indptr[i+1]]". The
|
|
105
|
+
format is the same as that used by "scipy.sparse.csc_array". This
|
|
106
|
+
argument can be omitted if no linear constraints are being added.
|
|
107
|
+
sense – (optional) The senses for the model constraints, as a
|
|
108
|
+
list or 1-D array of length "numconstrs". Options are
|
|
109
|
+
"GRB.EQUAL", "GRB.LESS_EQUAL", or "GRB.GREATER_EQUAL". Can be
|
|
110
|
+
omitted if no linear constraints are being added.
|
|
111
|
+
rhs – (optional) Right-hand side values for the new
|
|
112
|
+
constraints, as a list or 1-D array of length "numconstrs". Can
|
|
113
|
+
be omitted if no linear constraints are being added.
|
|
114
|
+
qobj_coo – (optional) Quadratic objective matrix in
|
|
115
|
+
coordinate format as a tuple "(qval, (qrow, qcol))". The i^{th}
|
|
116
|
+
quadratic term is represented using three values: a pair of
|
|
117
|
+
indices (stored in "qrow[i]" and "qcol[i]"), and a coefficient
|
|
118
|
+
(stored in "qval[i]"). The format is the same as that used by
|
|
119
|
+
"scipy.sparse.coo_array". This argument can be omitted if no
|
|
120
|
+
quadratic objective terms are being added.
|
|
121
|
+
name – (optional) The name of the model.
|
|
122
|
+
|
|
123
|
+
RETURN VALUE:
|
|
124
|
+
A Model object.
|
|
125
|
+
"""
|
|
126
|
+
|
|
127
|
+
import numpy as np
|
|
128
|
+
|
|
129
|
+
if name is None:
|
|
130
|
+
modelname = b""
|
|
131
|
+
elif isinstance(name, str):
|
|
132
|
+
modelname = name.encode()
|
|
133
|
+
else:
|
|
134
|
+
raise TypeError("'modelname' must be a string or None")
|
|
135
|
+
|
|
136
|
+
try:
|
|
137
|
+
numvars = int(numvars)
|
|
138
|
+
except ValueError as e:
|
|
139
|
+
raise ValueError("'numvars' must be an integer") from e
|
|
140
|
+
|
|
141
|
+
try:
|
|
142
|
+
numconstrs = int(numconstrs)
|
|
143
|
+
except ValueError as e:
|
|
144
|
+
raise ValueError("'numconstrs' must be an integer") from e
|
|
145
|
+
|
|
146
|
+
if numvars < 0:
|
|
147
|
+
raise ValueError("'numvars' must be non-negative")
|
|
148
|
+
if numconstrs < 0:
|
|
149
|
+
raise ValueError("'numconstrs' must be non-negative")
|
|
150
|
+
|
|
151
|
+
try:
|
|
152
|
+
modelsense = int(modelsense)
|
|
153
|
+
except ValueError as e:
|
|
154
|
+
raise ValueError("'modelsense' must be an integer") from e
|
|
155
|
+
|
|
156
|
+
try:
|
|
157
|
+
objcon = float(objcon)
|
|
158
|
+
except ValueError as e:
|
|
159
|
+
raise ValueError("'objcon' must be numeric") from e
|
|
160
|
+
|
|
161
|
+
# Prepare variable attribute arrays, repeating scalars if needed
|
|
162
|
+
if obj is not None:
|
|
163
|
+
obj = _double_array_argument(obj, size=numvars)
|
|
164
|
+
if lb is not None:
|
|
165
|
+
lb = _double_array_argument(lb, size=numvars)
|
|
166
|
+
if ub is not None:
|
|
167
|
+
ub = _double_array_argument(ub, size=numvars)
|
|
168
|
+
if vtype is not None:
|
|
169
|
+
vtype = _char_array_argument(vtype, size=numvars)
|
|
170
|
+
|
|
171
|
+
if numconstrs == 0:
|
|
172
|
+
# No linear constraint matrix was given; construct an empty one
|
|
173
|
+
rhs = np.array([], dtype="float64")
|
|
174
|
+
sense = b""
|
|
175
|
+
vbeg = np.zeros((numvars,), dtype="uint64")
|
|
176
|
+
vlen = np.zeros((numvars,), dtype="int32")
|
|
177
|
+
vind = np.array([], dtype="int32")
|
|
178
|
+
vval = np.array([], dtype="float64")
|
|
179
|
+
|
|
180
|
+
else:
|
|
181
|
+
# To avoid ambiguity, a string for 'sense' must have length numconstrs.
|
|
182
|
+
# no '<=' or '<' allowed to set the same sense for all constraints.
|
|
183
|
+
sense = _char_array_argument(sense, size=None)
|
|
184
|
+
|
|
185
|
+
rhs = _double_array_argument(rhs, size=numconstrs)
|
|
186
|
+
|
|
187
|
+
try:
|
|
188
|
+
data, indices, indptr = constr_csc
|
|
189
|
+
except Exception as e:
|
|
190
|
+
raise ValueError(
|
|
191
|
+
"'constr_csc' must be a tuple of the form (data, indices, indptr)"
|
|
192
|
+
) from e
|
|
193
|
+
|
|
194
|
+
vind = np.require(indices, dtype="int32", requirements=["C"])
|
|
195
|
+
vval = np.require(data, dtype="float64", requirements=["C"])
|
|
196
|
+
|
|
197
|
+
indptr = np.require(indptr, dtype="uint64", requirements=["C"])
|
|
198
|
+
vlen = np.empty(len(indptr) - 1, dtype="int32")
|
|
199
|
+
np.subtract(indptr[1:], indptr[:-1], out=vlen)
|
|
200
|
+
vbeg = indptr[:-1]
|
|
201
|
+
|
|
202
|
+
model = _load_model_memoryview(
|
|
203
|
+
env=env,
|
|
204
|
+
numvars=numvars,
|
|
205
|
+
numconstrs=numconstrs,
|
|
206
|
+
modelname=modelname,
|
|
207
|
+
objsense=modelsense,
|
|
208
|
+
objcon=objcon,
|
|
209
|
+
obj=obj,
|
|
210
|
+
sense=sense,
|
|
211
|
+
rhs=rhs,
|
|
212
|
+
vbeg=vbeg,
|
|
213
|
+
vlen=vlen,
|
|
214
|
+
vind=vind,
|
|
215
|
+
vval=vval,
|
|
216
|
+
lb=lb,
|
|
217
|
+
ub=ub,
|
|
218
|
+
vtype=vtype,
|
|
219
|
+
)
|
|
220
|
+
|
|
221
|
+
# Any further operations must be followed by an update() call. The model
|
|
222
|
+
# must be cleaned up if an exception is raised after this point.
|
|
223
|
+
|
|
224
|
+
if qobj_coo is not None:
|
|
225
|
+
|
|
226
|
+
try:
|
|
227
|
+
qval, (qrow, qcol) = qobj_coo
|
|
228
|
+
except Exception as e:
|
|
229
|
+
model.close()
|
|
230
|
+
raise ValueError(
|
|
231
|
+
"'qobj_coo' must be a tuple of the form (qval, (qrow, qcol))"
|
|
232
|
+
) from e
|
|
233
|
+
|
|
234
|
+
try:
|
|
235
|
+
numqnz = len(qrow)
|
|
236
|
+
_add_qp_terms_memoryview(
|
|
237
|
+
model=model,
|
|
238
|
+
numqnz=numqnz,
|
|
239
|
+
qrow=np.require(qrow, dtype="int32", requirements=["C"]),
|
|
240
|
+
qcol=np.require(qcol, dtype="int32", requirements=["C"]),
|
|
241
|
+
qval=np.require(qval, dtype="float64", requirements=["C"]),
|
|
242
|
+
)
|
|
243
|
+
model.update()
|
|
244
|
+
except Exception:
|
|
245
|
+
model.close()
|
|
246
|
+
raise
|
|
247
|
+
|
|
248
|
+
return model
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|