kwant.graph.
CGraph
[source]¶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.
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.
If edge_nr_translation
was not enabled during graph compression.
first_edge_id
()[source]¶Return the edge ID of the first edge (tail, head).
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)?
If tail
is negative and the graph is not two-way compressed.
head
()[source]¶Return the head of an edge, given its edge ID.
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.
If the graph is not two-way compressed.
in_neighbors
()[source]¶Return the nodes which point to a node.
If the graph is not two-way compressed.
out_edge_ids
()[source]¶Return the IDs of outgoing edges of node.
out_neighbors
()[source]¶Return the nodes a node points to.
tail
()[source]¶Return the tail of an edge, given its edge ID.
If the edge exists and is positive.
If the tail is negative.
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.
Notes
That resulting file can be visualized with dot(1) or neato(1) form the graphviz package.
Attributes