Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust Routine for Loading DR Polishing Model Solutions to Master Model #2700

Merged
merged 3 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions pyomo/contrib/pyros/master_problem_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,10 @@ def get_state_vars(model, iterations):
"""
iter_state_var_map = dict()
for itn in iterations:
fsv_set = ComponentSet(
model.scenarios[itn, 0].util.first_stage_variables)
state_vars = list()
for blk in model.scenarios[itn, :]:
ssv_set = ComponentSet(blk.util.second_stage_variables)
state_vars.extend(
v for v in blk.component_data_objects(
Var,
active=True,
descend_into=True,
sort=SortComponents.deterministic, # guarantee order
)
if v not in fsv_set and v not in ssv_set
)
state_vars = [
var for blk in model.scenarios[itn, :]
for var in blk.util.state_vars
]
iter_state_var_map[itn] = state_vars

return iter_state_var_map
Expand Down Expand Up @@ -466,10 +456,9 @@ def minimize_dr_vars(model_data, config):
polishing_model.scenarios[idx].util.second_stage_variables,
)
sv_zip = zip(
get_state_vars(model_data.master_model, [idx[0]])[idx[0]],
get_state_vars(polishing_model, [idx[0]])[idx[0]],
blk.util.state_vars,
polishing_model.scenarios[idx].util.state_vars,
)

for master_ssv, polish_ssv in ssv_zip:
master_ssv.set_value(value(polish_ssv))
for master_sv, polish_sv in sv_zip:
Expand Down
1 change: 1 addition & 0 deletions pyomo/contrib/pyros/tests/test_grcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3406,6 +3406,7 @@ def test_minimize_dr_norm(self):
m.working_model.util.second_stage_variables = [m.z1, m.z2]
m.working_model.util.uncertain_params = [m.p1, m.p2]
m.working_model.util.first_stage_variables = []
m.working_model.util.state_vars = []

m.working_model.util.first_stage_variables = []
config = Block()
Expand Down