From 34335f9d66e6b34dca5ac198da6c38929e0024f8 Mon Sep 17 00:00:00 2001 From: wujian Date: Thu, 12 Oct 2023 17:31:34 +0800 Subject: [PATCH] Fix issues --- pyomo/contrib/appsi/solvers/copt.py | 36 +++++++++++++++++------------ 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/pyomo/contrib/appsi/solvers/copt.py b/pyomo/contrib/appsi/solvers/copt.py index 1572815bad6..db1e8f44560 100644 --- a/pyomo/contrib/appsi/solvers/copt.py +++ b/pyomo/contrib/appsi/solvers/copt.py @@ -125,7 +125,7 @@ def __init__(self): self.copt_model = None def update(self): - self.copt_model.sefCoeff(self.con, self.var, value(self.expr)) + self.copt_model.setCoeff(self.con, self.var, value(self.expr)) class _MutableRangeConstant(object): @@ -148,17 +148,27 @@ def __init__(self): self.con = None def update(self): - if self.con.equality or (self.con.has_lb() and self.con.has_ub()): - self.con.lb = value(self.expr) - self.con.ub = value(self.expr) - elif self.con.has_lb(): - self.con.lb = value(self.expr) - elif self.con.has_ub(): - self.con.ub = value(self.expr) + if isinstance(self.con, coptpy.Constraint): + lb = self.con.lb + ub = self.con.ub + # lb <= con <= ub + if lb > -coptpy.COPT.INFINITY and ub < +coptpy.COPT.INFINITY: + self.con.lb = value(self.expr) + self.con.ub = value(self.expr) + # con >= lb + elif lb > -coptpy.COPT.INFINITY and ub >= +coptpy.COPT.INFINITY: + self.con.lb = value(self.expr) + # con <= ub + elif lb <= -coptpy.COPT.INFINITY and ub < +coptpy.COPT.INFINITY: + self.con.ub = value(self.expr) + else: + raise ValueError( + "Constraint does not has lower/upper bound: {0} \n".format(self.con) + ) + elif isinstance(self.con, coptpy.QConstraint): + self.con.rhs = value(self.expr) else: - raise ValueError( - "Constraint does not has lower/upper bound: {0} \n".format(self.con) - ) + raise TypeError("Unexpected constraint type") class _MutableQuadraticConstraint(object): @@ -990,8 +1000,6 @@ def get_duals(self, cons_to_load=None): if cons_to_load is None: cons_to_load = con_map.keys() - else: - cons_to_load = [id(con) for con in cons_to_load] copt_cons_to_load = [con_map[pyomo_con_id] for pyomo_con_id in cons_to_load] vals = list() @@ -1018,8 +1026,6 @@ def get_slacks(self, cons_to_load=None): if cons_to_load is None: cons_to_load = con_map.keys() - else: - cons_to_load = [id(con) for con in cons_to_load] copt_cons_to_load = [con_map[pyomo_con_id] for pyomo_con_id in cons_to_load] vals = list()