Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion pyomo/contrib/solver/solvers/highs.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,26 @@ def _postsolve(self, stream: io.StringIO):
results.objective_bound = None
else:
results.objective_bound = info.mip_dual_bound
results.iteration_count = info.simplex_iteration_count

if info.valid:
# The method that ran will have a non-negative iteration count
# and the others will be 0 or -1.
counts = [
info.simplex_iteration_count,
info.ipm_iteration_count,
info.mip_node_count,
info.pdlp_iteration_count,
info.qp_iteration_count,
]
assert (
len([c for c in counts if c > 1]) <= 1
), "Only one method should have a positive iteration count"
assert any(
[c >= 0 for c in counts]
), "Should have a non-negative count if info valid"
results.iteration_count = max(counts)
else:
results.iteration_count = 0

if config.load_solutions:
if has_feasible_solution:
Expand Down
40 changes: 40 additions & 0 deletions pyomo/contrib/solver/tests/solvers/test_highs.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,43 @@ def test_fix_and_unfix(self):
self.assertAlmostEqual(m.fx.value, 1, places=5)
self.assertAlmostEqual(m.fy.value, 0, places=5)
self.assertAlmostEqual(r.objective_bound, 0.5, places=5)


class TestHighsMiniDemos(unittest.TestCase):
def test_lp_methods(self):
for method in ("simplex", "ipm", "pdlp"):
# Build LP
m = pyo.ConcreteModel()
m.x = pyo.Var(domain=pyo.NonNegativeReals)
m.y = pyo.Var(domain=pyo.NonNegativeReals)
m.c = pyo.Constraint(expr=m.x + m.y >= 1)
m.obj = pyo.Objective(expr=m.x + m.y, sense=pyo.minimize)

solver = Highs()
solver.config.solver_options["solver"] = (
method # 'simplex' | 'ipm' | 'pdlp'
)

solver.solve(m, tee=False)

def test_mip_demo(self):
# Build MIP
m = pyo.ConcreteModel()
m.a = pyo.Var(domain=pyo.Binary)
m.b = pyo.Var(domain=pyo.Binary)
m.cap = pyo.Constraint(expr=m.a + m.b <= 1)
m.obj = pyo.Objective(expr=3 * m.a + 2 * m.b, sense=pyo.maximize)

solver = Highs()
solver.solve(m, tee=False)

def test_qp_demo(self):
# Build convex QP
m = pyo.ConcreteModel()
m.x = pyo.Var(domain=pyo.Reals, bounds=(0, None))
m.y = pyo.Var(domain=pyo.Reals, bounds=(0, None))
m.c = pyo.Constraint(expr=m.x + m.y >= 1)
m.obj = pyo.Objective(expr=(m.x - 1) ** 2 + (m.y - 2) ** 2, sense=pyo.minimize)

solver = Highs()
solver.solve(m, tee=False)
Loading