def solveMaxFlow(self, instance, timeThreshold): storedSolutionFileName = '../storedSolutions/' + dataToMD5(self.makeMD5Data(instance, timeThreshold)) try: storedSolution = open(storedSolutionFileName) import ast print("Found a ready solution!") # the following works for now # need to be careful when paths of agents aren't ordered # according to the agents' current location maxFlowPaths = [ast.literal_eval(myStr) for myStr in storedSolution] except: print("Solving by MaxFlow...") network = expandedNetwork.ExpandedNetwork(instance, timeThreshold) maxFlowPaths = network.solveMaxFlow() storedSolutionFile = open(storedSolutionFileName, mode='w') for path in maxFlowPaths: print(path, file = storedSolutionFile) solution = Solution(maxFlowPaths, instance.exits) solution.checkSolution(fixFlag = True) #printPlan(instance, simulation) solution.checkSolution() return solution