Advanced pathfinding system with real-time traffic simulation, emergency routing, and interactive visualization.
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
- β 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
- π₯ Fire evacuation routing
- π Earthquake safe paths
β οΈ Security threat navigation- π₯ Medical emergency routes
- 500m hazard zone penalties
- Auto-detect nearest safe exit
- Graph (Adjacency List) - Campus map representation
- Priority Queue (Min-Heap) - Dijkstra's algorithm
- Hash Map/Dictionary - Distance tracking, path reconstruction
- Set - Visited nodes, blocked paths, hazard zones
- Array - Algorithm steps, final path
- Python 3.8+
- pip
# 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.txtFlask==2.3.0
Flask-CORS==4.0.0
python api.pyServer will start on http://localhost:5000
# 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
}'- Node.js 16+
- npm or yarn
# Navigate to frontend directory
cd frontend
# Install dependencies
npm install
# Or with yarn
yarn install{
"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"
}
}Create .env file in frontend directory:
REACT_APP_API_URL=http://localhost:5000/api
npm start
# Or
yarn startApp will open on http://localhost:3000
GET /api/health - Health check
GET /api/graph - Get complete campus graph
GET /api/nodes - Get list of all nodes
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": [...]
}POST /api/paths/block - Block a path
POST /api/paths/unblock - Unblock a path
GET /api/paths/blocked - Get all blocked paths
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
POST /api/reset - Reset all constraints
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)")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);
};cd backend
python -m pytest test_api.pycd frontend
npm testOption 1: Heroku
heroku create campus-nav-api
git push heroku mainOption 2: Docker
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "api.py"]Option 1: Vercel
npm install -g vercel
vercel deployOption 2: Netlify
npm run build
netlify deploy --prod --dir=build| 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 |
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: 'ποΈ'
}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
)- Time Complexity: O((V + E) log V) where V = nodes, E = edges
- Space Complexity: O(V)
- Average Path Computation: < 50ms
- API Response Time: < 100ms
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 -9CORS Errors:
- Ensure Flask-CORS is installed
- Check frontend API URL in .env file
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 installMIT License - feel free to use in your projects!
- Fork the repository
- Create feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open Pull Request
For issues and questions:
- GitHub Issues: [Create an issue]
- Email: support@example.com
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