Functions | |
def | solve_warehouse (workspace, nr_warehouses, result, lock) |
Variables | |
str | GAMS_MODEL |
sys | sys_dir = sys.argv[1] if len(sys.argv) > 1 else None |
GamsWorkspace | ws = GamsWorkspace(system_directory=sys_dir) |
GamsWorkspace | result_db = ws.add_database() |
str | status_string = "" |
int | status = 0 |
Lock | lock = Lock() |
list | threads = [] |
Thread | t = Thread(target=solve_warehouse, args=(ws, i, result_db, lock)) |
Function Documentation
◆ solve_warehouse()
def warehouse.solve_warehouse | ( | workspace, | |
nr_warehouses, | |||
result, | |||
lock | |||
) |
Definition at line 96 of file warehouse.py.
96def solve_warehouse(workspace, nr_warehouses, result, lock):
97 global status
98 global status_string
99 try:
100 # instantiate GamsOptions and define some scalars
101 opt = workspace.add_options()
102 opt.all_model_types = "cplex"
103 opt.defines["Warehouse"] = str(nr_warehouses)
104 opt.defines["Store"] = "65"
105 opt.defines["fixed"] = "22"
106 opt.defines["disaggregate"] = "0"
107 opt.optcr = 0.0 # solve to optimality
108
109 # create a GamsJob from string and write results to the result database
110 job = workspace.add_job_from_string(GAMS_MODEL)
111 job.run(opt)
112
113 # need to lock database write operations
114 lock.acquire()
115 result["objrep"].add_record(str(nr_warehouses)).value = (
116 job.out_db["obj"].first_record().level
117 )
118 lock.release()
119 for supply_rec in job.out_db["supply"]:
120 if supply_rec.level > 0.5:
121 lock.acquire()
122 result["supplyMap"].add_record(
123 (str(nr_warehouses), supply_rec.key(0), supply_rec.key(1))
124 )
125 lock.release()
126 except Exception as e:
127 lock.acquire()
128 if isinstance(e, GamsExceptionExecution):
129 # check if we see a user triggered abort and look for the user defined result
130 if e.rc == GamsExitCode.ExecutionError:
131 status_string = (
132 job.out_db["res"]
133 .find_record(job.out_db["ares"].first_record().key(0))
134 .text
135 )
136 status = e.rc
137 else:
138 print(e)
139 status = -1 if isinstance(e, GamsException) else -2
140 lock.release()
141
142
Variable Documentation
◆ GAMS_MODEL
str warehouse.GAMS_MODEL |
Definition at line 16 of file warehouse.py.
◆ lock
Lock warehouse.lock = Lock() |
Definition at line 156 of file warehouse.py.
◆ result_db
GamsWorkspace warehouse.result_db = ws.add_database() |
Definition at line 148 of file warehouse.py.
◆ status
int warehouse.status = 0 |
Definition at line 153 of file warehouse.py.
◆ status_string
str warehouse.status_string = "" |
Definition at line 152 of file warehouse.py.
◆ sys_dir
sys warehouse.sys_dir = sys.argv[1] if len(sys.argv) > 1 else None |
Definition at line 144 of file warehouse.py.
◆ t
Thread warehouse.t = Thread(target=solve_warehouse, args=(ws, i, result_db, lock)) |
Definition at line 159 of file warehouse.py.
◆ threads
list warehouse.threads = [] |
Definition at line 157 of file warehouse.py.
◆ ws
GamsWorkspace warehouse.ws = GamsWorkspace(system_directory=sys_dir) |
Definition at line 145 of file warehouse.py.