Graph
Basic Graph Data Structure
Usage
Graph()
Methods
| Method | Description |
|---|---|
| add_vertex | Add a vertex into the graph |
| delete_vertex | Delete a vertex from the graph |
| list_vertices | List the vertices in the graph |
| num_vertices | Find the number of vertices in the graph |
| add_edge | Add a directed edge into the graph |
| add_bidirected_edge | Add a bi-directed edge into the graph |
| delete_edge | Remove a directed edge from the graph |
| update_edge_weight | Update the weight of an edge |
| neighbours_of | Find the neighbours of a vertice |
| num_neighbours | Find the total number of neighbours of a vertice |
| edges_of | Find the outgoing edges of a vertex |
| can_reach | Find the incoming edges of a vertex |
| to_edge_list | Generate an edge list from the graph |
| transpose | Transpose the current graph |
| to_adj_list | Generate an adjancency list from the graph |
| to_adj_matrix | Generate an adjacency matrix from the graph |
| is_tree | Check if the graph is a tree |
| is_unweighted | Check if the graph is unweighted |
| is_positive | Check if the graph contains only positive edge weights |
| is_dag | Check if the graph is a Directed Acyclic Graph |
Example
from jellybeans.structures import Graphg = Graph()