Skip to content

Commit

Permalink
redesign initialize_feas_subproblem function
Browse files Browse the repository at this point in the history
  • Loading branch information
ZedongPeng committed Dec 7, 2023
1 parent 3d1db13 commit 7e69413
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pyomo/contrib/mindtpy/algorithm_base_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -2629,7 +2629,7 @@ def initialize_mip_problem(self):

self.fixed_nlp = self.working_model.clone()
TransformationFactory('core.fix_integer_vars').apply_to(self.fixed_nlp)
initialize_feas_subproblem(self.fixed_nlp, config)
initialize_feas_subproblem(self.fixed_nlp, config.feasibility_norm)

def initialize_subsolvers(self):
"""Initialize and set options for MIP and NLP subsolvers."""
Expand Down
14 changes: 7 additions & 7 deletions pyomo/contrib/mindtpy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,22 @@ def calc_jacobians(model, differentiate_mode):
return jacobians


def initialize_feas_subproblem(m, config):
def initialize_feas_subproblem(m, feasibility_norm):
"""Adds feasibility slack variables according to config.feasibility_norm (given an infeasible problem).
Defines the objective function of the feasibility subproblem.
Parameters
----------
m : Pyomo model
The feasbility NLP subproblem.
config : ConfigBlock
The specific configurations for MindtPy.
feasibility_norm : String
The norm used to generate the objective function.
"""
MindtPy = m.MindtPy_utils
# generate new constraints
for i, constr in enumerate(MindtPy.nonlinear_constraint_list, 1):
if constr.has_ub():
if config.feasibility_norm in {'L1', 'L2'}:
if feasibility_norm in {'L1', 'L2'}:
MindtPy.feas_opt.feas_constraints.add(
constr.body - constr.upper <= MindtPy.feas_opt.slack_var[i]
)
Expand All @@ -94,7 +94,7 @@ def initialize_feas_subproblem(m, config):
constr.body - constr.upper <= MindtPy.feas_opt.slack_var
)
if constr.has_lb():
if config.feasibility_norm in {'L1', 'L2'}:
if feasibility_norm in {'L1', 'L2'}:
MindtPy.feas_opt.feas_constraints.add(
constr.body - constr.lower >= -MindtPy.feas_opt.slack_var[i]
)
Expand All @@ -103,11 +103,11 @@ def initialize_feas_subproblem(m, config):
constr.body - constr.lower >= -MindtPy.feas_opt.slack_var
)
# Setup objective function for the feasibility subproblem.
if config.feasibility_norm == 'L1':
if feasibility_norm == 'L1':
MindtPy.feas_obj = Objective(
expr=sum(s for s in MindtPy.feas_opt.slack_var.values()), sense=minimize
)
elif config.feasibility_norm == 'L2':
elif feasibility_norm == 'L2':
MindtPy.feas_obj = Objective(
expr=sum(s * s for s in MindtPy.feas_opt.slack_var.values()), sense=minimize
)
Expand Down

0 comments on commit 7e69413

Please sign in to comment.