def call_solver(solver,instance,options,solver_options,relaxed=False, set_instance=True): tee = options.output_solver_logs if not tee: egret_logger.setLevel(logging.WARNING) symbolic_solver_labels = options.symbolic_solver_labels mipgap = options.ruc_mipgap solver_options_dict = dict() for s in solver_options: opts = s.split(' ') for opt in opts: option, val = opt.split('=') try: val = float(val) except: pass solver_options_dict[option] = val m, results, solver = _solve_unit_commitment(instance, solver, mipgap, None, tee, symbolic_solver_labels, solver_options_dict, None, relaxed, set_instance=set_instance) md = _save_uc_results(m, relaxed) if hasattr(results, 'egret_metasolver_status'): time = results.egret_metasolver_status['time'] else: time = results.solver.wallclock_time return md, time, solver
def call_solver(solver, instance, options, solver_options, relaxed=False, set_instance=True): tee = options.output_solver_logs if not tee: egret_logger.setLevel(logging.WARNING) symbolic_solver_labels = options.symbolic_solver_labels mipgap = options.ruc_mipgap m, results, solver = _solve_unit_commitment(instance, solver, mipgap, None, tee, symbolic_solver_labels, solver_options, None, relaxed, set_instance=set_instance) md = _save_uc_results(m, relaxed) if hasattr(results, 'egret_metasolver_status'): time = results.egret_metasolver_status['time'] else: time = results.solver.wallclock_time return md, time, solver
def write_solution(spcomm, opt_dict, solution_dir): from mpisppy.cylinders.xhatshufflelooper_bounder import XhatShuffleInnerBound from mpisppy.extensions.xhatclosest import XhatClosest from mpisppy.opt.ph import PH if spcomm.rank_global == 0: if spcomm.last_ib_idx is None: best_rank_inter = -1 print("No incumbent solution to print") else: best_rank_inter = spcomm.last_ib_idx else: best_rank_inter = None best_rank_inter = spcomm.fullcomm.bcast(best_rank_inter, root=0) if spcomm.rank_inter != best_rank_inter: # Nothing to do return ## else this spoke/hub is the winner! # do some checks, to make sure the solution we print will be nonantipative if best_rank_inter != 0: assert opt_dict["spoke_class"] in (XhatShuffleInnerBound, ) else: # this is the hub, TODO: also could check for XhatSpecific assert opt_dict["opt_class"] in (PH, ) assert XhatClosest in opt_dict["opt_kwargs"]["PH_extension_kwargs"][ "ext_classes"] assert "keep_solution" in opt_dict["opt_kwargs"]["PHoptions"][ "xhat_closest_options"] assert opt_dict["opt_kwargs"]["PHoptions"]["xhat_closest_options"][ "keep_solution"] is True ## if we've passed the above checks, the scenarios should have the tree solution ## make solution dir if it doesn't exist, ## but only on rank 0 if spcomm.rank_intra == 0: if not os.path.exists(solution_dir): os.makedirs(solution_dir) spcomm.intracomm.Barrier() for sname, s in spcomm.opt.local_scenarios.items(): file_name = os.path.join(solution_dir, sname + '.json') mds = uc._save_uc_results(s, relaxed=False) mds.write(file_name) return
def scenario_tree_solution_writer(solution_dir, sname, scenario, bundling): file_name = os.path.join(solution_dir, sname + '.json') mds = uc._save_uc_results(scenario, relaxed=False) mds.write(file_name)