Skip to content

Commit 7ea1ea3

Browse files
committed
improve single tree implementation
1 parent 596ddb7 commit 7ea1ea3

File tree

6 files changed

+218
-748
lines changed

6 files changed

+218
-748
lines changed

pyomo/contrib/mindtpy/algorithm_base_class.py

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,8 +1536,6 @@ def fix_dual_bound(self, config, last_iter_cuts):
15361536
main_mip_results = self.mip_opt.solve(
15371537
self.mip, tee=config.mip_solver_tee, load_solutions=False, **mip_args
15381538
)
1539-
if config.use_tabu_list:
1540-
self.update_attributes()
15411539
if len(main_mip_results.solution) > 0:
15421540
self.mip.solutions.load_from(main_mip_results)
15431541

@@ -1570,12 +1568,10 @@ def set_up_tabulist_callback(self):
15701568
tabulist = self.mip_opt._solver_model.register_callback(
15711569
tabu_list.IncumbentCallback_cplex
15721570
)
1573-
self.solve_data = MindtPySolveData()
1574-
self.export_attributes()
1575-
tabulist.solve_data = self.solve_data
15761571
tabulist.opt = self.mip_opt
15771572
tabulist.config = self.config
1578-
self.mip_opt._solver_model.parameters.preprocessing.reduce.set(1)
1573+
tabulist.mindtpy_object = self
1574+
self.mip_opt.options['preprocessing_reduce'] = 1
15791575
# If the callback is used to reject incumbents, the user must set the
15801576
# parameter c.parameters.preprocessing.reduce either to the value 1 (one)
15811577
# to restrict presolve to primal reductions only or to 0 (zero) to disable all presolve reductions
@@ -1597,19 +1593,15 @@ def set_up_lazy_OA_callback(self):
15971593
)
15981594
# pass necessary data and parameters to lazyoa
15991595
lazyoa.main_mip = self.mip
1600-
self.solve_data = MindtPySolveData()
1601-
self.export_attributes()
1602-
lazyoa.solve_data = self.solve_data
16031596
lazyoa.config = self.config
16041597
lazyoa.opt = self.mip_opt
1598+
lazyoa.mindtpy_object = self
16051599
self.mip_opt._solver_model.set_warning_stream(None)
16061600
self.mip_opt._solver_model.set_log_stream(None)
16071601
self.mip_opt._solver_model.set_error_stream(None)
16081602
if self.config.mip_solver == 'gurobi_persistent':
16091603
self.mip_opt.set_callback(single_tree.LazyOACallback_gurobi)
1610-
self.solve_data = MindtPySolveData()
1611-
self.export_attributes()
1612-
self.mip_opt.solve_data = self.solve_data
1604+
self.mip_opt.mindtpy_object = self
16131605
self.mip_opt.config = self.config
16141606

16151607
##########################################################################################################################################
@@ -1641,8 +1633,6 @@ def solve_main(self, config):
16411633
self.mip, tee=config.mip_solver_tee, load_solutions=False, **mip_args
16421634
)
16431635
# update_attributes should be before load_from(main_mip_results), since load_from(main_mip_results) may fail.
1644-
if config.single_tree or config.use_tabu_list:
1645-
self.update_attributes()
16461636
if len(main_mip_results.solution) > 0:
16471637
self.mip.solutions.load_from(main_mip_results)
16481638
except (ValueError, AttributeError, RuntimeError):
@@ -1789,8 +1779,10 @@ def set_up_mip_solver(self, config, regularization_problem=False):
17891779
# determine if persistent solver is called.
17901780
if isinstance(self.mip_opt, PersistentSolver):
17911781
self.mip_opt.set_instance(self.mip, symbolic_solver_labels=True)
1792-
if config.single_tree or config.use_tabu_list:
1793-
self.export_attributes()
1782+
if config.single_tree:
1783+
self.set_up_lazy_OA_callback()
1784+
if config.use_tabu_list:
1785+
self.set_up_tabulist_callback()
17941786
mip_args = dict(config.mip_solver_args)
17951787
if config.mip_solver in {
17961788
'cplex',
@@ -2251,14 +2243,6 @@ def setup_regularization_main(self, config):
22512243
+ config.level_coef * self.dual_bound
22522244
)
22532245

2254-
def export_attributes(self):
2255-
for name, val in self.__dict__.items():
2256-
setattr(self.solve_data, name, val)
2257-
2258-
def update_attributes(self):
2259-
for name, val in self.solve_data.__dict__.items():
2260-
self.__dict__[name] = val
2261-
22622246
def update_result(self):
22632247
if self.objective_sense == minimize:
22642248
self.results.problem.lower_bound = self.dual_bound
@@ -2699,14 +2683,6 @@ def initialize_subsolvers(self):
26992683
self.nlp_opt = SolverFactory(config.nlp_solver)
27002684
self.feasibility_nlp_opt = SolverFactory(config.nlp_solver)
27012685

2702-
# determine if persistent solver is called.
2703-
# if isinstance(mainopt, PersistentSolver):
2704-
# mainopt.set_instance(self.mip, symbolic_solver_labels=True)
2705-
if config.single_tree:
2706-
self.set_up_lazy_OA_callback()
2707-
if config.use_tabu_list:
2708-
self.set_up_tabulist_callback()
2709-
27102686
set_solver_mipgap(self.mip_opt, config.mip_solver, config)
27112687
set_solver_mipgap(
27122688
self.regularization_mip_opt, config.mip_regularization_solver, config
@@ -2756,7 +2732,7 @@ def set_appsi_solver_update_config(self):
27562732
if config.mip_solver in {'appsi_cplex', 'appsi_gurobi', 'appsi_highs'}:
27572733
# mip main problem
27582734
self.mip_opt.update_config.check_for_new_or_removed_constraints = True
2759-
self.mip_opt.update_config.check_for_new_or_removed_vars = True # TODO
2735+
self.mip_opt.update_config.check_for_new_or_removed_vars = True
27602736
self.mip_opt.update_config.check_for_new_or_removed_params = False
27612737
self.mip_opt.update_config.check_for_new_objective = True
27622738
self.mip_opt.update_config.update_constraints = True

0 commit comments

Comments
 (0)