📄 statistics.cc
字号:
// -*- C++ -*-
// Copyright (C) 2003 Leherstuh f黵 Betrieb System/ Verteilte System,
// Universitaet Dortmund
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// Author: Muddassar Farooq
// Informatik III, Universitaet Dortmund
// Germany
//-------------------------------------------------------------
// file: statisitics.h -- A Singleton Class for Global Statisitics
// (part of AntNet Routing Simulation)
//-------------------------------------------------------------
#include "statistics.h"
Define_Module( statistics );
statistics::statistics(const char *name, cModule *parentmodule, unsigned stacksize)
:cSimpleModule(name, parentmodule, stacksize)
{
totalBitsGenerated = 0;
totalBitsDelivered = 0;
totalBitsLost = 0;
totalAntsGenerated = 0;
totalAntsDelivered = 0;
totalAntsDeleted = 0;
queueDelay = 0;
qEntries = 0;
packetDelay = 0;
pEntries = 0;
i = 0;
packetsInQueue = 0;
hops = 0;
hEntries = 0;
antHops = 0;
aEntries = 0;
totalBitsUnDelivered = 0;
bitsGenerated = 0;
bitsDelivered = 0;
}
statistics::~statistics()
{
}
void statistics::initialize()
{
strcpy(sFileName,par("statFile"));
numStations = par("numStations");
}
void statistics::incrNumHops(int nHops)
{
hops += nHops;
hEntries++;
}
void statistics::incrBitsGenerated(double bits)
{
bitsGenerated += bits;
}
void statistics::incrBitsDelivered(double bits)
{
bitsDelivered += bits;
}
void statistics::incrAntHops(int aHops)
{
antHops += aHops;
aEntries++;
}
void statistics::incrTotalBitsGenerated()
{
totalBitsGenerated++;
}
void statistics::incrTotalBitsDelivered()
{
totalBitsDelivered++;
}
void statistics:: incrTotalBitsLost()
{
totalBitsLost++;
}
void statistics::incrTotalBitsUndeliverable()
{
totalBitsUnDelivered++;
}
void statistics:: incrTotalAntsGenerated()
{
totalAntsGenerated++;
}
void statistics:: incrTotalAntsReceived()
{
totalAntsDelivered++;
}
void statistics:: incrTotalAntsDeleted()
{
totalAntsDeleted++;
}
void statistics:: insertQueueDelay(double qDelay)
{
queueDelay+= qDelay,
qEntries++;
}
void statistics::insertPacketDelay(double delay)
{
pDelay.collect(delay);
packetDelay += delay;
pEntries++;
}
void statistics::insertAntLife(double lValue)
{
antLife.collect(lValue);
}
void statistics::incrPacketInQueue(double lPacket)
{
packetsInQueue += lPacket;
}
void statistics::insertThroughPutPacketDelay(double tPut, double tDelay, int time)
{
throughputTimePair *temp = new throughputTimePair;
temp->tPut = tPut;
temp->pDelay = tDelay;
temp->i = time;
simTime = time;
tPutVector.push_back( temp ) ;
}
void statistics::calculateThroughPutPacketDelay(int time)
{
vector<throughputTimePair*>::iterator iter;
double totalThroughPut = 0.0;
int i = 0;
tEntry = new double[time];
pEntry = new double[time];
for(i = 0; i < time; i++)
{
tEntry[i] = 0.0;
pEntry[i] = 0.0;
}
for(iter = tPutVector.begin(); iter != tPutVector.end(); ++iter)
{
throughputTimePair *temp = *iter;
tEntry[temp->i] += temp->tPut;
pEntry[temp->i] += temp->pDelay;
delete temp;
}
}
double statistics::ninteythPercentile(cStdDev tVal)
{
double mean = tVal.mean();
double stdDev = tVal.stddev();
double z = 1.29;
double value = mean + z * stdDev;
return value;
}
void statistics::showStatistics()
{
sFile = fopen(sFileName,"w+");
fprintf(sFile, "SimTime: %d\n", simTime);
fprintf(sFile, "PGenerated:: %f\n", totalBitsGenerated);
fprintf(sFile, "PDelivered: %f\n",totalBitsDelivered);
fprintf(sFile, "PDropped: %f\n",totalBitsLost);
fprintf(sFile, "PUndeliverable: %f\n",totalBitsUnDelivered);
fprintf(sFile, "PQueue: %f\n",packetsInQueue);
fprintf(sFile, "PercentDelivered: %f\n",(totalBitsDelivered/(totalBitsGenerated-totalBitsUnDelivered)*100.0));
fprintf(sFile, "AGenerated: %f\n", totalAntsGenerated);
fprintf(sFile, "AReceived: %f\n",totalAntsDelivered);
fprintf(sFile, "ADropped: %f\n",totalAntsDeleted);
fprintf(sFile, "AHop: %f\n", (float) antHops/aEntries);
fprintf(sFile, "ALife: %f\n", (float) antLife.mean());
double aLife = ninteythPercentile(antLife);
fprintf(sFile, "A90Life: %f\n", aLife);
fprintf(sFile, "PQueueDelay: %f\n",queueDelay/qEntries);
fprintf(sFile, "PacketDelay: %f\n",packetDelay/pEntries);
double ninteyDelay = ninteythPercentile(pDelay);
fprintf(sFile, "90PacketDelay: %f\n",ninteyDelay);
fprintf(sFile, "ThroughPut: %f\n", bitsDelivered/simTime);
float fHops = (float) hops /hEntries;
fprintf(sFile, "PHops: %f\n", fHops);
calculateThroughPutPacketDelay(simTime);
for(int k = 0; k < simTime; k++)
{
fprintf(sFile,"%d %f\n",k,tEntry[k]);
}
for(int l = 0; l < simTime; l++)
{
fprintf(sFile,"%d %f\n",l,pEntry[l]/numStations);
}
delete[] tEntry;
delete[] pEntry;
fclose(sFile);
}
void statistics::finish()
{
ev<<"Module" << fullPath() << endl;
showStatistics();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -