Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Clean Python implementation of graph data structures and algorithms using city networks. Features DFS/BFS traversal, Dijkstra's shortest path, and graph analysis tools. Zero dependencies, comprehensive tests, educational examples.

Notifications You must be signed in to change notification settings

gajeshbhat/Python-Graph-Cities

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

8 Commits

Repository files navigation

Graph Cities 🌐

A clean Python implementation of graph data structures and algorithms using city networks. Features graph representations, traversal algorithms, and shortest path calculations.

✨ Features

  • Graph Representations: Edge lists, adjacency lists, and adjacency matrices
  • Traversal Algorithms: Depth-First Search (DFS) and Breadth-First Search (BFS)
  • Shortest Paths: Dijkstra's algorithm with path reconstruction
  • Graph Analysis: Connectivity, cycle detection, and statistics
  • Modern Python: Type hints, error handling, comprehensive tests

πŸš€ Quick Start

  1. Clone and setup:

    git clone <repository-url>
    cd Graph-Cities-1
    ./setup_venv.sh
  2. Run the demo:

    source venv/bin/activate
    python examples/main.py

πŸ“ Project Structure

Graph-Cities/
β”œβ”€β”€ src/ # Core graph classes
β”‚ β”œβ”€β”€ Node.py # Node implementation
β”‚ β”œβ”€β”€ Edge.py # Edge implementation
β”‚ └── Graph.py # Main graph class
β”œβ”€β”€ examples/ # Demo applications
β”‚ β”œβ”€β”€ main.py # Basic demo
β”‚ β”œβ”€β”€ demo_enhanced.py # Advanced features
β”‚ └── graph_utils.py # Utility functions
β”œβ”€β”€ tests/ # Unit tests
β”‚ β”œβ”€β”€ test_graph.py # Core tests
β”‚ └── test_algorithms.py # Algorithm tests
└── setup_venv.sh # Setup script

Usage

from src.Graph import Graph
# Create graph
graph = Graph()
graph.set_node_names(('New York', 'Los Angeles', 'Chicago'))
# Add connections (weight, from, to)
graph.insert_edge(2445, 0, 1) # NY ↔ LA
graph.insert_edge(713, 0, 2) # NY ↔ Chicago 
graph.insert_edge(1745, 1, 2) # LA ↔ Chicago
# Traverse
dfs_path = graph.dfs_names(0) # DFS from NY
bfs_path = graph.bfs_names(0) # BFS from NY
# Find shortest path
path, distance = graph.shortest_path(0, 1) # NY to LA

πŸ§ͺ Testing

# Run tests
source venv/bin/activate
pytest tests/
# Run specific test
pytest tests/test_graph.py -v

🌍 Sample Data

The demo includes major world cities:

  • Mountain View ↔ San Francisco (51 miles)
  • London ↔ Berlin (932 miles)
  • Shanghai ↔ San Francisco (9,900 miles)
  • And more realistic connections...

πŸ“‹ Requirements

  • Python 3.8+
  • No external dependencies for core functionality
  • pytest for testing (optional)

πŸ› οΈ Manual Setup

If you prefer manual setup:

# Create virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install test dependencies (optional)
pip install pytest
# Run demo
python examples/main.py

About

Clean Python implementation of graph data structures and algorithms using city networks. Features DFS/BFS traversal, Dijkstra's shortest path, and graph analysis tools. Zero dependencies, comprehensive tests, educational examples.

Topics

Resources

Stars

Watchers

Forks

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /