forked from SWE501-Spring2017-Bogazici/FinalProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDES.cpp
More file actions
91 lines (65 loc) · 2.34 KB
/
DES.cpp
File metadata and controls
91 lines (65 loc) · 2.34 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
//============================================================================
// Name : DES.cpp
// Author : Can Candan
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <fstream>
#include "Cpu.h"
#include "Event.h"
#include "easylogging++.h"
INITIALIZE_EASYLOGGINGPP
using namespace std;
int main(int argc, char *argv[]) {
// Setup logging
el::Configurations defaultConf;
defaultConf.setToDefault();
// make this true to enable logging
defaultConf.set(el::Level::Global, el::ConfigurationType::Enabled, "false");
el::Loggers::reconfigureLogger("default", defaultConf);
// load inputFile, initialize Simulation object, run the simulation, write the results to outputFile
if ( argc != 3 ) {
cout << "usage: " << argv[0] << " inputFile outputFile\n";
} else {
Simulation *sim = new Simulation();
ifstream inputFile(argv[1]);
int numCpus;
inputFile >> numCpus;
for (int i = 0; i < numCpus; i++) {
int freq;
inputFile >> freq;
Cpu *cpu = new Cpu(i + 1, freq);
sim->addCpu(cpu);
}
int numOuts;
inputFile >> numOuts;
for (int i = 0; i < numOuts; i++) {
int quantum;
inputFile >> quantum;
OutputDevice *out = new OutputDevice(i + 1, quantum);
sim->addOutputDevice(out);
}
int numTasks;
inputFile >> numTasks;
for (int i = 0; i < numTasks; i++) {
double arrTime, cpuWork, outWork;
inputFile >> arrTime >> cpuWork >> outWork;
Task *t = new Task(arrTime, cpuWork, outWork);
sim->addTask(t);
}
sim->run();
ofstream outputFile;
outputFile.open(argv[2]);
outputFile << sim->sjf_queue_max_size << endl;
outputFile << sim->rr_queue_max_size << endl;
outputFile << sim->max_active_cpu_id << endl;
outputFile << sim->max_active_out_id << endl;
outputFile << sim->average_wait_time << endl;
outputFile << sim->longest_wait_time << endl;
outputFile << sim->average_time_spent << endl;
outputFile.close();
}
return 0;
}