Skip to content

Commit

Permalink
add test for call_before_subproblem_solve
Browse files Browse the repository at this point in the history
  • Loading branch information
ZedongPeng committed May 7, 2024
1 parent add489c commit e4920cb
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pyomo/contrib/mindtpy/tests/test_mindtpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,30 @@ def test_OA_rNLP(self):
)
self.check_optimal_solution(model)

def test_OA_callback(self):
"""Test the outer approximation decomposition algorithm."""
with SolverFactory('mindtpy') as opt:

def callback(model):
model.Y[1].value = 0
model.Y[2].value = 0
model.Y[3].value = 0

model = SimpleMINLP2()
# The callback function will make the OA method cycling.
results = opt.solve(
model,
strategy='OA',
init_strategy='rNLP',
mip_solver=required_solvers[1],
nlp_solver=required_solvers[0],
call_before_subproblem_solve=callback,
)
self.assertIs(
results.solver.termination_condition, TerminationCondition.feasible
)
self.assertAlmostEqual(value(results.problem.lower_bound), 5, places=1)

def test_OA_extreme_model(self):
"""Test the outer approximation decomposition algorithm."""
with SolverFactory('mindtpy') as opt:
Expand Down

0 comments on commit e4920cb

Please sign in to comment.