Loading...
Searching...
No Matches
benders_2stage.py File Reference

This example demonstrates a sequential implementation of a simple Benders decomposition method for a stochastic linear program. More...

Go to the source code of this file.

Variables

str benders_2stage.GAMS_DATA
 
str benders_2stage.GAMS_MASTER_MODEL
 
str benders_2stage.GAMS_SUB_MODEL
 
sys benders_2stage.sys_dir = sys.argv[1] if len(sys.argv) > 1 else None
 
GamsWorkspace benders_2stage.ws = GamsWorkspace(system_directory=sys_dir)
 
GamsWorkspace benders_2stage.data = ws.add_job_from_string(GAMS_DATA)
 
GamsWorkspace benders_2stage.opt_data = ws.add_options()
 
GamsWorkspace benders_2stage.scenario_data = data.out_db["ScenarioData"]
 
GamsWorkspace benders_2stage.opt = ws.add_options()
 
int benders_2stage.max_iter = 40
 
 benders_2stage.all_model_types
 
GamsWorkspace benders_2stage.cp_master = ws.add_checkpoint()
 
GamsWorkspace benders_2stage.cp_sub = ws.add_checkpoint()
 
GamsWorkspace benders_2stage.master = ws.add_job_from_string(GAMS_MASTER_MODEL)
 
 benders_2stage.databases
 
GamsWorkspace benders_2stage.mi_master = cp_master.add_modelinstance()
 
GamsWorkspace benders_2stage.cutconst
 
GamsWorkspace benders_2stage.cutcoeff
 
GamsWorkspace benders_2stage.theta
 
GamsWorkspace benders_2stage.theta_fix = mi_master.sync_db.add_parameter("thetaFix", 0)
 
GamsWorkspace benders_2stage.sub = ws.add_job_from_string(GAMS_SUB_MODEL)
 
GamsWorkspace benders_2stage.mi_sub = cp_sub.add_modelinstance()
 
GamsWorkspace benders_2stage.received = mi_sub.sync_db.add_parameter("received", 1, "units received from master")
 
GamsWorkspace benders_2stage.demand = mi_sub.sync_db.add_parameter("demand", 1, "stochastic demand")
 
float benders_2stage.lower_bound = float("-inf")
 
float benders_2stage.upper_bound = float("inf")
 
float benders_2stage.obj_master = float("inf")
 
int benders_2stage.it = 1
 
 benders_2stage.value
 
float benders_2stage.obj_sub = 0.0
 
GamsWorkspace benders_2stage.probability = scenario_data.find_record((s.key(0), "prob")).value
 

Detailed Description

This example demonstrates a sequential implementation of a simple Benders decomposition method for a stochastic linear program.

The underlying model implements a simple distribution system with stochastic demand data. Both the master and the sub problems are implemented with the GamsModelInstance which allows resolving the model with modified input without regenerating the model. A GamsModelInstance has a fixed model rim, so this provides a challenge for Benders master problem because every iteration adds new constraints (the Benders cuts) to the master. We get around this limitation of GamsModelInstance by initializing the GamsModelInstance of the master with a fixed number of empty (i.e. non-binding) placeholder constraints and turn them into valid Benders cuts during the run of the algorithm.

Definition in file benders_2stage.py.