Beispiel #1
0
def tabu(N,NL,S,items, completion,tardiness,lambda1,lambda2):
	TL = [None]*NL
	pairs = generate.pairsets(S)
	completion_temp = completion[:]
	tardiness_temp = tardiness[:]
	delta_star = 0
	Delta = 0
	S_star = S[:]
	for k in xrange(N):
		delta = []
		for s in pairs:
			if s not in TL:
				job = list(s)
				a = S[max(S.index(job[0]),S.index(job[1]))]
				b = S[min(S.index(job[0]),S.index(job[1]))]
				delta_c_a = - items[b].process
				delta_c_b = items[a].process
				delta_t_a = - min(items[b].process,tardiness_temp[a])
				delta_t_b = max(completion_temp[a] - items[b].due,0) - tardiness_temp[b]
				wt_a,wt_b,wc_a,wc_b = items[a].wt,items[b].wt,items[a].wc,items[b].wc
				delta_a = h(delta_t_a,delta_c_a,wt_a,wc_a,lambda1,lambda2)
				delta_b = h(delta_t_b,delta_c_b,wt_b,wc_b,lambda1,lambda2)
				delta_h = delta_a + delta_b
				if delta == []:
					delta = delta_h
					delta_a_star = delta_a
					delta_b_star = delta_b 
					a_star,b_star = a,b
				elif delta_h < delta:
					delta = delta_h
					delta_a_star = delta_a
					delta_b_star = delta_b 
					a_star,b_star = a,b
		if delta == []:
			break
		a = S.index(a_star)
		b = S.index(b_star)
		S = generate.innerswap(S,a,b)
		change_set = set([a_star,b_star])
		generate.pairsets_update(pairs,change_set)
		TL.pop(0)
		TL.append(change_set)
		completion_temp[a_star] -= items[b_star].process
		completion_temp[b_star] += items[a_star].process
		tardiness_temp[a_star] = max(completion_temp[a_star] - items[a_star].due,0)
		tardiness_temp[b_star] = max(completion_temp[b_star] - items[b_star].due,0)
		Delta += delta
		if Delta < delta_star:
			delta_star = Delta
			S_star = S[:]
	return delta_star,S_star
Beispiel #2
0
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
Beispiel #3
0
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
Beispiel #4
0
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