def value_generator(S,items,lambda1,lambda2): completion = complete_time(S,items) lateness = generate.late(completion,items) tardiness = generate.tard(lateness) item_values = [] for j in xrange(len(items)): item = items[j] wt,wc = item.wt,item.wc t,c = tardiness[j],completion[j] value = h(t,c,wt,wc,lambda1,lambda2) item_values.append(value) return completion,tardiness,item_values
def value_generator(S, items, lambda1, lambda2): # generate completion, tardniess, and item contribution values completion = complete_time(S, items) item = [items[j] for j in S] lateness = generate.late(completion, item) tardiness = generate.tard(lateness) item_values = [] for j in xrange(len(item)): itm = item[j] wt, wc = itm.wt, itm.wc t, c = tardiness[j], completion[j] value = h(t, c, wt, wc, lambda1, lambda2) item_values.append(value) return completion, tardiness, item_values
def solve(input_data, N, NL, m, lambda1): lambda2 = 1 - lambda1 Data = input_data.split("\n") # load data n = len(Data) - 1 # get the amount of items items = [] for j in xrange(n): data = Data[j] parts = data.split() p = int(parts[0]) # get the process time s = int(parts[2]) # get the setup time d = int(parts[3]) # get the due date wt = int(parts[4]) # get the tardiness weights wc = int(parts[5]) # get the completion weights items.append(Item(p + s, d, wt, wc)) # combine those item data print "Data loaded!" S, L, completion = generate.initialization(items, n, m) lateness = generate.late(completion, items) tardiness = generate.tard(lateness) item_values = [] for j in xrange(len(items)): item = items[j] wt, wc = item.wt, item.wc t, c = tardiness[j], completion[j] value = h(t, c, wt, wc, lambda1, lambda2) item_values.append(value) print "Initialization done!" G = generate.H(item_values, L) line_values = [] for s in S: value = generate.H(item_values, s) line_values.append(value) print "Initial values done!" for l in xrange(m): delta, S[l] = basictabu.tabu(1500, NL, S[l], items, completion, tardiness, lambda1, lambda2) G += delta line_values[l] += delta completion, tardiness, item_values = generate.verify(S, items, lambda1, lambda2) print "Initial Tabu Search Done!" delta, S, L, line_values, item_values, completion, tardiness = tabu( N, NL, S, L, items, completion, tardiness, line_values, item_values, G, lambda1, lambda2 ) G += delta completion, tardiness, item_values = generate.verify(S, items, lambda1, lambda2) u = tardiness.count(0) cv = u / len(tardiness) print tardiness return G, cv, S
def solve(input_data,m,lambda1,NR): lambda2 = 1- lambda1 Data = input_data.split('\n') # load data n = len(Data) -1 # get the amount of items items = [] for j in xrange(n): data = Data[j] parts = data.split() p = int(parts[0]) # get the process time s = int(parts[2]) # get the setup time d = int(parts[3]) # get the due date wt = int(parts[4]) # get the tardiness weights wc = int(parts[5]) # get the completion weights items.append(Item(p+s,d,wt,wc)) # combine those item data print 'Data loaded!' S,L,completion = generate.initialization(items,n,m) print 'Initialization done!' lateness = generate.late(completion,items) # begin the value initialization tardiness = generate.tard(lateness) item_values = [] for j in xrange(n): item = items[j] wt,wc = item.wt,item.wc t,c = tardiness[j],completion[j] value = h(t,c,wt,wc,lambda1,lambda2) item_values.append(value) G = generate.H(item_values,L) line_values = [] for s in S: value = generate.H(item_values,s) line_values.append(value) print 'Initial values done!' for k in xrange(NR): l_p,l_m = generate.reorder(items,S,line_values,item_values) S[l_p],c_p = ATC(items,S[l_p]) S[l_m],c_m = ATC(items,S[l_m]) for j in S[l_p]: completion[j] = c_p.pop(0) c = completion[j] item = items[j] wt,wc = item.wt,item.wc late = completion[j] - item.due t = generate.tard(late) item_values[j] = h(t[0],c,wt,wc,lambda1,lambda2) for j in S[l_m]: completion[j] = c_m.pop(0) c = completion[j] item = items[j] wt,wc = item.wt,item.wc late = completion[j] - item.due t = generate.tard(late) item_values[j] = h(t[0],c,wt,wc,lambda1,lambda2) delta_p = generate.H(item_values,S[l_p]) - line_values[l_p] delta_m = generate.H(item_values,S[l_m]) - line_values[l_m] line_values[l_p] += delta_p line_values[l_m] += delta_m G = G + delta_m + delta_p lateness = generate.late(completion,items) tardiness = generate.tard(lateness) u = tardiness.count(0) cv = u/len(tardiness) return G,cv,S
def solve(input_data, m, lambda1, NR): lambda2 = 1 - lambda1 Data = input_data.split('\n') # load data n = len(Data) - 1 # get the amount of items items = [] for j in xrange(n): data = Data[j] parts = data.split() p = int(parts[0]) # get the process time s = int(parts[2]) # get the setup time d = int(parts[3]) # get the due date wt = int(parts[4]) # get the tardiness weights wc = int(parts[5]) # get the completion weights items.append(Item(p + s, d, wt, wc)) # combine those item data print 'Data loaded!' S, L, completion = generate.initialization(items, n, m) print 'Initialization done!' lateness = generate.late(completion, items) # begin the value initialization tardiness = generate.tard(lateness) item_values = [] for j in xrange(n): item = items[j] wt, wc = item.wt, item.wc t, c = tardiness[j], completion[j] value = h(t, c, wt, wc, lambda1, lambda2) item_values.append(value) G = generate.H(item_values, L) line_values = [] for s in S: value = generate.H(item_values, s) line_values.append(value) print 'Initial values done!' for k in xrange(NR): l_p, l_m = generate.reorder(items, S, line_values, item_values) S[l_p], c_p = ATC(items, S[l_p]) S[l_m], c_m = ATC(items, S[l_m]) for j in S[l_p]: completion[j] = c_p.pop(0) c = completion[j] item = items[j] wt, wc = item.wt, item.wc late = completion[j] - item.due t = generate.tard(late) item_values[j] = h(t[0], c, wt, wc, lambda1, lambda2) for j in S[l_m]: completion[j] = c_m.pop(0) c = completion[j] item = items[j] wt, wc = item.wt, item.wc late = completion[j] - item.due t = generate.tard(late) item_values[j] = h(t[0], c, wt, wc, lambda1, lambda2) delta_p = generate.H(item_values, S[l_p]) - line_values[l_p] delta_m = generate.H(item_values, S[l_m]) - line_values[l_m] line_values[l_p] += delta_p line_values[l_m] += delta_m G = G + delta_m + delta_p lateness = generate.late(completion, items) tardiness = generate.tard(lateness) u = tardiness.count(0) cv = u / len(tardiness) return G, cv, S