def createRequestObj(self, Id): self.nodeList = self.pathNetwork.getNodeList() newRequest = Request(Id) newRequest.date = self.datetime.date() newRequest.TSubmit = self.datetime.time() if config.localisedRequests: nodeLocalisedList = [ self.pathNetwork.graphMain.getNodeByName(nodeName) for nodeName in config.localisedRequests ] newRequest.startNode = random.choice(nodeLocalisedList) elif config.weightedRequest: nodes = self.nodeList if 1 == random.randint(1, 4): newRequest.startNode = self.pathNetwork.graphMain.getNodeByName( 1) elif 2 == random.randint(1, 4): newRequest.startNode = self.pathNetwork.graphMain.getNodeByName( 60) else: newRequest.startNode = random.choice(self.nodeList) else: newRequest.startNode = random.choice(self.nodeList) self.nodeList.remove(newRequest.startNode) newRequest.endNode = random.choice(self.nodeList) return newRequest
def process_requests(self, in_file): #The assignment will be based on the proximity of the pod to the request point requestsList = [] if len(self.waitingRequests) > 0: for request in self.waitingRequests: closestPod = self.findClosestRequestPod(request.startNode) if closestPod: self.assignPod(closestPod, request) self.waitingRequests.remove(request) #print("Waiting request {0} to {1} is being completed\nThere are {2} requests waiting".format(request.startNode,requestDict["endNode"],len(self.waitingRequests))) for req in self.newRequests: details = req.strip(' ').split(',') if len(details) < 4: break if len(details) == 4: requestDict = { "date": details[0], "time": details[1], "startNode": int(details[2].strip(" ")), "endNode": int(details[3].strip(" ")) } dateTimeStr = details[0] + details[1] newRequest = Request(self.requestNum) newRequest.TSubmit = self.strToDateTime(dateTimeStr) newRequest.startNode = int(requestDict['startNode']) newRequest.endNode = int(requestDict['endNode']) requestsList.append(newRequest) closestPod = self.findClosestRequestPod( requestDict["startNode"]) self.requestNum += 1 if closestPod: newRequest.PodUsed = closestPod self.assignPod(closestPod, newRequest) else: print("No pods availible for request {0} to {1}".format( requestDict["startNode"], requestDict["endNode"])) self.waitingRequests.append(newRequest)