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 built-in 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.
tail (integer) –
head (integer) –
edge_id
integer
NodeDoesNotExist –
EdgeDoesNotExistError –
DisabledFeatureError – If tail
is negative and the graph is not two-way compressed.
edge_id
()[source]¶Return the edge ID of an edge given its sequential number.
edge_nr (integer) –
edge_id
integer
DisabledFeatureError – If edge_nr_translation
was not enabled during graph compression.
EdgeDoesNotExistError –
first_edge_id
()[source]¶Return the edge ID of the first edge (tail, head).
tail (integer) –
head (integer) –
edge_id
integer
NodeDoesNotExist –
EdgeDoesNotExistError –
DisabledFeatureError – If tail
is negative and the graph is not two-way compressed.
Notes
This method is useful for graphs where each edge occurs only once.
has_edge
()[source]¶Does the graph contain the edge (tail, head)?
tail (integer) –
head (integer) –
had_edge
boolean
NodeDoesNotExistError –
EdgeDoesNotExistError –
DisabledFeatureError – If tail
is negative and the graph is not two-way compressed.
head
()[source]¶Return the head of an edge, given its edge ID.
edge_id (integer) –
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.
node (integer) –
edge_ids
sequence of integers
NodeDoesNotExistError –
DisabledFeatureError – If the graph is not two-way compressed.
in_neighbors
()[source]¶Return the nodes which point to a node.
node (integer) –
nodes
sequence of integers
NodeDoesNotExistError –
DisabledFeatureError – If the graph is not two-way compressed.
out_edge_ids
()[source]¶Return the IDs of outgoing edges of node.
node (integer) –
edge_ids
sequence of integers
NodeDoesNotExistError –
out_neighbors
()[source]¶Return the nodes a node points to.
node (integer) –
nodes
sequence of integers
NodeDoesNotExistError –
tail
()[source]¶Return the tail of an edge, given its edge ID.
edge_id (integer) –
tail (integer) – If the edge exists and is positive.
None – If the tail is negative.
EdgeDoesNotExistError –
Notes
The average performance of this method is O(log num_nodes) for non-negative tails and O(1) for negative ones.
write_dot
()[source]¶Write a representation of the graph in dot format to file.
file (file-like object) –
Notes
That resulting file can be visualized with dot(1) or neato(1) form the graphviz package.
Attributes