OptSeq |
#rcpsp35.py
from optseq import *
import math
#====データセット
#i:[名前、後続、時数]
data={
1:["搬入", [2],1],
2:["作業1",[3],10],
3:["作業2",[4],20],
4:["搬出", [0],1],
}
#====アクティビティ
prob=Model()
act={}
for i in data:
act[i]=prob.addActivity(name=data[i][0])
#====先行制約
for i in data:
for j in data[i][1]:
if j>0: prob.addTemporal(act[i],act[j])
#----搬入日・搬出日の固定
prob.addTemporal("source",act[1],tempType="CC",delay= 1)
prob.addTemporal(act[1],"source",tempType="CC",delay=-1)
# prob.addTemporal("source",act[4],tempType="CC",delay= 10)
# prob.addTemporal(act[4],"source",tempType="CC",delay=-10)
#====資源制約
res=prob.addResource("worker",capacity={(0,"inf"):5})
mode={}
for i in data:
if i in [2,3]:
period=math.ceil(data[i][2]/8) #1人で何日かかるか
mode[i]=Mode("M{0:02d}_{1:02d}".format(i,period),duration=period)
mode[i].addResource(res,requirement=1)
mode[i].addParallel(start=1,finish=period,maxparallel=2)
act[i].addModes(mode[i])
else:
mode[i]=Mode("M{0:02d}".format(i),duration=1)
act[i].addModes(mode[i])
#----場所取り
d_act={}
d_act=prob.addActivity("場所取り")
place=prob.addResource("place",capacity={(0,"inf"):1})
d_mode={}
d_mode=Mode("M01_")
d_mode.addBreak(0,'inf')
d_mode.addResource(place,1,"break")
d_act.addModes(d_mode)
prob.addTemporal(act[1],d_act,tempType="CS")
prob.addTemporal(d_act,act[1],tempType="SC")
prob.addTemporal(d_act,act[4],tempType="CS")
prob.addTemporal(act[4],d_act,tempType="SC")
#====求解
prob.Params.Makespan=True
prob.Params.TimeLimit=1
prob.optimize()
prob.write("rcpsp35.txt")
prob.writeExcel("rcpsp35.csv")
|