@@ -160,13 +160,13 @@ def get_operator(mdl: Model, auto_penalty: bool = True,
160
160
161
161
# convert constraints into penalty terms.
162
162
for constraint in mdl .iter_constraints ():
163
- constant = constraint .right_expr . get_constant ()
163
+ constant = constraint .cplex_num_rhs ()
164
164
165
165
# constant parts of penalty*(Constant-func)**2: penalty*(Constant**2)
166
166
shift += penalty * constant ** 2
167
167
168
168
# linear parts of penalty*(Constant-func)**2: penalty*(-2*Constant*func)
169
- for __l in constraint .left_expr . iter_terms ():
169
+ for __l in constraint .iter_net_linear_coefs ():
170
170
z_p = np .zeros (num_nodes , dtype = np .bool )
171
171
index = q_d [__l [0 ]]
172
172
weight = __l [1 ]
@@ -176,8 +176,8 @@ def get_operator(mdl: Model, auto_penalty: bool = True,
176
176
shift += - penalty * constant * weight
177
177
178
178
# quadratic parts of penalty*(Constant-func)**2: penalty*(func**2)
179
- for __l in constraint .left_expr . iter_terms ():
180
- for l_2 in constraint .left_expr . iter_terms ():
179
+ for __l in constraint .iter_net_linear_coefs ():
180
+ for l_2 in constraint .iter_net_linear_coefs ():
181
181
index1 = q_d [__l [0 ]]
182
182
index2 = q_d [l_2 [0 ]]
183
183
weight1 = __l [1 ]
@@ -258,8 +258,8 @@ def _auto_define_penalty(mdl: Model, default_penalty: float = 1e5) -> float:
258
258
# if a constraint has float coefficient, return 1e5 for the penalty coefficient.
259
259
terms = []
260
260
for constraint in mdl .iter_constraints ():
261
- terms .append (constraint .right_expr . get_constant ())
262
- terms .extend (term [1 ] for term in constraint .left_expr . iter_terms ())
261
+ terms .append (constraint .cplex_num_rhs ())
262
+ terms .extend (term [1 ] for term in constraint .iter_net_linear_coefs ())
263
263
if any (isinstance (term , float ) and not term .is_integer () for term in terms ):
264
264
logger .warning ('Using %f for the penalty coefficient because a float coefficient exists '
265
265
'in constraints. \n The value could be too small. '
0 commit comments