def main(): scenario_creator_kwargs = { 'solar_filename' : 'solar.csv', 'use_LP' : False, 'lam' : 467, # Dual weight for dualized chance constr } PH_options = { 'solvername' : 'gurobi', 'PHIterLimit' : 250, 'defaultPHrho' : 1e-1, 'convthresh' : 1e-3, 'verbose' : False, 'display_timing' : False, 'display_progress' : True, 'iter0_solver_options' : dict(), 'iterk_solver_options' : dict(), 'tee-rank0-solves': False, } # extensions? names = ['s' + str(i) for i in range(50)] ph = PH(PH_options, names, scenario_creator, scenario_denouement, scenario_creator_kwargs=scenario_creator_kwargs) ph.ph_main() res = get_solutions(ph) for (sname, sol) in res.items(): z = sol['z'] print(sname, z)
def write_test(): scen_count = 3 scenario_creator = uc_funcs.pysp2_callback scenario_denouement = nonsense scenario_rhosetter = uc_funcs.scenario_rhos PH_options = { 'solvername': 'gurobi', 'PHIterLimit': 2, 'defaultPHrho': 1, 'convthresh': 1e-6, 'verbose': False, 'display_timing': False, 'display_progress': False, 'iter0_solver_options': dict(), 'iterk_solver_options': dict(), 'W_fname': 'david/weights.csv', 'separate_W_files': False, 'Xbar_fname': 'somexbars.csv', 'extensions': WXBarReader, 'rho_setter': scenario_rhosetter, } names = ['Scenario' + str(i + 1) for i in range(scen_count)] ph = PH(PH_options, names, scenario_creator, scenario_denouement) conv, obj, bound = ph.ph_main()
def read_test(): scen_count = 3 scenario_creator = uc_funcs.pysp2_callback scenario_denouement = nonsense scenario_rhosetter = uc_funcs.scenario_rhos os.environ[uc_funcs.UC_NUMSCENS_ENV_VAR] = 'examples/uc/' + str(scen_count) PH_options = { 'solvername': 'gurobi', 'PHIterLimit': 2, 'defaultPHrho': 1, 'convthresh': 1e-6, 'verbose': False, 'display_timing': False, 'display_progress': False, 'iter0_solver_options': dict(), 'iterk_solver_options': dict(), 'init_W_fname': 'david/weights.csv', # Path to the weight files 'init_separate_W_files': False, 'init_Xbar_fname': 'david/somexbars.csv', } names = ['Scenario' + str(i + 1) for i in range(scen_count)] ph = PH(PH_options, names, scenario_creator, scenario_denouement) conv, obj, bound = ph.ph_main(PH_extensions=WXBarReader, rho_setter=scenario_rhosetter)
def main(): scen_count = 25 scenario_creator = uc_funcs.pysp2_callback scenario_denouement = empty_denouement scenario_rhosetter = uc_funcs.scenario_rhos scenario_fixer = uc_funcs.id_fix_list_fct os.environ[uc_funcs.UC_NUMSCENS_ENV_VAR] = '../../uc/' + str(scen_count) fixer_options = { 'verbose': False, 'boundtol': 1e-2, 'id_fix_list_fct': scenario_fixer, } rho_setter_kwargs = { 'rho_scale_factor': 1.0, } PH_options = { 'solvername': 'gurobi_persistent', 'PHIterLimit': 25, 'defaultPHrho': 1, 'convthresh': 1e-6, 'verbose': False, 'display_timing': False, 'display_progress': False, 'iter0_solver_options': dict(), 'iterk_solver_options': dict(), 'rho_setter_kwargs': rho_setter_kwargs, # Comment either of these two lines out to disable fixing/initialization # 'fixeroptions': fixer_options, # 'init_W_fname': 'uc_25.5itr.weights', # 'init_Xbar_fname': 'uc_25.5itr_nobundle.xbar', } names = ['Scenario' + str(i+1) for i in range(scen_count)] ph = PH(PH_options, names, scenario_creator, scenario_denouement) conv, obj, bound = ph.ph_main(PH_extensions=UCExtension, rho_setter=scenario_rhosetter) print('Objective:', obj)
def main(): solver_name = 'gurobi' fname = 'data/network-10-20-L-01.dat' num_scen = int(fname.split('-')[2]) scenario_names = ['Scen' + str(i) for i in range(num_scen)] scenario_creator_kwargs = {"path": fname} ''' Now solve with PH to see what happens (very little, I imagine) ''' PH_options = { 'solvername': 'gurobi_persistent', 'PHIterLimit': 20, 'defaultPHrho': 10000, 'convthresh': 1e-8, 'verbose': False, 'display_progress': False, 'display_timing': False, 'iter0_solver_options': dict(), 'iterk_solver_options': dict(), 'bundles_per_rank': 2, # 0 = no bundles } ph = PH( PH_options, scenario_names, scenario_creator, scenario_denouement, PH_extensions=NetworkDesignTracker, scenario_creator_kwargs=scenario_creator_kwargs, ) conv, obj, triv = ph.ph_main() # Obj includes prox (only ok if we find a non-ant soln) if (conv < 1e-8): print(f'Objective value: {obj:.2f}') else: print('Did not find a non-anticipative solution ' f'(conv = {conv:.1e})') ph.post_solve_bound(verbose=False)
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( options=phoptions, all_scenario_names=farmer.all_scenario_names, scenario_creator=farmer.scenario_creator, scenario_denouement=farmer.scenario_denouement, ) ph.ph_main() ef = sputils.create_EF(farmer.all_scenario_names, farmer.scenario_creator) solver = pyo.SolverFactory(solver_name) if 'persistent' in solver_name: solver.set_instance(ef, symbolic_solver_labels=True) solver.solve(tee=True) else: solver.solve( ef, tee=True, symbolic_solver_labels=True,
def main(): scen_count = 3 integer = False true = -108390 scenario_creator = gf.scenario_creator scenario_denouement = gf.scenario_denouement cb_data = {'use_integer': integer} PH_options_base = { 'solvername': 'gurobi_persistent', 'PHIterLimit': 1500, 'defaultPHrho': 1.5, 'convthresh': 1e-6, 'verbose': False, 'display_timing': False, 'display_progress': False, 'iter0_solver_options': { 'mipgap': 1e-4 }, 'iterk_solver_options': { 'mipgap': 1e-4 }, 'use_lagrangian': False, } if PH_options_base['solvername'].endswith('persistent'): print('Using persistent solver') else: print('Using standard solver') inst = 'farmer/intfarmer_3' if integer else 'farmer/farmer_3' schema = { '0-init': dict(), '*-init-w': { 'init_W_fname': f'{inst}.opt.weights' }, '*-init-x': { 'init_Xbar_fname': f'{inst}.opt.xbar' }, '*-init': { 'init_W_fname': f'{inst}.opt.weights', 'init_Xbar_fname': f'{inst}.opt.xbar' }, '5/1-init-w': { 'init_W_fname': f'{inst}.5itr.weights' }, '5/1-init-x': { 'init_Xbar_fname': f'{inst}.5itr.xbar' }, '5/1-init': { 'init_W_fname': f'{inst}.5itr.weights', 'init_Xbar_fname': f'{inst}.5itr.xbar' }, } names = ['Scenario' + str(i) for i in range(scen_count)] for rho in [0.5, 0.75, 1.0, 1.25, 1.50]: for (name, opts) in schema.items(): PH_options = {**PH_options_base, **opts} PH_options['defaultPHrho'] = rho ph = PH(PH_options, names, scenario_creator, scenario_denouement) conv, obj, bound = ph.ph_main(PH_extensions=FarmerExtension, cb_data=cb_data) itr = ph._PHIter gap = 100 * (obj - true) / abs(true) print(f'{name},{rho},{itr},{gap}') if (ph.rank == 0): with open('continuous_farmer', 'a') as f: f.write(f'{name},{rho},{itr},{gap}\n')
def main(): def nonsense(arg1, arg2, arg3): pass inst = 'sslp_5_25_50' sslp_path = os.path.dirname(ref_model.__file__) path = os.sep.join([sslp_path, 'data', inst, 'scenariodata']) scen_count = int(inst.split('_')[-1]) scenario_creator = ref_model.scenario_creator scenario_denouement = ref_model.scenario_denouement PH_options_base = { 'solvername': 'gurobi_persistent', 'PHIterLimit': 500, 'defaultPHrho': 20, 'convthresh': 1e-6, 'verbose': False, 'display_timing': False, 'display_progress': False, 'iter0_solver_options': dict(), 'iterk_solver_options': dict(), 'use_lagrangian': False, } names = ['Scenario' + str(i + 1) for i in range(scen_count)] true = -121.6 schema = { '0-init': dict(), '*-init-w': { 'init_W_fname': f'sslp/{inst}.opt.weights' }, '*-init-x': { 'init_Xbar_fname': f'sslp/{inst}.opt.xbar' }, '*-init': { 'init_W_fname': f'sslp/{inst}.opt.weights', 'init_Xbar_fname': f'sslp/{inst}.opt.xbar' }, '5/30-init-w': { 'init_W_fname': f'sslp/{inst}.5-30.weights' }, '5/30-init-x': { 'init_Xbar_fname': f'sslp/{inst}.5-30.xbar' }, '5/30-init': { 'init_W_fname': f'sslp/{inst}.5-30.weights', 'init_Xbar_fname': f'sslp/{inst}.5-30.xbar' }, } for rho in [10, 20, 30, 40, 50]: for (name, opts) in schema.items(): PH_options = {**PH_options_base, **opts} PH_options['defaultPHrho'] = rho ph = PH(PH_options, names, scenario_creator, scenario_denouement) conv, obj, bound = ph.ph_main(PH_extensions=SSLPExtension, cb_data=path) itr = ph._PHIter gap = 100 * (obj - true) / abs(true) if (ph.rank == 0): with open('tmp', 'a') as f: f.write(f'{name},{rho},{itr},{gap}\n') print('Gap =', gap)