forked from sgkruk/Apress-AI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_job_shop.py
30 lines (27 loc) · 968 Bytes
/
test_job_shop.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from job_shop import gen_data, solve_model
def main():
import sys
import random
import tableutils
m=4
n=3
if len(sys.argv)<=1:
print('Usage is main [data|run] [seed]')
return
elif len(sys.argv)>2:
random.seed(int(sys.argv[2]))
D=gen_data(m,n)
if sys.argv[1]=='data':
T=[]
for i in range(m):
T.append([str(D[i][j][0])+'-'+str(D[i][j][1]) for j in range(n)])
left=['J'+str(i) for i in range(m)]
header=['Job']+['Machine-Duration' for _ in range(n)]
T=tableutils.wrapmat(T,left,header)
tableutils.printmat(T,True)
elif sys.argv[1]=='run':
rc,Val,x=solve_model(D)
T=[[tableutils.set2string((x[i][D[i][k][0]], D[i][k][0], D[i][k][1])) for k in range(n) if D[i][k][1]>0] for i in range(m)]
T=tableutils.wrapmat(T,['Job:'+str(i) for i in range(m)],['(S; M; D)' for _ in range(n)])
tableutils.printmat(T,True)
main()