PySP: solving extensive form for stochastic optimization problem without using a reference model stored in a file ?

140 views
Skip to first unread message

Tarik Berrada

unread,
Nov 21, 2018, 10:32:37 AM11/21/18
to Pyomo Forum
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

David Woodruff

unread,
Nov 21, 2018, 12:29:42 PM11/21/18
to pyomo...@googlegroups.com
... answering this part: """


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
"""
Yes, there are multiple ways to do this. One example is shown in the master version (on Gitbub) of Pyomo in
pyomo/examples/pysp/farmer/concreteNetX

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tarik Berrada

unread,
Nov 22, 2018, 3:26:02 AM11/22/18
to Pyomo Forum
Dear David,

Thanks for your answer ! So I see how to create the scenario tree using a call-back function. But still, when you solve the model using runef -m ReferenceModel.py , you make a mention to the ReferenceModel.py.

Let me restate my question: can you have a separate script (let's call it "solver_script.py") where you import the reference model, modify it and solve the stochastic optimization problem ?

I picture something like :

solver_script.py

from ReferenceModel.py import model

model.TOTAL_ACREAGE = 1000.0 # instead of the original value 500.0 - I guess you may have to define TOTAL_ACREAGE as mutable in the reference model

# create extensive form of model
extensive_form = some function that takes "model" as its input + either a scenario tree or a reference to the "scenario_tree.dat" file.

# solve it 
solver = SolverFactory('glpk')
solver.solve(extensive_form)


Thanks for your support and for developing this wonderful library !

Tarik

David Woodruff

unread,
Nov 22, 2018, 10:21:35 AM11/22/18
to pyomo...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages