class Test_sizes_abstract(unittest.TestCase): """ Test PySPModel using abstract sizes case """ def setUp(self): self.pysp_sizes3 = PySPModel( os.path.join(sizes_dir, 'ReferenceModel.py'), os.path.join(sizes_dir, 'SIZES3', 'ScenarioStructure.dat')) def tearDown(self): self.pysp_sizes3.close() def test_ph_constructor(self): pysp_sizes = self.pysp_sizes3 options = _get_ph_base_options() options['PHIterLimit'] = 0 ph = mpisppy.opt.ph.PH( options, pysp_sizes.all_scenario_names, pysp_sizes.scenario_creator, lambda *args: None, ) def test_ef_constructor(self): pysp_sizes = self.pysp_sizes3 options = {"solver": "cplex"} ef = mpisppy.opt.ef.ExtensiveForm( options, pysp_sizes.all_scenario_names, pysp_sizes.scenario_creator, ) @unittest.skipIf(not solver_available, "no solver is available") def test_ef_solve(self): pysp_sizes = self.pysp_sizes3 options = _get_ph_base_options() options = {"solver": options["solvername"]} ef = mpisppy.opt.ef.ExtensiveForm( options, pysp_sizes.all_scenario_names, pysp_sizes.scenario_creator, ) results = ef.solve_extensive_form(tee=False) sig2eobj = round_pos_sig(pyo.value(ef.ef.EF_Obj), 2) self.assertEqual(220000.0, sig2eobj)
def main(): args = _parse_args() with_xhatshuffle = args.with_xhatshuffle with_lagrangian = args.with_lagrangian # This is multi-stage, so we need to supply node names hydro = PySPModel("./PySP/models/", "./PySP/nodedata/") rho_setter = None # Things needed for vanilla cylinders beans = (args, hydro.scenario_creator, hydro.scenario_denouement, hydro.all_scenario_names) # Vanilla PH hub hub_dict = vanilla.ph_hub(*beans, ph_extensions=None, rho_setter=rho_setter, all_nodenames=hydro.all_nodenames) # Standard Lagrangian bound spoke if with_lagrangian: lagrangian_spoke = vanilla.lagrangian_spoke( *beans, rho_setter=rho_setter, all_nodenames=hydro.all_nodenames) if with_xhatshuffle: xhatshuffle_spoke = vanilla.xhatshuffle_spoke(*beans, hydro.all_nodenames) list_of_spoke_dict = list() if with_lagrangian: list_of_spoke_dict.append(lagrangian_spoke) if with_xhatshuffle: list_of_spoke_dict.append(xhatshuffle_spoke) wheel = WheelSpinner(hub_dict, list_of_spoke_dict) wheel.spin() if wheel.global_rank == 0: # we are the reporting hub rank print( f"BestInnerBound={wheel.BestInnerBound} and BestOuterBound={wheel.BestOuterBound}" ) if write_solution: wheel.write_first_stage_solution('hydro_first_stage.csv') wheel.write_tree_solution('hydro_full_solution') hydro.close()
def main(): args = _parse_args() with_xhatshuffle = args.with_xhatshuffle with_lagrangian = args.with_lagrangian # This is multi-stage, so we need to supply node names hydro = PySPModel("./PySP/models/", "./PySP/nodedata/") rho_setter = None # Things needed for vanilla cylinders beans = (args, hydro.scenario_creator, hydro.scenario_denouement, hydro.all_scenario_names) # Vanilla PH hub hub_dict = vanilla.ph_hub(*beans, ph_extensions=None, rho_setter = rho_setter, all_nodenames=hydro.all_nodenames) # Standard Lagrangian bound spoke if with_lagrangian: lagrangian_spoke = vanilla.lagrangian_spoke(*beans, rho_setter = rho_setter, all_nodenames=hydro.all_nodenames) if with_xhatshuffle: xhatshuffle_spoke = vanilla.xhatshuffle_spoke(*beans, hydro.all_nodenames) list_of_spoke_dict = list() if with_lagrangian: list_of_spoke_dict.append(lagrangian_spoke) if with_xhatshuffle: list_of_spoke_dict.append(xhatshuffle_spoke) spcomm, opt_dict = sputils.spin_the_wheel(hub_dict, list_of_spoke_dict) if "hub_class" in opt_dict: # we are a hub rank if spcomm.opt.cylinder_rank == 0: # we are the reporting hub rank print("BestInnerBound={} and BestOuterBound={}".\ format(spcomm.BestInnerBound, spcomm.BestOuterBound)) if write_solution: sputils.write_spin_the_wheel_first_stage_solution(spcomm, opt_dict, 'hydro_first_stage.csv') sputils.write_spin_the_wheel_tree_solution(spcomm, opt_dict, 'hydro_full_solution') hydro.close()
def setUp(self): self.pysp_sizes3 = PySPModel( os.path.join(sizes_dir, 'ReferenceModel.py'), os.path.join(sizes_dir, 'SIZES3', 'ScenarioStructure.dat'))
_print_usage() sys.exit() elif int(sys.argv[1]) not in [3,10]: _print_usage() sys.exit() try: solver_avail = SolverFactory(sys.argv[2]).available() if not solver_avail: print(f"Cannot find solver {sys.argv[2]}") sys.exit() except: print(f"Cannot find solver {sys.argv[2]}") _print_usage() sys.exit() num_scen = int(sys.argv[1]) solver = sys.argv[2] sizes = PySPModel(scenario_creator='./models/ReferenceModel.py', tree_model=f'./SIZES{num_scen}/ScenarioStructure.dat', ) ef = ExtensiveForm(options={'solver':solver}, all_scenario_names=sizes.all_scenario_names, scenario_creator=sizes.scenario_creator, model_name='sizes_EF') ef.solve_extensive_form(tee=True)
sys.exit() solver_name = sys.argv[1] try: solver_avail = SolverFactory(solver_name).available() if not solver_avail: print(f"Cannot find solver {solver_name}") sys.exit() except: print(f"Cannot find solver {solver_name}") _print_usage() sys.exit() pref = os.path.join("..", "PySP", "abstract") farmer = PySPModel(model=os.path.join(pref, "ReferenceModel.py"), scenario_tree=os.path.join(pref, "ScenarioStructure.dat"), data_dir=pref) phoptions = { 'defaultPHrho': 1.0, 'solvername': solver_name, 'PHIterLimit': 50, 'convthresh': 0.01, 'verbose': False, 'display_progress': True, 'display_timing': False, 'iter0_solver_options': None, 'iterk_solver_options': None } ph = PH(
elif int(sys.argv[1]) not in [3,10]: _print_usage() sys.exit() try: solver_avail = SolverFactory(sys.argv[2]).available() if not solver_avail: print(f"Cannot find solver {sys.argv[2]}") sys.exit() except: print(f"Cannot find solver {sys.argv[2]}") _print_usage() sys.exit() num_scen = int(sys.argv[1]) solver = sys.argv[2] sizes = PySPModel(model='./models/ReferenceModel.py', scenario_tree=f'./SIZES{num_scen}/ScenarioStructure.dat', ) ef = ExtensiveForm(options={'solver':solver}, all_scenario_names=sizes.all_scenario_names, scenario_creator=sizes.scenario_creator, model_name='sizes_EF') ef.solve_extensive_form(tee=True) sizes.close()
if len(sys.argv) < 2: _print_usage() sys.exit() try: solver_avail = SolverFactory(sys.argv[1]).available() if not solver_avail: print(f"Cannot find solver {sys.argv[1]}") sys.exit() except: print(f"Cannot find solver {sys.argv[1]}") _print_usage() sys.exit() pref = os.path.join("..", "PySP") farmer = PySPModel(scenario_creator=os.path.join(pref, "concrete", "ReferenceModel.py"), tree_model=os.path.join(pref, "ScenarioStructure.dat")) phoptions = { 'defaultPHrho': 1.0, 'solvername': sys.argv[1], 'PHIterLimit': 50, 'convthresh': 0.01, 'verbose': False, 'display_progress': True, 'display_timing': False, 'iter0_solver_options': None, 'iterk_solver_options': None } ph = PH(
if len(sys.argv) < 2: _print_usage() sys.exit() try: solver_avail = SolverFactory(sys.argv[1]).available() if not solver_avail: print(f"Cannot find solver {sys.argv[1]}") sys.exit() except: print(f"Cannot find solver {sys.argv[1]}") _print_usage() sys.exit() farmer = PySPModel(scenario_creator='./PySP/concrete/ReferenceModel.py', tree_model='./PySP/ScenarioStructure.dat') phoptions = { 'defaultPHrho': 1.0, 'solvername': sys.argv[1], 'PHIterLimit': 50, 'convthresh': 0.01, 'verbose': False, 'display_progress': True, 'display_timing': False, 'iter0_solver_options': None, 'iterk_solver_options': None } ph = PH( PHoptions=phoptions,
if len(sys.argv) < 2: _print_usage() sys.exit() try: solver_avail = SolverFactory(sys.argv[1]).available() if not solver_avail: print(f"Cannot find solver {sys.argv[1]}") sys.exit() except: print(f"Cannot find solver {sys.argv[1]}") _print_usage() sys.exit() pref = os.path.join("..", "PySP") farmer = PySPModel(model=os.path.join(pref, "concrete", "ReferenceModel.py"), scenario_tree=os.path.join(pref, "ScenarioStructure.dat")) phoptions = { 'defaultPHrho': 1.0, 'solvername': sys.argv[1], 'PHIterLimit': 50, 'convthresh': 0.01, 'verbose': False, 'display_progress': True, 'display_timing': False, 'iter0_solver_options': None, 'iterk_solver_options': None } ph = PH( options=phoptions,