File Reference

Go to the source code of this file.


def benders_2stage_mt.scen_solve (i, subi, cutconst, cutcoeff, dem_queue, objsub, queue_lock, io_lock)
def benders_2stage_mt.get_data_text ()
def benders_2stage_mt.get_master_text ()
def benders_2stage_mt.get_sub_text ()

Variables = GamsWorkspace(system_directory = sys.argv[1]) = ws.add_job_from_string(get_data_text())
 benders_2stage_mt.opt_data = ws.add_options()
 benders_2stage_mt.scenario_data = data.out_db.get_parameter("ScenarioData")
 benders_2stage_mt.opt = ws.add_options()
int benders_2stage_mt.maxiter = 40
 benders_2stage_mt.cp_master = ws.add_checkpoint()
 benders_2stage_mt.cp_sub = ws.add_checkpoint()
 benders_2stage_mt.master = ws.add_job_from_string(get_master_text())
 benders_2stage_mt.masteri = cp_master.add_modelinstance()
 benders_2stage_mt.cutconst = masteri.sync_db.add_parameter("cutconst", 1, "Benders optimality cut constant")
 benders_2stage_mt.cutcoeff = masteri.sync_db.add_parameter("cutcoeff", 2, "Benders optimality coefficients")
 benders_2stage_mt.theta = masteri.sync_db.add_variable("theta", 0, VarType.Free, "Future profit function variable")
 benders_2stage_mt.theta_fix = masteri.sync_db.add_parameter("thetaFix", 0, "")
int benders_2stage_mt.num_threads = 2
list benders_2stage_mt.subi = []
 benders_2stage_mt.dem_queue = queue.Queue()
list benders_2stage_mt.received = subi[0].sync_db.add_parameter("received", 1, "units received from first stage solution")
list benders_2stage_mt.demand = subi[0].sync_db.add_parameter("demand", 1, "stochastic demand")
 benders_2stage_mt.lowerbound = float('-inf')
 benders_2stage_mt.upperbound = float('inf')
 benders_2stage_mt.objmaster = float('inf')
int = 1
dictionary benders_2stage_mt.dem_dict = {}
float benders_2stage_mt.objsubsum = 0.0
 benders_2stage_mt.queue_lock = threading.Lock()
 benders_2stage_mt.io_lock = threading.Lock()
dictionary benders_2stage_mt.coef = {}
list benders_2stage_mt.objsub = []
list benders_2stage_mt.cons = []
dictionary benders_2stage_mt.threads = {}

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 example by solving the independent subproblems 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 effective 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 subproblems 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