Package pygraph :: Package classes :: Module digraph :: Class digraph

Class digraph


Digraph class.

Digraphs are built of nodes and directed edges.

Instance Methods
boolean
__eq__(self, other)
Return whether this graph is equal to another one.
 
__init__(self)
Initialize a digraph.
boolean
__ne__(self, other)
Return whether this graph is not equal to another one.
 
add_edge(self, edge, wt=1, label='', attrs=[])
Add an directed edge to the graph connecting two nodes.
 
add_node(self, node, attrs=None)
Add given node to the graph.
 
del_edge(self, edge)
Remove an directed edge from the graph.
 
del_node(self, node)
Remove a node from the graph.
list
edges(self)
Return all edges in the graph.
boolean
has_edge(self, edge)
Return whether an edge exists.
boolean
has_node(self, node)
Return whether the requested node exists.
list
incidents(self, node)
Return all nodes that are incident to the given node.
list
neighbors(self, node)
Return all nodes that are directly accessible from given node.
number
node_order(self, node)
Return the order of the given node.
list
nodes(self)
Return node list.

Inherited from mixins.common.common: __getitem__, __iter__, __len__, __repr__, __str__, add_graph, add_nodes, add_spanning_tree, complete, inverse, order, reverse

Inherited from mixins.labeling.labeling: add_edge_attribute, add_edge_attributes, add_node_attribute, del_edge_labeling, del_node_labeling, edge_attributes, edge_label, edge_weight, get_edge_properties, node_attributes, set_edge_label, set_edge_properties, set_edge_weight

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Class Variables
  DIRECTED = True

Inherited from mixins.labeling.labeling: DEFAULT_LABEL, DEFAULT_WEIGHT, LABEL_ATTRIBUTE_NAME, WEIGHT_ATTRIBUTE_NAME

Properties

Inherited from object: __class__

Method Details

__eq__(self, other)
(Equality operator)

 

Return whether this graph is equal to another one.

Parameters:
  • other (graph, digraph) - Other graph or digraph
Returns: boolean
Whether this graph and the other are equal.
Overrides: mixins.labeling.labeling.__eq__

__init__(self)
(Constructor)

 

Initialize a digraph.

Overrides: object.__init__

__ne__(self, other)

 

Return whether this graph is not equal to another one.

Parameters:
  • other (graph, digraph) - Other graph or digraph
Returns: boolean
Whether this graph and the other are different.

add_edge(self, edge, wt=1, label='', attrs=[])

 

Add an directed edge to the graph connecting two nodes.

An edge, here, is a pair of nodes like (n, m).

Parameters:
  • edge (tuple) - Edge.
  • wt (number) - Edge weight.
  • label (string) - Edge label.
  • attrs (list) - List of node attributes specified as (attribute, value) tuples.

add_node(self, node, attrs=None)

 

Add given node to the graph.

Parameters:
  • node (node) - Node identifier.
  • attrs (list) - List of node attributes specified as (attribute, value) tuples.

Attention: While nodes can be of any type, it's strongly recommended to use only numbers and single-line strings as node identifiers if you intend to use write().

del_edge(self, edge)

 

Remove an directed edge from the graph.

Parameters:
  • edge (tuple) - Edge.

del_node(self, node)

 

Remove a node from the graph.

Parameters:
  • node (node) - Node identifier.

edges(self)

 

Return all edges in the graph.

Returns: list
List of all edges in the graph.

has_edge(self, edge)

 

Return whether an edge exists.

Parameters:
  • edge (tuple) - Edge.
Returns: boolean
Truth-value for edge existence.

has_node(self, node)

 

Return whether the requested node exists.

Parameters:
  • node (node) - Node identifier
Returns: boolean
Truth-value for node existence.

incidents(self, node)

 

Return all nodes that are incident to the given node.

Parameters:
  • node (node) - Node identifier
Returns: list
List of nodes directly accessible from given node.

neighbors(self, node)

 

Return all nodes that are directly accessible from given node.

Parameters:
  • node (node) - Node identifier
Returns: list
List of nodes directly accessible from given node.

node_order(self, node)

 

Return the order of the given node.

Returns: number
Order of the given node.

nodes(self)

 

Return node list.

Returns: list
Node list.