Loading...
Searching...
No Matches
benders_2stage_mt Namespace Reference

Functions

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

Variables

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

Function Documentation

◆ scen_solve()

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

Definition at line 163 of file benders_2stage_mt.py.

163def scen_solve(i, mi_sub, cutconst, cutcoeff, dem_queue, obj_sub, queue_lock, io_lock):
164 while True:
165 queue_lock.acquire()
166 if dem_queue.empty():
167 queue_lock.release()
168 break
169 dem_dict = dem_queue.get()
170 queue_lock.release()
171
172 mi_sub[i].sync_db["demand"].clear()
173
174 for k, v in dem_dict[2].items():
175 mi_sub[i].sync_db["demand"].add_record(k).value = v
176 mi_sub[i].solve(SymbolUpdateType.BaseCase)
177
178 io_lock.acquire()
179 print(
180 f" Sub {mi_sub[i].model_status} : obj={mi_sub[i].sync_db['zsub'].first_record().level}"
181 )
182 io_lock.release()
183
184 probability = dem_dict[1]
185 obj_sub[i] += probability * mi_sub[i].sync_db["zsub"].first_record().level
186 for k, v in iter(dem_dict[2].items()):
187 cutconst[i] += (
188 probability * mi_sub[i].sync_db["market"].find_record(k).marginal * v
189 )
190 cutcoeff[i][k] += (
191 probability * mi_sub[i].sync_db["selling"].find_record(k).marginal
192 )
193
194

Variable Documentation

◆ all_model_types

benders_2stage_mt.all_model_types

Definition at line 211 of file benders_2stage_mt.py.

◆ args

benders_2stage_mt.args

Definition at line 316 of file benders_2stage_mt.py.

◆ coef

dict benders_2stage_mt.coef
Initial value:
1= {
2 i: {j.key(0): 0.0 for j in data.out_db["j"]} for i in range(num_threads)
3 }

Definition at line 307 of file benders_2stage_mt.py.

◆ cons

list benders_2stage_mt.cons = [0.0] * num_threads

Definition at line 306 of file benders_2stage_mt.py.

◆ cp_master

benders_2stage_mt.cp_master = ws.add_checkpoint()

Definition at line 213 of file benders_2stage_mt.py.

◆ cp_sub

benders_2stage_mt.cp_sub = ws.add_checkpoint()

Definition at line 214 of file benders_2stage_mt.py.

◆ cutcoeff

GamsWorkspace benders_2stage_mt.cutcoeff
Initial value:
1= mi_master.sync_db.add_parameter(
2 "cutcoeff", 2, "Benders optimality coefficients"
3 )

Definition at line 223 of file benders_2stage_mt.py.

◆ cutconst

GamsWorkspace benders_2stage_mt.cutconst
Initial value:
1= mi_master.sync_db.add_parameter(
2 "cutconst", 1, "Benders optimality cut constant"
3 )

Definition at line 220 of file benders_2stage_mt.py.

◆ data

GamsWorkspace benders_2stage_mt.data = ws.add_job_from_string(GAMS_DATA)

Definition at line 199 of file benders_2stage_mt.py.

◆ databases

benders_2stage_mt.databases

Definition at line 217 of file benders_2stage_mt.py.

◆ dem_dict

dict benders_2stage_mt.dem_dict
Initial value:
1= {
2 j.key(0): scenario_data.find_record([s.key(0), j.key(0)]).value
3 for j in data.out_db["j"]
4 }

Definition at line 282 of file benders_2stage_mt.py.

◆ dem_queue

Queue benders_2stage_mt.dem_queue = Queue()

Definition at line 244 of file benders_2stage_mt.py.

◆ demand

list benders_2stage_mt.demand = mi_sub[0].sync_db.add_parameter("demand", 1, "stochastic demand")

Definition at line 249 of file benders_2stage_mt.py.

◆ GAMS_DATA

str benders_2stage_mt.GAMS_DATA

Definition at line 25 of file benders_2stage_mt.py.

◆ GAMS_MASTER_MODEL

str benders_2stage_mt.GAMS_MASTER_MODEL

