Ejemplo n.º 1
0
def main():
    inst = "network-10-20-L-01"
    num_scen = int(inst.split("-")[-3])
    scenario_names = [f"Scen{i}" for i in range(num_scen)]
    scenario_creator_options = {"cb_data": f"./data/{inst}.dat"}
    options = {"solver": "gurobi"}
    ef = ExtensiveForm(options,
                       scenario_names,
                       scenario_creator,
                       model_name=f"{inst}-EF",
                       scenario_creator_options=scenario_creator_options)
    results = ef.solve_extensive_form()
    print("Netdes objective value:", pyo.value(ef.ef.EF_Obj))
    def solve_program(self):
        options = {"solver": self.solver_string}

        self.ef = ExtensiveForm(
            options=options,
            all_scenario_names=self.all_scenario_names,
            scenario_creator=self.scenario_creator,
        )

        self.results = self.ef.solve_extensive_form(
            solver_options=self.solver_options)

        objval = self.ef.get_objective_value()

        return objval
Ejemplo n.º 3
0
# Copyright 2020 by B. Knueven, D. Mildebrath, C. Muir, J-P Watson, and D.L. Woodruff
# This software is distributed under the 3-clause BSD License.
import sys
import hydro
import pyomo.environ as pyo
from mpisppy.opt.ef import ExtensiveForm
import mpisppy.utils.sputils as sputils

options = {"solver": sys.argv[1]}
num_scenarios = 9
BFs = [3, 3]
all_scenario_names = [f"Scen{i+1}" for i in range(num_scenarios)]

# This is multi-stage, so we need to supply node names
all_nodenames = sputils.create_nodenames_from_branching_factors(BFs)

options["branching_factors"] = BFs
ef = ExtensiveForm(options,
                   all_scenario_names,
                   hydro.scenario_creator,
                   scenario_creator_kwargs={"branching_factors": BFs},
                   all_nodenames=all_nodenames)
ef.solve_extensive_form(tee=True)
print(f'hydro objective value {pyo.value(ef.ef.EF_Obj)}')
ef.report_var_values_at_rank0("Hydro")
Ejemplo n.º 4
0
# Copyright 2020 by B. Knueven, D. Mildebrath, C. Muir, J-P Watson, and D.L. Woodruff
# This software is distributed under the 3-clause BSD License.
import sys
import uc_funcs as uc
import pyomo.environ as pyo

from mpisppy.opt.ef import ExtensiveForm
""" UC """
solver_name = sys.argv[1]
scen_count = 3
scenario_names = [f"Scenario{i+1}" for i in range(scen_count)]
scenario_creator_kwargs = {"path": f"{scen_count}scenarios_r1/"}
options = {"solver": solver_name}
ef = ExtensiveForm(
    options,
    scenario_names,
    uc.scenario_creator,
    model_name="TestEF",
    scenario_creator_kwargs=scenario_creator_kwargs,
)
results = ef.solve_extensive_form(tee=True)
print(f"{scen_count}-scenario UC objective value:", pyo.value(ef.ef.EF_Obj))
Ejemplo n.º 5
0
    _print_usage()
    sys.exit()
elif int(sys.argv[1]) not in [3,10]:
    _print_usage()
    sys.exit()

try:
    solver_avail = SolverFactory(sys.argv[2]).available()
    if not solver_avail:
        print(f"Cannot find solver {sys.argv[2]}")
        sys.exit()
except:
    print(f"Cannot find solver {sys.argv[2]}")
    _print_usage()
    sys.exit()

num_scen = int(sys.argv[1])
solver = sys.argv[2]

sizes = PySPModel(scenario_creator='./models/ReferenceModel.py',
                  tree_model=f'./SIZES{num_scen}/ScenarioStructure.dat',
                  )


ef = ExtensiveForm(options={'solver':solver}, 
                   all_scenario_names=sizes.all_scenario_names,
                   scenario_creator=sizes.scenario_creator,
                   model_name='sizes_EF')

ef.solve_extensive_form(tee=True)