kwant.graph.
CGraph
[source]¶Bases: object
A compressed graph which can be efficiently queried for the existence of edges and outgoing neighbors.
Objects of this class do not initialize the members themselves, but expect
that they hold usable values. A good way to create them is by compressing
a Graph
.
Iterating over a graph yields a sequence of (tail, head) pairs of all edges. The number of an edge in this sequence equals its edge ID. The builtin function enumerate can thus be used to easily iterate over all edges along with their edge IDs.
Methods
all_edge_ids
()[source]¶Return an iterator over all edge IDs of edges with a given tail and head.
Parameters:  tail : integer head : integer 

Returns:  edge_id : integer 
Raises:  NodeDoesNotExist EdgeDoesNotExistError DisabledFeatureError

edge_id
()[source]¶Return the edge ID of an edge given its sequential number.
Parameters:  edge_nr : integer 

Returns:  edge_id : integer 
Raises:  DisabledFeatureError
EdgeDoesNotExistError 
first_edge_id
()[source]¶Return the edge ID of the first edge (tail, head).
Parameters:  tail : integer head : integer 

Returns:  edge_id : integer 
Raises:  NodeDoesNotExist EdgeDoesNotExistError DisabledFeatureError

Notes
This method is useful for graphs where each edge occurs only once.
has_edge
()[source]¶Does the graph contain the edge (tail, head)?
Parameters:  tail : integer head : integer 

Returns:  had_edge : boolean 
Raises:  NodeDoesNotExistError EdgeDoesNotExistError DisabledFeatureError

head
()[source]¶Return the head of an edge, given its edge ID.
Parameters:  edge_id : integer 

Raises:  EdgeDoesNotExistError 
Notes
This method executes in constant time. It works for all edge IDs, returning both positive and negative heads.
in_edge_ids
()[source]¶Return the IDs of incoming edges of a node.
Parameters:  node : integer 

Returns:  edge_ids : sequence of integers 
Raises:  NodeDoesNotExistError DisabledFeatureError

in_neighbors
()[source]¶Return the nodes which point to a node.
Parameters:  node : integer 

Returns:  nodes : sequence of integers 
Raises:  NodeDoesNotExistError DisabledFeatureError

out_edge_ids
()[source]¶Return the IDs of outgoing edges of node.
Parameters:  node : integer 

Returns:  edge_ids : sequence of integers 
Raises:  NodeDoesNotExistError 
out_neighbors
()[source]¶Return the nodes a node points to.
Parameters:  node : integer 

Returns:  nodes : sequence of integers 
Raises:  NodeDoesNotExistError 
tail
()[source]¶Return the tail of an edge, given its edge ID.
Parameters:  edge_id : integer 

Returns:  tail : integer
None

Raises:  EdgeDoesNotExistError 
Notes
The average performance of this method is O(log num_nodes) for nonnegative tails and O(1) for negative ones.
write_dot
()[source]¶Write a representation of the graph in dot format to file.
Parameters:  file : filelike object 

Notes
That resulting file can be visualized with dot(1) or neato(1) form the graphviz package.
Attributes