forked from Pyomo/mpi-sppy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsslp_cylinders.py
149 lines (124 loc) · 5.16 KB
/
sslp_cylinders.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
###############################################################################
# mpi-sppy: MPI-based Stochastic Programming in PYthon
#
# Copyright (c) 2024, Lawrence Livermore National Security, LLC, Alliance for
# Sustainable Energy, LLC, The Regents of the University of California, et al.
# All rights reserved. Please see the files COPYRIGHT.md and LICENSE.md for
# full copyright and license information.
###############################################################################
import sslp
from mpisppy.spin_the_wheel import WheelSpinner
from mpisppy.extensions.fixer import Fixer
from mpisppy.utils import config
import mpisppy.utils.cfg_vanilla as vanilla
def _parse_args():
cfg = config.Config()
cfg.popular_args()
cfg.num_scens_optional()
cfg.ph_args()
cfg.add_to_config("instance_name",
description="sslp instance name (e.g., sslp_15_45_10)",
domain=str,
default=None,
argparse_args = {"required": True})
cfg.two_sided_args()
cfg.fixer_args()
cfg.xhatlooper_args()
cfg.fwph_args()
cfg.lagrangian_args()
cfg.xhatshuffle_args()
cfg.subgradient_bounder_args()
cfg.reduced_costs_args()
cfg.coeff_rho_args()
cfg.integer_relax_then_enforce_args()
cfg.parse_command_line("sslp_cylinders")
return cfg
def main():
cfg = _parse_args()
inst = cfg.instance_name
num_scen = int(inst.split("_")[-1])
if cfg.num_scens is not None and cfg.num_scens != num_scen:
raise RuntimeError("Argument num-scens={} does not match the number "
"implied by instance name={} "
"\n(--num-scens is not needed for sslp)")
fwph = cfg.fwph
fixer = cfg.fixer
fixer_tol = cfg.fixer_tol
xhatlooper = cfg.xhatlooper
xhatshuffle = cfg.xhatshuffle
lagrangian = cfg.lagrangian
subgradient = cfg.subgradient
reduced_costs = cfg.reduced_costs
if cfg.default_rho is None:
raise RuntimeError("The --default-rho option must be specified")
scenario_creator_kwargs = {"data_dir": f"{sslp.__file__[:-8]}/data/{inst}/scenariodata"}
scenario_creator = sslp.scenario_creator
scenario_denouement = sslp.scenario_denouement
all_scenario_names = [f"Scenario{i+1}" for i in range(num_scen)]
if fixer:
ph_ext = Fixer
else:
ph_ext = None
# Things needed for vanilla cylinders
beans = (cfg, scenario_creator, scenario_denouement, all_scenario_names)
# Vanilla PH hub
hub_dict = vanilla.ph_hub(*beans,
scenario_creator_kwargs=scenario_creator_kwargs,
ph_extensions=ph_ext,
rho_setter = None)
if fixer:
hub_dict["opt_kwargs"]["options"]["fixeroptions"] = {
"verbose": False,
"boundtol": fixer_tol,
"id_fix_list_fct": sslp.id_fix_list_fct,
}
if reduced_costs:
vanilla.add_reduced_costs_fixer(hub_dict, cfg)
if cfg.coeff_rho:
vanilla.add_coeff_rho(hub_dict, cfg)
if cfg.integer_relax_then_enforce:
vanilla.add_integer_relax_then_enforce(hub_dict, cfg)
# FWPH spoke
if fwph:
fw_spoke = vanilla.fwph_spoke(*beans, scenario_creator_kwargs=scenario_creator_kwargs)
# Need to fix FWPH to support extensions
# if cfg.coeff_rho:
# vanilla.add_coeff_rho(fw_spoke, cfg)
# Standard Lagrangian bound spoke
if lagrangian:
lagrangian_spoke = vanilla.lagrangian_spoke(*beans,
scenario_creator_kwargs=scenario_creator_kwargs,
rho_setter = None)
if subgradient:
subgradient_spoke = vanilla.subgradient_spoke(*beans,
scenario_creator_kwargs=scenario_creator_kwargs,
rho_setter = None)
if cfg.coeff_rho:
vanilla.add_coeff_rho(subgradient_spoke, cfg)
# xhat looper bound spoke
if xhatlooper:
xhatlooper_spoke = vanilla.xhatlooper_spoke(*beans, scenario_creator_kwargs=scenario_creator_kwargs)
# xhat shuffle bound spoke
if xhatshuffle:
xhatshuffle_spoke = vanilla.xhatshuffle_spoke(*beans, scenario_creator_kwargs=scenario_creator_kwargs)
# reduced costs spoke
if reduced_costs:
reduced_costs_spoke = vanilla.reduced_costs_spoke(*beans,
scenario_creator_kwargs=scenario_creator_kwargs,
rho_setter = None)
list_of_spoke_dict = list()
if fwph:
list_of_spoke_dict.append(fw_spoke)
if lagrangian:
list_of_spoke_dict.append(lagrangian_spoke)
if subgradient:
list_of_spoke_dict.append(subgradient_spoke)
if xhatlooper:
list_of_spoke_dict.append(xhatlooper_spoke)
if xhatshuffle:
list_of_spoke_dict.append(xhatshuffle_spoke)
if reduced_costs:
list_of_spoke_dict.append(reduced_costs_spoke)
WheelSpinner(hub_dict, list_of_spoke_dict).spin()
if __name__ == "__main__":
main()