Skip to content

create a C++ application to allocate tasks among workers using Djikstra algorithm

Notifications You must be signed in to change notification settings

ilngaska/course_project_firstyear

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿง  Task Distribution Application Using Dijkstra's Algorithm

C++/CLI Windows Forms Coursework Project

This software application implements a task allocation model using Dijkstraโ€™s algorithm to minimize total execution time. It provides a graphical interface that allows users to add tasks, define dependencies, and distribute them among available workers.


๐Ÿ—๏ธ 1. General Program Structure

The program consists of three main files:

File Description
MyForm.h Header file containing the declaration of the form class and the Task data structure.
MyForm.cpp Implementation file that contains the function definitions for the form class.
Program.cpp Entry point that launches the graphical user interface (GUI).

The program is implemented using C++/CLI and Windows Forms to create a GUI for managing and visualizing task allocation.


๐Ÿ’พ 2. Main Data Structures

Task Structure

Used to store information about a single task:

  • name โ€” name of the task
  • cost โ€” task cost (complexity or duration)
  • mandatory โ€” flag indicating whether the task is mandatory
  • taskId โ€” unique task identifier

Other Data Structures (MyForm class)

Variable Description
tasks List of tasks (List<Task^>)
taskWeights Matrix of edge weights (execution time between tasks), size MAX_TASKS ร— MAX_TASKS
nextTaskId Counter for assigning unique IDs to new tasks

๐Ÿ–ฅ๏ธ 3. Description of the User Interface

The application window is divided into several logical sections:

โž• Adding Tasks

  • Fields for task name and cost
  • Checkbox for marking the task as mandatory
  • Buttons for adding and removing tasks
  • List box displaying all added tasks

๐Ÿ”— Setting Task Connections

  • Drop-down menus for selecting start and end tasks
  • Field for entering the execution time (weight)
  • Buttons to add or remove connections
  • List of existing connections

โš™๏ธ Task Distribution

  • Field to input the number of workers
  • Button to start task distribution
  • Output window displaying results

๐Ÿ“ File Operations

  • Button to save data to a file
  • Button to load data from a file

๐Ÿงฉ 4. Structural Diagram and Module Descriptions

The application consists of 14 modules, each performing a specific function.

๐Ÿ”น UpdateTaskCountLabel()

Updates the label showing the number of tasks and disables the Add Task button when the maximum number of tasks (MAX_TASKS) is reached.

void MyForm::UpdateTaskCountLabel() {
    lblTaskCount->Text = String::Format("Tasks added: {0}/{1}", tasks->Count, MAX_TASKS);
    btnAddTask->Enabled = (tasks->Count < MAX_TASKS);
}

๐Ÿ”น UpdateTaskList()

Clears and refills the list of tasks. Also updates combo boxes and counters.

void MyForm::UpdateTaskList() {
    listTasks->Items->Clear();
    for (int i = 0; i < tasks->Count; i++) {
        Task^ task = tasks[i];
        String^ displayText = String::Format(
            "[{0}] {1} (Cost: {2}, {3})",
            task->taskId, task->name, task->cost,
            task->mandatory ? "Mandatory" : "Optional"
        );
        listTasks->Items->Add(displayText);
    }
    UpdateTaskCombos();
    UpdateTaskCountLabel();
}

๐Ÿ”น btnAddTask_Click()

Handles adding a new task after validating user input.

void MyForm::btnAddTask_Click(System::Object^ sender, System::EventArgs^ e) {
    int cost;
    if (!Int32::TryParse(txtTaskCost->Text, cost) || cost <= 0) {
        MessageBox::Show("Cost should be a positive number", "Input error");
        return;
    }

    Task^ newTask = gcnew Task(txtTaskName->Text, cost, chkMandatory->Checked, nextTaskId++);
    tasks->Add(newTask);
    UpdateTaskList();

    txtTaskName->Clear();
    txtTaskCost->Clear();
    chkMandatory->Checked = false;
}

๐Ÿ”น btnRemoveTask_Click()

Removes the selected task and all its associated edges.

void MyForm::btnRemoveTask_Click(System::Object^ sender, System::EventArgs^ e) {
    int selectedIndex = listTasks->SelectedIndex;
    if (selectedIndex >= 0 && selectedIndex < tasks->Count) {
        int taskId = tasks[selectedIndex]->taskId;
        for (int i = 0; i < MAX_TASKS; i++) {
            taskWeights[taskId][i] = 0;
            taskWeights[i][taskId] = 0;
        }
        tasks->RemoveAt(selectedIndex);
        UpdateTaskList();
        UpdateWeightsList();
    } else {
        MessageBox::Show("Please choose a task to delete", "Error");
    }
}

๐Ÿ”น UpdateTaskCombos()

Updates the combo boxes used for defining task connections.

๐Ÿ”น UpdateWeightsList()

Displays all task relationships (edges) based on the taskWeights matrix.

๐Ÿ”น btnAddWeight_Click() / btnRemoveWeight_Click()

Add or remove edges between tasks after validating input.


๐Ÿ”น FindEarliestAvailableWorker()

Finds the earliest available worker based on previous task completion time and workload.


๐Ÿ”น DijkstraSingleSource() & MinDistance()

Implement Dijkstraโ€™s algorithm for finding the shortest paths between tasks in the dependency graph.


๐Ÿ”น AllocateTasksUsingDijkstra()

Performs task allocation among workers, considering dependencies and earliest possible start times.

Steps include:

  1. Running Dijkstraโ€™s algorithm for all active tasks
  2. Dividing tasks into mandatory and optional
  3. Sorting tasks by start time
  4. Assigning each to the earliest available worker

๐Ÿ”น OutputAllocationResultsWithDijkstra()

Displays the results of the allocation process.

๐Ÿ”น File Handling Modules

  • Save to file โ€” writes tasks and connections using SaveFileDialog
  • Load from file โ€” reads data and reconstructs the graph structure

๐Ÿงพ 5. Conclusion

This coursework project demonstrates a software system that models task distribution among workers using Dijkstraโ€™s algorithm.

โœ… Achievements:

  • Implementation of Dijkstraโ€™s algorithm for optimal task assignment
  • Development of a graphical interface for user interaction
  • Functionality for data saving and loading
  • Visualization of tasks, dependencies, and results

๐Ÿ’ก Educational Outcome:

The project provides a practical understanding of graph theory in programming and its application to real-world task scheduling problems. Creating the GUI also enhances visualization and user interaction, making it easier to perceive the sequence of operations.

๐Ÿš€ Future Enhancements:

  • Add user account identification
  • Implement saving/loading of full program state
  • Extend analysis and visualization features

๐Ÿ“š Source List

  1. GeeksforGeeks โ€” Dijkstra's Algorithm
  2. Saylor Academy โ€” Dijkstra's Algorithm
  3. TutorialsPoint โ€” Dijkstraโ€™s Shortest Path Algorithm
  4. GeeksforGeeks โ€” Introduction to .NET Framework
  5. Simplilearn โ€” Creating C++ GUI Applications

About

create a C++ application to allocate tasks among workers using Djikstra algorithm

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages