@@ -2196,6 +2196,18 @@ cdef class Constraint:
2196
2196
constype = bytes(SCIPconshdlrGetName(SCIPconsGetHdlr(self .scip_cons))).decode(' UTF-8' )
2197
2197
return constype == ' knapsack'
2198
2198
2199
+ def isLinearType (self ):
2200
+ """
2201
+ Returns True if constraint can be represented as a linear constraint.
2202
+
2203
+ Returns
2204
+ -------
2205
+ bool
2206
+
2207
+ """
2208
+ constype = bytes(SCIPconshdlrGetName(SCIPconsGetHdlr(self .scip_cons))).decode(' UTF-8' )
2209
+ return constype in (' linear' , ' knapsack' , ' setppc' , ' logicor' , ' varbound' )
2210
+
2199
2211
def isNonlinear (self ):
2200
2212
"""
2201
2213
Returns True if constraint is nonlinear.
@@ -6024,7 +6036,11 @@ cdef class Model:
6024
6036
6025
6037
SCIPgetConsNVars(self ._scip, constraint.scip_cons, & nvars, & success)
6026
6038
_vars = < SCIP_VAR** > malloc(nvars * sizeof(SCIP_VAR* ))
6027
- SCIPgetConsVars(self ._scip, constraint.scip_cons, _vars, nvars* sizeof(SCIP_VAR* ), & success)
6039
+ SCIPgetConsVars(self ._scip, constraint.scip_cons, _vars, nvars, & success)
6040
+
6041
+ if not success:
6042
+ free(_vars)
6043
+ return None
6028
6044
6029
6045
vars = []
6030
6046
for i in range (nvars):
@@ -6039,7 +6055,39 @@ cdef class Model:
6039
6055
self ._modelvars[ptr] = var
6040
6056
vars .append(var)
6041
6057
6058
+ free(_vars)
6042
6059
return vars
6060
+
6061
+ def getConsVals (self , Constraint constraint ):
6062
+ """
6063
+ Returns the value array of an arbitrary SCIP constraint that can be represented as a single linear constraint.
6064
+
6065
+ Parameters
6066
+ ----------
6067
+ constraint : Constraint
6068
+ Constraint to get the values from.
6069
+
6070
+ Returns
6071
+ -------
6072
+ list of float
6073
+
6074
+ """
6075
+ cdef SCIP_Real* _vals
6076
+ cdef int nvars
6077
+ cdef SCIP_Bool success
6078
+ cdef int i
6079
+
6080
+ nvars = self .getConsNVars(constraint)
6081
+ _vals = < SCIP_Real* > malloc(nvars * sizeof(SCIP_Real))
6082
+ PY_SCIP_CALL(SCIPgetConsVals(self ._scip, constraint.scip_cons, _vals, nvars, & success))
6083
+
6084
+ if not success:
6085
+ free(_vals)
6086
+ return None
6087
+
6088
+ vals = [_vals[i] for i in range (nvars)]
6089
+ free(_vals)
6090
+ return vals
6043
6091
6044
6092
def getNVarsAnd (self , Constraint and_cons ):
6045
6093
"""
@@ -6055,8 +6103,6 @@ cdef class Model:
6055
6103
int
6056
6104
6057
6105
"""
6058
- cdef int nvars
6059
- cdef SCIP_Bool success
6060
6106
6061
6107
return SCIPgetNVarsAnd(self ._scip, and_cons.scip_cons)
6062
6108
@@ -6074,9 +6120,9 @@ cdef class Model:
6074
6120
list of Variable
6075
6121
6076
6122
"""
6123
+
6077
6124
cdef SCIP_VAR** _vars
6078
6125
cdef int nvars
6079
- cdef SCIP_Bool success
6080
6126
cdef int i
6081
6127
6082
6128
constype = bytes(SCIPconshdlrGetName(SCIPconsGetHdlr(and_cons.scip_cons))).decode(' UTF-8' )
@@ -6114,8 +6160,8 @@ cdef class Model:
6114
6160
Variable
6115
6161
6116
6162
"""
6163
+
6117
6164
cdef SCIP_VAR* _resultant
6118
- cdef SCIP_Bool success
6119
6165
6120
6166
_resultant = SCIPgetResultantAnd(self ._scip, and_cons.scip_cons)
6121
6167
@@ -6145,8 +6191,7 @@ cdef class Model:
6145
6191
bool
6146
6192
6147
6193
"""
6148
- cdef SCIP_Bool success
6149
-
6194
+
6150
6195
return SCIPisAndConsSorted(self ._scip, and_cons.scip_cons)
6151
6196
6152
6197
def sortAndCons (self , Constraint and_cons ):
@@ -6159,7 +6204,6 @@ cdef class Model:
6159
6204
Constraint to sort.
6160
6205
6161
6206
"""
6162
- cdef SCIP_Bool success
6163
6207
6164
6208
PY_SCIP_CALL(SCIPsortAndCons(self ._scip, and_cons.scip_cons))
6165
6209
@@ -7275,9 +7319,13 @@ cdef class Model:
7275
7319
float
7276
7320
7277
7321
"""
7322
+ cdef SCIP_Bool success
7278
7323
constype = bytes(SCIPconshdlrGetName(SCIPconsGetHdlr(cons.scip_cons))).decode(' UTF-8' )
7279
- if constype == ' linear' :
7280
- return SCIPgetRhsLinear(self ._scip, cons.scip_cons)
7324
+
7325
+ if cons.isLinearType():
7326
+ rhs = SCIPconsGetRhs(self ._scip, cons.scip_cons, & success)
7327
+ assert (success)
7328
+ return rhs
7281
7329
elif constype == ' nonlinear' :
7282
7330
return SCIPgetRhsNonlinear(cons.scip_cons)
7283
7331
else :
@@ -7316,9 +7364,13 @@ cdef class Model:
7316
7364
float
7317
7365
7318
7366
"""
7367
+ cdef SCIP_Bool success
7319
7368
constype = bytes(SCIPconshdlrGetName(SCIPconsGetHdlr(cons.scip_cons))).decode(' UTF-8' )
7320
- if constype == ' linear' :
7321
- return SCIPgetLhsLinear(self ._scip, cons.scip_cons)
7369
+
7370
+ if cons.isLinearType():
7371
+ lhs = SCIPconsGetLhs(self ._scip, cons.scip_cons, & success)
7372
+ assert (success)
7373
+ return lhs
7322
7374
elif constype == ' nonlinear' :
7323
7375
return SCIPgetLhsNonlinear(cons.scip_cons)
7324
7376
else :
0 commit comments