Skip to content

Commit d5d6afd

Browse files
authored
Merge pull request #8 from keeks05/pr-402
Pr 402
2 parents 7441080 + b211318 commit d5d6afd

File tree

6 files changed

+817
-58
lines changed

6 files changed

+817
-58
lines changed

examples/farmer/ag_gurobipy.bash

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
SOLVERNAME=gurobi
4+
5+
# mpiexec -np 1 python -m mpi4py agnostic_gurobipy_cylinders.py --num-scens 3 --default-rho 1 --solver-name $SOLVERNAME --max-iterations=10 --rel-gap 0.01 --display-progress
6+
7+
# mpiexec -np 2 python -m mpi4py agnostic_gurobipy_cylinders.py --num-scens 3 --default-rho 1 --solver-name $SOLVERNAME --max-iterations=10 --xhatshuffle --rel-gap 0.01 --display-progress
8+
9+
mpiexec -np 3 python -m mpi4py agnostic_gurobipy_cylinders.py --num-scens 3 --default-rho 1 --solver-name $SOLVERNAME --max-iterations=10 --xhatshuffle --lagrangian --rel-gap 0.01 --display-progress
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# This software is distributed under the 3-clause BSD License.
2+
3+
import farmer_gurobipy_agnostic
4+
from mpisppy.spin_the_wheel import WheelSpinner
5+
import mpisppy.utils.cfg_vanilla as vanilla
6+
import mpisppy.utils.config as config
7+
import mpisppy.agnostic.agnostic as agnostic
8+
9+
def _farmer_parse_args():
10+
# create a config object and parse JUST FOR TESTING
11+
cfg = config.Config()
12+
13+
farmer_gurobipy_agnostic.inparser_adder(cfg)
14+
15+
cfg.popular_args()
16+
cfg.two_sided_args()
17+
cfg.ph_args()
18+
cfg.aph_args()
19+
cfg.xhatlooper_args()
20+
cfg.fwph_args()
21+
cfg.lagrangian_args()
22+
cfg.lagranger_args()
23+
cfg.xhatshuffle_args()
24+
25+
cfg.parse_command_line("farmer_gurobipy_agnostic_cylinders")
26+
return cfg
27+
28+
29+
if __name__ == "__main__":
30+
print("begin ad hoc main for agnostic.py")
31+
32+
cfg = _farmer_parse_args()
33+
Ag = agnostic.Agnostic(farmer_gurobipy_agnostic, cfg)
34+
35+
scenario_creator = Ag.scenario_creator
36+
scenario_denouement = farmer_gurobipy_agnostic.scenario_denouement # should we go though Ag?
37+
all_scenario_names = ['scen{}'.format(sn) for sn in range(cfg.num_scens)]
38+
39+
# Things needed for vanilla cylinders
40+
beans = (cfg, scenario_creator, scenario_denouement, all_scenario_names)
41+
42+
# Vanilla PH hub
43+
hub_dict = vanilla.ph_hub(*beans,
44+
scenario_creator_kwargs=None, # kwargs in Ag not here
45+
ph_extensions=None,
46+
ph_converger=None,
47+
rho_setter = None)
48+
# pass the Ag object via options...
49+
hub_dict["opt_kwargs"]["options"]["Ag"] = Ag
50+
51+
# xhat shuffle bound spoke
52+
if cfg.xhatshuffle:
53+
xhatshuffle_spoke = vanilla.xhatshuffle_spoke(*beans, scenario_creator_kwargs=None)
54+
xhatshuffle_spoke["opt_kwargs"]["options"]["Ag"] = Ag
55+
if cfg.lagrangian:
56+
lagrangian_spoke = vanilla.lagrangian_spoke(*beans, scenario_creator_kwargs=None)
57+
lagrangian_spoke["opt_kwargs"]["options"]["Ag"] = Ag
58+
59+
list_of_spoke_dict = list()
60+
if cfg.xhatshuffle:
61+
list_of_spoke_dict.append(xhatshuffle_spoke)
62+
if cfg.lagrangian:
63+
list_of_spoke_dict.append(lagrangian_spoke)
64+
65+
wheel = WheelSpinner(hub_dict, list_of_spoke_dict)
66+
wheel.spin()
67+
68+
write_solution = False
69+
if write_solution:
70+
wheel.write_first_stage_solution('farmer_plant.csv')
71+
wheel.write_first_stage_solution('farmer_cyl_nonants.npy',
72+
first_stage_solution_writer=sputils.first_stage_nonant_npy_serializer)
73+
wheel.write_tree_solution('farmer_full_solution')
74+

0 commit comments

Comments
 (0)