-
Notifications
You must be signed in to change notification settings - Fork 6
/
FileGeneration.cpp
127 lines (97 loc) · 3.81 KB
/
FileGeneration.cpp
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
#include "FileGeneration.h"
#include <sys/stat.h>
#include <unistd.h>
#include <iostream>
#include <random>
using namespace std;
FileGeneration::FileGeneration(){
}
FileGeneration::~FileGeneration(){
}
void FileGeneration::generateInputFile(string fileName, bool isDistributed){
srand(time(NULL));
totalProc = rand() % (MAX_PROCESSES - 6)+ 5; //rand() % ( high - low + 1 ) + low
setFileName(fileName);
setTotalProc(totalProc);
if(fileExists(this->fileName)){
cout << endl << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl
<< "!! That File Name Is Taken !!" << endl
<< "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl << endl;
}
else{
cout << endl << "================================" << endl
<< "== FILE GENERATION ==" << endl
<< "================================" << endl << endl;
generateFile(isDistributed);
cout << endl << "================================" << endl
<< "== FINISH FILE GENERATION ==" << endl
<< "================================" << endl << endl;
}
}
void FileGeneration::generateInputFile(string fileName, int totalProc, bool isDistributed){
setFileName(fileName);
setTotalProc(totalProc);
if(totalProc >= 5){
if(fileExists(this->fileName)){
cout << endl << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl
<< "!! That File Name Is Taken !!" << endl
<< "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl << endl;
}
else{
cout << endl << "================================" << endl
<< "== FILE GENERATION ==" << endl
<< "================================" << endl << endl;
generateFile(isDistributed);
cout << endl << "================================" << endl
<< "== FINISH FILE GENERATION ==" << endl
<< "================================" << endl << endl;
}
}
}
void FileGeneration::generateFile(bool isDistributed){
outputFile.open(fileName);
if(isDistributed){
procSwitch = 5;
}
else{
procSwitch = 0;
}
outputFile << totalProc << " " << procSwitch << endl;
cout << totalProc << " " << procSwitch << endl;
for(procNum; procNum <= totalProc; procNum++){
(isDistributed) ? randomizeDist():randomizeNotDist();
outputFile << procNum << " " << arrivalTime << " " << burstTime << " " << relativeDealine << " " << period << endl;
cout << procNum << " " << arrivalTime << " " << burstTime << " " << relativeDealine << " " << period << endl;
}
outputFile.close();
}
void FileGeneration::setFileName(string fileName){
this->fileName = "./Process_Files/" + fileName;
}
void FileGeneration::setTotalProc(int totalProc){
this->totalProc = totalProc;
}
bool FileGeneration::fileExists(const string& fileName){
struct stat buffer;
return (stat (fileName.c_str(), &buffer) == 0);
}
void FileGeneration::randomizeDist(){
// @mt19937 - produces high quality unsigned integer random numbers
random_device rd;
mt19937 gen(rd());
exponential_distribution<double> exp_dist(1);
arrivalTime = exp_dist(gen) * 20;
randomizeNotDist();
}
void FileGeneration::randomizeNotDist(){
random_device rd;
mt19937 gen(rd());
uniform_int_distribution<int> uni_dist_burstTime(30,100);
uniform_int_distribution<int> uni_dist_x(1,500);
uniform_int_distribution<int> uni_dist_y(1,1000);
burstTime = uni_dist_burstTime(gen);
int x = uni_dist_x(gen);
relativeDealine = burstTime + x;
int y = uni_dist_y(gen);
period = relativeDealine + y;
}