Skip to content

Commit

Permalink
improve the LDSDA implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ZedongPeng committed Feb 5, 2024
1 parent 0b93e7c commit 5cc9a4b
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions pyomo/contrib/gdpopt/ldsda.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ def _solve_gdp(self, model, config):
add_transformed_boolean_variable_list(self.working_model_util_block)

self._log_header(logger)
self.working_model_external_var_info_list = self.get_external_information(
self.working_model_util_block, config
)
self.get_external_information(self.working_model_util_block, config)
self.directions = self.get_directions(self.number_of_external_variables, config)
self.best_direction = None
self.current_point = config.starting_point
Expand All @@ -133,14 +131,14 @@ def _solve_gdp(self, model, config):
if not hasattr(self.working_model_util_block, 'BigM'):
self.working_model_util_block.BigM = Suffix()

locally_optimal = False
# Solve the initial point
self.fix_disjunctions_with_external_var(
self.working_model_util_block, self.current_point
)
_ = self._solve_rnGDP_subproblem(self.working_model, config, 'Initial point')

# Main loop
locally_optimal = False
while not locally_optimal:
self.iteration += 1
if self.any_termination_criterion_met(config):
Expand Down Expand Up @@ -296,15 +294,13 @@ def get_directions(self, dimension, config):
directions.remove((0,) * dimension)
return directions

def check_valid_neighbor(self, neighbor, external_var_info_list):
def check_valid_neighbor(self, neighbor):
"""Function that checks if a given neighbor is valid.
Parameters
----------
neighbor : list
the neighbor
external_var_info_list : list
the list of the external variable information
the neighbor to be checked
Returns
-------
Expand All @@ -317,7 +313,7 @@ def check_valid_neighbor(self, neighbor, external_var_info_list):
external_var_value >= external_var_info.LB
and external_var_value <= external_var_info.UB
for external_var_value, external_var_info in zip(
neighbor, external_var_info_list
neighbor, self.working_model_util_block.external_var_info_list
)
):
return True
Expand All @@ -340,9 +336,7 @@ def neighbor_search(self, model, config):
self.best_direction = None
for direction in self.directions:
neighbor = tuple(map(sum, zip(self.current_point, direction)))
if self.check_valid_neighbor(
neighbor, self.working_model_util_block.external_var_info_list
):
if self.check_valid_neighbor(neighbor):
self.fix_disjunctions_with_external_var(
self.working_model_util_block, neighbor
)
Expand Down Expand Up @@ -370,16 +364,17 @@ def line_search(self, model, config):
primal_improved = True
while primal_improved:
next_point = tuple(map(sum, zip(self.current_point, self.best_direction)))
if not self.check_valid_neighbor(
next_point, self.working_model_util_block.external_var_info_list
):
if self.check_valid_neighbor(next_point):
self.fix_disjunctions_with_external_var(
self.working_model_util_block, next_point
)
primal_improved = self._solve_rnGDP_subproblem(
model, config, 'Line search'
)
if primal_improved:
self.current_point = next_point
else:
break
self.fix_disjunctions_with_external_var(
self.working_model_util_block, next_point
)
primal_improved = self._solve_rnGDP_subproblem(model, config, 'Line search')
if primal_improved:
self.current_point = next_point
print("Line search finished.")

def handle_subproblem_result(
Expand Down

0 comments on commit 5cc9a4b

Please sign in to comment.