Dear Pyomo Forum members,
What is the "right" way to set up a stochastic optimization problem in PySP if I want to create the reference model dynamically, instead of resorting to a model stored in a file, but instead using a pyomo model object ?
I have defined a concrete reference model in the file "ReferenceModel.py, as well as a call-back function pysp_instance_creation_callback which sets the value of parameter X, which is different for each scenario. It works, but I don't know how to modify the other parameters of the model in the main script.
For example: is there a way to initialize a ScenarioTreeManager using a (concrete?) model object instead of passing a reference to the file where it is stored
I hope you can help me by answering this question or directing me to an existing answer !
Best regards,
Tarik
----------------------------------------------------------------------------------------------------------
MAIN SCRIPT:
from pyomo.pysp.scenariotree.manager import ScenarioTreeManagerClientSerial
from pyomo.pysp.ef import create_ef_instance
from pyomo.opt import SolverFactory
options = ScenarioTreeManagerClientSerial.register_options()
options.scenario_tree_location = 'ReferenceModel.py'
options.model_location = 'ScenarioStructure.dat'
manager = ScenarioTreeManagerClientSerial(options)
manager.initialize()
# create extensive form of model
extensive_form = create_ef_instance(manager.scenario_tree)
# solve it with GLPK
solver = SolverFactory('glpk')
solver.solve(extensive_form)
ReferenceModel.py :
sop_model = ConcreteModel()
( ... definition of the concrete model -> includes the parameter data)
def pysp_instance_creation_callback(scenario_name, node_names):
instance = sop_model.clone()
instance.X.store_values(X[scenario_name])
return instance