Exemplo n.º 1
0
        print ("SUGAR_BEETS0 for scenario",sname,"is",
               pyo.value(s.DevotedAcreage["SUGAR_BEETS0"]))
        print ("FirstStageCost for scenario",sname,"is", pyo.value(s.FirstStageCost))


if __name__ == "__main__":
# To test: python afarmer.py --num-scens=3
    
    refmodel = "afarmer" #Change this path to use a different model
    #Compute the nonant xhat (the one used in the left term of MMW (9) ) using
    #                                                        the first scenarios
    
    ama_options = {"EF-2stage": True,# 2stage vs. mstage
               "start": False}   #Are the scenario shifted by a start arg ?
    
    #add information about batches
    ama_extraargs = argparse.ArgumentParser(add_help=False)

    print(ama_extraargs)
    
    ama_object = ama.from_module(refmodel, ama_options,extraargs=ama_extraargs)
    ama_object.run()
    
    if global_rank==0 :
        print("inner bound=", ama_object.best_inner_bound)
        # This the xhat of the left term of LHS of MMW (9)
        print("outer bound=", ama_object.best_outer_bound)
    
    ########### get the nonants (the xhat)  
    sputils.ef_ROOT_nonants_npy_serializer(ama_object.ef, "farmer_root_nonants_temp.npy")
Exemplo n.º 2
0
    ef = sputils.create_EF(
        scenario_names,
        scenario_creator,
        scenario_creator_kwargs=scenario_creator_kwargs,
    )

    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,
        )

    return ef


if __name__ == '__main__':
    if len(sys.argv) != 4:
        print(
            "usage python farmer_ef.py {crops_multiplier} {scen_count} {solver_name}"
        )
        print("e.g., python farmer_ef.py 1 3 gurobi")
        quit()
    main_ef = main()
    print(f"EF objective: {pyo.value(main_ef.EF_Obj)}")
    sputils.ef_ROOT_nonants_npy_serializer(main_ef, "farmer_root_nonants.npy")
Exemplo n.º 3
0
    # get the xhat
    xhat = sputils.nonant_cache_from_ef(ama.ef)

    return xhat


if __name__ == "__main__":
    bfs = [3]
    num_scens = np.prod(bfs)  #To check with a full tree
    ama_options = {
        "EF-2stage": True,
        "EF_solver_name": "gurobi_direct",
        "num_scens": num_scens,
        "_mpisppy_probability": 1 / num_scens,
        "BFs": bfs,
        "mudev": 0,
        "sigmadev": 80,
        "start": 1
    }
    refmodel = "aaircond"  # WARNING: Change this in SPInstances
    #We use from_module to build easily an Amalgomator object
    ama = amalgomator.from_module(refmodel,
                                  ama_options,
                                  use_command_line=False)
    ama.run()
    print(f"inner bound=", ama.best_inner_bound)
    print(f"outer bound=", ama.best_outer_bound)

    sputils.ef_ROOT_nonants_npy_serializer(ama.ef,
                                           "aircond_root_nonants_temp.npy")