def isFeasible(node, currPath, definingBounds): task = taskList[node] routeIndex = int(currPath[0]) / dayLength noEndingTime = currPath[1:] if not definingBounds[0]: for r in range(len(task.dependencyTasks)): releaseTask = int(task.dependencyTasks[r]) if releaseTask not in noEndingTime: return None #limit is the earliest we could reach node and begin proposed task limit = currPath[0] if len(currPath) > 2: dist = helperFunctions.getDistanceBetweenTasks(taskList[currPath[-1]], taskList[node]) if int(limit + dist)/dayLength == int(limit)/dayLength: limit += dist #return a proposedEnd based on the earliest we can schedule the node, considering its time windows for d in range(routeIndex - 1, len(task.timeWindows)): for tw in range(len(task.timeWindows[d])): timeWindow = task.timeWindows[d][tw] proposedEnd = max(timeWindow[0], limit) + task.duration #if we could fit the task in its time window after the earliest possible starting time if timeWindow[1] - task.duration >= limit and proposedEnd <= timeLimit: return proposedEnd #if it's not possible to schedule the task (visit the node) then it's not feasible return None
def makeDijConstants(taskList): numTasks = len(taskList) dijConstants = [[None for j in range(numTasks)] for i in range(numTasks)] for i in range(numTasks): for j in range(numTasks): if i != j: dijConstants[i][j] = helperFunctions.getDistanceBetweenTasks(taskList[i], taskList[j]) return dijConstants
def makeDijConstants(taskList): numTasks = len(taskList) dijConstants = [[None for j in range(numTasks)] for i in range(numTasks)] for i in range(numTasks): for j in range(numTasks): if i != j: dijConstants[i][j] = helperFunctions.getDistanceBetweenTasks( taskList[i], taskList[j]) return dijConstants
def getDistanceTraveled(self): distanceTraveled = 0 for route in self.routeList: for i in range(len(route.taskList)): if i == len(route.taskList) - 1: pass else: extraDistance = helperFunctions.getDistanceBetweenTasks(route.taskList[i], route.taskList[i + 1]) distanceTraveled += extraDistance return distanceTraveled
def getDistanceTraveled(self): distanceTraveled = 0 for route in self.routeList: for i in range(len(route.taskList)): if i == len(route.taskList) - 1: pass else: extraDistance = helperFunctions.getDistanceBetweenTasks( route.taskList[i], route.taskList[i + 1]) distanceTraveled += extraDistance return distanceTraveled
def scheduleASAP(path, initTime = 0): ''' returns a new path with the lowest possible ending time, as well as a duration @param path: a list of task ids in order that they're scheduled. the first index is the ending time of the path ''' currentTime = initTime dayIndex = 0 if len(path) <= 1: return 0, 0 task = taskList[path[1]] setTime = False #schedule the first task as early as possible t = 1 for day in range(0, len(task.timeWindows)): for tw in range(len(task.timeWindows[day])): #if task can be scheduled in this time window.. timeWindow = task.timeWindows[day][tw] if timeWindow[1] - task.duration >= currentTime: currentTime = max(timeWindow[0], currentTime) + task.duration schedStartTime = currentTime - task.duration setTime = True dayIndex = day break if setTime: break if not setTime: return None #schedule each task as early as possible and update currentTime for t in range(2, len(path)): task = taskList[path[t]] setTime = False # find the next possible time window to schedule node in in this day or any later days... for day in range(dayIndex, len(task.timeWindows)): for tw in range(len(task.timeWindows[day])): #if task can be scheduled in this time window.. timeWindow = task.timeWindows[day][tw] travelTime = helperFunctions.getDistanceBetweenTasks(taskList[path[t-1]], taskList[path[t]]) if timeWindow[1] - task.duration >= currentTime + travelTime: currentTime = max(timeWindow[0], currentTime + travelTime) + task.duration setTime = True dayIndex = day break if setTime: break if not setTime: return None return currentTime, currentTime - schedStartTime
def getWaitingTime(self): waitingTime = 0 for route in self.routeList: for i in range(len(route.taskList)): if i == len(route.taskList)-1: pass else: extraWaitingTime = (route.endingTimes[i + 1] - route.endingTimes[i]) extraWaitingTime -= route.taskList[i + 1].duration extraWaitingTime -= helperFunctions.getDistanceBetweenTasks(route.taskList[i], route.taskList[i + 1]) waitingTime += extraWaitingTime return waitingTime
def getWaitingTime(self): waitingTime = 0 for route in self.routeList: for i in range(len(route.taskList)): if i == len(route.taskList) - 1: pass else: extraWaitingTime = (route.endingTimes[i + 1] - route.endingTimes[i]) extraWaitingTime -= route.taskList[i + 1].duration extraWaitingTime -= helperFunctions.getDistanceBetweenTasks( route.taskList[i], route.taskList[i + 1]) waitingTime += extraWaitingTime return waitingTime
def getExtraDistanceFromInsertion(route, position): if len(route) == 0: extraDist = 0 elif position == 0: if len(route) > 1: extraDist = helperFunctions.getDistanceBetweenTasks( route[0], route[1]) # takes care of case in which the route only has one task scheduled else: extraDist = 0 elif position == len(route) - 1: # last task in the route extraDist = helperFunctions.getDistanceBetweenTasks( route[position - 1], route[position]) else: # triangle inequality extraDist = helperFunctions.getDistanceBetweenTasks( route[position], route[position + 1]) extraDist += helperFunctions.getDistanceBetweenTasks( route[position], route[position - 1]) extraDist -= helperFunctions.getDistanceBetweenTasks( route[position - 1], route[position + 1]) return extraDist
def getWaitingTimeOfRoute(route): if len(route) == 0: return 0 else: # accounts for time before first task starts totalWaitingTime = route.endingTimes[0] - route[0].duration for i in range(len(route) - 1): # add waiting time between task i and task i + 1 firstTask = route[i] endingTimeOfFirstTask = route.endingTimes[i] secondTask = route[i + 1] startingTimeOfSecondTask = route.endingTimes[ i + 1] - secondTask.duration distanceBetweenTasks = helperFunctions.getDistanceBetweenTasks( route[i], route[i + 1]) taskWaitTime = startingTimeOfSecondTask - endingTimeOfFirstTask - distanceBetweenTasks totalWaitingTime += taskWaitTime return totalWaitingTime
def findAvgDistance(taskList): distance = 0.0 for task in taskList: for task2 in taskList: distance += helperFunctions.getDistanceBetweenTasks(task, task2) return distance / (len(taskList) * (len(taskList) - 1))