def test_seqsampling_running(self): #We need a very small instance for testing on GitHub. optionsBM = { 'h': 1.75, 'hprime': 0.5, 'eps': 0.2, 'epsprime': 0.1, "p": 0.1, "q": 1.2, "solvername": solvername, "xhat_gen_options": { "crops_multiplier": 3 }, "crops_multiplier": 3, } seq_pb = seqsampling.SeqSampling( "mpisppy.tests.examples.farmer", seqsampling.xhat_generator_farmer, optionsBM, stochastic_sampling=False, stopping_criterion="BM", solving_type="EF-2stage", ) x = seq_pb.run(maxit=50) T = x['T'] ub = round_pos_sig(x['CI'][1], 2) self.assertEqual((T, ub), (1, 7400.0))
def test_seqsampling_creator(self): BFs = [4, 3, 2] xhat_gen_options = self._get_xhat_gen_options(BFs) optionsBM = {'h':0.2, 'hprime':0.015, 'eps':0.5, 'epsprime':0.4, "p":2, "q":1.2, "solvername":solvername, "xhat_gen_options": xhat_gen_options, "branching_factors": BFs, } seqsampling.SeqSampling(self.refmodelname, aircond.xhat_generator_aircond, optionsBM, stochastic_sampling=False, stopping_criterion="BM", solving_type="EF-mstage", )
def test_seqsampling_creator(self): optionsBM = { 'h': 0.2, 'hprime': 0.015, 'eps': 0.5, 'epsprime': 0.4, "p": 2, "q": 1.2, "solvername": solvername, "xhat_gen_options": { "crops_multiplier": 3 }, "crops_multiplier": 3, } seqsampling.SeqSampling( "mpisppy.tests.examples.farmer", seqsampling.xhat_generator_farmer, optionsBM, stochastic_sampling=False, stopping_criterion="BM", )
def main(args): """ Code for farmer sequential sampling (in a function for easier testing) Args: args (parseargs): the command line arguments object from parseargs Returns: results (dict): the solution, gap confidence interval and T """ refmodelname = "afarmer" scenario_creator = afarmer.scenario_creator scen_count = args.num_scens solver_name = args.EF_solver_name crops_multiplier = args.crops_multiplier scenario_names = ['Scenario' + str(i) for i in range(scen_count)] xhat_gen_options = { "scenario_names": scenario_names, "solvername": solver_name, "solver_options": None, "use_integer": False, "crops_multiplier": crops_multiplier, "start_seed": 0, } # simply called "options" by the SeqSampling constructor inneroptions = { "solvername": solver_name, "solver_options": None, "sample_size_ratio": args.sample_size_ratio, "xhat_gen_options": xhat_gen_options, "ArRP": args.ArRP, "kf_xhat": args.kf_GS, "kf_xhat": args.kf_xhat, "confidence_level": args.confidence_level, } if args.BM_vs_BPL == "BM": # Bayraksan and Morton optionsBM = { 'h': args.BM_h, 'hprime': args.BM_hprime, 'eps': args.BM_eps, 'epsprime': args.BM_eps_prime, "p": args.BM_p, "q": args.BM_q, "xhat_gen_options": xhat_gen_options, } optionsBM.update(inneroptions) sampler = seqsampling.SeqSampling( refmodelname, xhat_generator_farmer, optionsBM, stochastic_sampling=False, stopping_criterion="BM", solving_type="EF-2stage", ) else: # must be BPL optionsBPL = { 'eps': args.BPL_eps, "c0": args.BPL_c0, "n0min": args.BPL_n0min, "xhat_gen_options": xhat_gen_options, } optionsBPL.update(inneroptions) ss = int(args.BPL_n0min) != 0 sampler = seqsampling.SeqSampling( refmodelname, xhat_generator_farmer, optionsBPL, stochastic_sampling=ss, stopping_criterion="BPL", solving_type="EF-2stage", ) xhat = sampler.run() return xhat