Skip to content

Commit

Permalink
Merge branch 'benchmark' into OA_convexification
Browse files Browse the repository at this point in the history
  • Loading branch information
ZedongPeng committed Nov 3, 2023
2 parents c68d051 + 3b01104 commit cb29149
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pyomo/contrib/mindtpy/algorithm_base_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def __init__(self, **kwds):
self.curr_int_sol = []
self.should_terminate = False
self.integer_list = []
# dictionary {integer solution (list): cuts index (list)}
self.int_sol_2_cuts_ind = dict()

# Set up iteration counters
self.nlp_iter = 0
Expand Down Expand Up @@ -794,6 +796,7 @@ def MindtPy_initialization(self):
self.integer_list.append(self.curr_int_sol)
fixed_nlp, fixed_nlp_result = self.solve_subproblem()
self.handle_nlp_subproblem_tc(fixed_nlp, fixed_nlp_result)
self.int_sol_2_cuts_ind[self.curr_int_sol] = list(range(1, len(self.mip.MindtPy_utils.cuts.oa_cuts) + 1))
elif config.init_strategy == 'FP':
self.init_rNLP()
self.fp_loop()
Expand Down
11 changes: 11 additions & 0 deletions pyomo/contrib/mindtpy/single_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,15 +941,26 @@ def LazyOACallback_gurobi(cb_m, cb_opt, cb_where, mindtpy_solver, config):
)
return
elif config.strategy == 'OA':
# Refer to the official document of GUROBI.
# Your callback should be prepared to cut off solutions that violate any of your lazy constraints, including those that have already been added. Node solutions will usually respect previously added lazy constraints, but not always.
# https://www.gurobi.com/documentation/current/refman/cs_cb_addlazy.html
# If this happens, MindtPy will look for the index of corresponding cuts, instead of solving the fixed-NLP again.
for ind in mindtpy_solver.int_sol_2_cuts_ind[mindtpy_solver.curr_int_sol]:
cb_opt.cbLazy(mindtpy_solver.mip.MindtPy_utils.cuts.oa_cuts[ind])
return
else:
mindtpy_solver.integer_list.append(mindtpy_solver.curr_int_sol)
if config.strategy == 'OA':
cut_ind = len(mindtpy_solver.mip.MindtPy_utils.cuts.oa_cuts)

# solve subproblem
# The constraint linearization happens in the handlers
fixed_nlp, fixed_nlp_result = mindtpy_solver.solve_subproblem()

mindtpy_solver.handle_nlp_subproblem_tc(fixed_nlp, fixed_nlp_result, cb_opt)
if config.strategy == 'OA':
# store the cut index corresponding to current integer solution.
mindtpy_solver.int_sol_2_cuts_ind[mindtpy_solver.curr_int_sol] = list(range(cut_ind + 1, len(mindtpy_solver.mip.MindtPy_utils.cuts.oa_cuts) + 1))


def handle_lazy_main_feasible_solution_gurobi(cb_m, cb_opt, mindtpy_solver, config):
Expand Down

0 comments on commit cb29149

Please sign in to comment.