Skip to content

Commit d70f719

Browse files
author
Ruaridh Williamson
committed
⚡ Avoid calling set_bounds() when not necessary
1 parent 3e5ac43 commit d70f719

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

pyomo/solvers/plugins/solvers/cplex_direct.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@ def _add_var(self, var, cplex_var_data=None):
331331
else:
332332
ub = self._cplex.infinity
333333

334+
if var.is_fixed():
335+
lb = value(var)
336+
ub = value(var)
334337

335338
ctx = (
336339
_VariableData(self._solver_model)
@@ -346,10 +349,6 @@ def _add_var(self, var, cplex_var_data=None):
346349
self._ndx_count += 1
347350
self._referenced_variables[var] = 0
348351

349-
if var.is_fixed():
350-
self._solver_model.variables.set_lower_bounds(varname, var.value)
351-
self._solver_model.variables.set_upper_bounds(varname, var.value)
352-
353352
def _set_instance(self, model, kwds={}):
354353
self._pyomo_var_to_ndx_map = ComponentMap()
355354
self._ndx_count = 0
@@ -441,14 +440,15 @@ def _add_constraint(self, con, cplex_lin_con_data=None):
441440
con.body, self._max_constraint_degree
442441
)
443442

444-
if con.has_lb():
445-
if not is_fixed(con.lower):
446-
raise ValueError("Lower bound of constraint {0} "
447-
"is not constant.".format(con))
448-
if con.has_ub():
449-
if not is_fixed(con.upper):
450-
raise ValueError("Upper bound of constraint {0} "
451-
"is not constant.".format(con))
443+
if con.has_lb() and not is_fixed(con.lower):
444+
raise ValueError(
445+
"Lower bound of constraint {0} is not constant.".format(con)
446+
)
447+
448+
if con.has_ub() and not is_fixed(con.upper):
449+
raise ValueError(
450+
"Upper bound of constraint {0} is not constant.".format(con)
451+
)
452452

453453
range_ = 0.0
454454
if con.equality:

0 commit comments

Comments
 (0)