Skip to content

Commit

Permalink
improve int_sol_2_cuts_ind
Browse files Browse the repository at this point in the history
  • Loading branch information
ZedongPeng committed Nov 28, 2023
1 parent 4ac390e commit a755067
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
9 changes: 5 additions & 4 deletions pyomo/contrib/mindtpy/algorithm_base_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def __init__(self, **kwds):
self.curr_int_sol = []
self.should_terminate = False
self.integer_list = []
# dictionary {integer solution (list): cuts index (list)}
# dictionary {integer solution (list): [cuts begin index, cuts end index] (list)}
self.int_sol_2_cuts_ind = dict()

# Set up iteration counters
Expand Down Expand Up @@ -810,9 +810,10 @@ 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)
)
self.int_sol_2_cuts_ind[self.curr_int_sol] = [
1,
len(self.mip.MindtPy_utils.cuts.oa_cuts),
]
elif config.init_strategy == 'FP':
self.init_rNLP()
self.fp_loop()
Expand Down
14 changes: 7 additions & 7 deletions pyomo/contrib/mindtpy/single_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,9 +900,10 @@ def LazyOACallback_gurobi(cb_m, cb_opt, cb_where, mindtpy_solver, config):
# 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[
begin_index, end_index = mindtpy_solver.int_sol_2_cuts_ind[
mindtpy_solver.curr_int_sol
]:
]
for ind in range(begin_index, end_index + 1):
cb_opt.cbLazy(mindtpy_solver.mip.MindtPy_utils.cuts.oa_cuts[ind])
return
else:
Expand All @@ -917,11 +918,10 @@ def LazyOACallback_gurobi(cb_m, cb_opt, cb_where, mindtpy_solver, config):
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
)
)
mindtpy_solver.int_sol_2_cuts_ind[mindtpy_solver.curr_int_sol] = [
cut_ind + 1,
len(mindtpy_solver.mip.MindtPy_utils.cuts.oa_cuts),
]


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

0 comments on commit a755067

Please sign in to comment.