これを得るプログラムを、本資料では次のように分割して示しています。
プログラムIII ************************ 再計画 ************************
・プログラムIII-1 リソース(場所)の定義
・プログラムIII-2 リソース(作業員)の定義
・プログラムIII-3 再計画アクティビティ(仕掛作業、未着手作業)の定義
未着手作業の先行制約の設定
・プログラムIII-4 モードの設定
仕掛作業のモード継承
未着手作業の資源制約(配員)
未着手作業の資源制約(作業場所)
・プログラムIII-5 RCPSP求解
プログラム:Part III
#プログラムIII-1.0
from optseq import *
import math
#=======================================================================
print("")
print(' ************************ リスケ on rdate **********************')
import dill
dill.load_session('usukiR040510b.pkl')
#=======================================================================
usuki3=Model()
CS=["CS","CC","SS","SC"]
プログラムIII-1
#プログラムIII-1
#=======================================================================
#リソースの定義(場所)
#=======================================================================
#-----メッシュの使用可否
resPL={}
for id in R:
resPL[id]=0
if not id in [4,5,6,13]:
for i in range(0,R[id][1]):
for j in range(0,R[id][2]):
resPL[id,i,j] =usuki3.addResource(R[id][0]+"[{0:02d}_{1:02d}]".format(i,j), capacity={(0,"inf"):1})
if id==4:
for i in range(0,R[id][1]):
for j in range(0,R[id][2]):
if i in range(0,11) and j in range(0,12):
resPL[id,i,j] =usuki3.addResource(R[id][0]+"[{0:02d}_{1:02d}]".format(i,j), capacity={(0,"inf"):0})
else:
resPL[id,i,j] =usuki3.addResource(R[id][0]+"[{0:02d}_{1:02d}]".format(i,j), capacity={(0,"inf"):1})
if id==5:
for i in range(0,R[id][1]):
for j in range(0,R[id][2]):
if i in range(0,7) and j in range(0,10):
resPL[id,i,j] =usuki3.addResource(R[id][0]+"[{0:02d}_{1:02d}]".format(i,j), capacity={(0,"inf"):0})
else:
resPL[id,i,j] =usuki3.addResource(R[id][0]+"[{0:02d}_{1:02d}]".format(i,j), capacity={(0,"inf"):1})
if id==6:
for i in range(0,R[id][1]):
for j in range(0,R[id][2]):
if i in [0,22,23,24,25,26,27,28,29,30,31,32,33,34,35] and j in range(0,13):
resPL[id,i,j] =usuki3.addResource(R[id][0]+"[{0:02d}_{1:02d}]".format(i,j), capacity={(0,"inf"):0})
elif i in range(1,17) and j in range(0,1):
resPL[id,i,j] =usuki3.addResource(R[id][0]+"[{0:02d}_{1:02d}]".format(i,j), capacity={(0,"inf"):0})
else:
resPL[id,i,j] =usuki3.addResource(R[id][0]+"[{0:02d}_{1:02d}]".format(i,j), capacity={(0,"inf"):1})
if id==13:
for i in range(0,R[id][1]):
for j in range(0,R[id][2]):
if i in [31,32,33,34,35,36,37,63,64,65,66,67,68,69,70,71] and j in range(0,24):
resPL[id,i,j] =usuki3.addResource(R[id][0]+"[{0:02d}_{1:02d}]".format(i,j), capacity={(0,"inf"):0})
else:
resPL[id,i,j] =usuki3.addResource(R[id][0]+"[{0:02d}_{1:02d}]".format(i,j), capacity={(0,"inf"):1})
プログラムIII-2
#プログラムIII-2
#=======================================================================
#リソースの定義(作業員)
#=======================================================================
eps1=1.25
resWH={} #取付28人
r=math.floor(28*4*eps1);
resWH=usuki3.addResource("R[WH]", capacity={(0,"inf"):r})
#-----
resWW={} #溶接43人
r=math.floor(43*4*eps1);
resWW=usuki3.addResource("R[WW]", capacity={(0,"inf"):r})
#-----
eps2=1.25
resWF1={} #鉄艤5人
r=math.floor(5*4*eps2);
resWF1=usuki3.addResource("R[WF1]", capacity={(0,"inf"):r})
#-----
resWF2={} #甲配7人
r=math.floor(7*4*eps2);
resWF2=usuki3.addResource("R[WF2]", capacity={(0,"inf"):r})
#-----
resWF3={} #機配5人⇒10人
r=math.floor(10*4*eps2);
resWF3=usuki3.addResource("R[WF3]", capacity={(0,"inf"):r})
#-----
resWP={} #塗装内4人⇒8人
r=math.floor(8*4*eps2);
resWP=usuki3.addResource("R[WP]", capacity={(0,"inf"):r})
#-----
resWP2={} #塗装外8人
r=math.floor(8*4*eps2);
resWP2=usuki3.addResource("R[WP2]", capacity={(0,"inf"):r})
プログラムIII-3
#プログラムIII-3.1
#=======================================================================
#再計画 アクティビティ idata3
#=======================================================================
rdate=179
w1=[]; w2=[]; w3=[];
idata12=idata1.union(idata2)
for i in idata12:
if data[i][3]+data[i][2] < rdate: w1.append(i)
if data[i][3] <= rdate and rdate <= data[i][3]+data[i][2]: w2.append(i)
if rdate < data[i][3]: w3.append(i)
idata3a=w2; #仕掛かり中のアクティビティ
idata3b=w3; #仕掛かっていないアクティビティ
idata3=w2+w3; #リスケすべきアクティビティ
print(idata3)
#プログラムIII-3.2
#=======================================================================
#再計画 作業の定義
#=======================================================================
act3={}
for i in idata3:
j=i
while data[j][1]!=0:
j=data[j][4][0]
act3[i]=usuki3.addActivity(data[i][0], duedate=data[j][3]+data[j][2], \
backward=True)
#プログラムIII-3.3
#=======================================================================
#再計画 先行制約
#=======================================================================
for i in idata3b:
if data[i][1] in ACT_gisou+ACT_kumitate:
for iw in[0,1,2,3,4]:
if data[i][4][iw] in idata3:
usuki3.addTemporal(act3[i],act3[data[i][4][iw]],\
tempType=CS[data[i][5][iw][0]], delay= int(data[i][5][iw][1]*2))
if data[i][1] in ["A02010","A02610","A03010","A03210","A04310",\
"A09210"] and data[i][5][iw][0]==0:
usuki3.addTemporal(act3[data[i][4][iw]],act3[i],\
tempType=CS[3], delay=-int(data[i][5][iw][1]*2))
#-----
for i in idata3b:
if data[i][1] in PL_gisou+PL_kumitate:
for iw in [0]:
if data[i][4][iw] in idata3b:
ii=data[i][4][iw]
usuki3.addTemporal(act3[i],act3[ii],tempType="CS")
usuki3.addTemporal(act3[ii],act3[i],tempType="SC")
for jj in idata3b:
for iw in [0]:
if data[i][4][iw] in idata3b:
if data[jj][4][iw]==i:
usuki3.addTemporal(act3[jj],act3[i],tempType="CS")
usuki3.addTemporal(act3[i],act3[jj],tempType="SC")
#-----開始日の制約
for i in idata3a:
usuki3.addTemporal("source",act3[i],tempType="SS",delay= int(data[i][3]))
usuki3.addTemporal(act3[i],"source",tempType="SS",delay=-int(data[i][3]))
#-----
for i in idata3b:
usuki3.addTemporal("source",act3[i],tempType="SS",delay= rdate)
プログラムIII-4
#プログラムIII-4.1
#=======================================================================
#仕掛作業 資源制約(配員、場所)
#=======================================================================
mode3={}
for i in idata3a:
if data[i][1] in ACT_gisou:
mode3[i]=mode1[i]
mode3[i].name='mode3['+i+']'
act3[i].addModes(mode3[i])
#-----
if data[i][1] in [11,1,2,3,4,5,6,12,13,14,15,36,37,38]: #ACT_kumitate.remove(16):
mode3[i]=mode2[i]
mode3[i].name='mode3['+i+']'
act3[i].addModes(mode3[i])
#-----
if data[i][1] in PL_gisou:
mode3[i]=mode1[i]
s=mode1[i].name
mode3[i].name=s[:4]+"3"+s[6:]
act3[i].addModes(mode3[i])
#-----
if data[i][1] in PL_kumitate:
mode3[i]=mode2[i]
s=mode2[i].name
mode3[i].name=s[:4]+"3"+s[6:]
act3[i].addModes(mode3[i])
#プログラムIII-4.2
#=======================================================================
#再計画 資源制約(配員)
#=======================================================================
for i in idata3b:
if data[i][1] in ACT_gisou+ACT_kumitate:
#-----
#1F #2W #3C #4CC #20ブラスト #31鉄艤 #32甲配 #33機配 #34PA #39_甲配 #40_機配
if data[i][1] in [1,2,3,4,20,31,32,33,34,39,40]:
n=math.ceil(data[i][9][0][0]/5) #1人で何日かかるか
if data[i][1] in [1,3]: #取付
mode3[i]=Mode("mode3["+i+"]",duration=n)
mode3[i].addBreak(0,0)
mode3[i].addResource(resWH,{(0,n):5})
mode3[i].addParallel(1,n,28)
if data[i][1] in [2,4]: #溶接
mode3[i]=Mode("mode3["+i+"]",duration=n)
mode3[i].addBreak(0,0)
mode3[i].addResource(resWW,{(0,n):5})
mode3[i].addParallel(1,n,43)
if data[i][1] in [31]: #鉄艤装
mode3[i]=Mode("mode3["+i+"]",duration=n)
mode3[i].addBreak(0,0)
mode3[i].addResource(resWF1,{(0,n):5})
mode3[i].addParallel(1,n,5)
if data[i][1] in [32,39]: #甲板配管
mode3[i]=Mode("mode3["+i+"]",duration=n)
mode3[i].addBreak(0,0)
mode3[i].addResource(resWF2,{(0,n):5})
mode3[i].addParallel(1,n,7)
if data[i][1] in [33,40]: #機関配管
mode3[i]=Mode("mode3["+i+"]",duration=n)
mode3[i].addBreak(0,0)
mode3[i].addResource(resWF3,{(0,n):5})
mode3[i].addParallel(1,n,10)
if data[i][1]==20: #塗装内
mode3[i]=Mode("mode3["+i+"]",duration=n)
mode3[i].addBreak(0,0)
mode3[i].addResource(resWP, {(0,n):5})
mode3[i].addParallel(1,n,8)
if data[i][1]==34: #塗装外
mode3[i]=Mode("mode3["+i+"]",duration=n)
mode3[i].addBreak(0,0)
mode3[i].addResource(resWP2,{(0,n):5})
mode3[i].addParallel(1,n,8)
act3[i].addModes(mode3[i])
#-----
#10:入荷 #7:社0 #8:検0 #9:W0 #16:運 #17:運0 #18:運2 #19:合体 #21:運ブ #25:運ブ2 #35:AT #0:搭載
elif data[i][1] in [10,7,8,9,16,17,18,19,21,25,35,0]:
mode3[i]=Mode("mode3["+i+"]",duration=data[i][2])
act3[i].addModes(mode3[i])
#-----
#11:開始 #5:社 #6:検 #12:正 #13:反 #14:積み #15:一体 #36:磨き #37:O/P #38:_鉄艤 #16:運
elif data[i][1] in [11,5,6,12,13,14,15,36,37,38,16]:
mode3[i]=Mode("mode3["+i+"]",duration=data[i][2])
act3[i].addModes(mode3[i])
#プログラムIII-4.3
#=======================================================================
#再計画 資源制約(作業場所)
#=======================================================================
for i in idata3b:
if data[i][1] in PL_gisou+PL_kumitate:
#-----
if data[i][1] in [22,23,24,70,71,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87]: #PL_gisou.remove(72): #72:D5_AH
if data[i][1] in [22,23,24]: data[i][6]=AB
for no in range(len(data[i][6])):
no1=data[i][6][no][0];
L=R[no1][1]; B=R[no1][2];
L1=data[i][6][no][1]; L2=data[i][6][no][2];
B1=data[i][6][no][3]; B2=data[i][6][no][4];
skipL=math.floor(L/8); skipL=1
skipB=math.floor(B/2);
l=math.floor(data[i][8][0]); b=math.floor(data[i][8][1]);
if data[i][1] in [22,23,24]: l=19; b=16;
for j in range(L1,L2-l+1,skipL):
for k in range(B1,B2-b+1,skipB):
mode3[i]=Mode("mode3["+i+"]_R[{0:03d}][{1:03d}_{2:03d}][{3:03d}_{4:03d}]".format(no1,j,k,l,b))
for s in range(0,l):
for t in range(0,b):
mode3[i].addBreak(0,0)
mode3[i].addResource(resPL[no1,j+s,k+t],1,"break")
act3[i].addModes(mode3[i])
#-----
elif data[i][1] in [51,53,54,55,56,57,58,59,60,61,62,63,64]: #PL_kumitate.remove(65): #65:K4_1AS1
for no in range(len(data[i][6])):
no1=data[i][6][no][0];
L=R[no1][1]; B=R[no1][2];
L1=data[i][6][no][1]; L2=data[i][6][no][2];
B1=data[i][6][no][3]; B2=data[i][6][no][4];
skipL=math.floor(L/8); skipL=1
skipB=math.floor(B/2);
l=math.floor(data[i][8][0]); b=math.floor(data[i][8][1]);
if data[i][1] in [22,23,24]: l=19; b=16;
for j in range(L1,L2-l+1,skipL):
for k in range(B1,B2-b+1,skipB):
mode3[i]=Mode("mode3["+i+"]_R[{0:03d}][{1:03d}_{2:03d}][{3:03d}_{4:03d}]".format(no1,j,k,l,b))
for s in range(0,l):
for t in range(0,b):
mode3[i].addBreak(0,0)
mode3[i].addResource(resPL[no1,j+s,k+t],1,"break")
act3[i].addModes(mode1[i])
#-----
elif i in {"A01431","A11701","A11711","A11721"}: #場所と期間が固定されている場合
if data[i][6]!=0:
for no in range(len(data[i][6])):
no1=data[i][6][no][0];
L=R[no1][1]; B=R[no1][2];
L1=data[i][6][no][1]; L2=data[i][6][no][2];
B1=data[i][6][no][3]; B2=data[i][6][no][4];
skipL=math.floor(L/4); skipL=2;
skipB=math.floor(B/2); # skipB=1;
l=math.floor(data[i][8][0]); b=math.floor(data[i][8][1]);
for j in range(L1,L2-l+1,skipL):
for k in range(B1,B2-b+1,skipB):
mode3[i]=Mode("mode3["+i+"]_R[{0:03d}][{1:03d}_{2:03d}][{3:03d}_{4:03d}]".format(no1,j,k,l,b),duration=int(data[i][2]))
for s in range(0,l):
for t in range(0,b):
mode3[i].addResource(resPL[no1,j+s,k+t],1)
act3[i].addModes(mode1[i,no1,j,k])
プログラムIII-5
#プログラムIII-5
#=======================================================================
#再計画 問題の規模
#=======================================================================
N=len(usuki3.act)
print("アクティビティ総数(含待機数):",N)
M=[]
for a in usuki3.act: M.append(len(a.modes))
print("モード数:",M)
print("平均モード数:",round(sum(M)/N))
P=math.ceil(math.log10(round(sum(M)/N)**N))
print("問題の規模: 10**",P)
#=======================================================================
#組立工程計画 問題求解
#=======================================================================
#usuki3.Params.Makespan=True
usuki3.Params.Initial=False
usuki3.Params.TimeLimit=600
usuki3.Params.Neighborhood=20
usuki3.Params.OutputFlag=False
usuki3.optimize()
プログラムIII-6
#プログラムIII-6
#=======================================================================
#データセットの更新
#=======================================================================
print("")
for a in usuki3.act:
for i in idata3b:
if a.name==data[i][0]:
if len(a.modes)==1: nam=a.selected.name
else: nam=a.selected
#print("_"+a.name,len(a.modes),nam,a.start,a.completion)
data[i][3]=a.start
data[i][2]=a.completion-a.start
if len(nam)>15:
r=int(nam[16:19])
x=int(nam[21:24])
y=int(nam[25:28])
l=int(nam[30:33])
b=int(nam[34:37])
place=[[ r, x, x+l, y, y+b]]
data[i][6]=place
print(data[i][0:8])
#========================================================================
filename="usu_S1777_resche_R040510c.csv"
print("writing "+filename)
usuki3.writeExcel(filename)
import dill
dill.dump_session('usukiR040510c.pkl')
#------
#eof