From ff6e78fe5cb567ef53498443af731893642c53f0 Mon Sep 17 00:00:00 2001 From: John Siirola Date: Fri, 15 Nov 2024 15:01:33 -0700 Subject: [PATCH 1/2] xpress: fix typo calling method to retrieve reduced costs --- pyomo/solvers/plugins/solvers/xpress_direct.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyomo/solvers/plugins/solvers/xpress_direct.py b/pyomo/solvers/plugins/solvers/xpress_direct.py index 43316603a41..764314deee9 100644 --- a/pyomo/solvers/plugins/solvers/xpress_direct.py +++ b/pyomo/solvers/plugins/solvers/xpress_direct.py @@ -1126,7 +1126,7 @@ def _load_rc(self, vars_to_load=None): vars_to_load = var_map.keys() xpress_vars_to_load = [var_map[pyomo_var] for pyomo_var in vars_to_load] - vals = self._getRedCost(self._solver_model, xpress_vars_to_load) + vals = self._getRedCosts(self._solver_model, xpress_vars_to_load) for var, val in zip(vars_to_load, vals): if ref_vars[var] > 0: From 03ec9d28332837608b77b7b61c63720ada6656fe Mon Sep 17 00:00:00 2001 From: John Siirola Date: Fri, 15 Nov 2024 15:02:11 -0700 Subject: [PATCH 2/2] xpress: add test exercising retrieving RC/Slacks --- .../solvers/tests/checks/test_xpress_persistent.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pyomo/solvers/tests/checks/test_xpress_persistent.py b/pyomo/solvers/tests/checks/test_xpress_persistent.py index d5107f9dda7..329ba38e164 100644 --- a/pyomo/solvers/tests/checks/test_xpress_persistent.py +++ b/pyomo/solvers/tests/checks/test_xpress_persistent.py @@ -40,10 +40,23 @@ def test_basics(self): res = opt.solve() self.assertAlmostEqual(m.x.value, -0.4, delta=1e-6) self.assertAlmostEqual(m.y.value, 0.2, delta=1e-6) + opt.load_duals() + self.assertEqual(len(m.dual), 1) self.assertAlmostEqual(m.dual[m.c1], -0.4, delta=1e-6) del m.dual + opt.load_rc() + self.assertEqual(len(m.rc), 2) + self.assertAlmostEqual(m.rc[m.x], 0, delta=1e-8) + self.assertAlmostEqual(m.rc[m.y], 0, delta=1e-8) + del m.rc + + opt.load_slacks() + self.assertEqual(len(m.slack), 1) + self.assertAlmostEqual(m.slack[m.c1], 0, delta=1e-6) + del m.slack + m.c2 = pe.Constraint(expr=m.y >= -m.x + 1) opt.add_constraint(m.c2) self.assertEqual(opt.get_xpress_attribute('cols'), 2)