An open API service indexing awesome lists of open source software.

https://github.com/jconleyscales/graph-adjacency-matrix

Undirected weighted graph utilities + Graph class (adjacency matrix) in Python.
https://github.com/jconleyscales/graph-adjacency-matrix

adjacency-matrix data-structures graphs python

Last synced: 3 months ago
JSON representation

Undirected weighted graph utilities + Graph class (adjacency matrix) in Python.

Awesome Lists containing this project

README

          

# Graph (Adjacency Matrix) — Python

Utilities and a `Graph` class for working with an undirected, weighted graph stored as an adjacency matrix.

## Features
- Helper functions to compute vertex/edge counts and shortest/longest edge weights
- `find_popular()` to find the vertex with the most neighbors
- `Graph` class with safe edge operations: `add_edge`, `adjust_edge`, `remove_edge`, `exists_edge`
- Validation: bounds checking, no self-loops, non-negative weights

## How to Run
1. Make sure you have Python 3 installed.
2. Run the file:

```bash```
python graph.py
## Example Usage

```python
from graph import Graph

g = Graph(5)
g.add_edge(0, 1, 7)
g.add_edge(0, 2, 3)

print(g.exists_edge(0, 1)) # True
g.remove_edge(0, 1)
print(g.exists_edge(0, 1)) # False