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.
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.
Used to store information about a single task:
nameโ name of the taskcostโ task cost (complexity or duration)mandatoryโ flag indicating whether the task is mandatorytaskIdโ unique task identifier
| 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 |
The application window is divided into several logical sections:
- 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
- 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
- Field to input the number of workers
- Button to start task distribution
- Output window displaying results
- Button to save data to a file
- Button to load data from a file
The application consists of 14 modules, each performing a specific function.
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);
}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();
}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;
}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");
}
}Updates the combo boxes used for defining task connections.
Displays all task relationships (edges) based on the taskWeights matrix.
Add or remove edges between tasks after validating input.
Finds the earliest available worker based on previous task completion time and workload.
Implement Dijkstraโs algorithm for finding the shortest paths between tasks in the dependency graph.
Performs task allocation among workers, considering dependencies and earliest possible start times.
Steps include:
- Running Dijkstraโs algorithm for all active tasks
- Dividing tasks into mandatory and optional
- Sorting tasks by start time
- Assigning each to the earliest available worker
Displays the results of the allocation process.
- Save to file โ writes tasks and connections using
SaveFileDialog - Load from file โ reads data and reconstructs the graph structure
This coursework project demonstrates a software system that models task distribution among workers using Dijkstraโs algorithm.
- 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
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.
- Add user account identification
- Implement saving/loading of full program state
- Extend analysis and visualization features