added more code
This commit is contained in:
43
CPE348/HW4/HW4.code-workspace
Normal file
43
CPE348/HW4/HW4.code-workspace
Normal file
@ -0,0 +1,43 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": ".."
|
||||
}
|
||||
],
|
||||
"settings": {
|
||||
"files.associations": {
|
||||
"fstream": "cpp",
|
||||
"cmath": "cpp",
|
||||
"array": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"cctype": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"functional": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"new": "cpp",
|
||||
"ostream": "cpp",
|
||||
"numeric": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"utility": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"iomanip": "cpp"
|
||||
}
|
||||
}
|
||||
}
|
21
CPE348/HW4/P3A.txt
Normal file
21
CPE348/HW4/P3A.txt
Normal file
@ -0,0 +1,21 @@
|
||||
Iteration # SampleRTT EstimatedRTT Deviation Difference Timeout
|
||||
0 - 4.0000 0.5000 - -
|
||||
1 1.0000 3.6250 0.8125 -3.0000 6.8750
|
||||
2 1.0000 3.2969 1.0391 -2.6250 7.4531
|
||||
3 1.0000 3.0098 1.1963 -2.2969 7.7949
|
||||
4 1.0000 2.7585 1.2980 -2.0098 7.9504
|
||||
5 1.0000 2.5387 1.3555 -1.7585 7.9609
|
||||
6 1.0000 2.3464 1.3784 -1.5387 7.8602
|
||||
7 1.0000 2.1781 1.3744 -1.3464 7.6758
|
||||
8 1.0000 2.0308 1.3499 -1.1781 7.4304
|
||||
9 1.0000 1.9020 1.3100 -1.0308 7.1420
|
||||
10 1.0000 1.7892 1.2590 -0.9020 6.8252
|
||||
11 1.0000 1.6906 1.2003 -0.7892 6.4917
|
||||
12 1.0000 1.6043 1.1366 -0.6906 6.1505
|
||||
13 1.0000 1.5287 1.0700 -0.6043 5.8088
|
||||
14 1.0000 1.4626 1.0024 -0.5287 5.4721
|
||||
15 1.0000 1.4048 0.9349 -0.4626 5.1444
|
||||
16 1.0000 1.3542 0.8686 -0.4048 4.8287
|
||||
17 1.0000 1.3099 0.8043 -0.3542 4.5273
|
||||
18 1.0000 1.2712 0.7425 -0.3099 4.2413
|
||||
19 1.0000 1.2373 0.6836 -0.2712 3.9717
|
22
CPE348/HW4/P3B.txt
Normal file
22
CPE348/HW4/P3B.txt
Normal file
@ -0,0 +1,22 @@
|
||||
Iteration # SampleRTT EstimatedRTT Deviation Difference Timeout
|
||||
0 - 4.0000 1.5000 - -
|
||||
1 1.0000 3.6250 1.6875 -3.0000 10.3750
|
||||
2 1.0000 3.2969 1.8047 -2.6250 10.5156
|
||||
3 1.0000 3.0098 1.8662 -2.2969 10.4746
|
||||
4 1.0000 2.7585 1.8842 -2.0098 10.2952
|
||||
5 1.0000 2.5387 1.8685 -1.7585 10.0125
|
||||
6 1.0000 2.3464 1.8272 -1.5387 9.6553
|
||||
7 1.0000 2.1781 1.7671 -1.3464 9.2466
|
||||
8 1.0000 2.0308 1.6935 -1.1781 8.8048
|
||||
9 1.0000 1.9020 1.6107 -1.0308 8.3446
|
||||
10 1.0000 1.7892 1.5221 -0.9020 7.8775
|
||||
11 1.0000 1.6906 1.4305 -0.7892 7.4125
|
||||
12 1.0000 1.6043 1.3380 -0.6906 6.9562
|
||||
13 1.0000 1.5287 1.2463 -0.6043 6.5138
|
||||
14 1.0000 1.4626 1.1566 -0.5287 6.0889
|
||||
15 1.0000 1.4048 1.0698 -0.4626 5.6841
|
||||
16 1.0000 1.3542 0.9867 -0.4048 5.3010
|
||||
17 1.0000 1.3099 0.9076 -0.3542 4.9405
|
||||
18 1.0000 1.2712 0.8329 -0.3099 4.6029
|
||||
19 1.0000 1.2373 0.7627 -0.2712 4.2881
|
||||
20 1.0000 1.2076 0.6970 -0.2373 3.9958
|
12
CPE348/HW4/P3C.txt
Normal file
12
CPE348/HW4/P3C.txt
Normal file
@ -0,0 +1,12 @@
|
||||
Iteration # SampleRTT EstimatedRTT Deviation Difference Timeout
|
||||
0 - 4.0000 0.5000 - -
|
||||
1 1.0000 3.2500 1.1250 -3.0000 7.7500
|
||||
2 1.0000 2.6875 1.4062 -2.2500 8.3125
|
||||
3 1.0000 2.2656 1.4766 -1.6875 8.1719
|
||||
4 1.0000 1.9492 1.4238 -1.2656 7.6445
|
||||
5 1.0000 1.7119 1.3052 -0.9492 6.9326
|
||||
6 1.0000 1.5339 1.1569 -0.7119 6.1614
|
||||
7 1.0000 1.4005 1.0011 -0.5339 5.4050
|
||||
8 1.0000 1.3003 0.8510 -0.4005 4.7042
|
||||
9 1.0000 1.2253 0.7133 -0.3003 4.0785
|
||||
10 1.0000 1.1689 0.5913 -0.2253 3.5341
|
31
CPE348/HW4/P4A.txt
Normal file
31
CPE348/HW4/P4A.txt
Normal file
@ -0,0 +1,31 @@
|
||||
Iteration # SampleRTT EstimatedRTT TimeOut
|
||||
1 1.0000 1.2500 2.5000
|
||||
2 1.0000 1.1250 2.2500
|
||||
3 1.0000 1.0625 2.1250
|
||||
4 1.0000 1.0312 2.0625
|
||||
5 1.0000 1.0156 2.0312
|
||||
6 5.0000 3.0078 6.0156
|
||||
7 1.0000 2.0039 4.0078
|
||||
8 1.0000 1.5020 3.0039
|
||||
9 1.0000 1.2510 2.5020
|
||||
10 1.0000 1.1255 2.2510
|
||||
11 1.0000 1.0627 2.1255
|
||||
12 5.0000 3.0314 6.0627
|
||||
13 1.0000 2.0157 4.0314
|
||||
14 1.0000 1.5078 3.0157
|
||||
15 1.0000 1.2539 2.5078
|
||||
16 1.0000 1.1270 2.2539
|
||||
17 1.0000 1.0635 2.1270
|
||||
18 5.0000 3.0317 6.0635
|
||||
19 1.0000 2.0159 4.0317
|
||||
20 1.0000 1.5079 3.0159
|
||||
21 1.0000 1.2540 2.5079
|
||||
22 1.0000 1.1270 2.2540
|
||||
23 1.0000 1.0635 2.1270
|
||||
24 5.0000 3.0317 6.0635
|
||||
25 1.0000 2.0159 4.0317
|
||||
26 1.0000 1.5079 3.0159
|
||||
27 1.0000 1.2540 2.5079
|
||||
28 1.0000 1.1270 2.2540
|
||||
29 1.0000 1.0635 2.1270
|
||||
30 5.0000 3.0317 6.0635
|
31
CPE348/HW4/P4B.txt
Normal file
31
CPE348/HW4/P4B.txt
Normal file
@ -0,0 +1,31 @@
|
||||
Iteration # SampleRTT EstimatedRTT TimeOut
|
||||
1 1.0000 1.4000 2.8000
|
||||
2 1.0000 1.3200 2.6400
|
||||
3 1.0000 1.2560 2.5120
|
||||
4 1.0000 1.2048 2.4096
|
||||
5 1.0000 1.1638 2.3277
|
||||
6 5.0000 1.9311 3.8621
|
||||
7 1.0000 1.7449 3.4897
|
||||
8 1.0000 1.5959 3.1918
|
||||
9 1.0000 1.4767 2.9534
|
||||
10 1.0000 1.3814 2.7627
|
||||
11 1.0000 1.3051 2.6102
|
||||
12 5.0000 2.0441 4.0882
|
||||
13 1.0000 1.8353 3.6705
|
||||
14 1.0000 1.6682 3.3364
|
||||
15 1.0000 1.5346 3.0691
|
||||
16 1.0000 1.4277 2.8553
|
||||
17 1.0000 1.3421 2.6842
|
||||
18 5.0000 2.0737 4.1474
|
||||
19 1.0000 1.8590 3.7179
|
||||
20 1.0000 1.6872 3.3743
|
||||
21 1.0000 1.5497 3.0995
|
||||
22 1.0000 1.4398 2.8796
|
||||
23 1.0000 1.3518 2.7037
|
||||
24 5.0000 2.0815 4.1629
|
||||
25 1.0000 1.8652 3.7303
|
||||
26 1.0000 1.6921 3.3843
|
||||
27 1.0000 1.5537 3.1074
|
||||
28 1.0000 1.4430 2.8859
|
||||
29 1.0000 1.3544 2.7087
|
||||
30 5.0000 2.0835 4.1670
|
31
CPE348/HW4/P4C.txt
Normal file
31
CPE348/HW4/P4C.txt
Normal file
@ -0,0 +1,31 @@
|
||||
Iteration # SampleRTT EstimatedRTT TimeOut
|
||||
1 1.0000 1.4500 2.9000
|
||||
2 1.0000 1.4050 2.8100
|
||||
3 1.0000 1.3645 2.7290
|
||||
4 1.0000 1.3280 2.6561
|
||||
5 1.0000 1.2952 2.5905
|
||||
6 5.0000 1.6657 3.3314
|
||||
7 1.0000 1.5991 3.1983
|
||||
8 1.0000 1.5392 3.0785
|
||||
9 1.0000 1.4853 2.9706
|
||||
10 1.0000 1.4368 2.8736
|
||||
11 1.0000 1.3931 2.7862
|
||||
12 5.0000 1.7538 3.5076
|
||||
13 1.0000 1.6784 3.3568
|
||||
14 1.0000 1.6106 3.2211
|
||||
15 1.0000 1.5495 3.0990
|
||||
16 1.0000 1.4946 2.9891
|
||||
17 1.0000 1.4451 2.8902
|
||||
18 5.0000 1.8006 3.6012
|
||||
19 1.0000 1.7205 3.4411
|
||||
20 1.0000 1.6485 3.2970
|
||||
21 1.0000 1.5836 3.1673
|
||||
22 1.0000 1.5253 3.0505
|
||||
23 1.0000 1.4727 2.9455
|
||||
24 5.0000 1.8255 3.6509
|
||||
25 1.0000 1.7429 3.4858
|
||||
26 1.0000 1.6686 3.3373
|
||||
27 1.0000 1.6018 3.2035
|
||||
28 1.0000 1.5416 3.0832
|
||||
29 1.0000 1.4874 2.9749
|
||||
30 5.0000 1.8387 3.6774
|
BIN
CPE348/HW4/p3
Executable file
BIN
CPE348/HW4/p3
Executable file
Binary file not shown.
BIN
CPE348/HW4/p3-back
Executable file
BIN
CPE348/HW4/p3-back
Executable file
Binary file not shown.
64
CPE348/HW4/p3-back.cpp
Normal file
64
CPE348/HW4/p3-back.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <fstream>
|
||||
#include <math.h>
|
||||
|
||||
#define MAX_ARRAY_SIZE 1000
|
||||
|
||||
using namespace std;
|
||||
|
||||
void calculations(float deltaVal, float deviationVal, string outputFileName);
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
// calculate part a
|
||||
calculations(0.125, 0.500, "P3A.txt");
|
||||
calculations(0.125, 1.500, "P3B.txt");
|
||||
calculations(0.25, 0.500, "P3C.txt");
|
||||
|
||||
}
|
||||
|
||||
void calculations(float deltaVal, float deviationVal, string outputFileName)
|
||||
{
|
||||
ofstream outputFile;
|
||||
outputFile.open(outputFileName.c_str());
|
||||
// difference = sampleRTT - estimatedRTT
|
||||
// estimatedRTT = estimatedRTT + (delta * difference)
|
||||
// deviation = deviation + delta(|difference| - deviation)
|
||||
// timeOut = mu * estimatedRTT + (phi * deviation)
|
||||
|
||||
float delta = 0.0, mu = 0.0, phi = 0.0; //
|
||||
float difference[MAX_ARRAY_SIZE], estimatedRTT[MAX_ARRAY_SIZE], sampleRTT;
|
||||
float deviation[MAX_ARRAY_SIZE], timeOut = 0.0, tmpDeviation = 0.0, tmpestimateRTT = 0.0;
|
||||
// Values for Jacobson/Karels Algorithim
|
||||
delta = deltaVal;
|
||||
mu = 1.0;
|
||||
phi = 4.0;
|
||||
|
||||
// do-while loop
|
||||
int i = 0;
|
||||
outputFile << "Iteration #\t\tSampleRTT\t\tEstimatedRTT\t\t Deviation\t\tDifference\t\tTimeout\n";
|
||||
do
|
||||
{
|
||||
// initial values
|
||||
if (i == 0)
|
||||
{
|
||||
outputFile << fixed << setprecision(4);
|
||||
estimatedRTT[0] = 4.000;
|
||||
deviation[0] = deviationVal;
|
||||
outputFile << i << "\t\t\t\t - \t\t\t\t\t" << estimatedRTT[0] << "\t\t\t\t" << deviation[0] << "\t\t\t - \t\t\t - \n";
|
||||
i++;
|
||||
}
|
||||
sampleRTT = 1.0000;
|
||||
difference[i] = sampleRTT - estimatedRTT[i-1];
|
||||
// calculate estimatedRTT again
|
||||
estimatedRTT[i] = estimatedRTT[i-1] + (delta * difference[i]);
|
||||
deviation[i] = deviation[i-1] + delta*(fabs(difference[i]) - deviation[i-1]);
|
||||
timeOut = mu * estimatedRTT[i] + (phi * deviation[i]);
|
||||
// "Iteration #\t\tSampleRTT\t\tEstimatedRTT\t\tDeviation\t\tTimeout\n"
|
||||
outputFile << i << "\t\t\t\t" << setw(5) << setfill(' ') << sampleRTT << setw(10) << setfill(' ') << "\t\t" << estimatedRTT[i] << setw(8) << setfill(' ') <<
|
||||
"\t\t" << deviation[i] << setw(3) << setfill(' ') << "\t\t" << difference[i] << setw(8) << setfill(' ') << "\t" << timeOut << endl;
|
||||
i++;
|
||||
} while (timeOut > 4.0);
|
||||
outputFile.close();
|
||||
}
|
63
CPE348/HW4/p3.cpp
Normal file
63
CPE348/HW4/p3.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <fstream>
|
||||
#include <math.h>
|
||||
|
||||
#define MAX_ARRAY_SIZE 1000
|
||||
|
||||
using namespace std;
|
||||
|
||||
void calculations(float deltaVal, float deviationVal, string outputFileName);
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
// calculate part a
|
||||
calculations(0.125, 0.500, "P3A.txt");
|
||||
calculations(0.125, 1.500, "P3B.txt");
|
||||
calculations(0.25, 0.500, "P3C.txt");
|
||||
|
||||
}
|
||||
|
||||
void calculations(float deltaVal, float deviationVal, string outputFileName)
|
||||
{
|
||||
ofstream outputFile;
|
||||
outputFile.open(outputFileName.c_str());
|
||||
// difference = sampleRTT - estimatedRTT
|
||||
// estimatedRTT = estimatedRTT + (delta * difference)
|
||||
// deviation = deviation + delta(|difference| - deviation)
|
||||
// timeOut = mu * estimatedRTT + (phi * deviation)
|
||||
|
||||
float delta = 0.0, mu = 0.0, phi = 0.0; //
|
||||
float difference = 0.0, estimatedRTT = 0.0, sampleRTT = 0.0;
|
||||
float deviation = 0.0, timeOut = 0.0, tmpDeviation = 0.0, tmpestimateRTT = 0.0;
|
||||
// Values for Jacobson/Karels Algorithim
|
||||
delta = deltaVal;
|
||||
mu = 1.0;
|
||||
phi = 4.0;
|
||||
|
||||
// do-while loop
|
||||
int i = 0;
|
||||
outputFile << "Iteration #\t\tSampleRTT\t\tEstimatedRTT\t\t Deviation\t\tDifference\t\tTimeout\n";
|
||||
do
|
||||
{
|
||||
// initial values
|
||||
if (i == 0)
|
||||
{
|
||||
outputFile << fixed << setprecision(4);
|
||||
estimatedRTT = 4.000;
|
||||
deviation = deviationVal;
|
||||
outputFile << i << "\t\t\t\t - \t\t\t\t\t" << estimatedRTT << "\t\t\t\t" << deviation << "\t\t\t - \t\t\t - \n";
|
||||
i++;
|
||||
}
|
||||
sampleRTT = 1.0000;
|
||||
difference = sampleRTT - estimatedRTT;
|
||||
// calculate estimatedRTT again
|
||||
estimatedRTT = estimatedRTT + (delta * difference);
|
||||
deviation = deviation + delta*(fabs(difference) - deviation);
|
||||
timeOut = mu * estimatedRTT + (phi * deviation);
|
||||
outputFile << i << "\t\t\t\t" << setw(5) << setfill(' ') << sampleRTT << setw(10) << setfill(' ') << "\t\t" << estimatedRTT << setw(8) << setfill(' ') <<
|
||||
"\t\t" << deviation << setw(3) << setfill(' ') << "\t\t" << difference << setw(8) << setfill(' ') << "\t" << timeOut << endl;
|
||||
i++;
|
||||
} while (timeOut > 4.0);
|
||||
outputFile.close();
|
||||
}
|
BIN
CPE348/HW4/p4
Executable file
BIN
CPE348/HW4/p4
Executable file
Binary file not shown.
42
CPE348/HW4/p4.cpp
Normal file
42
CPE348/HW4/p4.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <fstream>
|
||||
#include <math.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void calculations(float alphaVal, string outputFileName);
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
// calculate part a
|
||||
calculations(0.5, "P4A.txt");
|
||||
calculations(0.8, "P4B.txt");
|
||||
calculations(0.9, "P4C.txt");
|
||||
|
||||
}
|
||||
|
||||
void calculations(float alphaVal, string outputFileName)
|
||||
{
|
||||
ofstream outputFile;
|
||||
outputFile.open(outputFileName.c_str());
|
||||
float alpha = alphaVal;
|
||||
outputFile << fixed << setprecision(4);
|
||||
float estimatedRTT = 1.50, sampleRTT = 0.0;
|
||||
float timeOut = 0.0;
|
||||
outputFile << "Iteration #\t\tSampleRTT\t\tEstimatedRTT\t\tTimeOut\n";
|
||||
for (int i = 1; i < 31; i++)
|
||||
{
|
||||
if((i % 6)==0)
|
||||
{
|
||||
sampleRTT = 5.0;
|
||||
}
|
||||
else sampleRTT = 1.0;
|
||||
estimatedRTT = alpha * estimatedRTT + (1 - alpha) * sampleRTT;
|
||||
timeOut = 2 * estimatedRTT;
|
||||
outputFile << i << "\t\t\t\t" << setw(5) << setfill(' ') << sampleRTT << setw(10) << setfill(' ')
|
||||
<< "\t\t" << estimatedRTT << setw(16) << setfill(' ') << timeOut << endl;
|
||||
}
|
||||
|
||||
outputFile.close();
|
||||
}
|
8
CPE348/HW4/test.cpp
Normal file
8
CPE348/HW4/test.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
const char* byteToBitString (value) {
|
||||
char output[9];
|
||||
output[8] = 0;
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
output[7 - i] = (value & (1 << i)) ? '1' : '0';
|
||||
}
|
||||
return output;
|
||||
}
|
Reference in New Issue
Block a user