Skip to content

vtr054/Task-Scheduler-Optimization-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Task Scheduler Optimization System

An industry-oriented, portfolio-grade Data Structures and Algorithms (DSA) project implementing a single-processor batch task scheduling simulator. This system optimizes task execution order to maximize total value/profit and meet deadline constraints using a custom Max-Heap (Priority Queue) and Greedy Heuristics.


📖 Project Overview

In cloud computing, operating system kernels, and project management pipelines, resources (CPU, threads, workers) are finite, while tasks are dynamic. If tasks are executed randomly or in simple arrival order (First-In, First-Out), critical deadlines can be missed, leading to system failure, SLA violations, or loss of business profit.

The Task Scheduler Optimization System is a modular Python command-line utility that simulates execution queues. It implements two distinct scheduling paradigms:

  1. Profit-Greedy Scheduler (Max-Heap driven): Prioritizes scheduling tasks with high profit density (value per time-unit) as late as possible before their deadlines to optimize total value.
  2. Earliest Deadline First (EDF) Scheduler: Focuses on task urgency by sorting tasks ascending by their deadlines to maximize completed task counts.

💡 Problem Statement

Given a set of $N$ tasks, where each task has:

  • A unique Task ID and Name.
  • A Priority (criticality rank from 1 to 10).
  • A Deadline (the time-step by which it must complete).
  • A Duration (execution time steps required, non-preemptive).
  • A Profit (value or weight earned if completed on time).

The goal is to determine the optimal sequence of tasks to execute on a single CPU resource such that we maximize the total profit earned and analyze scheduling tradeoffs (turnaround time, waiting time, and CPU utilization).


🛠️ DSA Concepts & Data Structures Used

  • Custom Max-Heap (Priority Queue): Implemented from scratch in heap.py to extract the most important/highest profit task dynamically in $O(\log N)$ time.
  • Greedy Strategy: Uses profit density ($\frac{\text{Profit}}{\text{Duration}}$) and deadline-matching backwards allocation to find high-yield schedules.
  • Sorting Algorithms: Timsort is utilized to pre-sort timelines and format data reports.
  • Array-Based Execution Timeline: Simulates sequential CPU slots to track idle and active intervals.

🗂️ Folder Structure

Task-Scheduler-Optimization-System/
│
├── data/
│   └── sample_tasks.csv        # Default CSV file containing simulation workloads
│
├── src/
│   ├── __init__.py
│   ├── task.py                 # Task class & CSV Loader
│   ├── heap.py                 # Custom Max-Heap implementation
│   ├── scheduler.py            # Greedy and EDF scheduling engines
│   ├── metrics.py              # Performance calculations & comparison tables
│   ├── report.py               # ASCII visualizer & CSV/Text exporters
│   └── test_heap.py            # Unit tests for verification
│
├── outputs/
│   ├── schedule_report.txt     # Formatted report showing comparison and timeline
│   └── schedule_report.csv     # Detailed tabular log of CPU execution steps
│
├── docs/
│   └── project_guide.md        # Technical deep-dive & interview preparation guide
│
├── requirements.txt            # Project python environment dependencies
├── .gitignore                  # Git tracking exclusions
├── main.py                     # CLI Interactive Controller
└── README.md                   # Repository landing page

🚀 How to Run the Project

Prerequisites

  • Python 3.8 or higher installed on your system.
  • Standard libraries only (No external dependencies required).

Installation & Execution Steps

  1. Clone or download the project folder:

    cd "Task Scheduler Optimization System"
  2. Run the interactive CLI application:

    • Windows (PowerShell / cmd):
      python main.py
    • macOS / Linux (Terminal):
      python3 main.py
  3. Verify the Custom Heap: You can run unit tests to verify the correctness of the heap operations:

    python -m unittest src/test_heap.py

📊 Sample Output

Below is an example of the terminal simulation comparison for a workload of 8 tasks:

Interactive Menu

============================================================
             TASK SCHEDULER OPTIMIZATION SYSTEM             
============================================================

1. Load and Run Default Sample Tasks (from CSV)
2. Load and Run Custom CSV Task File
3. Enter Tasks Manually via Command Line
4. Generate and Run Random Task Workload
5. Exit

Enter choice (1-5): 1

Execution Timelines (ASCII Visual)

[ Profit-Greedy (Max-Heap) Timeline ]
Time: t=1   |t=2   |t=3   |t=4   |t=5   |t=6   |t=7   |t=8   |t=9   |t=10  |
----------------------------------------------------------------------------
CPU:  [IDLE]|[ T3 ]|[ T6 ]|[ T1 ]|[ T1 ]|[ T1 ]|[ T4 ]|[ T4 ]|[IDLE]|[IDLE]|

[ Earliest Deadline First (EDF) Timeline ]
Time: t=1   |t=2   |t=3   |t=4   |t=5   |t=6   |t=7   |t=8   |
--------------------------------------------------------------
CPU:  [ T3 ]|[ T6 ]|[ T5 ]|[ T5 ]|[ T8 ]|[ T8 ]|[ T4 ]|[ T4 ]|

Comparison Matrix

|--------------------------------+----------------------------+--------------------------------|
| Metric                         | Profit-Greedy (Max-Heap)   | Earliest Deadline First (EDF)  |
|--------------------------------+----------------------------+--------------------------------|
| Algorithm Strategy             | Greedy (Profit Optimization) | Chronological Deadline-First   |
| Tasks Completed On-Time        | 4/8 (50.0%)                | 5/8 (62.5%)                    |
| Tasks Missed (Lateness)        | 4                          | 3                              |
| Total Profit/Value Earned      | $250.00                    | $240.00                        |
| CPU Utilization Rate           | 70.0%                      | 100.0%                         |
| Average Waiting Time           | 3.00 units                 | 2.60 units                     |
| Average Turnaround Time        | 4.75 units                 | 4.20 units                     |
|--------------------------------+----------------------------+--------------------------------|

[Analysis] Tradeoff Analysis:
1. **Profit/Value**: Profit-Greedy earned $10.00 more than EDF because it prioritized high-value tasks.
2. **Success Rate (Throughput)**: EDF completed 1 more task(s) on-time by focusing on urgency first.
3. **Wait & Turnaround**: EDF achieved lower average waiting time, which is common as it processes tasks sequentially without gaps.

🎯 Learning Outcomes & Portfolio Benefits

By completing and review this project, you will demonstrate:

  1. Core Data Structure Mastery: Writing a custom Binary Max-Heap from scratch rather than importing library wrappers.
  2. Heuristic Algorithm Design: Understanding the mechanics of greedy scheduling and identifying its performance boundaries.
  3. Software Architecture Best Practices: Developing modular, production-ready Python packages with separate folders for models, services, reports, and tests.
  4. Interview Readiness: Explaining core system design principles behind process scheduling, cloud optimization, and latency tradeoffs (see docs/project_guide.md).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages