def testConnection(self): try: self.stub.testConnection(vrpAPI_pb2.Empty()) return True except grpc.RpcError as e: self.handleGrpcError(e, 'Error when testing the connection') return False
def isReadyForOnline(self): try: response = self.stub.isReadyForOnline(vrpAPI_pb2.Empty()) return response.b except grpc.RpcError as e: self.handleGrpcError( e, 'Error with function isReadyForOnline() from simulatorAPI')
def startOnlineSimulation(self): try: reply = self.stub.startOnlineSimulation(vrpAPI_pb2.Empty()) return reply.value except grpc.RpcError as e: self.handleGrpcError( e, 'Error when sending startSimulation to solver')
def sendContinueMessage(self): try: reply = self.stub.continueSimulation(vrpAPI_pb2.Empty()) return reply.value except grpc.RpcError as e: self.handleGrpcError( e, 'Error when sending continueMessage to solver')
def run(self): try: reply = self.stub.pauseSimulation(vrpAPI_pb2.Empty()) #, timeout = 2) self.pauseMessageQueue.put(("OK", reply.value)) except grpc.RpcError as e: self.handleGrpcError(e, '') if e.details() == "Deadline Exceeded": # the solver didn't answers self.pauseMessageQueue.put(("KO", None)) else: print("Error when sending pauseMessage to solver") print(e.details())
def sendBestSolution(self, request, context): # correct the instance returned by the initial solver of michael # solverSol = json.loads(request.jsonstring) # for road in solverSol['Routes']: # for node in solverSol['Routes'][road]: # if 'InstanceVertexID' in node: # node['RequestId'] = node['InstanceVertexID'] # del(node['InstanceVertexID']) # if 'RequestInstanceId' in node: # node['Node'] = node['RequestInstanceId'] # del(node['RequestInstanceId']) # send the sol to SimulationManager self.solutionsQueue.put(('updateBestSolution', request.jsonstring)) #self.solutionsQueue.put(('updateBestSolution', json.dumps(solverSol))) self.eventLock.acquire() self.eventSMQueue.set() self.eventLock.release() return vrpAPI_pb2.Empty()
def testConnection(self, request, context): return vrpAPI_pb2.Empty()
def notifyEndOnline(self, request, context): self.eventLock.acquire() self.solutionsQueue.put(("SolverEndOnline", )) self.eventSMQueue.set() self.eventLock.release() return vrpAPI_pb2.Empty()
def sendCloseMessage(self): try: self.stub.shutdown(vrpAPI_pb2.Empty()) except grpc.RpcError as e: self.handleGrpcError(e, 'Error when sending closeMessage to solver')