Graph

mod

Graph

synopsis

graph

graph

class DIRAC.Core.Utilities.Graph.DynamicProps(name, bases, classdict)

Bases: type

metaclass allowing to create properties on the fly

__init__(*args, **kwargs)
mro()

Return a type’s method resolution order.

class DIRAC.Core.Utilities.Graph.Edge(fromNode, toNode, rwAttrs=None, roAttrs=None)

Bases: object

Directed link between two nodes

__init__(fromNode, toNode, rwAttrs=None, roAttrs=None)

c’tor

Parameters
  • fromNode (Node) – edge start

  • toNode (Node) – edge end

  • rwAttrs (dict) – read/write properties dict

  • roAttrs (dict) – read only properties dict

makeProperty(name, value, readOnly=False)

Add property :name: to class

This also creates a private :_name: attribute If you want to make read only property, set :readOnly: flag to True :warn: could raise AttributeError if :name: of :_name: is already defined as an attribute

class DIRAC.Core.Utilities.Graph.Graph(name, nodes=None, edges=None)

Bases: object

A generic directed graph with attributes attached to its nodes and edges

property POSTORDER

POSTORDER getter

property PREORDER

PREORDER getter

__init__(name, nodes=None, edges=None)

c’tor

Parameters
  • self – self reference

  • name (str) – graph name

  • nodes (list) – initial node list

  • edges (list) – initial edge list

addEdge(edge)

Add edge :edge: to the graph

addNode(node)

Add Node :node: to graph

bfs(preVisit=None, postVisit=None)

bfs walk

connect(fromNode, toNode, rwAttrs=None, roAttrs=None)

Connect :fromNode: to :toNode: with edge of attributes

dfs(preVisit=None, postVisit=None)

dfs recursive walk

dfsIter(preVisit=None, postVisit=None)

Iterative dfs - no recursion

edges()

Get edges dict

explore(node, preVisit=None, postVisit=None)

Explore node

getEdge(edgeName)

Get edge :edgeName:

getNode(nodeName)

Get node :nodeName:

makeProperty(name, value, readOnly=False)

Add property :name: to class

This also creates a private :_name: attribute If you want to make read only property, set :readOnly: flag to True :warn: could raise AttributeError if :name: of :_name: is already defined as an attribute

nodes()

Get nodes dict

reset()

Set visited for all nodes to False

walkAll(nodeFcn=None, edgeFcn=None, res=None)

Wall all nodes excuting :nodeFcn: on each node and :edgeFcn: on each edge result is a dict { Node.name : result from :nodeFcn:, Edge.name : result from edgeFcn }

walkNode(node, nodeFcn=None, edgeFcn=None, res=None)

Walk through the graph calling nodeFcn on nodes and edgeFcn on edges

class DIRAC.Core.Utilities.Graph.Node(name, rwAttrs=None, roAttrs=None)

Bases: object

graph node

__init__(name, rwAttrs=None, roAttrs=None)

c’tor

Parameters
  • name (str) – node name

  • rwAttrs (dict) – read/write properties dict

  • roAttrs (dict) – read-only properties dict

addEdge(edge)

Add edge to the node

connect(other, rwAttrs=None, roAttrs=None)

Connect self to Node :other: with edge attibutes rw :rwAttrs: and ro :roAttrs:

edges()

get edges

makeProperty(name, value, readOnly=False)

Add property :name: to class

This also creates a private :_name: attribute If you want to make read only property, set :readOnly: flag to True :warn: could raise AttributeError if :name: of :_name: is already defined as an attribute