⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 analyzer_bytes.cpp

📁 clustering for ns-2 simulation
💻 CPP
字号:
#include "analyzer_bytes.h"/*** Questo metodo serve per calcolare la strongness su differenti * backbone di differenti layer. * Il metodo scandisce un file di dump registrando le medie dei  * valori dei differenti layer in maniera additiva: se i layer sono  * tre registra la media delle trasmissioni del primo layer, del primo e * del secondo e di tutti e tre. * Si assume che tutte le simulazioni contenute nel file di dump * siano legate alla stessa associazione di layers. */void analyze_bytes(string resultFile, 				   ResultLayers & results, 				   map<int, int> & totalNodes, 				   map<int, int> & activeNodes, 				   map<int, int> & CH,				   int & topologies){	// Legge simulazione per simulazione.	// Ad ogni simulazione legge i dati di un layer restituendo	// la somma dei 10 valori di dump e la conta dei nodi che hanno	// un tempo di esecuzione diverso da 0.	// Infine vengono registrati i valori totali di bytes e messaggi	// trasmessi.		results.clear();	topologies = 0;		double bytes_row;		string topology, stack, line, currentLayer;	vector<string> layers;	int n, k, tmp, nodes;	unsigned int l;		activeNodes.clear();	totalNodes.clear();		map<int, vector<double> > tot_bytes;		// Apre il file di dump in lettura.	istream * inFile;		if (use_zipped)		inFile = new igzstream((resultFile + ".gz").c_str());	else		inFile = new ifstream((resultFile).c_str());		set<int> initiated;		while (*inFile >> topology >> stack) {		cout << ".";		cout.flush();				extractLayers(stack, layers);				for (l = 0; l < layers.size(); l++) {						if (initiated.find(l) == initiated.end()) {				tot_bytes[l].resize(24);				for (int i = 0; i < 24; i++)					tot_bytes[l][i] = 0;								CH[l] = 0;				activeNodes[l] = 0;				totalNodes[l] = 0;								initiated.insert(l);			}						*inFile >> currentLayer >> nodes;						totalNodes[l] += nodes;						for (n = 0; n < nodes; n++) {								*inFile >> tmp;								// Memorizza i dati nel giusto layer.				for (k = 0; k < 10; k++) {					*inFile >> bytes_row;					tot_bytes[l][k] += bytes_row;					// Se il nodo ha un tempo diverso da 0					// incrementa il contatore.										if ((k == 8) && (bytes_row > 0))						activeNodes[l]++;				}			}						// Da memorizzare			*inFile >> bytes_row;			tot_bytes[l][10] += bytes_row;						// cout << "Pkt = " << bytes_row << endl;						*inFile >> bytes_row;			tot_bytes[l][11] += bytes_row;						// cout << "Bytes = " << bytes_row << endl;						//			// Skip rest of layer.			//			if ((currentLayer == "CLUSTERING") ||				(currentLayer == "RAJARAMAN")) {				// Skip colors.				*inFile >> tmp;				for (int t = 0; t < (tmp + 1); t++)					getline(*inFile, line, '\n');			}			if (currentLayer == "RAJARAMAN") {				getline(*inFile, line, '\n');								istringstream inRow(line);				long rounds, tot, count;				tot = count = 0 ;				while (inRow >> rounds) {					tot += rounds;					count++;				}								tot_bytes[l][ROUNDS_RAJA] += tot;			}			if ((currentLayer == "BACKBONE") ||				(currentLayer == "SHIVA") ||				(currentLayer == "CONNECTOR")) {				// Skip colors.				*inFile >> tmp;				for (int t = 0; t < (tmp + 1); t++)					getline(*inFile, line, '\n');				// Skip backbone.				*inFile >> tmp;				for (int t = 0; t < (tmp + 1); t++)					getline(*inFile, line, '\n');			}			if (currentLayer == "SHIVA") {				getline(*inFile, line, '\n');								istringstream inRow(line);				long arcs[10];								for (int i_ = 0; i_ < 10; i_++) 					inRow >> arcs[i_];								tot_bytes[l][VIRTUAL_LEN_0] += arcs[VIRTUAL_LEN_0 - VIRTUAL_LEN_0];				tot_bytes[l][VIRTUAL_LEN_1] += arcs[VIRTUAL_LEN_1 - VIRTUAL_LEN_0];				tot_bytes[l][VIRTUAL_LEN_2] += arcs[VIRTUAL_LEN_2 - VIRTUAL_LEN_0];								tot_bytes[l][TO_ERASE_VIRTUAL_LEN_0] += arcs[TO_ERASE_VIRTUAL_LEN_0 - VIRTUAL_LEN_0];				tot_bytes[l][TO_ERASE_VIRTUAL_LEN_1] += arcs[TO_ERASE_VIRTUAL_LEN_1 - VIRTUAL_LEN_0];				tot_bytes[l][TO_ERASE_VIRTUAL_LEN_2] += arcs[TO_ERASE_VIRTUAL_LEN_2 - VIRTUAL_LEN_0];								tot_bytes[l][ERASED_VIRTUAL_LEN_0] += arcs[ERASED_VIRTUAL_LEN_0 - VIRTUAL_LEN_0];				tot_bytes[l][ERASED_VIRTUAL_LEN_1] += arcs[ERASED_VIRTUAL_LEN_1 - VIRTUAL_LEN_0];				tot_bytes[l][ERASED_VIRTUAL_LEN_2_2] += arcs[ERASED_VIRTUAL_LEN_2_2 - VIRTUAL_LEN_0];							tot_bytes[l][ERASED_VIRTUAL_LEN_2_1] += arcs[ERASED_VIRTUAL_LEN_2_1 - VIRTUAL_LEN_0];			}			if (currentLayer == "CONNECTOR") {				getline(*inFile, line, '\n');								istringstream inRow(line);				long connected_ch, count;				inRow >> count;				inRow >> connected_ch; 				tot_bytes[l][CONNECTED_CH] += connected_ch;				CH[l] += count;			}			if (currentLayer == "LEADER") {				getline(*inFile, line, '\n');				getline(*inFile, line, '\n');				getline(*inFile, line, '\n');			}			// ...					}				topologies++;	}		// La media finale dei valori si ottiene per layer dividendo	// la somma dei valori per lo stesso layer per il conteggio dei	// nodi che hanno fatto qualcosa in quel layer.	cout << endl << endl;		for (unsigned int l = 0; l < layers.size(); l++) {		ResultLayer result;		for (unsigned int k = 0; k <= l; k++) {			result.first += layers[k];			if (k != l)				result.first += "-";		}		result.second.resize(24);		for (int n = 0; n < 24; n++)			(result.second)[n] = tot_bytes[l][n];		results[l] = result;	}		/*	 for (int l = 1; l < layers.size(); l++)	 for (int n = 0; n < 12; n++)	 results[l].second[n] += results[l - 1].second[n];	 */		delete(inFile);	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -