Exemple #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
def tabu(N, NL, S, l, items, G, completion, line_values, lambda1, lambda2):
    TL = [None] * NL
    pairs = generate.pairsets(S[l])
    completion_temp = completion[:]
    line_values_temp = line_values[:]
    G_star = G
    S_star = []
    test_G = []
    for s in S:
        S_star.append(s[:])
    for k in xrange(N):
        test_S = []
        s = random.choice(pairs)
        move = 0
        if s not in TL:
            job = list(s)
            a = job[0]
            b = job[1]
            a_idx = S_star[l].index(a)
            b_idex = S_star[l].index(b)
            S_temp = generate.innerswap(S_star[l], a_idx, b_idex)
            c, v = continueatcs.complete_time(
                S_star[:l] + [S_temp] + S_star[l + 1:], items, lambda1,
                lambda2)
            G_temp = sum(v)
            if test_G == [] or G_temp < test_G:
                test_G = G_temp
                test_S = S_temp[:]
                completion_temp = c[:]
                line_values_temp = v[:]
                a_star = a
                b_star = b
                move = 1
        else:
            continue
        if move == 0:
            continue
        change_set = set([a_star, b_star])
        generate.pairsets_update(pairs, change_set)
        S_star[l] = test_S[:]
        TL.pop(0)
        TL.append(change_set)
        if test_G < G_star:
            G_star = test_G
            S[l] = test_S[:]
            line_values = line_values_temp[:]
            completion = completion_temp[:]
    return G_star, S, line_values, completion
Exemple #3
0
def tabu(N, NL, S, L, items, G, lambda1, lambda2):
    TL = [None] * NL
    from_same = []
    from_diff = []
    pairs = generate.pairsets(L)
    G_star = G
    L_star = L[:]
    S_c = []
    S_ori = []
    for s in S:
        S_ori.append(s[:])
        S_c.append(s[:])
    G_test = 0
    for k in xrange(N):
        issame = 0
        isdiff = 0
        out = 0
        s = random.choice(pairs)
        move = 0
        job = list(s)
        a_L_index = max(L.index(job[0]), L.index(job[1]))
        b_L_index = min(L.index(job[0]), L.index(job[1]))
        a = L[a_L_index]
        b = L[b_L_index]
        l_a = generate.find_job(a, S)
        l_b = generate.find_job(b, S)
        a_idx = S[l_a].index(a)
        b_idx = S[l_b].index(b)
        if s not in TL:
            if l_a == l_b:
                # a <--> b
                S_temp = same_S(S, l_a, a_idx, b_idx)
                G_temp = test_G(items, S_temp, lambda1, lambda2)
            else:
                # a -> b's
                S_temp_1 = diff1_S(S, l_a, l_b, a, b_idx)
                G_temp_1 = test_G(items, S_temp_1, lambda1, lambda2)
                # b -> a's
                S_temp_2 = diff2_S(S, l_a, l_b, b, a_idx)
                G_temp_2 = test_G(items, S_temp_2, lambda1, lambda2)
                # a <--> b
                S_temp_3 = diff3_S(S, l_a, l_b, a, b, a_idx, b_idx)
                G_temp_3 = test_G(items, S_temp_3, lambda1, lambda2)
                G_temp = min(G_temp_1, G_temp_2, G_temp_3)
        elif s in from_same:
            continue
        elif s in from_diff:
            # a -> b's
            S_temp_1 = diff1_S(S, l_a, l_b, a, b_idx)
            G_temp_1 = test_G(items, S_temp_1, lambda1, lambda2)
            # b -> a's
            S_temp_2 = diff2_S(S, l_a, l_b, b, a_idx)
            G_temp_2 = test_G(items, S_temp_2, lambda1, lambda2)
            G_temp = min(G_temp_1, G_temp_2)
        if G_test == 0 or G_temp < G_test:
            move = 1
            G_test = G_temp
            a_temp, b_temp = a, b
            l_a_temp, l_b_temp = l_a, l_b
            if l_a == l_b:
                S_star = S_temp
                issame, isdiff = 1, 0
                out = 0
            else:
                if s in TL:
                    out = 1
                    issame, isdiff = 0, 0
                    if G_temp == G_temp_1:
                        S_star = S_temp_1
                    elif G_temp == G_temp_2:
                        S_star = S_temp_2
                else:
                    out = 0
                    if G_temp == G_temp_1:
                        S_star = S_temp_1
                        issame, isdiff = 0, 0
                    elif G_temp == G_temp_2:
                        S_star = S_temp_2
                        issame, isdiff = 0, 0
                    elif G_temp == G_temp_3:
                        S_star = S_temp_3
                        issame, isdiff = 0, 1
        if move == 0:
            continue
        L = generate.innerswap(L, L.index(a_temp), L.index(b_temp))
        pairs = generate.pairsets(L)
        change_set = set([a_temp, b_temp])
        if out:
            TL[TL.index(change_set)] = None
            from_diff.remove(change_set)
        delete_set = TL.pop(0)
        if delete_set in from_same:
            from_same.remove(delete_set)
        elif delete_set in from_diff:
            from_diff.remove(delete_set)
        if isdiff or issame:
            TL.append(change_set)
            if isdiff:
                from_diff.append(change_set)
            if issame:
                from_same.append(change_set)
        else:
            TL.append(None)
        S = S_star
        G = G_test
        TL, from_same, from_diff = generate.TL_update(TL, from_same, from_diff,
                                                      S)
        if G < G_star:
            G_star = G
            l = 0
            for s in S:
                S_c[l][:] = s[:]
                l += 1
            L_star = L[:]
    return G_star, S_c
Exemple #4
0
def same_S(S, l, a_idx, b_idx):
    S_t = []
    for s in S:
        S_t.append(s[:])
    S_t[l] = generate.innerswap(S_t[l], a_idx, b_idx)
    return S_t