Graph class.
|
__init__(self)
Initialize a graph. |
|
|
number
|
__len__(self)
Return the size of the graph when requested by len(). |
|
|
string
|
__str__(self)
Return a string representing the graph when requested by str() (or
print). |
|
|
|
generate(self,
num_nodes,
num_edges,
directed=False)
Add nodes and random edges to the graph. |
|
|
|
read(self,
string,
fmt=None)
Read a graph from a string. |
|
|
string
|
write(self,
fmt=None)
Write the graph to a string. |
|
|
|
add_arrow(self,
u,
v,
wt=1)
Add an arrow (u,v) to the directed graph connecting node u to node v. |
|
|
|
add_edge(self,
u,
v,
wt=1)
Add an edge (u,v) to the graph connecting nodes u and v. |
|
|
|
add_graph(self,
graph)
Add other graph to the graph. |
|
|
|
add_nodes(self,
nodelist)
Add given nodes to the graph. |
|
|
|
|
|
del_arrow(self,
u,
v)
Remove an arrow (u, v) from the directed graph. |
|
|
|
del_edge(self,
u,
v)
Remove an edge (u, v) from the graph. |
|
|
number
|
|
number
|
|
list
|
get_edges(self,
node)
Return all outgoing edges from given node. |
|
|
list
|
|
boolean
|
has_arrow(self,
u,
v)
Return whether an arrow from node u to node v exists. |
|
|
boolean
|
has_edge(self,
u,
v)
Return whether an edge between nodes u and v exists. |
|
|
boolean
|
has_node(self,
node)
Return whether the requested node exists. |
|
|
dictionary
|
|
dictionary
|
|
dictionary
|
|
list
|
cut_edges(self)
Return the cut-edges of the given graph. |
|
|
list
|
cut_nodes(self)
Return the cut-nodes of the given graph. |
|
|
tuple
|
|
list
|
|
list
|
|
tuple
|
shortest_path(self,
source)
Return the shortest path distance between source node and all other
nodes using Dijkstra's algorithm. |
|
|
list
|
|