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
|
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
int main()
{
ofstream fout("TPDR[3-4-30].tr");
ifstream fin("TTEST.tr");// if u use this as ur input file u will always get ur num as 6 because the range stops at 50 therefore u will get the throughputs calculated as 0z
ofstream fOut("TPDR30(3-4).tr");
ofstream MYFILE("TPDR(3-4).tr");
if (!fin)
{
cout << "input file not open" << endl;
return 1;
}
fout << fixed << setprecision(9);
fOut << fixed << setprecision(9);
cout << fixed << setprecision(9);
MYFILE << fixed << setprecision(9);
double timelimit = 0.0; // ending time of first block of data
double timeincr = 10.0; // duration of each block of data
string s1, s2, s3, sequenceno1,sequenceno2, s4, s5; // dummy variables to hold unwanted data
string line,oldline;
char type;
double time;
int bytes;
int num = 0;
istringstream ss;
double received[21] = {0.0};
double send[21] = {0.0};
int drop[21] = {0};
double Re[21]= {0.0};
double Se[21] = {0.0};
double De[21] = {0.0};
int R = 0;
int S = 0;
double PDR =0.0;
double PDRR[21] = {0.0};
int Range;
//------- Priming read. Get first line.
getline(fin, line);
ss.str(line);
ss >> type >> time;
while (fin)
{
while (ss && time <= timelimit)
{
//------------- process the line here ------------------
// ss >> s1 >> s2 >> s3 >> s4 >> s5 ;
if (type == 's') {
ss >> s1 >> s2 >> s3 >> sequenceno1 >> s4 >> s5;
oldline = line;
send[num]++;
S = send[num];
Se[num] = S;
}
if (type =='r') {
ss >> s1 >> s2 >> s3 >> sequenceno2 >> s4 >> s5;
if ((time < timelimit)&&(sequenceno1 == sequenceno2)) {
cout << sequenceno1 << " " << sequenceno2 << " " << time << " " << timelimit << ".\n";
received[num]++;
R = received[num];
Re[num] = R;
PDR = Re[num]/ Se[num];
PDRR[num] = PDR*100;
fout << "Received = " << Re[num] <<" " << time <<" " << "Send= " << Se[num] << " " << "Packet Delivery Ratio" << PDRR[num] << " "<< "sequenceno1 =" << sequenceno1 << " "<< "sequenceno2 =" << sequenceno2 << ".\n";
}
}
//------------- end of process, now read the next line -----
if (getline(fin, line))
{
ss.clear(); // clear all flags
ss.str(line);
ss >> type >> time;
}
else
{
ss.clear(ios::failbit); // set the fail flag
}
}
timelimit += timeincr; // increment limit to next value
cout << timelimit << ".\n\n";
num++;
fout << "\n------------------\n";
fout << "time limit: " << timelimit << endl;
cout << "num = " << num << ".\n";
}
// ..... Writting the Range and PDR within each Range in a separate File .....
for (Range = 10,num =1; Range <= 200, num <=20; Range+=10, num++) {
fOut << Range << " " << PDRR[num] << ".\n";
}
double average = 0.0;
double TPDR = 0.0;
for (num = 1; num <=20 ; num++) { // For loop to compute the Total PDR within each Range
TPDR += PDRR[num];
// cout << "TPDR" << TPDR << "%" << ".\n";
}
average = TPDR /(num-1);
cout << "average = " << average << "%" << ".\n";// Compute Average PDR
cout << "Done" << endl;
return 0;
}
|