-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
215 lines (181 loc) · 6.84 KB
/
Copy pathmain.cpp
File metadata and controls
215 lines (181 loc) · 6.84 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#include <iostream>
#include <chrono>
#include <fstream>
#include <imgui-SFML.h>
#include <thread>
#include <SFML/Graphics.hpp>
#include "imgui.h"
#include "Renderer.h"
#include "Simulator.h"
#include "Scheduler/FCFS/FCFS.h"
#include "Scheduler/MLFQ/MLFQ.h"
#include "Scheduler/SJF/SJF.h"
#include "Scheduler/SRTF/SRTF.h"
#include "Scheduler/RR/RR.h"
#include "Scheduler/PSRR/PSRR.h"
#include "Utils/Random.h"
#include "Utils/TestData.h"
using namespace std;
int main() {
vector<ProcessBlueprint> blueprints;
blueprints.emplace_back(0,0,2,3);
blueprints.emplace_back(1,2,8,1);
blueprints.emplace_back(2,2,5,1);
blueprints.emplace_back(3,2,3,1);
blueprints.emplace_back(4,2,9,1);
blueprints.emplace_back(5,2,4,1);
blueprints.emplace_back(6,5,3,2);
blueprints.emplace_back(7,1,1,4);
blueprints.emplace_back(8,4,4,6);
blueprints.emplace_back(9,3,1,2);
// RR - Exemplu de pe Wiki
// blueprints.emplace_back(1,0, 1, 0);
// blueprints.emplace_back(2,0, 2, 0);
// blueprints.emplace_back(3,0, 3, 0);
// blueprints.emplace_back(4,0, 4, 0);
// blueprints.emplace_back(5,0, 5, 0);
//
// blueprints.emplace_back(6,11, 8, 0);
// blueprints.emplace_back(7,11, 6, 0);
// blueprints.emplace_back(8,11, 4, 0);
// blueprints.emplace_back(9,11, 2, 0);
// blueprints.emplace_back(10,11, 1, 0);
// RR - Exemplu din 5.22
// blueprints.emplace_back(1,0, 24, 0);
// blueprints.emplace_back(2,0, 3, 0);
// blueprints.emplace_back(3,0, 3, 0);
// std::vector<IScheduler*> schedulers{new FCFS, new SJF};
// for (const auto& scheduler : schedulers) {
// Simulator sim(scheduler);
// sim.AssignData(blueprints);
// sim.Run();
//
// cout<<sim.getResults().size();
//
// for (const auto value:sim.getResults()) {
// cout << value <<endl;
// }
// }
Simulator sim(new MLFQ, 4);
sim.AssignData(blueprints);
sim.Run();
sf::Font font;
font.loadFromFile("../assets/Coolvetica.otf");
int numberOfProcesses=6;
int numberOfTests=5;
int maxTime=100;
int maxDuration=50;
vector<Stats> globalTestsResults;
std::string algorithmNames[7]={
"Round Robin 4 unit",
"Round Robin 1 units",
"First Come First Serve",
"Shortest Job First",
"Shortest Remaining Time First",
"Multi Level Feetback Queue",
"(Priority Scheduling + Round Robin)"
};
vector<Simulator> sims = {
Simulator(new RR, 4),
Simulator(new RR, 1),
Simulator(new FCFS, 4),
Simulator(new SJF, 4),
Simulator(new SRTF, 4),
Simulator(new MLFQ, 4),
Simulator(new PSRR, 4),
};
for (auto& sim : sims) {
sim.AssignData(blueprints);
}
sf::RenderWindow window;
Renderer renderer(&window);
window.create(sf::VideoMode({1600, 1000}), "My Window", sf::Style::Titlebar|sf::Style::Close);
window.clear(sf::Color(70,70,70));
ImGui::SFML::Init(window);
std::cout << "Fereastra a fost creată\n";
window.setVerticalSyncEnabled(true);
sf::Clock deltaClock;
while(window.isOpen()) {
bool shouldExit = false;
sf::Event event;
while(window.pollEvent(event)) {
ImGui::SFML::ProcessEvent(event);
if (event.type==sf::Event::Closed) {
window.close();
} else if (event.type==sf::Event::Resized) {
std::cout << "New width: " << window.getSize().x << '\n'
<< "New height: " << window.getSize().y << '\n';
}
}
ImGui::SFML::Update(window, deltaClock.restart());
ImGui::Begin("Global statistics");
ImGui::SliderInt("Number of tests", &numberOfTests, 0, 100, "%d00");
ImGui::SliderInt("Number of processes", &numberOfProcesses, 1, 100);
ImGui::SliderInt("Max arriving time", &TestData::maxArrivalTime, 0, 1000);
ImGui::SliderInt("Max burst time", &TestData::maxBurstTime, 0, 1000);
if(ImGui::Button("Run All Tests")) {
globalTestsResults = TestData::RunAll(sims, numberOfTests * 100, numberOfProcesses);
}
if (ImGui::BeginTable("StatsTable", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg)) {
ImGui::TableSetupColumn("Algorithm");
ImGui::TableSetupColumn("Avg Waiting");
ImGui::TableSetupColumn("Avg Turnaround");
ImGui::TableHeadersRow();
for(int i = 0; i < globalTestsResults.size(); i++) {
auto res = globalTestsResults[i];
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::Text("%s", algorithmNames[i].c_str());
ImGui::TableSetColumnIndex(1);
ImGui::Text("%.2f", res.avgWaitingTime);
ImGui::TableSetColumnIndex(2);
ImGui::Text("%.2f", res.avgTurnAroundTime);
}
ImGui::EndTable();
}
ImGui::End();
ImGui::Begin("Control Panel");
ImGui::SliderInt("Number of processes", &numberOfProcesses, 1, 100);
ImGui::SliderInt("Max arriving time", &TestData::maxArrivalTime, 0, 1000);
ImGui::SliderInt("Max burst time", &TestData::maxBurstTime, 0, 1000);
ImGui::Separator();
ImGui::Text("Test types");
if(ImGui::Button("Run Random Test")) {
auto test = TestData::GenerateRandomTest(numberOfProcesses);
for(auto& sim : sims) sim.AssignData(test);
}
if(ImGui::Button("Run Convoy Test")) {
auto test = TestData::GenerateConvoyTest(numberOfProcesses);
for(auto& sim : sims) sim.AssignData(test);
}
if(ImGui::Button("Run Burst Test")) {
auto test = TestData::GenerateBurstTest(numberOfProcesses);
for(auto& sim : sims) sim.AssignData(test);
}
if(ImGui::Button("Run Starvation Test")) {
auto test = TestData::GenerateStarvationTest(numberOfProcesses);
for(auto& sim : sims) sim.AssignData(test);
}
ImGui::End();
window.clear();
for (int i = 0; i < 7; i++) {
std::unique_ptr<sf::RenderTexture> rt=Renderer::renderResults(sims[i].GetResults());
sf::Text text;
text.setFont(font);
text.setCharacterSize(20);
text.setPosition({100,i*130.0f});
text.setFillColor(sf::Color::White);
text.setString(algorithmNames[i]);
window.draw(text);
sf::Transform transform;
transform.translate({100,30+i*130.0f});
transform.scale({0.8,0.1});
sf::Sprite sprite(rt->getTexture());
window.draw(sprite,transform);
}
ImGui::SFML::Render(window); // render ImGui peste tot
window.display();
}
ImGui::SFML::Shutdown();
return 0;
}