-
Notifications
You must be signed in to change notification settings - Fork 0
/
MLTD2020.cs
366 lines (317 loc) · 14.9 KB
/
MLTD2020.cs
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace Failure_prevention
{
class Program
{
\\delays are set
public static double FDelay = 1.4;
public static double CDelay = 2.6;
static void Main(string[] args)
{
string[] Save1 = new string[210];
\\TSWC is set
for (int kk = 1; kk < 11; kk++)
{
\\the definitions of functions
string[] F1_30size = new string[200];
string[] F1_30time = new string[200];
string[] F1_50size = new string[200];
string[] F1_50time = new string[200];
string[] F1_70size = new string[200];
string[] F1_70time = new string[200];
string[] F2_30size = new string[200];
string[] F2_30time = new string[200];
string[] F2_50size = new string[200];
string[] F2_50time = new string[200];
string[] F2_70size = new string[200];
string[] F2_70time = new string[200];
string[] C1_30size = new string[200];
string[] C1_30time = new string[200];
string[] C1_50size = new string[200];
string[] C1_50time = new string[200];
string[] C1_70size = new string[200];
string[] C1_70time = new string[200];
string[] F1_30sizeR = new string[200];
string[] F1_30timeR = new string[200];
string[] F1_50sizeR = new string[200];
string[] F1_50timeR = new string[200];
string[] F1_70sizeR = new string[200];
string[] F1_70timeR = new string[200];
string[] F2_30sizeR = new string[200];
string[] F2_30timeR = new string[200];
string[] F2_50sizeR = new string[200];
string[] F2_50timeR = new string[200];
string[] F2_70sizeR = new string[200];
string[] F2_70timeR = new string[200];
string[] C1_30sizeR = new string[200];
string[] C1_30timeR = new string[200];
string[] C1_50sizeR = new string[200];
string[] C1_50timeR = new string[200];
string[] C1_70sizeR = new string[200];
string[] C1_70timeR = new string[200];
\\real and estimated size and response times are loaded
Read_DATA_All(Application.StartupPath + "\\In\\F1\\30.txt", F1_30sizeR, F1_30timeR, F1_30size, F1_30time, 1, 1);
Read_DATA_All(Application.StartupPath + "\\In\\F1\\30.txt", F1_50sizeR, F1_50timeR, F1_50size, F1_50time, 1, 1);
Read_DATA_All(Application.StartupPath + "\\In\\F1\\30.txt", F1_70sizeR, F1_70timeR, F1_70size, F1_70time, 1, 1);
Read_DATA_All(Application.StartupPath + "\\In\\F2\\30.txt", F2_30sizeR, F2_30timeR, F2_30size, F2_30time, 1, 1);
Read_DATA_All(Application.StartupPath + "\\In\\F2\\30.txt", F2_50sizeR, F2_50timeR, F2_50size, F2_50time, 1, 1);
Read_DATA_All(Application.StartupPath + "\\In\\F2\\30.txt", F2_70sizeR, F2_70timeR, F2_70size, F2_70time, 1, 1);
Read_DATA_All(Application.StartupPath + "\\In\\C\\30.txt", C1_30sizeR, C1_30timeR, C1_30size, C1_30time, 1, 1);
Read_DATA_All(Application.StartupPath + "\\In\\C\\50.txt", C1_50sizeR, C1_50timeR, C1_50size, C1_50time, 1, 1);
Read_DATA_All(Application.StartupPath + "\\In\\C\\70.txt", C1_70sizeR, C1_70timeR, C1_70size, C1_70time, 1, 1);
//The workloads are randomly set
string[] randNumberF1 = new string[200];
string[] randNumberF2 = new string[200];
string[] randNumberC1 = new string[200];
//definitions of variables that will be used later
string[] AllC1 = new string[200];
double SumC1 = 0;
string[] RandomF1F2 = new string[200];
Random RandVal = new Random();
string[] RandomF1F2C1 = new string[200];
double SumC1_In_F1F2C1 = 0;
//the workloads are loaded
Read_DATA_All(Application.StartupPath + "\\RandomUseCPU_F1N" + kk.ToString() + ".txt", randNumberF1, null, null, null, 2, 1);
Read_DATA_All(Application.StartupPath + "\\RandomUseCPU_F2N" + kk.ToString() + ".txt", randNumberF2, null, null, null, 2, 1);
Read_DATA_All(Application.StartupPath + "\\RandomUseCPU_C1N" + kk.ToString() + ".txt", randNumberC1, null, null, null, 2, 1);
\\the processing times are set with regard to the workloads of servers
double F1 = 0, F2 = 0, C1 = 0, FR1 = 0, FR2 = 0, CR1 = 0;
int F1Count = 0, F2Count = 0, C1Count = 0;
double SizeC = 0;
double[] timeRun = new double[200];
for (int i = 0; i < randNumberF1.LongLength; i++)
{
switch (randNumberF1[i])
{
case "1":
FR1 = Convert.ToDouble(F1_30timeR[i]);
F1 = Convert.ToDouble(F1_30time[i]);
break;
case "2":
FR1 = Convert.ToDouble(F1_50timeR[i]);
F1 = Convert.ToDouble(F1_50time[i]);
break;
case "3":
FR1 = Convert.ToDouble(F1_70timeR[i]);
F1 = Convert.ToDouble(F1_70time[i]);
break;
}
switch (randNumberF2[i])
{
case "1":
FR2 = Convert.ToDouble(F2_30timeR[i]);
F2 = Convert.ToDouble(F2_30time[i]);
break;
case "2":
FR2 = Convert.ToDouble(F2_50timeR[i]);
F2 = Convert.ToDouble(F2_50time[i]);
break;
case "3":
FR2 = Convert.ToDouble(F2_70timeR[i]);
F2 = Convert.ToDouble(F2_70time[i]);
break;
}
switch (randNumberC1[i])
{
case "1":
CR1 = Convert.ToDouble(C1_30timeR[i]);
C1 = Convert.ToDouble(C1_30time[i]);
break;
case "2":
CR1 = Convert.ToDouble(C1_50timeR[i]);
C1 = Convert.ToDouble(C1_50time[i]);
break;
case "3":
CR1 = Convert.ToDouble(C1_70timeR[i]);
C1 = Convert.ToDouble(C1_70time[i]);
break;
}
F1 += FDelay;
F2 += FDelay;
C1 += CDelay;
FR1 += FDelay;
FR2 += FDelay;
CR1 += CDelay;
//////////////////////////////////////////////////////////////////
AllC1[i] = CR1.ToString();
SumC1 += Convert.ToDouble(C1_30size[i]);
/////////////////////////////////////////////////////////////////
{
int valRand = RandVal.Next(1, 3);
if (valRand == 1)
RandomF1F2[i] = F1.ToString();
else
RandomF1F2[i] = F2.ToString();
}
/////////////////////////////////////////////////////////////////
{
int valRand = RandVal.Next(1, 4);
switch (valRand)
{
case 1:
RandomF1F2C1[i] = F1.ToString();
break;
case 2:
RandomF1F2C1[i] = F2.ToString();
break;
case 3:
RandomF1F2C1[i] = C1.ToString();
SumC1_In_F1F2C1 += Convert.ToDouble(F1_30size[i]);
break;
}
}
/////////////////////////////////////////////////////////////////
\\ Task distribution with regard to predicted response times
if (F1 <= F2 && F1 <= C1)
{
timeRun[i] = FR1;
F1Count++;
}
else
if (F2 <= F1 && F2 <= C1)
{
timeRun[i] = FR2;
F2Count++;
}
else
{
timeRun[i] = CR1;
C1Count++;
SizeC += Convert.ToDouble(C1_30sizeR[i]);
}
}
int ll = 0;
Save1[ll++] += kk.ToString() + " " + " " + " " + " " + " ";
Save1[ll++] += "SizeC" + " " + SizeC.ToString() + " " + "SumC1_In_F1F2C1 " + SumC1_In_F1F2C1.ToString() + " ";
Save1[ll++] += "F1Count " + F1Count.ToString() + " " + " " + " " + " ";
Save1[ll++] += "F2Count " + F2Count.ToString() + " " + " " + " " + " ";
Save1[ll++] += "C1Count " + C1Count.ToString() + " " + " " + " " + " ";
Save1[ll++] += " " + " " + "AllC1" + " " + "RandomF1F2" + " " + "RandomF1F2C1" + " ";
for (int i = 0; i < randNumberC1.Length; i++)
Save1[ll++] += " " + timeRun[i] + " " + AllC1[i] + " " + RandomF1F2[i] + " " + RandomF1F2C1[i] + " ";
}
for (int i = 0; i <= 205; i++)
Save(Save1[i], "\\out\\All.txt", 1);
}
public static void Read_DATA_All(String PathF, string[] Par1, string[] Par2, string[] Par3, string[] Par4, int mode, int indexFile)
{
string path = PathF;
if (!File.Exists(path))
{
using (FileStream fs = File.Create(path))
{
Byte[] info =
new UTF8Encoding(true).GetBytes("error in Write/Read NO:531");
fs.Write(info, 0, info.Length);
}
}
int index = 0, indexLine = 0;
string _temp = "";
using (StreamReader sr = File.OpenText(path))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
if (mode == 2)
{
Par1[index++] = s.ToString();
continue;
}
for (int k = 0; k < s.Length; k++)
if (s[k] != '\t')
_temp += s[k];
else
{
switch (indexLine)
{
case 0:
Par1[index] = _temp;
break;
case 1:
Par2[index] = _temp;
break;
case 2:
Par3[index] = _temp;
break;
}
_temp = "";
indexLine++;
}
Par4[index] = _temp;
_temp = "";
index++;
indexLine = 0;
}
}
}
public static void Save(string Data, string Path, int mood)
{
string path = Application.StartupPath + Path;
/* if (mood == 5)
{
path = Application.StartupPath + "\\Temp"+Convert.ToString(n)+".bat";
// File.Delete(path);
// File.Create(path);
// return;
}*/
/*if (mood == 6)
{
path = Application.StartupPath + "\\Temp" + Convert.ToString(n) + ".bat";
mood = 1;
}*/
// sialog1.ShowDialog();
// string path = sialog1.FileName;
// This text is added only once to the file.
/* if (!File.Exists(path))
{
// Create a file to write to.
string[] createText = { "" };
File.WriteAllLines(path, createText);
}*/
// This text is always added, making the file longer over time
// if it is not deleted.
// string appendText = textBox1.Text + Environment.NewLine;
// if (mood == 0||mood==2)
// File.AppendAllText(path, Data);
if (mood == 2)
{
File.Delete(path);
// File.Create(path);
return;
}
if (1 == mood)
Data += Environment.NewLine;
File.AppendAllText(path, Data);
string[] readText = File.ReadAllLines(path);
foreach (string s in readText)
{
Console.WriteLine(s);
}
// Refresh();
// Open the file to read from.
/* string[] readText = File.ReadAllLines(path);
foreach (string s in readText)
{
Console.WriteLine(s);
}*/
// MessageBox.Show("Chenging Password.", "Admin", MessageBoxButtons.OK);
}
public static Random RandNo = new Random();
public static int RandomGen(int N1, int N2, int N3)
{
int N = RandNo.Next(1, 12);
if (N < N1)
return 1;
else
if (N < N2)
return 2;
else
return 3;
}
}
}