Skip to main content

Graph

Basic Graph Data Structure

Usage

Graph()

Methods

MethodDescription
add_vertexAdd a vertex into the graph
delete_vertexDelete a vertex from the graph
list_verticesList the vertices in the graph
num_verticesFind the number of vertices in the graph
add_edgeAdd a directed edge into the graph
add_bidirected_edgeAdd a bi-directed edge into the graph
delete_edgeRemove a directed edge from the graph
update_edge_weightUpdate the weight of an edge
neighbours_ofFind the neighbours of a vertice
num_neighboursFind the total number of neighbours of a vertice
edges_ofFind the outgoing edges of a vertex
can_reachFind the incoming edges of a vertex
to_edge_listGenerate an edge list from the graph
transposeTranspose the current graph
to_adj_listGenerate an adjancency list from the graph
to_adj_matrixGenerate an adjacency matrix from the graph
is_treeCheck if the graph is a tree
is_unweightedCheck if the graph is unweighted
is_positiveCheck if the graph contains only positive edge weights
is_dagCheck if the graph is a Directed Acyclic Graph

Example

from jellybeans.structures import Graphg = Graph()