Skip to content

Commit

Permalink
⚡ Avoid calling set_bounds() when not necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
ruaridhw committed Apr 28, 2020
1 parent 3e5ac43 commit d70f719
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions pyomo/solvers/plugins/solvers/cplex_direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ def _add_var(self, var, cplex_var_data=None):
else:
ub = self._cplex.infinity

if var.is_fixed():
lb = value(var)
ub = value(var)

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

if var.is_fixed():
self._solver_model.variables.set_lower_bounds(varname, var.value)
self._solver_model.variables.set_upper_bounds(varname, var.value)

def _set_instance(self, model, kwds={}):
self._pyomo_var_to_ndx_map = ComponentMap()
self._ndx_count = 0
Expand Down Expand Up @@ -441,14 +440,15 @@ def _add_constraint(self, con, cplex_lin_con_data=None):
con.body, self._max_constraint_degree
)

if con.has_lb():
if not is_fixed(con.lower):
raise ValueError("Lower bound of constraint {0} "
"is not constant.".format(con))
if con.has_ub():
if not is_fixed(con.upper):
raise ValueError("Upper bound of constraint {0} "
"is not constant.".format(con))
if con.has_lb() and not is_fixed(con.lower):
raise ValueError(
"Lower bound of constraint {0} is not constant.".format(con)
)

if con.has_ub() and not is_fixed(con.upper):
raise ValueError(
"Upper bound of constraint {0} is not constant.".format(con)
)

range_ = 0.0
if con.equality:
Expand Down

0 comments on commit d70f719

Please sign in to comment.