Skip to content

Adesh0512/Smart-Navigation-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ—ΊοΈ Smart Campus Navigation System

Advanced pathfinding system with real-time traffic simulation, emergency routing, and interactive visualization.

πŸ“ Project Structure

campus-navigation/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ campus_navigation.py    # Core pathfinding logic
β”‚   β”œβ”€β”€ api.py                   # Flask REST API
β”‚   β”œβ”€β”€ requirements.txt         # Python dependencies
β”‚   └── test_api.py             # API tests
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   └── CampusNavigation.jsx
β”‚   β”‚   β”œβ”€β”€ App.jsx
β”‚   β”‚   └── index.jsx
β”‚   β”œβ”€β”€ package.json
β”‚   └── tailwind.config.js
└── README.md

πŸš€ Features

Core Features

  • βœ… Dijkstra's Algorithm - Optimal pathfinding
  • πŸ•’ Traffic Simulation - Dynamic weights based on time of day
  • 🚨 Emergency Routing - Automatic nearest exit detection
  • ⚠️ Hazard Avoidance - Mark dangerous zones
  • 🚧 Path Blocking - Simulate construction/obstacles
  • πŸ“Š Algorithm Visualization - Step-by-step animation

Emergency Features

  • πŸ”₯ Fire evacuation routing
  • 🌊 Earthquake safe paths
  • ⚠️ Security threat navigation
  • πŸ₯ Medical emergency routes
  • 500m hazard zone penalties
  • Auto-detect nearest safe exit

πŸ“Š Data Structures Used

  1. Graph (Adjacency List) - Campus map representation
  2. Priority Queue (Min-Heap) - Dijkstra's algorithm
  3. Hash Map/Dictionary - Distance tracking, path reconstruction
  4. Set - Visited nodes, blocked paths, hazard zones
  5. Array - Algorithm steps, final path

πŸ”§ Backend Setup (Python)

Prerequisites

  • Python 3.8+
  • pip

Installation

# Navigate to backend directory
cd backend

# Create virtual environment
python -m venv venv

# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

requirements.txt

Flask==2.3.0
Flask-CORS==4.0.0

Run Backend Server

python api.py

Server will start on http://localhost:5000

Test the API

# Test health endpoint
curl http://localhost:5000/api/health

# Get campus graph
curl http://localhost:5000/api/graph

# Find path (POST request)
curl -X POST http://localhost:5000/api/path \
  -H "Content-Type: application/json" \
  -d '{
    "start": "Main Gate",
    "end": "Hostel",
    "time_of_day": "morning",
    "emergency_mode": false
  }'

🎨 Frontend Setup (React)

Prerequisites

  • Node.js 16+
  • npm or yarn

Installation

# Navigate to frontend directory
cd frontend

# Install dependencies
npm install

# Or with yarn
yarn install

package.json dependencies

{
  "dependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "lucide-react": "^0.263.1",
    "axios": "^1.4.0"
  },
  "devDependencies": {
    "tailwindcss": "^3.3.0",
    "autoprefixer": "^10.4.14",
    "postcss": "^8.4.24"
  }
}

Environment Variables

Create .env file in frontend directory:

REACT_APP_API_URL=http://localhost:5000/api

Run Frontend

npm start
# Or
yarn start

App will open on http://localhost:3000

πŸ”Œ API Endpoints

Graph Endpoints

GET  /api/health              - Health check
GET  /api/graph               - Get complete campus graph
GET  /api/nodes               - Get list of all nodes

Pathfinding Endpoints

POST /api/path                - Find shortest path
POST /api/emergency/nearest-exit - Find nearest safe exit

Request Body for /api/path:

{
  "start": "Main Gate",
  "end": "Hostel",
  "time_of_day": "morning",
  "emergency_mode": false,
  "track_steps": true
}

Response:

{
  "path": ["Main Gate", "Library", "Computer Lab", "..."],
  "distance": 450,
  "steps": [...],
  "visited_nodes": [...]
}

Path Blocking Endpoints

POST /api/paths/block         - Block a path
POST /api/paths/unblock       - Unblock a path
GET  /api/paths/blocked       - Get all blocked paths

Hazard Zone Endpoints

POST /api/hazards/add         - Add hazard zone
POST /api/hazards/remove      - Remove hazard zone
POST /api/hazards/clear       - Clear all hazards
GET  /api/hazards             - Get all hazard zones

Utility Endpoints

POST /api/reset               - Reset all constraints

πŸ’» Usage Examples

Python Backend Usage

