# -*- coding: utf-8 -*-
"""
Created on Tue Aug 21 19:02:06 2018
@author: kimmy
"""
import numpy as np
DUR = [0,7,9,6,6,8,7,1,3,1,5,0]
IS = [[2,3],[4],[4],[5,6,7],[8],[8],[8],[9],[10,11],[12],[12],[0]]
IP = [[0],[1],[1],[2,3],[4],[4],[4],[5,6,7],[8],[9],[9],[10,11]]
NB_TASKS = 12
NB_RE = 4
Re_De = [[0,0,0,0],[0,0,0,0],[5,0,0,0],[0,0,0,7],[0,0,0,4],[0,0,3,0],[0,0,8,0],[0,7,0,0],[0,5,0,0],[6,0,0,0],[5,0,0,0],[0,0,0,0]]
Re_Cap = [10,10,10,10]
#Step 1
EST= [0]* NB_TASKS
for i in range(1,NB_TASKS):
M = []
for j in IP[i]:
M.append(EST[j-1] + DUR[j-1])
N = max(M)
EST[i] = N
#print(EST)
LST = [0]* NB_TASKS
LST[NB_TASKS-1] = EST[NB_TASKS-1]
for i in range(NB_TASKS-2,-1,-1):
M1 = []
for j in IS[i]:
M1.append(LST[j-1] - DUR[i])
N1 = min(M1)
LST[i] = N1
TF = [0]* NB_TASKS
for i in range(0,NB_TASKS):
TF[i] = LST[i] - EST[i]
t = LST[NB_TASKS-1]
# Step 2
while t > 0:
AS = [i for i in range(NB_TASKS) if LST[i] <= t-1 and LST[i] + DUR[i] > t-1]
print(AS)
a = []
for i in AS:
a.append(Re_De[i])
b = np.sum(a,axis = 0)
R = [0]* NB_RE
for k in range(0,4):
R[k] = b[k] - Re_Cap[k]
print(R)
if R[0] <= 0 and R[1] <= 0 and R[2] <= 0 and R[3] <= 0:
t = t - 1
if t > 0:
continue
else:
print(LST[NB_TASKS-1])
break
else: #Step 3
RCS_k = []
RCS_k_r_k = []
for k in range(0,4):
if R[k] > 0:
for i in AS:
if Re_De[i][k] >= 0:
RCS_k.append(i)
RCS_k_r_k.append((i,R[k]))
print(k)
print(RCS_k)
RCS_k_R_k = []
for r in RCS_k_r_k:
m = r[1]/len(RCS_k)
RCS_k_R_k.append((r[0],m))
#print(RCS_k_R_k)
dur = []
for i in RCS_k:
dur.append(DUR[i])
#STEP 4
dic = zip(dur, RCS_k)
dic_sorted = sorted(dic, reverse = True)
RCS_k_sorted = []
for r in dic_sorted:
RCS_k_sorted.append(r[1])
#print(RCS_k_sorted)
C = 5
for v in RCS_k_sorted:
for item in RCS_k_R_k:
if v == item[0]:
R[k] = item[1]
EC_k = R[k]* DUR[v]*1
#print(EC_k)
NRCS = []
if EC_k <= C:
NRCS.append(v)
C = C - EC_k
if v == RCS_k_sorted[-1]:
t = t -1
#STEP5
if EC_k > C:
est = []
lst = []
N = RCS_k_sorted
for n in N:
if n not in NRCS:
est.append(EST[n])
est_N = sorted(zip(est,N))
q = est_N[0][1]
for n in N:
if n not in NRCS:
lst.append(LST[n])
lst_N = sorted(zip(lst,N), reverse = True)
p = lst_N[0][1]
IS[q].append(p)
IP[p].append(q)
版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。