알파카징징이 알파카징징이 코딩하는 알파카

데이터 구조 및 분석 ch_4_6 Assembly Line Scheduling in Recursion and DP

» writing

KAIST 산업및시스템공학과 문일철_ 데이터 구조 및 분석 수업을 참고하여 작성하였습니다

ch_4_6 Assembly Line Scheduling in Recursion and DP

정의


Assembly Line Scheduling in Recursion and DP

1. Assembly Line Scheduling in Recursion and DP
class Assemblylines :
    timeStation = [[7,9,3,4,8,4],[8,5,6,4,5,7]]
    timeBelt = [[2,2,3,1,3,4,3],[4,2,1,2,2,1,2]]
    intCount = 0
    def Scheduling(self, idxLine, idxStation):
        print("Calculate scheduling : line, sation :", idxLine, idxStation,"(", self.intCount, "recursion colis")
        self.intCount = self.intCount + 1
        if idxStation == 0:
            if idxLine == 1:
                return self.timeBelt[0][0] + self.timeStation[0][0]
            elif idxLine == 2:
                return self.timeBelt[1][0] + self.timeStation[1][0]
            if idxLine == 1:
                costLine1 = self.Scheduling(1, idxStation - 1) + self.timeStation[0][idxStation]
                costLine2 = self.Scheduling(2, idxStation - 1) + self.timeStation[0][idxStation] + self.timeBelt[1][idxStation]
            elif idxLine == 2:
                costLine1 = self.Scheduling(1, idxStation - 1) + self.timeStation[1][idxStation] + self.timeBelt[0][idxStation]
                costLine2 = self.Scheduling(2, idxStation - 1) + self.timeStation[1][idxStation]
            if costLine1 > costLine2 :
                return costLine2
            else :
                return costLine1
            
    def startScheduling(self):
        numStation = len(self.timeStation[0])
        costLine1 = self.Scheduling(1, numStation-1) + self.timeBelt[0][numStation]
        costLine2 = self.Scheduling(2, numStation - 1) + self.timeBelt[1][numStation]
        if costLine1 > costLine2:
            return costLine2
        else:
            return costLine1

lines = Assemblylines()
time = lines.startScheduling()
print(time)