-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenerateMatrices.java
139 lines (118 loc) · 5.66 KB
/
GenerateMatrices.java
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
package utils;
import java.io.*;
import java.util.Random;
public class GenerateMatrices {
private static double[][] commMatrix, execMatrix;
private static double[] deadlineMatrix;
private static int[] VMMipsList;
private File commFile = new File("CommunicationTimeMatrix.txt");
private File execFile = new File("ExecutionTimeMatrix.txt");
private File deadlineFile;
private File VMMipsFile;
public GenerateMatrices(String inputDir) {
commMatrix = new double[Constants.NO_OF_TASKS][Constants.NO_OF_DATA_CENTERS];
execMatrix = new double[Constants.NO_OF_TASKS][Constants.NO_OF_DATA_CENTERS];
deadlineMatrix = new double[Constants.NO_OF_TASKS];
VMMipsList = new int[Constants.NO_OF_DATA_CENTERS];
// commFile = new File(Constants.baseDir + "/" + Constants.matrixDir + "/CommunicationTimeMatrix-task" + Constants.NO_OF_TASKS + "vm" + Constants.NO_OF_DATA_CENTERS + ".txt");
// execFile = new File(Constants.baseDir + "/" + Constants.matrixDir + "/ExecutionTimeMatrix-task" + Constants.NO_OF_TASKS + "vm" + Constants.NO_OF_DATA_CENTERS + ".txt");
commFile = new File(Constants.baseDir + "/" + inputDir + "/" + Constants.matrixDir + "/CommunicationTimeMatrix-task" + Constants.NO_OF_TASKS + "vm" + Constants.NO_OF_DATA_CENTERS + ".txt");
execFile = new File(Constants.baseDir + "/" + inputDir + "/" + Constants.matrixDir + "/ExecutionTimeMatrix-task" + Constants.NO_OF_TASKS + "vm" + Constants.NO_OF_DATA_CENTERS + ".txt");
deadlineFile = new File(Constants.baseDir + "/" + inputDir + "/" + Constants.matrixDir + "/DeadlineMatrix-task" + Constants.NO_OF_TASKS + "vm" + Constants.NO_OF_DATA_CENTERS + ".txt");
VMMipsFile = new File(Constants.baseDir + "/" + inputDir + "/" + "VMMips" + ".txt");
try {
initDirectories(inputDir);
initCostMatrix();
initVMMips();
} catch (IOException e) {
e.printStackTrace();
}
}
private void initDirectories(String inputDir){
String input = Constants.baseDir + "/" + inputDir;
String inputMatrices = input + "/" + Constants.matrixDir;
java.io.File directoryInput = new java.io.File(input);
java.io.File directoryInputMatrices = new java.io.File(inputMatrices);
if (!directoryInput.exists()) {
directoryInput.mkdir();
}
if (!directoryInputMatrices.exists()) {
directoryInputMatrices.mkdir();
}
}
private void initVMMips() throws IOException {
System.out.println("Initializing VM Mips...");
BufferedWriter VMBufferedWriter = new BufferedWriter(new FileWriter(VMMipsFile));
Random random = new Random();
for (int i = 0; i < Constants.NO_OF_DATA_CENTERS; i++) {
int mips = random.nextInt(1001) + 1000;
VMMipsList[i] = mips;
VMBufferedWriter.write(String.valueOf(mips));
VMBufferedWriter.write('\n');
}
VMBufferedWriter.close();
}
private void initCostMatrix() throws IOException {
System.out.println("Initializing new Matrices...");
BufferedWriter commBufferedWriter = new BufferedWriter(new FileWriter(commFile));
BufferedWriter execBufferedWriter = new BufferedWriter(new FileWriter(execFile));
BufferedWriter deadlineBufferedWriter = new BufferedWriter(new FileWriter(deadlineFile));
Random random = new Random();
for (int i = 0; i < Constants.NO_OF_TASKS; i++) {
double avgExecTime = 0;
for (int j = 0; j < Constants.NO_OF_DATA_CENTERS; j++) {
double commTime = Math.random() * 600 + 20;
double execTime = Math.random() * 500 + 10;
commMatrix[i][j] = commTime;
execMatrix[i][j] = execTime;
avgExecTime += commTime + execTime;
commBufferedWriter.write(String.valueOf(commTime) + ' ');
execBufferedWriter.write(String.valueOf(execTime) + ' ');
// deadlineBufferedWriter.write(String.valueOf(deadlineTime) + ' ');
}
double deadlineTime = (avgExecTime/Constants.NO_OF_DATA_CENTERS) * (random.nextInt(1, 4) + Math.random());
deadlineMatrix[i] = deadlineTime;
commBufferedWriter.write('\n');
execBufferedWriter.write('\n');
deadlineBufferedWriter.write('\n');
}
commBufferedWriter.close();
execBufferedWriter.close();
deadlineBufferedWriter.close();
}
private void readCostMatrix() throws IOException {
System.out.println("Reading the Matrices...");
BufferedReader commBufferedReader = new BufferedReader(new FileReader(commFile));
int i = 0, j = 0;
do {
String line = commBufferedReader.readLine();
for (String num : line.split(" ")) {
commMatrix[i][j++] = new Double(num);
}
++i;
j = 0;
} while (commBufferedReader.ready());
BufferedReader execBufferedReader = new BufferedReader(new FileReader(execFile));
i = j = 0;
do {
String line = execBufferedReader.readLine();
for (String num : line.split(" ")) {
execMatrix[i][j++] = new Double(num);
}
++i;
j = 0;
} while (execBufferedReader.ready());
}
public static double[][] getCommMatrix() {
return commMatrix;
}
public static double[][] getExecMatrix() {
return execMatrix;
}
public static double[] getDeadlineMatrix() {
return deadlineMatrix;
}
public static int[] getVMMipsList() {
return VMMipsList;
}
}