def testDFS( self ): """ dfs """ global clock def topoA( graph ): """ topological sort """ global clock nodes = graph.nodes() for node in nodes: node.makeProperty( "clockA", 0 ) def postVisit( node ): global clock node.clockA = clock clock += 1 graph.dfs( postVisit = postVisit ) nodes = graph.nodes() nodes.sort( key = lambda node: node.clockA ) return nodes def topoB( graph ): """ topological sort """ global clock nodes = graph.nodes() for node in nodes: node.makeProperty( "clockB", 0 ) def postVisit( node ): global clock node.clockB = clock clock += 1 graph.dfsIter( postVisit = postVisit ) nodes = graph.nodes() nodes.sort( key = lambda node: node.clockB ) return nodes clock = 0 gr = Graph( "testGraph", self.nodes, self.edges ) gr.addNode( self.aloneNode ) nodesSorted = topoA( gr ) nodes = gr.nodes() nodes.sort( key = lambda node: node.clockA, reverse = True ) self.assertEqual( nodes, nodesSorted, "topoA sort failed" ) clock = 0 gr = Graph( "testGraph", self.nodes, self.edges ) gr.addNode( self.aloneNode ) gr.reset() nodesSorted = topoB( gr ) nodes = gr.nodes() nodes.sort( key = lambda node: node.clockB, reverse = True ) self.assertEqual( nodes, nodesSorted, "topoB sort failed" )
def testBFS(self): """ bfs walk """ global clock def walk(graph): """ bfs walk """ global clock nodes = graph.nodes() for node in nodes: node.makeProperty("clockC", 0) def postVisit(node): global clock node.clockC = clock clock += 1 nodes = graph.bfs(postVisit=postVisit) nodes.sort(key=lambda node: node.clockC) return nodes clock = 0 gr = Graph("testGraph", self.nodes, self.edges) gr.addNode(self.aloneNode) gr.reset() nodesSorted = walk(gr) nodes = gr.nodes() nodes.sort(key=lambda node: node.clockC) self.assertEqual(nodesSorted, nodes, "bfs failed")
def __init__(self, name, ftsHistoryViews=None, accFailureRate=0.75, accFailedFiles=5, schedulingType="Files"): """ c'tor :param str name: graph name :param list ftsHistoryViews: list with FTSHistoryViews :param float accFailureRate: acceptable failure rate :param int accFailedFiles: acceptable failed files :param str schedulingType: scheduling type """ Graph.__init__(self, name) self.log = gLogger.getSubLogger(name, True) self.accFailureRate = accFailureRate self.accFailedFiles = accFailedFiles self.schedulingType = schedulingType self.initialize(ftsHistoryViews)
def __init__( self, name, ftsHistoryViews = None, accFailureRate = 0.75, accFailedFiles = 5, schedulingType = "Files" ): """ c'tor :param str name: graph name :param list ftsHistoryViews: list with FTSHistoryViews :param float accFailureRate: acceptable failure rate :param int accFailedFiles: acceptable failed files :param str schedulingType: scheduling type """ Graph.__init__( self, name ) self.log = gLogger.getSubLogger( name, True ) self.accFailureRate = accFailureRate self.accFailedFiles = accFailedFiles self.schedulingType = schedulingType self.initialize( ftsHistoryViews )
def testBFS( self ): """ bfs walk """ global clock def walk( graph ): """ bfs walk """ global clock nodes = graph.nodes() for node in nodes: node.makeProperty( "clockC", 0 ) def postVisit( node ): global clock node.clockC = clock clock += 1 nodes = graph.bfs( postVisit = postVisit ) nodes.sort( key = lambda node: node.clockC ) return nodes clock = 0 gr = Graph( "testGraph", self.nodes, self.edges ) gr.addNode( self.aloneNode ) gr.reset() nodesSorted = walk( gr ) nodes = gr.nodes() nodes.sort( key = lambda node: node.clockC ) self.assertEqual( nodesSorted, nodes, "bfs failed" )
def __init__( self, name, ftsHistoryViews = None, accFailureRate = None, accFailedFiles = None, schedulingType = None, maxActiveJobs = None ): """ c'tor :param str name: graph name :param list ftsHistoryViews: list with FTSHistoryViews :param float accFailureRate: acceptable failure rate :param int accFailedFiles: acceptable failed files :param str schedulingType: scheduling type """ Graph.__init__( self, name ) self.log = gLogger.getSubLogger( name, True ) self.accFailureRate = accFailureRate if accFailureRate else 0.75 self.accFailedFiles = accFailedFiles if accFailedFiles else 5 self.schedulingType = schedulingType if schedulingType else "Files" self.maxActiveJobs = maxActiveJobs if maxActiveJobs else 50 self.initialize( ftsHistoryViews )
def testDFS(self): """ dfs """ global clock def topoA(graph): """ topological sort """ global clock nodes = graph.nodes() for node in nodes: node.makeProperty("clockA", 0) def postVisit(node): global clock node.clockA = clock clock += 1 graph.dfs(postVisit=postVisit) nodes = graph.nodes() nodes.sort(key=lambda node: node.clockA) return nodes def topoB(graph): """ topological sort """ global clock nodes = graph.nodes() for node in nodes: node.makeProperty("clockB", 0) def postVisit(node): global clock node.clockB = clock clock += 1 graph.dfsIter(postVisit=postVisit) nodes = graph.nodes() nodes.sort(key=lambda node: node.clockB) return nodes clock = 0 gr = Graph("testGraph", self.nodes, self.edges) gr.addNode(self.aloneNode) nodesSorted = topoA(gr) nodes = gr.nodes() nodes.sort(key=lambda node: node.clockA, reverse=True) self.assertEqual(nodes, nodesSorted, "topoA sort failed") clock = 0 gr = Graph("testGraph", self.nodes, self.edges) gr.addNode(self.aloneNode) gr.reset() nodesSorted = topoB(gr) nodes = gr.nodes() nodes.sort(key=lambda node: node.clockB, reverse=True) self.assertEqual(nodes, nodesSorted, "topoB sort failed")
def testGraph(self): """ ctor nodes edges connect walk """ # # create graph gr = Graph("testGraph", self.nodes, self.edges) # # nodes and edges for node in self.nodes: self.assertEqual(node in gr, True) for edge in self.edges: self.assertEqual(edge in gr, True) self.assertEqual(sorted(self.nodes, key=lambda x: x.name), sorted(gr.nodes(), key=lambda x: x.name)) self.assertEqual(sorted(self.edges, key=lambda x: x.name), sorted(gr.edges(), key=lambda x: x.name)) # # getNode for node in self.nodes: self.assertEqual(gr.getNode(node.name), node) # # connect aloneEdge = gr.connect(self.nodes[0], self.aloneNode) self.assertEqual(self.aloneNode in gr, True) self.assertEqual(aloneEdge in gr, True) # # addNode anotherNode = Node("5") anotherEdge = anotherNode.connect(self.aloneNode) gr.addNode(anotherNode) self.assertEqual(anotherNode in gr, True) self.assertEqual(anotherEdge in gr, True) # # walk no nodeFcn ret = gr.walkAll() self.assertEqual(ret, {}) for node in gr.nodes(): self.assertEqual(node.visited, True) gr.reset() for node in gr.nodes(): self.assertEqual(node.visited, False) # # walk with nodeFcn def nbEdges(node): """ dummy node fcn """ return len(node.edges()) ret = gr.walkAll(nodeFcn=nbEdges) self.assertEqual(ret, {'1': 3, '2': 0, '3': 0, '4': 0, '5': 1})
def __init__( self, name, nodes=None, edges=None ): """ c'tor """ Graph.__init__( self, name, nodes, edges )
def testGraph( self ): """ ctor nodes edges connect walk """ # # create graph gr = Graph( "testGraph", self.nodes, self.edges ) # # nodes and edges for node in self.nodes: self.assertEqual( node in gr, True ) for edge in self.edges: self.assertEqual( edge in gr, True ) self.assertEqual( sorted( self.nodes ), sorted( gr.nodes() ) ) self.assertEqual( sorted( self.edges ), sorted( gr.edges() ) ) # # getNode for node in self.nodes: self.assertEqual( gr.getNode( node.name ), node ) # # connect aloneEdge = gr.connect( self.nodes[0], self.aloneNode ) self.assertEqual( self.aloneNode in gr, True ) self.assertEqual( aloneEdge in gr, True ) # # addNode anotherNode = Node( "5" ) anotherEdge = anotherNode.connect( self.aloneNode ) gr.addNode( anotherNode ) self.assertEqual( anotherNode in gr, True ) self.assertEqual( anotherEdge in gr, True ) # # walk no nodeFcn ret = gr.walkAll() self.assertEqual( ret, {} ) for node in gr.nodes(): self.assertEqual( node.visited, True ) gr.reset() for node in gr.nodes(): self.assertEqual( node.visited, False ) # # walk with nodeFcn def nbEdges( node ): """ dummy node fcn """ return len( node.edges() ) ret = gr.walkAll( nodeFcn = nbEdges ) self.assertEqual( ret, { '1': 3, '2' : 0, '3': 0, '4' : 0, '5': 1 } )
def __init__(self, name, nodes=None, edges=None): """ c'tor """ Graph.__init__(self, name, nodes, edges)