-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
173 lines (140 loc) · 4.87 KB
/
Copy pathmain.cpp
File metadata and controls
173 lines (140 loc) · 4.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include <iostream>
#include <vector>
#include <algorithm>
#include<fstream>
#include "src/core/task.h"
#include "src/core/policy_engine.h"
#include "src/engine/scheduler_runner.h"
using namespace std;
int main() {
std::ofstream clearFile("frontend/public/output.txt", std::ios::trunc);
clearFile.close();
vector<Task> allTasks;
while (true) {
cout << "\n===== FocusForge Scheduler Kernel =====\n";
cout << "1. Add tasks & run scheduler\n";
cout << "2. Remove a task\n";
cout << "3. Remove all tasks\n";
cout << "4. Exit\n";
cout << "Select option: ";
int option;
cin >> option;
// =====================================================
// ADD TASKS AND RUN
// =====================================================
if (option == 1) {
int n;
cout << "\nEnter number of tasks: ";
cin >> n;
for (int i = 0; i < n; i++) {
Task t;
cout << "\nTask " << allTasks.size() + 1 << " Name: ";
cin >> t.name;
cout << "Burst Time: ";
cin >> t.burst;
t.remaining = t.burst;
cout << "Priority: ";
cin >> t.priority;
cout << "Arrival Time: ";
cin >> t.arrival;
cout << "Queue Level: ";
cin >> t.queue_level;
allTasks.push_back(t);
}
if (allTasks.empty()) {
cout << "No tasks available.\n";
continue;
}
cout << "\nRun Scheduler Using:\n";
cout << "1. AUTO (kernel decides)\n";
cout << "2. Manual algorithm selection\n";
cout << "Choice: ";
int mode;
cin >> mode;
PolicyType policy;
// ================= AUTO MODE =================
if (mode == 1) {
policy = PolicyEngine::choosePolicy(allTasks);
}
// ================= MANUAL MODE =================
else {
cout << "\nChoose Algorithm:\n";
cout << "1. FCFS\n";
cout << "2. SJF\n";
cout << "3. Priority\n";
cout << "4. Round Robin\n";
cout << "5. SRTF\n";
cout << "6. MLFQ\n";
cout << "Choice: ";
int c;
cin >> c;
if (c == 1) policy = PolicyType::FCFS;
else if (c == 2) policy = PolicyType::SJF;
else if (c == 3) policy = PolicyType::PRIORITY;
else if (c == 4) policy = PolicyType::ROUND_ROBIN;
else if (c == 5) policy = PolicyType::SRTF;
else if (c == 6) policy = PolicyType::MLFQ;
else {
cout << "Invalid choice.\n";
continue;
}
}
// 🔥 Single execution point
SchedulerRunner::run(allTasks, policy);
}
// =====================================================
// REMOVE ONE TASK
// =====================================================
else if (option == 2) {
if (allTasks.empty()) {
cout << "\nNo tasks to remove.\n";
continue;
}
cout << "\nCurrent tasks:\n";
for (auto& t : allTasks)
cout << " - " << t.name << "\n";
cout << "Enter task name to remove: ";
string name;
cin >> name;
auto it = remove_if(
allTasks.begin(),
allTasks.end(),
[&](const Task& t) {
return t.name == name;
}
);
if (it == allTasks.end()) {
cout << "Task not found.\n";
} else {
allTasks.erase(it, allTasks.end());
cout << "Task removed successfully.\n";
}
cout << "\nRemaining tasks:\n";
if (allTasks.empty()) {
cout << "No tasks left.\n";
} else {
for (auto& t : allTasks) {
cout << " - " << t.name << "\n";
}
}
}
// =====================================================
// CLEAR ALL TASKS
// =====================================================
else if (option == 3) {
allTasks.clear();
cout << "\nAll tasks removed.\n";
}
// =====================================================
// EXIT
// =====================================================
else if (option == 4) {
cout << "\nShutting down FocusForge kernel...\n";
break;
}
else {
cout << "Invalid option.\n";
}
}
return 0;
}