Definition at line 63 of file benders_2stage_mt.py.

◆ GAMS_SUB_MODEL

str benders_2stage_mt.GAMS_SUB_MODEL

Definition at line 121 of file benders_2stage_mt.py.

◆ io_lock

Lock benders_2stage_mt.io_lock = Lock()

Definition at line 304 of file benders_2stage_mt.py.

◆ it

int benders_2stage_mt.it = 1

Definition at line 261 of file benders_2stage_mt.py.

◆ lower_bound

max benders_2stage_mt.lower_bound = float("-inf")

Definition at line 258 of file benders_2stage_mt.py.

◆ master

GamsWorkspace benders_2stage_mt.master = ws.add_job_from_string(GAMS_MASTER_MODEL)

Definition at line 216 of file benders_2stage_mt.py.

◆ max_iter

int benders_2stage_mt.max_iter = 40

Definition at line 209 of file benders_2stage_mt.py.

◆ mi_master

GamsWorkspace benders_2stage_mt.mi_master = cp_master.add_modelinstance()

Definition at line 219 of file benders_2stage_mt.py.

◆ mi_sub

list benders_2stage_mt.mi_sub = []

Definition at line 243 of file benders_2stage_mt.py.

◆ num_threads

int benders_2stage_mt.num_threads = 2

Definition at line 242 of file benders_2stage_mt.py.

◆ obj_master

tuple benders_2stage_mt.obj_master = float("inf")

Definition at line 260 of file benders_2stage_mt.py.

◆ obj_sub

list benders_2stage_mt.obj_sub = [0.0] * num_threads

Definition at line 305 of file benders_2stage_mt.py.

◆ obj_sub_sum

float benders_2stage_mt.obj_sub_sum = 0.0

Definition at line 322 of file benders_2stage_mt.py.

◆ opt

benders_2stage_mt.opt = ws.add_options()

Definition at line 207 of file benders_2stage_mt.py.

◆ opt_data

GamsWorkspace benders_2stage_mt.opt_data = ws.add_options()

Definition at line 201 of file benders_2stage_mt.py.

◆ queue_lock

Lock benders_2stage_mt.queue_lock = Lock()

Definition at line 303 of file benders_2stage_mt.py.

◆ received

list benders_2stage_mt.received
Initial value:
1= mi_sub[0].sync_db.add_parameter(
2 "received", 1, "units received from first stage solution"
3 )

Definition at line 246 of file benders_2stage_mt.py.

◆ scenario_data

GamsWorkspace benders_2stage_mt.scenario_data = data.out_db["ScenarioData"]

Definition at line 206 of file benders_2stage_mt.py.

◆ sub

GamsWorkspace benders_2stage_mt.sub = ws.add_job_from_string(GAMS_SUB_MODEL)

Definition at line 240 of file benders_2stage_mt.py.

◆ sys_dir

sys benders_2stage_mt.sys_dir = sys.argv[1] if len(sys.argv) > 1 else None

Definition at line 196 of file benders_2stage_mt.py.

◆ target

benders_2stage_mt.target

Definition at line 315 of file benders_2stage_mt.py.

◆ theta

GamsWorkspace benders_2stage_mt.theta
Initial value:
1= mi_master.sync_db.add_variable(
2 "theta", 0, VarType.Free, "Future profit function variable"
3 )

Definition at line 226 of file benders_2stage_mt.py.

◆ theta_fix

GamsWorkspace benders_2stage_mt.theta_fix = mi_master.sync_db.add_parameter("thetaFix", 0)

Definition at line 229 of file benders_2stage_mt.py.

◆ threads

dict benders_2stage_mt.threads = {}

Definition at line 312 of file benders_2stage_mt.py.

◆ upper_bound

GamsWorkspace benders_2stage_mt.upper_bound = float("inf")

Definition at line 259 of file benders_2stage_mt.py.

◆ value

benders_2stage_mt.value

Definition at line 262 of file benders_2stage_mt.py.

◆ ws

GamsWorkspace benders_2stage_mt.ws = GamsWorkspace(system_directory=sys_dir)

Definition at line 197 of file benders_2stage_mt.py.