from campus_navigation import CampusGraph, PathFinder, TimeOfDay

# Initialize
campus = CampusGraph()
pathfinder = PathFinder(campus)

# Find normal path
result = pathfinder.dijkstra(
    start='Main Gate',
    end='Hostel',
    time_of_day=TimeOfDay.MORNING
)
print(f"Path: {' β†’ '.join(result.path)}")
print(f"Distance: {result.distance}m")

# Block a path
pathfinder.block_path('Library', 'Computer Lab')

# Emergency evacuation
pathfinder.add_hazard_zone('Library')
nearest_exit, distance = pathfinder.find_nearest_exit('Lecture Hall')
print(f"Nearest exit: {nearest_exit} ({distance}m)")

React Frontend Integration

import axios from 'axios';

// Find path
const findPath = async () => {
  const response = await axios.post('http://localhost:5000/api/path', {
    start: 'Main Gate',
    end: 'Hostel',
    time_of_day: 'morning',
    emergency_mode: false
  });
  
  console.log('Path:', response.data.path);
  console.log('Distance:', response.data.distance);
};

// Emergency mode
const findNearestExit = async () => {
  const response = await axios.post('http://localhost:5000/api/emergency/nearest-exit', {
    start: 'Lecture Hall',
    time_of_day: 'afternoon'
  });
  
  console.log('Nearest exit:', response.data.nearest_exit);
};

πŸ§ͺ Testing

Backend Tests

cd backend
python -m pytest test_api.py

Frontend Tests

cd frontend
npm test

πŸ“± Deployment

Backend (Python)

Option 1: Heroku

heroku create campus-nav-api
git push heroku main

Option 2: Docker

FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "api.py"]

Frontend (React)

Option 1: Vercel

npm install -g vercel
vercel deploy

Option 2: Netlify

npm run build
netlify deploy --prod --dir=build

🎯 Campus Locations

Location Type Icon Description
Main Gate Entrance πŸšͺ Primary entry/exit
Library Academic πŸ“š Study area
Computer Lab Lab πŸ’» IT facilities
Lecture Hall Academic πŸŽ“ Classrooms
Admin Block Admin 🏒 Administrative offices
Cafeteria Facility β˜• Food court
Sports Complex Sports ⚽ Athletics area
Auditorium Facility 🎭 Event venue
Hostel Residence 🏠 Student housing

πŸ› οΈ Customization

Adding New Locations

Backend (campus_navigation.py):

'New Building': Node(
    x=500, y=300,
    connections={
        'Library': Connection(100, TrafficMultiplier(1.2, 1.0, 1.1))
    },
    node_type=NodeType.ACADEMIC,
    icon='πŸ›οΈ'
)

Frontend (CampusNavigation.jsx):

'New Building': {
  x: 500, y: 300,
  connections: {
    'Library': { distance: 100, trafficMultiplier: {...} }
  },
  type: 'academic',
  icon: 'πŸ›οΈ'
}

Modifying Traffic Patterns

Adjust traffic multipliers in connections:

TrafficMultiplier(
    morning=1.5,    # 50% slower in morning
    afternoon=1.0,  # Normal speed
    evening=1.2     # 20% slower in evening
)

πŸ“ˆ Performance

  • Time Complexity: O((V + E) log V) where V = nodes, E = edges
  • Space Complexity: O(V)
  • Average Path Computation: < 50ms
  • API Response Time: < 100ms

πŸ› Troubleshooting

Backend Issues

Port Already in Use:

# Kill process on port 5000
# Windows:
netstat -ano | findstr :5000
taskkill /PID <PID> /F
# Linux/Mac:
lsof -ti:5000 | xargs kill -9

CORS Errors:

  • Ensure Flask-CORS is installed
  • Check frontend API URL in .env file

Frontend Issues

API Connection Failed:

  • Verify backend is running
  • Check REACT_APP_API_URL in .env
  • Ensure no firewall blocking

Dependencies Not Installing:

rm -rf node_modules package-lock.json
npm install

πŸ“„ License

MIT License - feel free to use in your projects!

🀝 Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/AmazingFeature)
  3. Commit changes (git commit -m 'Add AmazingFeature')
  4. Push to branch (git push origin feature/AmazingFeature)
  5. Open Pull Request

πŸ“§ Support

For issues and questions:

πŸŽ“ Academic Use

Perfect for:

  • Algorithm visualization projects
  • Data structures courses
  • Graph theory assignments
  • Emergency management systems
  • Campus navigation apps

Built with ❀️ using Python, Flask, React, and Dijkstra's Algorithm

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published