Esempio n. 1
0
def _main_body(args, model_module):
    # body of main, pulled out for testing
    solver_options = option_string_to_dict(args.solver_options)

    bfs = args.branching_factors
    solver_name = args.solver_name
    num_samples = args.num_samples

    ama_options = {
        "EF-mstage": True,
        "EF_solver_name": solver_name,
        "EF_solver_options": solver_options,
        "branching_factors": bfs,
        "args": args,
    }

    return run_samples(ama_options, args, model_module)
Esempio n. 2
0
 def test_lagrangian_bound(self):
     """ Make sure the lagrangian bound is at least a bound
     """
     from mpisppy.extensions.xhatlooper import XhatLooper
     PHoptions = self._copy_of_base_options()
     PHoptions["PHIterLimit"] = 1
     PHoptions["xhat_looper_options"] =  {"xhat_solver_options":\
                                          PHoptions["iterk_solver_options"],
                                          "scen_limit": 3}
     ph = mpisppy.opt.ph.PH(PHoptions,
                            self.all3_scenario_names,
                            scenario_creator,
                            scenario_denouement,
                            cb_data=3,
                            PH_extensions=XhatLooper)
     conv, basic_obj, tbound = ph.ph_main()
     xhatobj = ph.extobject._xhat_looper_obj_final
     dopts = sputils.option_string_to_dict("mipgap=0.0001")
     objbound = ph.post_solve_bound(solver_options=dopts, verbose=False)
     self.assertGreaterEqual(xhatobj, objbound)
Esempio n. 3
0
if __name__ == "__main__":
    # hardwired by dlw for debugging
    import mpisppy.examples.farmer.farmer as refmodel

    PHopt = {}
    PHopt["asynchronousPH"] = False  # APH is *projective* and always APH
    PHopt["solvername"] = "cplex"
    PHopt["PHIterLimit"] = 5
    PHopt["defaultPHrho"] = 1
    PHopt["APHgamma"] = 1
    PHopt["convthresh"] = 0.001
    PHopt["verbose"] = True
    PHopt["display_timing"] = True
    PHopt["display_progress"] = True
    # one way to set up options (never mind that this is not a MIP)
    PHopt["iter0_solver_options"] = sputils.option_string_to_dict(
        "mipgap=0.01")
    # another way
    PHopt["iterk_solver_options"] = {"mipgap": 0.001}

    ScenCount = 3
    cb_data = {'use_integer': False, "CropsMult": 1}
    all_scenario_names = list()
    for sn in range(ScenCount):
        all_scenario_names.append("scen" + str(sn))
    # end hardwire

    scenario_creator = refmodel.scenario_creator
    scenario_denouement = refmodel.scenario_denouement

    PHopt["async_frac_needed"] = 0.5
    PHopt["async_sleep_secs"] = 0.5
Esempio n. 4
0
    # hardwired by dlw for debugging
    import mpisppy.examples.farmer.farmer as refmodel
    import mpisppy.utils.sputils as sputils

    PHopt = {}
    PHopt["asynchronousPH"] = False
    PHopt["solvername"] = "cplex"
    PHopt["PHIterLimit"] = 5
    PHopt["defaultPHrho"] = 1
    PHopt["convthresh"] = 0.001
    PHopt["verbose"] = True
    PHopt["display_timing"] = True
    PHopt["display_progress"] = True
    # one way to set up options (never mind that this is not a MIP)
    PHopt["iter0_solver_options"]\
        = sputils.option_string_to_dict("mipgap=0.01")
    # another way
    PHopt["iterk_solver_options"] = {"mipgap": 0.001}

    ScenCount = 50
    all_scenario_names = ['scen' + str(i) for i in range(ScenCount)]
    # end hardwire

    scenario_creator = refmodel.scenario_creator
    scenario_denouement = refmodel.scenario_denouement

    # now test extensions and convergers together.
    # NOTE that the PHoptions is a reference,
    #   so you could have changed PHopt instead.
    PHopt["PHIterLimit"] = 5  # the converger will probably stop it.
    PHopt["asynchronousPH"] = False
Esempio n. 5
0
                            dest="num_batches",
                            type=int,
                            default=2)
    parser.add_argument("--MMW-batch-size",
                            help="batch size used for MMW confidence interval, if None then batch_size = num_scens (default to None)",
                            dest="batch_size",
                            type=int,
                            default=None) #None means take batch_size=num_scens
    parser.add_argument("--solver-options",
                            help="space separated string of solver options, e.g. 'option1=value1 option2 = value2'",
                            default='')

    args = parser.parse_args()

    #parses solver options string
    solver_options = option_string_to_dict(args.solver_options)

    if args.num_scens == None:
        print('\n')
        raise Exception("Please include number of scenes used to compute the candidate solutions xhat.")
        print('\n')

    # convert instance path to module name:
    modelpath = re.sub('/','.', args.instance)
    modelpath = re.sub(r'\.py','', modelpath)

    # Read xhats from xhatpath
    xhat = ciutils.read_xhat(args.xhatpath)


    if args.batch_size == None: