Skip to content

Latest commit

 

History

102 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🍽️ Restaurant Management Simulation

Data Structures & Algorithms Project – CMPG104 (Spring 2026)


📖 Table of Contents


🌟 Overview

Restaurant is a discrete-time, event-driven C++ simulation of a full restaurant operation. Every timestep the simulator:

  1. Receives new customer orders (Dine-In, TakeAway, Delivery, Combo)
  2. Assigns chefs and resources from a pool of Normal & Special chefs, Scooters, and Tables
  3. Tracks every order through its full lifecycle: Pending → Cooking → Ready → In-Service → Finished
  4. Handles edge cases like order cancellations, scooter failures, rescue scooters, and overwait promotions
  5. Outputs a detailed statistics file with timing metrics, utilization, and percentages

The simulation runs in two modes — Interactive (step-by-step with state display) and Silent (runs to completion, outputs file).


🎯 Features

Feature Description
🍽️ 7 Order Types ODG, ODN, OT, OVG, OVN, OVC, COMBO
👨‍🍳 2 Chef Types Normal (CN) and Special (CS) with different speeds
🛵 Smart Scooter System Priority-based dispatch, failure detection, rescue scooters, maintenance
🪑 Table Sharing Logic Best-fit table selection with optional seat sharing
OVC Cancellation Cancel orders at Pending / Cooking / Ready stages
Overwait Promotion OVG orders promoted after exceeding wait threshold TH
🎲 Scooter Failures 0.5% failure rate on delivery; rescue scooter dispatched
📊 Rich Statistics Avg times, utilization percentages, order type breakdown
🖥️ Dual Run Modes Interactive (step-through) and Silent (file output)
📁 File I/O Load configuration + actions from .txt, save results to .txt

🏗️ Architecture & Project Structure

Restaurant/
│
├── Restaurant/               ← Core simulation engine
│   ├── Restaurant.h          ← Main class declaration (all queues, resources, methods)
│   ├── Restaurant.cpp        ← Full simulation logic implementation
│   ├── Defs.h                ← Enums: OrderType, ProgramMode, ChefType
│   ├── UI.cpp                ← User interface (input/output prompts & state display)
│   └── helpers.cpp           ← Utility functions
│
├── Entities/                 ← Data model classes
│   ├── Order.h / Order.cpp   ← Base order class (ID, timestamps, chef/table/scooter)
│   ├── DineInOrder.h         ← Dine-in (seats, duration, canShare)
│   ├── DeliveryOrder.h       ← Delivery (distance, scooter assignment)
│   ├── TakeAway.h            ← Takeaway orders
│   ├── ComboOrder.h          ← Multi-chef, multi-scooter combo orders
│   ├── Chef.h / Chef.cpp     ← Chef entity (type, speed, current order)
│   ├── Scooter.h / Scooter.cpp ← Scooter entity (speed, distance, maintenance)
│   └── Tables.h / Tables.cpp ← Table entity (seats, sharing state)
│
├── Actions/                  ← Event-driven action system
│   ├── Actions.h             ← Base Action class
│   ├── RequestAction.h       ← Adds a new order to pending
│   └── CancelAction.h        ← Attempts to cancel an OVC order
│
├── DS/                       ← Custom Data Structures
│   ├── LinkedQueue.h         ← Generic FIFO linked queue
│   ├── priQueue.h            ← Priority queue (min/max heap)
│   ├── ArrayStack.h          ← Stack using dynamic array
│   ├── CancellingQueue.h     ← Queue with O(n) ID-based removal
│   ├── CancellingPriQueue.h  ← Priority queue with cancellation support
│   └── Fit_Tables.h          ← Priority queue specialized for table best-fit
│
├── UI/
│   ├── UI.h                  ← UI interface declaration
│   └── Entities.h            ← Forward declarations for UI display
│
├── outputs/                  ← Generated output files
├── File1.txt ... File6.txt   ← Sample input test files
└── Restaurant.sln            ← Visual Studio solution file

🧩 Order Types

Code Full Name Chef Required Delivery Dine-In Priority
ODG Dine-In Grilled Special (CS) FCFS
ODN Dine-In Normal Any (CN or CS) FCFS
OT TakeAway Any FCFS, +1 timestep pickup
OVG Delivery Grilled Special (CS) Price + Size + Distance
OVN Delivery Normal Normal (CN) FCFS
OVC Delivery Cancellable Any FCFS, cancellable
COMBO Combo Delivery CS + any others ✅ (multi-scooter) FCFS, requires ≥1 CS

Note: ODG and OVG are "Grilled" orders that exclusively require a Special Chef (CS). Normal chefs cannot handle them.


👨‍🍳 Resources

Chefs

┌─────────────────────────────────────────────────────────┐
│                     CHEF TYPES                          │
├──────────────────────┬──────────────────────────────────┤
│  Normal Chef (CN)    │  Special Chef (CS)                │
│  ─────────────────   │  ────────────────────────────     │
│  • Handles ODN, OT,  │  • Handles ALL order types       │
│    OVC, OVN          │  • Required for ODG, OVG, COMBO  │
│  • One order at      │  • One order at a time           │
│    a time            │  • Higher cooking speed          │
└──────────────────────┴──────────────────────────────────┘

Cook Time Formula: cookTime = ⌈ orderSize / chefSpeed ⌉

Scooters

┌───────────────────────────────────────────────────────────────┐
│                     SCOOTER STATES                            │
│                                                               │
│   AVAILABLE ──assign──► DELIVERING ──done──► RETURNING BACK  │
│       ▲                                            │         │
│       │                                     needs maint?     │
│       │                            ┌────yes─────┘  │no      │
│       │                            ▼               ▼         │
│       └──────── maint done ── MAINTENANCE      AVAILABLE     │
└───────────────────────────────────────────────────────────────┘
  • Priority: Scooter with least total distance traveled is dispatched first
  • Maintenance: After Main_Ords deliveries, goes to maintenance for Main_Dur timesteps
  • Failure: 0.5% chance on delivery completion → triggers rescue scooter
  • Rescue Scooters: Pre-configured pool; if available, finish the broken scooter's delivery

Tables

  • Best-Fit Selection: Table with fewest free seats that still fits the order is preferred
  • Seat Sharing: If order canShare, try to fill a busy-but-sharing table first
  • Seat Release: On dine-in completion, seats are released; table returns to available or stays shared

📊 Data Structures Used

Structure Used For Location
LinkedQueue<T> Pending ODG/ODN/OT/OVN, Ready OD/OT, Available Chefs, Maintenance Scooters, Cancelled, Actions DS/LinkedQueue.h
priQueue<T> Pending OVG (by priority), Cooking queues, In-Service queues, Available/Back Scooters, Overwait DS/priQueue.h
CancellingQueue<T> Pending OVC, Ready OV — need O(n) ID cancellation DS/CancellingQueue.h
CancellingPriQueue<T> Cooking OVC — priority + cancellation DS/CancellingPriQueue.h
ArrayStack<T> Finished orders (LIFO for output) DS/ArrayStack.h
Fit_Tables Available, Busy-Share, Busy-NoShare tables DS/Fit_Tables.h

🔄 Simulation Flow

Each timestep executes in this exact order:

╔══════════════════════════════════════════════════════════════╗
║                   TIMESTEP  t = t + 1                        ║
╠══════════════════════════════════════════════════════════════╣
║  1. FINISH        │ Move completed In-Service → Finished     ║
║                   │ Release tables / scooters                 ║
║─────────────────────────────────────────────────────────────║
║  2. BACK SCOOTERS │ Return scooters from delivery            ║
║                   │ → Maintenance OR Available               ║
║─────────────────────────────────────────────────────────────║
║  3. MAINTENANCE   │ Release maintained scooters → Available  ║
║─────────────────────────────────────────────────────────────║
║  4. COOKING→READY │ Move done-cooking orders to Ready queues ║
║─────────────────────────────────────────────────────────────║
║  5. ACTIONS       │ Execute all actions scheduled at time t  ║
║                   │ (RequestAction → AddPendingOrder,        ║
║                   │  CancelAction  → CancelOrder)            ║
║─────────────────────────────────────────────────────────────║
║  [Interactive Mode: Print state + wait for keypress]        ║
║─────────────────────────────────────────────────────────────║
║  6. PENDING→COOK  │ Assign chefs to pending orders           ║
║                   │ Priority: ODG > OVG > COMBO > ODN        ║
║                   │           > OT > OVC > OVN               ║
║─────────────────────────────────────────────────────────────║
║  7. READY→SERVICE │ Assign tables/scooters to ready orders   ║
║                   │ Priority: COMBO > OT > Delivery > DineIn ║
╚══════════════════════════════════════════════════════════════╝

Termination Condition: All action, pending, cooking, ready, in-service, back-scooter, and maintenance queues are empty.


📐 Flowcharts

Main Simulation Loop

                    ┌─────────────────┐
                    │   START / INIT  │
                    │  Load Input File│
                    └────────┬────────┘
                             │
                             ▼
                    ┌─────────────────┐
                    │  currentTime++  │◄──────────────────────────┐
                    └────────┬────────┘                           │
                             │                                     │
              ┌──────────────▼──────────────┐                     │
              │   1. MoveServiceToFinish()  │                     │
              │   2. HandleBackScooters()   │                     │
              │   3. MoveMaintToAvailable() │                     │
              └──────────────┬──────────────┘                     │
                             │                                     │
              ┌──────────────▼──────────────┐                     │
              │   4. MoveCookingToReady()   │                     │
              └──────────────┬──────────────┘                     │
                             │                                     │
              ┌──────────────▼──────────────┐                     │
              │  5. ExecuteTimeActions()    │                     │
              │  (Request / Cancel orders)  │                     │
              └──────────────┬──────────────┘                     │
                             │                                     │
              ┌──────────────▼──────────────┐                     │
              │   6. MovePendingToCooking() │                     │
              │   7. MoveReadyToService()   │                     │
              └──────────────┬──────────────┘                     │
                             │                                     │
              ┌──────────────▼──────────────┐                     │
              │     IsSimulationDone()?     │                     │
              └──────────────┬──────────────┘                     │
                             │                                     │
                    NO ──────┘◄────────────────────── loop back ──┘
                             │
                           YES
                             │
                    ┌────────▼────────┐
                    │  Write Output   │
                    │  File + Stats   │
                    └────────┬────────┘
                             │
                    ┌────────▼────────┐
                    │      END        │
                    └─────────────────┘

Order Lifecycle

  Customer Request
         │
         ▼
  ┌─────────────┐      ╔═══════════════════════════════════╗
  │  PENDING    │      ║  Queue assignment by type:        ║
  │  QUEUE      │      ║  ODG/ODN   → PEND_ODG / PEND_ODN ║
  │             │◄─────║  OT        → PEND_OT             ║
  │  Awaiting   │      ║  OVG       → PEND_OVG (priority) ║
  │  chef       │      ║  OVN       → PEND_OVN            ║
  └──────┬──────┘      ║  OVC       → PEND_OVC (cancel)  ║
         │             ║  COMBO     → PEND_COMBO          ║
         │ chef free   ╚═══════════════════════════════════╝
         ▼
  ┌─────────────┐
  │  COOKING    │  TA = currentTime
  │             │  TR = TA + ⌈size/chefSpeed⌉
  │  Chef busy  │
  └──────┬──────┘
         │
         │ TR reached
         ▼
  ┌─────────────┐      chef released → back to available pool
  │   READY     │
  │             │
  │  Awaiting   │
  │  resource   │
  └──────┬──────┘
         │
         │ resource (table/scooter) available
         ▼
  ┌─────────────┐      TS = currentTime
  │ IN-SERVICE  │      TF = TS + duration
  │             │
  │  Being      │
  │  served     │
  └──────┬──────┘
         │
         │ TF reached
         ▼
  ┌─────────────┐
  │  FINISHED   │  Pushed to ArrayStack (LIFO)
  │  (STACK)    │  Scooter → BACK_SCOOTERS
  └─────────────┘  Table   → freed/shared

Chef Assignment Logic

   MovePendingToCooking() called each timestep
              │
              ▼
   ┌──────────────────────────┐
   │  1. ODG Orders           │──► Needs CS chef ──► CS available? ──Yes──► Assign
   │     (Dine-In Grilled)    │                                     No──► skip
   └──────────────────────────┘
              │
              ▼
   ┌──────────────────────────┐
   │  2. OVG Orders           │──► Needs CS chef ──► CS available? ──Yes──► Assign
   │     (Delivery Grilled)   │
   └──────────────────────────┘
              │
              ▼
   ┌──────────────────────────┐
   │  3. COMBO Orders         │──► Need ≥1 CS + (N-1) any chef
   │     (Multi-chef)         │     All assigned simultaneously
   └──────────────────────────┘     CookTime = ⌈size / sumSpeeds⌉
              │
              ▼
   ┌──────────────────────────┐
   │  4. ODN (Dine-In Normal) │──► CN preferred, CS as fallback
   │  5. OT  (TakeAway)       │
   │  6. OVC (Cancellable Del)│
   │  7. OVN (Normal Del)     │──► Only CN chefs
   └──────────────────────────┘

Scooter Lifecycle

   ┌─────────────────────────────────────────────────────────────┐
   │                    SCOOTER LIFECYCLE                        │
   │                                                             │
   │   ┌──────────┐                                             │
   │   │ AVAILABLE│◄───────────────────────────────┐           │
   │   │ priQueue │   (priority = -totalDistance)   │           │
   │   └────┬─────┘                                 │           │
   │        │ order assigned                         │           │
   │        ▼                                        │           │
   │   ┌──────────┐    TF = TS + ⌈distance/speed⌉  │           │
   │   │DELIVERING│                                  │           │
   │   │(InServ)  │                                  │           │
   │   └────┬─────┘                                  │           │
   │        │ TF reached                             │           │
   │        ▼                                        │           │
   │   failure check ──0.5% fail──► rescue scooter  │           │
   │        │ 99.5% ok                               │           │
   │        ▼                                        │           │
   │   ┌──────────┐    TFback = TF + ⌈distance/speed⌉          │
   │   │  BACK    │    (returning journey)           │           │
   │   │ priQueue │                                  │           │
   │   └────┬─────┘                                  │           │
   │        │ TFback reached                         │           │
   │        ├── needs maintenance? ──yes──► ┌───────────────┐  │
   │        │   (orderCount ≥ Main_Ords)    │ MAINTENANCE   │  │
   │        │                               │ Queue         │  │
   │        │                               └───────┬───────┘  │
   │        │                                       │           │
   │        │                            TFback += Main_Dur    │
   │        │                                       │           │
   │        └──────────────no──────────────────────►┘           │
   │                                                             │
   └─────────────────────────────────────────────────────────────┘

Cancellation Flow

   CancelAction triggered for Order ID = X
               │
               ▼
   ┌───────────────────────┐
   │ Is order type OVC?    │──No──► Cancellation rejected
   └───────────┬───────────┘         (only OVC can be cancelled)
               │Yes
               ▼
   ┌───────────────────────┐
   │  Search PEND_OVC      │──Found──► Remove + Enqueue CANCELLED ✓
   └───────────┬───────────┘
               │Not found
               ▼
   ┌───────────────────────┐
   │  Search COOK_OVC      │──Found──► Remove, Release Chef → AVAIL
   └───────────┬───────────┘             + Enqueue CANCELLED ✓
               │Not found
               ▼
   ┌───────────────────────┐
   │  Search READY_OV      │──Found──► Remove + Enqueue CANCELLED ✓
   └───────────┬───────────┘
               │Not found
               ▼
           Not cancellable
        (already in service or finished)

📥 Input File Format

