def main(): import sys import random import tableutils m=15 n=25 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,C=gen_data(m,n) if sys.argv[1]=='data': T=[] for i in range(m): T.append([tableutils.set2string(D[i])]) T=tableutils.splitwrapmat(T,['S'+str(i) for i in range(m)],['Supplier','Part numbers']) tableutils.printmat(T,True) elif sys.argv[1]=='run': rc,Val,S,P=solve_model(D,None) T=[] for i in range(len(P)): T.append([tableutils.set2string(P[i])]) T.insert(0,[tableutils.set2string(S)]) T=tableutils.splitwrapmat(T,['All']+['Part #'+str(j) for j in range(n)],['Parts','Suppliers']) tableutils.printmat(T,True)
def main(): import sys import random import tableutils m = 15 n = 40 k = 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, C = gen_data(m, n, k) if sys.argv[1] == 'data': T = [] for i in range(m): T.append([tableutils.set2string(D[i])]) T = tableutils.splitwrapmat(T, [str(i) for i in range(m)], ['Roster #', 'Crew IDs']) tableutils.printmat(T, True) elif sys.argv[1] == 'run': rc, Val, S = solve_model(D, None) T = [] #for i in range(len(C)): # if len(C[i]): # T.append(['Crew id '+str(i),tableutils.set2string(C[i])]) T.insert( 0, ['Rosters chosen {0:}'.format(int(Val)), tableutils.set2string(S)]) tableutils.printmat(T, True)
def main(): import sys import random import tableutils m=15 n=40 k=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,k) if sys.argv[1]=='data': T=[] for i in range(m): T.append([tableutils.set2string(D[i])]) T=tableutils.wrapmat(T,[str(i) for i in range(m)],['Crew #','Crew ID']) tableutils.printmat(T,True) elif sys.argv[1]=='run': rc,Val,S=solve_model(D,None) T=[] #for i in range(len(C)): # if len(C[i]): # T.append(['Crew id '+str(i),tableutils.set2string(C[i])]) T.insert(0,['Rosters chosen',tableutils.set2string(S)]) tableutils.printmat(T,True)
def main(): import sys import random import tableutils n=7 if len(sys.argv)<=1: print('Usage is main [data|run|large] [seed]') return elif len(sys.argv)>=3: random.seed(int(sys.argv[2])) C=gen_data(n) if sys.argv[1]=='data': tableutils.printmat(tableutils.wrapmat(C,[str(i) for i in range(n)],['Order','Nb items','% Width'])) elif sys.argv[1]=='run': start = time.clock() rc,nb,rolls,w=solve_model(C) end = time.clock() if rc != 0: print 'Infeasible' else: R = [[str(rolls[i][0]) , tableutils.set2string(tableutils.flatten(rolls[i][1:]))] for i in range(nb)] tableutils.printmat(tableutils.wrapmat(R,[str(i) for i in range(nb)],['rolls','Waste '+str(sum(w)),'Cut widths']),True,0) elif sys.argv[1]=='large': #C = [[44, 81], [3,70],[48,68]] start = time.clock() C,y,rolls=solve_large_model(C) end = time.clock() nb = len(rolls) #tableutils.printmat(C) #tableutils.printmat([y]) #tableutils.printmat(rolls) R = [[str(rolls[i][0]) , tableutils.set2string(tableutils.flatten(rolls[i][1:]))] for i in range(nb)] tableutils.printmat(tableutils.wrapmat(R,[str(i) for i in range(nb)],['rolls','Waste '+str(sum(rolls[i][0] for i in range(nb))),'Cut widths ']),True,0)
def main(): import sys import random import tableutils nbdiv = 2 nbteam = [6, 7, 8] if len(sys.argv) <= 1: print('Usage is main [data|run|big] [seed]') return elif len(sys.argv) >= 3: random.seed(int(sys.argv[2])) D, T = gen_data(nbdiv, nbteam) if sys.argv[1] == 'data': R = [['(Intra Inter G/W Weeks)', tableutils.set2string(T)]] for i in range(len(D)): R.append( ['Division ' + str(i) + ' teams', tableutils.set2string(D[i])]) tableutils.printmat(R) elif sys.argv[1] in ['run', 'big', 'bug']: if sys.argv[1] == 'big': D, T = gen_data(4, [6]) T = (3, 2, 1, 52) R = [['(Intra Inter G/W Weeks)', tableutils.set2string(T)]] for i in range(len(D)): R.append([ 'Division ' + str(i) + ' teams', tableutils.set2string(D[i]) ]) tableutils.printmat(R) rc, v, Cal = solve_model_big(D, T) elif sys.argv[1] == 'bug': D = [[0, 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]] T = (3, 1, 2, 28) rc, v, Cal = solve_model_big(D, T) else: rc, v, Cal = solve_model(D, T) if rc != 0: print('Infeasible') else: R = [['Week', 'Matches']] nbWeeks = T[3] week = 0 for matches in Cal: RR = [] for match in matches: RR.append(str(match[0]) + ' vs ' + str(match[1])) RR.insert(0, week) R.append(RR) week += 1 tableutils.printmat(R, True, 0)
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)
def main(): import sys import random import tableutils nbdiv=2 nbteam=[6,7,8] if len(sys.argv)<=1: print('Usage is main [data|run|big] [seed]') return elif len(sys.argv)>=3: random.seed(int(sys.argv[2])) D,T=gen_data(nbdiv,nbteam) if sys.argv[1]=='data': R=[['(Intra Inter G/W Weeks)',tableutils.set2string(T)]] for i in range(len(D)): R.append(['Division '+str(i)+' teams',tableutils.set2string(D[i])]) tableutils.printmat(R) elif sys.argv[1]=='run' or sys.argv[1]=='big': if sys.argv[1]=='big': D,T=gen_data(4,[6]) T=(3,2,1,52) R=[['(Intra Inter G/W Weeks)',tableutils.set2string(T)]] for i in range(len(D)): R.append(['Division '+str(i)+' teams',tableutils.set2string(D[i])]) tableutils.printmat(R) rc,v,Cal=solve_model_big(D,T) else: rc,v,Cal=solve_model(D,T) if rc != 0: print 'Infeasible' else: R=[['Week', 'Matches', str(v)]] nbWeeks=T[3] week = 0 for matches in Cal: RR=[] for match in matches: RR.append(str(match[0]) + ' vs ' + str(match[1])) RR.insert(0,week) R.append(RR) week+=1 tableutils.printmat(R,True,0)
def main(): import sys import random import tableutils nbcourse=7 nbsets=6 nbinstructor=5 nbpairs=2 if len(sys.argv)<=1: print('Usage is main [section|sets|instructor|pairs|run] [seed]') return elif len(sys.argv)>=3: random.seed(int(sys.argv[2])) S,nbsection=gen_section(nbcourse) R=gen_sets(nbsection,nbsets) I=gen_instructor(nbinstructor,nbsets,nbcourse,nbpairs) P=gen_pairs(nbpairs,nbsection) if sys.argv[1]=='section': tableutils.printmat(tableutils.wrapmat(S,[],['Id','Course id','Meeting Time']),True,0) elif sys.argv[1]=='sets': RR=[] for i in range(len(R)): RR.append([R[i][0],tableutils.set2string(R[i][1])]) tableutils.printmat(tableutils.wrapmat(RR,[],['Id','Sections']),True,0) elif sys.argv[1]=='instructor': RI=[] for i in range(len(I)): RI.append([I[i][0], tableutils.set2string(I[i][1]), tableutils.set2string(I[i][2]), tableutils.set2string(I[i][3]), tableutils.set2string(I[i][4])]) tableutils.printmat(tableutils.wrapmat(RI,[],['Id','Load','Course weights','Set weights','Pair weights']),True,0) elif sys.argv[1]=='pairs': RP=[] for i in range(len(P)): X=[str('(')+str(e[0])+str(' ')+str(e[1])+str(')') for e in P[i][1]] RP.append([P[i][0],tableutils.set2string(X)]) tableutils.printmat(tableutils.wrapmat(RP,[],['Id','Section pairs']),True,0) elif sys.argv[1]=='run': rc,x,xs,v=solve_model(S,I,R,P) #tableutils.printmat(x) #print(xs) XS=[] for i in range(len(xs)): XS.append([xs[i][0], ['{0:2}'.format(e[0])+' : ('+'{0:2}'.format(e[1][0])+' '+'{0:2}'.format(e[1][1])+' '+'{0:2}'.format(e[1][2])+')' for e in xs[i][1]]]) tableutils.printmat(tableutils.wrapmat(XS,[],['Instructor','Section (WC WR WP)']),True,1)
def main(): import sys import random import tableutils nbcourse = 7 nbsets = 6 nbinstructor = 5 nbpairs = 2 if len(sys.argv) <= 1: print('Usage is main [section|sets|instructor|pairs|run] [seed]') return elif len(sys.argv) >= 3: random.seed(int(sys.argv[2])) S, nbsection = gen_section(nbcourse) R = gen_sets(nbsection, nbsets) I = gen_instructor(nbinstructor, nbsets, nbcourse, nbpairs) P = gen_pairs(nbpairs, nbsection) if sys.argv[1] == 'section': tableutils.printmat( tableutils.wrapmat(S, [], ['Id', 'Course id', 'Meeting Time']), True, 0) elif sys.argv[1] == 'sets': RR = [] for i in range(len(R)): RR.append([R[i][0], tableutils.set2string(R[i][1])]) tableutils.printmat(tableutils.wrapmat(RR, [], ['Id', 'Sections']), True, 0) elif sys.argv[1] == 'instructor': RI = [] for i in range(len(I)): RI.append([ I[i][0], tableutils.set2string(I[i][1]), tableutils.set2string(I[i][2]), tableutils.set2string(I[i][3]), tableutils.set2string(I[i][4]) ]) tableutils.printmat( tableutils.wrapmat(RI, [], [ 'Id', 'Load', 'Course weights', 'Set weights', 'Pair weights' ]), True, 0) elif sys.argv[1] == 'pairs': RP = [] for i in range(len(P)): X = [ str('(') + str(e[0]) + str(' ') + str(e[1]) + str(')') for e in P[i][1] ] RP.append([P[i][0], tableutils.set2string(X)]) tableutils.printmat( tableutils.wrapmat(RP, [], ['Id', 'Section pairs']), True, 0) elif sys.argv[1] == 'run': rc, x, xs, v = solve_model(S, I, R, P) #tableutils.printmat(x) #print(xs) XS = [] for i in range(len(xs)): XS.append([ xs[i][0], [ '{0:2}'.format(e[0]) + ' : (' + '{0:2}'.format(e[1][0]) + ' ' + '{0:2}'.format(e[1][1]) + ' ' + '{0:2}'.format(e[1][2]) + ')' for e in xs[i][1] ] ]) tableutils.printmat( tableutils.wrapmat(XS, [], ['Instructor', 'Section (WC WR WP)']), True, 1)