def updateRobLeaveCond(self, robID): ''' update robot's state when the leave event has been triggered. ''' rob = self.robotLst[robID] preTaskID = rob.taskID self._actionSeq.append(ActionTuple(robID=robID, taskID=rob.taskID, eventType=EventType.leave, eventTime=rob.leaveTime)) while True: if rob.encodeIndex == (self.taskNum - 1): rob.stopBool = True break rob.encodeIndex += 1 taskID = self.encode[robID][rob.encodeIndex] if self.taskCmplt(taskID): continue else: roadDur = self.calRoadDur(preTaskID, taskID, robID) arriveTime = rob.leaveTime + rob.roadDur if arriveTime > self.taskLst[taskID].cmpltTime: self.encode[robID][rob.encodeIndex] = -1 # print('optimal') continue rob.roadDur = roadDur rob.taskID = taskID rob.arriveTime = rob.leaveTime + rob.roadDur rob.stateType = RobotState['onRoad'] break
def arriveCmpltTask(self,actionID,encodeInd): rob = self.robotLst[actionID] rob.leaveTime = rob.arriveTime rob.stateType = RobotState['onTask'] self.decodeTime = rob.arriveTime taskID = rob.taskID arriveTime = rob.arriveTime self._actionSeq.append(ActionTuple(robID=actionID, taskID=taskID, eventType=EventType.arrive, eventTime=arriveTime))
def _calActionSeq(self, robID, taskID, preOnRoadPeriod): rob = self._robotLst[robID] robAbi = rob.ability preDictActTime = rob.leaveTime + preOnRoadPeriod if preDictActTime >= self._actionSeq.actionTime: calTask = copy.deepcopy(self._taskLst[taskID]) vaild = calTask.calCurrentState(rob.leaveTime + preOnRoadPeriod) cRate = sys.float_info.max executePeriod = sys.float_info.max if vaild == True: calTask.cRate = calTask.cRate - robAbi if calTask.cRate >= 0: executePeriod = sys.float_info.max else: executePeriod = calTask.calExecuteDur() cRate = calTask.cRate ''' bug?? ''' # print('executePeriod = ', executePeriod) cmplt_time = preDictActTime + executePeriod # raise Exception("dsadsa") action_tuple_lst = [] action_tuple_lst.append( ActionTuple(robID=robID, taskID=taskID, eventType=EventType.arrive, eventTime=preDictActTime)) if executePeriod != INF_NUM: action_tuple_lst.append( ActionTuple(robID=robID, taskID=taskID, eventType=EventType.leave, eventTime=cmplt_time)) self._predictActionSeq[RobTaskPair(robID=robID, taskID=taskID)] = action_tuple_lst self._predictActionSeqType[RobTaskPair(robID=robID, taskID=taskID)] = ActionSeqType.InOrder self._predictOnTaskPeriod[RobTaskPair(robID=robID, taskID=taskID)] = executePeriod self.taskVariableDic[RobTaskPair(robID=robID, taskID=taskID)] = calTask.variableInfo() return executePeriod # ActionSeq = ''' deepcopy 存在问题 ''' pass else: print("preDictActTime = ", preDictActTime) print("self._actionSeq.actionTime = ", self._actionSeq.actionTime) # test print(self._actionSeq) invalidEventNum = self._actionSeq.invalidEventTilTime(preDictActTime) print("invalidEventNum = ", invalidEventNum) action_seq = copy.deepcopy(self._actionSeq) action_seq.delActionEvent(invalidEventNum) action_seq.append( ActionTuple(robID=robID, taskID=taskID, eventType=EventType.arrive, eventTime=preDictActTime)) print(action_seq) print(self._actionSeq) # raise Exception() # action_seq = copy.copy(self._actionSeq) self._calActionSeqStatus(action_seq) raise Exception("nothingf")
def decodeProcessor(self): invalidFitness = False backBool = False validStateBool = True while not self._calEndCond(): cal_type, actionID = self.findActionID() if cal_type == CalType['arriveCond']: # ============================================================================= # arrive event # ============================================================================= rob = self.robotLst[actionID] arriveTime = rob.arriveTime encodeInd = rob.encodeIndex taskID = self.encode[actionID][encodeInd] # try: # except Exception as e: # print(e) # ActionTuple if self.taskCmplt(taskID): # ============================================================================= # the task has been cmplt # ============================================================================= self.arriveCmpltTask(actionID, encodeInd) else: # ============================================================================= # the task has not been cmplt # ============================================================================= task = self.taskLst[taskID] rob.taskID = taskID validStateBool = task.calCurrentState(arriveTime) if not validStateBool: break task.cRate = task.cRate - rob.ability # can not be cmplted if task.cRate >= 0: leaveTime = sys.float_info.max # can be completed else: rob.executeDur = task.calExecuteDur() rob.executeBool = False leaveTime = rob.arriveTime + rob.executeDur coordLst = self.findCoordRobot(actionID) for coordID in coordLst: coordRob = self.robotLst[coordID] coordRob.leaveTime = leaveTime coordRob.executeDur = coordRob.leaveTime - coordRob.arriveTime rob.leaveTime = leaveTime rob.stateType = RobotState['onTask'] self.decodeTime = rob.arriveTime self._actionSeq.append(ActionTuple(robID= actionID,taskID = taskID, eventType = EventType.arrive,eventTime=arriveTime)) # ============================================================================= # begin the leave condition for # ============================================================================= if cal_type == CalType['leaveCond']: rob = self.robotLst[actionID] # print(actionID) taskID = rob.taskID # try: # if taskID < 0: # raise Exception('taskID < 0') # except Exception as e: # print(e) # print(taskID) task = self.taskLst[taskID] # self._actionSeq.append(ActionTuple(robID= actionID,taskID = taskID, # eventType = EventType.leave,eventTime=arriveTime)) if self.cmpltLst[taskID] == True: self.leaveCmpltTask(actionID) # raise Exception('leaveCmpltTask') # print(self.cmpltLst) # validStateBool = True # while True: # print('bug',taskID) # return else: validStateBool = task.calCurrentState(rob.leaveTime) if not validStateBool: break if (task.isCmplt()): self.cmpltLst[taskID] = True try: self.updateEncode(taskID) except Exception as e: print(e) raise Exception("updateEnocde Error") coordLst = self.findCoordRobot(actionID) for coordID in coordLst: self.updateRobLeaveCond(coordID) self.robotLst[coordID].cmpltTaskLst.append(taskID) self.updateRobLeaveCond(actionID) self.robotLst[actionID].cmpltTaskLst.append(taskID) self.robotLst[actionID].cmpltTaskID = taskID ''' 没有debug信息 将来logging ''' # if self._degBool: # self.deg.write('taskID ' + str(taskID) + ' has been cmplt\n') # # self.deg.write('leaveChanged\n') # self.saveRobotInfo() task.cmpltTime = rob.leaveTime self.decodeTime = rob.leaveTime if self._actionSeq.actionTime != self.decodeTime: raise Exception('=d=') # print(taskID,' cmpltTime ', task.cmpltTime) if cal_type == CalType['endCond']: invalidFitness = True # raise Exception('end-Condition-bug, robots have been stuck') # print(self._actionSeq) # raise RobotStuckException() break if cal_type == CalType['backCond']: backBool = True self.backRobID = actionID self.backTaskID = self.robotLst[actionID].taskID self.backArriveTime = self.robotLst[actionID].arriveTime self.backInfo = self.robotLst[actionID].variableInfo() break # # print(task.cRate) # print(task.cRate) # ============================================================================= # the state is too big the decode process is wrong # ============================================================================= if not validStateBool: break # print('circleTime = ', circleTime) # print('decodeTime = ', self.decodeTime) # circleTime += 1 # if circleTime > 3000: # break # print(self.cmpltLst) if not validStateBool: cal_type = CalType['stateInvalidCond'] self.validStateBool = False # raise Exception('stateInvalidCond-bug, the state is too enormous') # raise InvalidStateException() # print(cal_type) return cal_type