def __init__(self, network, resettingEdges, lowerBoundTime, inflowRate, minCapacity, counter, outputDirectory, templateFile, scipFile, timeout): """ :param network: Networkx Digraph instance :param resettingEdges: list of resetting edges :param lowerBoundTime: \theta_k :param inflowRate: u_0 :param minCapacity: minimum capacity of all edges in network :param counter: unique ID of FlowInterval - needed for directory creation :param outputDirectory: directory to output scip logs :param templateFile: path of template which is used by SCIP :param scipFile: path to scip binary :param timeout: seconds until timeout. Deactivated if equal to 0 """ self.network = network self.resettingEdges = resettingEdges self.lowerBoundTime = lowerBoundTime # theta_k self.upperBoundTime = None # theta_{k+1} = theta_k + self.alpha self.inflowRate = inflowRate self.minCapacity = minCapacity # Needed for zimpl files self.id = counter self.outputDirectory = outputDirectory self.templateFile = templateFile self.scipFile = scipFile self.timeout = timeout self.foundNTF = False self.aborted = False self.alpha = None self.shortestPathNetwork = None # to be set from NashFlowClass self.numberOfSolvedIPs = 0 self.computationalTime = -1 # Elapsed computation time in seconds self.preprocessedNodes = 0 self.preprocessedEdges = 0 self.NTFNodeLabelDict = {node: 0 for node in self.network} self.NTFEdgeFlowDict = {edge: 0 for edge in self.network.edges()} self.binaryVariableNumberList = [ ] # List where each element is the size of E'_0 in a NTF call # Create FlowInterval Directory self.rootPath = os.path.join( self.outputDirectory, str(self.id) + '-FlowInterval-' + Utilities.get_time()) Utilities.create_dir(self.rootPath) if self.timeout > 0: # Start thread controlling whether computation should be aborted self.timeoutThread = threading.Thread(target=self.timeout_control) self.timeoutThread.start()
def __init__(self, graph, inflowRate, numberOfIntervals, outputDirectory, templateFile, scipFile, cleanUpBool, timeout): """ :param graph: Networkx Digraph instance :param inflowRate: u_0 :param numberOfIntervals: number of intervals that will be computed. -1 if all :param outputDirectory: path where output should be saved :param templateFile: Selected method, i.e. 0,1,2 :param scipFile: path to scip binary :param cleanUpBool: If true, then cleanup :param timeout: seconds until timeout. Deactivated if equal to 0 """ self.network = graph.copy() self.inflowRate = inflowRate # For the moment: constant self.numberOfIntervals = numberOfIntervals # No. of intervals to compute self.outputDirectory = outputDirectory # Template File from /source/templates self.templateFile = os.path.join( os.getcwd(), 'source', 'templates', 'algorithm_' + str(templateFile + 1) + '.zpl') self.allInOne = (templateFile == 1) self.advancedAlgo = ( templateFile == 2 ) # If true, then advanced backtracking with preprocessing is performed self.scipFile = scipFile self.cleanUpBool = cleanUpBool self.numberOfSolvedIPs = 0 self.computationalTime = 0 self.infinityReached = False # True if last interval has alpha = +inf self.timeout = timeout self.minCapacity = Utilities.compute_min_attr_of_network(self.network) self.counter = 0 self.preprocessedNodes = 0 self.preprocessedEdges = 0 # Create directory for Nash-Flow self.rootPath = os.path.join(self.outputDirectory, 'NashFlow-' + Utilities.get_time()) Utilities.create_dir(self.rootPath) self.flowIntervals = [ ] # List containing triplets of form (lowerBound, upperBound, FlowInterval-instance) self.lowerBoundsToIntervalDict = OrderedDict() self.animationIntervals = {edge: [] for edge in self.network.edges()}
def run_order(self): """Execution order""" self.rootPath = os.path.join( self.outputDirectory, str(self.id) + '-NTF-' + Utilities.get_time()) Utilities.create_dir(self.rootPath) copy(self.templateFile, self.rootPath) self.templateFile = os.path.join(self.rootPath, os.path.basename(self.templateFile)) self.logFile = os.path.join(self.rootPath, 'outputLog.txt') self.write_zimpl_files() self.start_process() self.check_result()
def run(self, nextIntervalOnly=False): """ Compute the flow intervals up to self.numberOfIntervals :param nextIntervalOnly: If True, only the next flow interval is computed """ computedUpperBound = 0 k = 1 if self.numberOfIntervals != -1 else -float('inf') if nextIntervalOnly: Utilities.create_dir(self.rootPath) self.compute_flowInterval() else: while computedUpperBound < float( 'inf') and k <= self.numberOfIntervals: self.compute_flowInterval() computedUpperBound = self.flowIntervals[-1][1] k += 1 # Clean up if self.cleanUpBool: rmtree(self.rootPath)