warehouse Namespace Reference

Functions

def get_model_text ()
 
def solve_warehouse (workspace, number_of_warehouses, result, db_lock)
 

Variables

 ws = GamsWorkspace(system_directory = sys.argv[1])
 
 result_db = ws.add_database()
 
string status_string = ""
 
int status = 0
 
 db_lock = threading.Lock()
 
dictionary threads = {}
 
 target
 
 solve_warehouse
 
 args
 

Function Documentation

◆ get_model_text()

def warehouse.get_model_text ( )

Definition at line 18 of file warehouse.py.

Referenced by solve_warehouse().

18def get_model_text():
19 return '''
20$title Warehouse.gms
21
22$eolcom //
23$SetDDList warehouse store fixed disaggregate // acceptable defines
24$if not set warehouse $set warehouse 10
25$if not set store $set store 50
26$if not set fixed $set fixed 20
27$if not set disaggregate $set disaggregate 1 // indicator for tighter bigM constraint
28$ife %store%<=%warehouse% $abort Increase number of stores (>%warehouse)
29
30set res respond codes / 0 Normal
31 1 License Error
32 2 No solution
33 3 Other Error /
34 ares(res) / 3 /;
35
36Sets Warehouse /w1*w%warehouse% /
37 Store /s1*s%store% /
38Alias (Warehouse,w), (Store,s);
39Scalar
40 fixed fixed cost for opening a warehouse / %fixed% /
41Parameter
42 capacity(WareHouse)
43 supplyCost(Store,Warehouse);
44
45$eval storeDIVwarehouse trunc(card(store)/card(warehouse))
46capacity(w) = %storeDIVwarehouse% + mod(ord(w),%storeDIVwarehouse%);
47supplyCost(s,w) = 1+mod(ord(s)+10*ord(w), 100);
48
49Variables
50 open(Warehouse)
51 supply(Store,Warehouse)
52 obj;
53Binary variables open, supply;
54
55Equations
56 defobj
57 oneWarehouse(s)
58 defopen(w);
59
60defobj.. obj =e= sum(w, fixed*open(w)) + sum((w,s), supplyCost(s,w)*supply(s,w));
61
62oneWarehouse(s).. sum(w, supply(s,w)) =e= 1;
63
64defopen(w).. sum(s, supply(s,w)) =l= open(w)*capacity(w);
65
66$ifthen %disaggregate%==1
67Equations
68 defopen2(s,w);
69defopen2(s,w).. supply(s,w) =l= open(w);
70$endif
71
72model distrib /all/;
73solve distrib min obj using mip;
74
75$macro setResult(n) option clear=ares; ares(n) = yes;
76if (distrib.modelstat=%ModelStat.LicensingProblem% or
77 distrib.solvestat=%Solvestat.LicensingProblems%,
78 setResult('1');
79 abort 'License Error';
80);
81if (distrib.solvestat<>%SolveStat.NormalCompletion% or
82 distrib.modelstat<>%ModelStat.Optimal% and
83 distrib.modelstat<>%ModelStat.IntegerSolution%,
84 setResult('2');
85 abort 'No solution';
86);
87setResult('0'); '''
88
def get_model_text()
Definition: warehouse.py:18

◆ solve_warehouse()

def warehouse.solve_warehouse (   workspace,
  number_of_warehouses,
  result,
  db_lock 
)

Definition at line 89 of file warehouse.py.

References get_model_text(), markowitz.key, and solve_warehouse.

89def solve_warehouse(workspace, number_of_warehouses, result, db_lock):
90 global status
91 global status_string
92 try:
93 # instantiate GAMSOptions and define some scalars
94 opt = workspace.add_options()
95 opt.all_model_types = "cplex"
96 opt.defines["Warehouse"] = str(number_of_warehouses)
97 opt.defines["Store"] = "65"
98 opt.defines["fixed"] = "22"
99 opt.defines["disaggregate"] = "0"
100 opt.optcr = 0.0 # Solve to optimality
101
102 # create a GAMSJob from string and write results to the result database
103 job = workspace.add_job_from_string(get_model_text())
104 job.run(opt)
105
106 # need to lock database write operations
107 db_lock.acquire()
108 result["objrep"].add_record(str(number_of_warehouses)).value = job.out_db["obj"][()].level
109 db_lock.release()
110 for supply_rec in job.out_db["supply"]:
111 if supply_rec.level > 0.5:
112 db_lock.acquire()
113 result["supplyMap"].add_record((str(number_of_warehouses), supply_rec.key(0), supply_rec.key(1)))
114 db_lock.release()
115 except GamsExceptionExecution as e:
116 # Check if we see a User triggered abort and look for the user defined result
117 if e.rc == GamsExitCode.ExecutionError:
118 db_lock.acquire()
119 status_string = job.out_db["res"]
120 status_string = status_string.find_record(job.out_db["ares"].first_record().key(0)).text
121 db_lock.release()
122 db_lock.acquire()
123 status = e.rc
124 db_lock.release()
125 except GamsException as e:
126 print(e)
127 db_lock.acquire()
128 status = -1
129 db_lock.release()
130 except Exception as e:
131 print(e)
132 db_lock.acquire()
133 status = -2
134 db_lock.release()
135
def get_model_text()
Definition: warehouse.py:18

Variable Documentation

◆ args

warehouse.args

Definition at line 155 of file warehouse.py.

◆ db_lock

warehouse.db_lock = threading.Lock()

Definition at line 152 of file warehouse.py.

◆ result_db

warehouse.result_db = ws.add_database()

Definition at line 143 of file warehouse.py.

◆ solve_warehouse

warehouse.solve_warehouse

Definition at line 155 of file warehouse.py.

Referenced by solve_warehouse().

◆ status

int warehouse.status = 0

Definition at line 148 of file warehouse.py.

◆ status_string

string warehouse.status_string = ""

Definition at line 147 of file warehouse.py.

◆ target

warehouse.target

Definition at line 155 of file warehouse.py.

◆ threads

dictionary warehouse.threads = {}

Definition at line 153 of file warehouse.py.

◆ ws

warehouse.ws = GamsWorkspace(system_directory = sys.argv[1])

Definition at line 138 of file warehouse.py.