No Matches
benders_2stage_mt.py File Reference

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

Go to the source code of this file.


def benders_2stage_mt.scen_solve (i, mi_sub, cutconst, cutcoeff, dem_queue, obj_sub, queue_lock, io_lock)


str benders_2stage_mt.GAMS_DATA
str benders_2stage_mt.GAMS_MASTER_MODEL
str benders_2stage_mt.GAMS_SUB_MODEL
sys benders_2stage_mt.sys_dir = sys.argv[1] if len(sys.argv) > 1 else None
GamsWorkspace benders_2stage_mt.ws = GamsWorkspace(system_directory=sys_dir)
GamsWorkspace benders_2stage_mt.data = ws.add_job_from_string(GAMS_DATA)
GamsWorkspace benders_2stage_mt.opt_data = ws.add_options()
GamsWorkspace benders_2stage_mt.scenario_data = data.out_db["ScenarioData"]
GamsWorkspace benders_2stage_mt.opt = ws.add_options()
int benders_2stage_mt.max_iter = 40
GamsWorkspace benders_2stage_mt.cp_master = ws.add_checkpoint()
GamsWorkspace benders_2stage_mt.cp_sub = ws.add_checkpoint()
GamsWorkspace benders_2stage_mt.master = ws.add_job_from_string(GAMS_MASTER_MODEL)
GamsWorkspace benders_2stage_mt.mi_master = cp_master.add_modelinstance()
GamsWorkspace benders_2stage_mt.cutconst
GamsWorkspace benders_2stage_mt.cutcoeff
GamsWorkspace benders_2stage_mt.theta
GamsWorkspace benders_2stage_mt.theta_fix = mi_master.sync_db.add_parameter("thetaFix", 0)
GamsWorkspace benders_2stage_mt.sub = ws.add_job_from_string(GAMS_SUB_MODEL)
int benders_2stage_mt.num_threads = 2
list benders_2stage_mt.mi_sub = []
Queue benders_2stage_mt.dem_queue = Queue()
list benders_2stage_mt.received
list benders_2stage_mt.demand = mi_sub[0].sync_db.add_parameter("demand", 1, "stochastic demand")
float benders_2stage_mt.lower_bound = float("-inf")
float benders_2stage_mt.upper_bound = float("inf")
float benders_2stage_mt.obj_master = float("inf")
int benders_2stage_mt.it = 1
dict benders_2stage_mt.dem_dict
Lock benders_2stage_mt.queue_lock = Lock()
Lock benders_2stage_mt.io_lock = Lock()
list benders_2stage_mt.obj_sub = [0.0] * num_threads
list benders_2stage_mt.cons = [0.0] * num_threads
dict benders_2stage_mt.coef
dict benders_2stage_mt.threads = {}
float benders_2stage_mt.obj_sub_sum = 0.0

Detailed Description

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

The underlying model implements a simple distribution system with stochastic demand data. This parallel version extends the benders_2stage.py example by solving the independent sub problems in parallel. For that we need to instantiate a separate GamsModelInstance for each parallel worker. We use the efficient GamsModelInstance.copy_modelinstance method to accomplish this in the most efficient way. The number of demand scenarios can be larger than the number of parallel workers. The distribution of work is handled through a work queue. The parallel execution of the sub problems is done in separate threads (the mt in the name of the example stands for multi threading), so there is very little overhead from disk activity. Note that the CPython implementation will not run threads in parallel due to its Global Interpreter Lock.

Definition in file benders_2stage_mt.py.