[CnCount] [CsCount]          ← Number of Normal and Special Chefs
[CnSpeed] [CsSpeed]          ← Speed of each chef type

[ScooterCount] [Speed]       ← Number of scooters and their speed
[Main_Ords] [Main_Dur]       ← Maintenance trigger count and duration
[RescueScooterCount]         ← Available rescue scooters

[TableCount]                 ← Total number of tables
[Count1] [Seats1]            ← e.g. "3 4" = three 4-seat tables
[Count2] [Seats2]            ← repeated until TableCount reached

[TH]                         ← Overwait threshold for OVG

[M]                          ← Number of actions
Q [t] [type] [size] [price] [params...]   ← Request order
X [t] [orderID]                           ← Cancel OVC order

Example Input

3 2
5 8
4 60
3 5
2
6
2 4
3 6
1 8
5
12
Q 1 ODG 3 120.0 2 10 1
Q 2 OVG 5 180.0 300.0
Q 3 OVC 2 90.0 150.0
Q 5 COMBO 4 250.0 200.0 2 3 2
X 7 3
...

📤 Output File Format

TF    ID    TQ    TA    TR    TS    Ti    TC    Tw    Tserv
────────────────────────────────────────────────────────
15    1     1     3     8     8     7     5     0     7
22    2     2     4     9     11    8     5     2     11
...

================ Statistics ================
Total number of orders: 12
ODG orders: 2  |  ODN orders: 1  |  OT orders: 3
OVG orders: 2  |  OVN orders: 1  |  OVC orders: 2  |  COMBO: 1

Finished orders percentage: 91.67%
Cancelled orders percentage: 8.33%
Overwait orders percentage: 16.67%

Average Ti: 8.54  |  Average TC: 5.20
Average Tw: 1.30  |  Average Tserv: 9.10

Scooters utilization percentage: 73.25%
Chefs utilization percentage: 81.40%
============================================

Timestamp Legend

Symbol Meaning
TQ Time order was Queued (requested)
TA Time chef was Assigned (cooking starts)
TR Time order was Ready (cooking done)
TS Time Service started (table seated / scooter dispatched)
TF Time order Finished
Ti Total idle time = TA - TQ
TC Cooking time = TR - TA
Tw Wait time after ready = TS - TR
Tserv Service time = TF - TS

▶️ Running the Simulation

Once the project is built, run the executable and follow the prompts:

SELECT MODE..
1. Interactive
2. Silent
Enter choice: 2

Enter input file name: File1.txt

Simulation Starts in Silent mode ..

Enter output file name: output1.txt

Simulation Ended, Output file created
  • Interactive mode — pauses at every timestep and prints the full state of all queues. Press any key to advance.
  • Silent mode — runs the entire simulation instantly and writes results to the output file.

🧮 Statistics & Metrics

The simulator calculates and outputs:

┌─────────────────────────────────────────────────────────────┐
│                     METRICS SUMMARY                         │
├─────────────────────┬───────────────────────────────────────┤
│ Metric              │ Formula                               │
├─────────────────────┼───────────────────────────────────────┤
│ Finished %          │ (finished / total) × 100              │
│ Cancelled %         │ (cancelled / total) × 100             │
│ Overwait %          │ (orders where TS-TR > TH) / finished  │
│ Avg Ti              │ Σ(TA - TQ) / finished                 │
│ Avg TC              │ Σ(TR - TA) / finished                 │
│ Avg Tw              │ Σ(TS - TR) / finished                 │
│ Avg Tserv           │ Σ(TF - TS) / finished                 │
│ Chef Utilization    │ totalChefBusyTime / (T × chefCount)   │
│ Scooter Utilization │ totalScooterBusyTime / (T × scooters) │
└─────────────────────┴───────────────────────────────────────┘

👥 Team

This project was built collaboratively as a Data Structures course project:

Member
Youmna Mohamed
Nour Ibrahim
Yasmine Ismail

Built with ❤️ and a lot of priQueue debugging

🍴 Bon Appétit! 🍴

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages