Skip to content

Tanmay-312/elevator_brain

Repository files navigation

Elevator Brain - Intelligent Elevator Management System

Elevator Brain is a web application that simulates an intelligent elevator management system. It provides a real-time visualization of elevator movements, passenger requests, and system performance within a building. The core logic aims to efficiently manage multiple elevators responding to passenger calls from various floors and internal elevator requests.

Core Features

  • Real-time Elevator Display: Visualizes elevator cars moving between floors, their current status, direction, and passenger load.
  • Interactive Request Handling: Allows users to simulate passenger hall calls (requesting an elevator to a floor) and internal elevator requests (selecting a destination floor from within an elevator).
  • SCAN-like Control Algorithm: Implements an efficient elevator dispatching and movement strategy, similar to the SCAN (or C-SCAN) disk scheduling algorithm, to optimize passenger wait times and elevator travel.
  • System Overview Dashboard: Displays live statistics for each elevator (current floor, direction, status, passenger load) and a list of pending floor requests.

Technology Stack

  • Frontend: Next.js (App Router), React, TypeScript
  • Styling: Tailwind CSS, ShadCN UI components
  • State Management: React Hooks (useState, useEffect, useCallback) for managing the simulation state.

Project Structure (src folder)

The src directory contains the core application code:

src/
├── app/                 # Next.js App Router: pages, layouts, global styles
│   ├── globals.css      # Global styles and Tailwind CSS setup
│   ├── layout.tsx       # Root layout for the application
│   └── page.tsx         # Main dashboard page component
├── components/          # Reusable UI components
│   ├── core/            # Components specific to the elevator simulation
│   │   ├── ElevatorCar.tsx
│   │   ├── ElevatorShaft.tsx
│   │   ├── ElevatorSystemView.tsx
│   │   └── FloorDisplay.tsx
│   ├── dashboard/       # Components for the system overview/dashboard
│   │   └── SystemOverview.tsx
│   ├── layout/          # Layout structure components (e.g., MainLayout)
│   └── ui/              # ShadCN UI primitive components (Button, Card, etc.)
├── hooks/               # Custom React hooks
│   ├── useElevatorSystem.ts # Core logic for the elevator simulation
│   └── use-toast.ts     # Hook for managing toast notifications
├── lib/                 # Utility functions and type definitions
│   ├── types.ts         # TypeScript type definitions for the simulation
│   └── utils.ts         # Utility functions (e.g., cn for classnames)

Elevator Control Algorithm (SCAN-like)

The elevator system employs a SCAN-like algorithm to manage elevator dispatch and movement. Key principles include:

  1. Committed Direction (Sweep): Each active elevator commits to a "sweep" direction (either 'up' or 'down').
  2. Servicing Requests: An elevator continues in its committed direction, servicing all internal passenger requests (destination floors) and any assigned hall calls that lie in its current path and match its committed direction.
  3. Reversal: Once an elevator reaches the furthest request in its current sweep direction (or the end of the shaft if necessary for that sweep), it will check for pending requests (internal or hall calls) in the opposite direction. If such requests exist, it reverses its committedDirection and begins a new sweep.
  4. Idle State: If no requests are pending in its current direction or the opposite direction after a sweep is complete, the elevator becomes idle. It remains idle until a new internal request is made within it or a new hall call is assigned to it by the system.
  5. Hall Call Assignment:
    • When a new hall call is made (e.g., a passenger requests an elevator to go "down" from floor 5), the system attempts to assign this call to the most suitable elevator.
    • Priority 1: An elevator already scanning in the request's direction, moving towards the call floor (and hasn't passed it yet), and has capacity.
    • Priority 2: An idle elevator. The closest idle elevator is typically preferred.
    • If no suitable elevator is immediately available, the request remains "waiting" and is re-evaluated in subsequent system ticks.
  6. Passenger Management: Elevators have a defined capacity. They handle alighting passengers at their destination floors and board new passengers from hall calls if space is available.

This approach aims to provide efficient and fair service, minimizing unnecessary travel and reducing passenger wait times.

Sample Code: Elevator Data Structure

The core state of each elevator is managed using a TypeScript interface:

// Relevant excerpt from src/lib/types.ts

export type ElevatorDirection = "up" | "down" | "idle";

export interface Elevator {
  id: number;
  currentFloor: number;
  destinationFloors: number[]; // Floors requested from inside the elevator
  targetFloor: number | null;    // Next specific floor to stop at
  direction: ElevatorDirection;  // Current operational direction (even if temporarily stopped)
  committedDirection: ElevatorDirection; // The direction of the current sweep (up or down)
  doorsOpen: boolean;
  passengers: number;
  capacity: number;
  status: "idle" | "moving" | "stopped" | "maintenance" | "doors_opening" | "doors_closing" | "boarding";
  passengersServedToday: number;
  doorOpenTimer: number; // Ticks for doors to remain open or for boarding
}

About

Intelligent Elevator Management System - Smart Elevator System

Topics

Resources

Stars

Watchers

Forks