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

📄 main.cpp

📁 clustering for ns-2 simulation
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		cout << endl;		cout << "Total Nodes: " << degree.getCount() << endl;				// cout << "Avg Degree On Backbone: " << (dd / (double)count) << endl;		cout << "Avg Degree On Backbone: " << degree.getAverage() << endl;		return 1;	}	else if (algorithm == "strongness") {				cout << "Ciao mamma" << endl;				if (layer < 0) {			cout << "Error Layer must be >= 0" << endl;			return 0;		}		if (trial < 1) {			cout << "Error Trial must be >= 1" << endl;			return 0;		}				// Calculate strongness.		double all, backbone;				string layer_name;		int nodes_in_dump;				analyze_strongness(topologyDirectory,						   resultFile,						   layer - 1,						   trial,						   &backbone,						   &all,						   layer_name,						   nodes_in_dump);				cout << "Strongness Graph: " << all << endl;		cout << "Strongness Backbone: " << backbone << endl;				// Save Results.		string destination = outputDirectory + "/analysis/" + layer_name + "/";		prepareDestination(outputDirectory, layer_name);				ofstream outStrongness1((outputDirectory + "/analysis/" + layer_name + "/StrongnessGraph.dat").c_str(), ios::app);		outStrongness1 << nodes_in_dump << " " << all << endl;		outStrongness1.close();				ofstream outStrongness2((outputDirectory + "/analysis/" + layer_name + "/StrongnessBackbone.dat").c_str(), ios::app);		outStrongness2 << nodes_in_dump << " " << backbone << endl;		outStrongness2.close();				return 1;	}	else if (algorithm == "bytes") {		if (numNodes == -1) {			cout << "Error Number of Nodes must be >= 0" << endl;			return 0;		}				cout << "Analyze BYTES: (" << basename((char*)resultFile.c_str()) << ")" << endl;				// Calculate bytes.		ResultLayers results;		map<int, int> totalNodes, activeNodes;		map<int, int> CH;		int topologies;				ofstream * out;				analyze_bytes(resultFile, results, totalNodes, activeNodes, CH, topologies);				for (unsigned int i = 0; i < results.size(); i++) {						string layerName = results[i].first;						prepareDestination(outputDirectory, layerName);						string destination = outputDirectory + "/analysis/";						// cout << layerName << ":\t (";			for (int n = 0; n < 12; n++) {				string fileName;				switch (n) {					case TX_BYTE_UNICAST :		fileName += "TxByUn"; break;					case TX_MSG_UNICAST :		fileName += "TxMsUn"; break;					case TX_BYTE_BROADCAST :	fileName += "TxByBr"; break;					case TX_MSG_BROADCAST :		fileName += "TxMsBr"; break;					case RX_BYTE_UNICAST :		fileName += "RxByUn"; break;					case RX_MSG_UNICAST :		fileName += "RxMsUn"; break;					case RX_BYTE_BROADCAST :	fileName += "RxByBr"; break;					case RX_MSG_BROADCAST :		fileName += "RxMsBr"; break;					case TIME :					fileName += "Time"; break;					case ENERGY :				fileName += "Energy"; break;					case MSG_PHYSIC :			fileName += "MsgPhysic"; break;					case BYTES_PHYSIC :			fileName += "BytesPhysic"; break;				}								// Il risultato totale e'pari alla somma di tutti i livelli				// precedenti.				double tmp_total = 0.0;								for (unsigned int kk = 0; kk <= i; kk++)					tmp_total += ( results[kk].second[n] / totalNodes[kk] );								out = new ofstream((outputDirectory + "/analysis/" + layerName + "/" + fileName + "Total.dat").c_str(), ios::app);				*out << numNodes << " " << tmp_total << endl;				out->close();				delete(out);								out = new ofstream((outputDirectory + "/analysis/" + layerName + "/" + fileName + "Active.dat").c_str(), ios::app);				*out << numNodes << " " << ( results[i].second[n] / activeNodes[i] ) << endl;				out->close();				delete(out);			}						if (results[i].second[ROUNDS_RAJA] > 0) {				out = new ofstream((outputDirectory + "/analysis/" + layerName + "/" + "RajaramanRounds.dat").c_str(), ios::app);				*out << numNodes << " " << ( results[i].second[ROUNDS_RAJA] / totalNodes[i] ) << endl;				out->close();				delete(out);			}						if (results[i].second[CONNECTED_CH] > 0) {				out = new ofstream((outputDirectory + "/analysis/" + layerName + "/" + "ConnectedCH.dat").c_str(), ios::app);				*out << numNodes << " " << ( results[i].second[CONNECTED_CH] / CH[i] ) << endl;				out->close();				delete(out);			}						// Average on Virtual Arcs.			double sum;						sum = results[i].second[VIRTUAL_LEN_0] + results[i].second[VIRTUAL_LEN_1] + results[i].second[VIRTUAL_LEN_2];						if (sum > 0) {				outputPercent(outputDirectory + "/analysis/" + layerName, string("VirtualArcs0"), numNodes, (double)results[i].second[VIRTUAL_LEN_0], sum, topologies);				outputPercent(outputDirectory + "/analysis/" + layerName, string("VirtualArcs1"), numNodes, (double)results[i].second[VIRTUAL_LEN_1], sum, topologies);				outputPercent(outputDirectory + "/analysis/" + layerName, string("VirtualArcs2"), numNodes, (double)results[i].second[VIRTUAL_LEN_2], sum, topologies);								outputPercent(outputDirectory + "/analysis/" + layerName, string("VirtualArcsToErase0"), numNodes, (double)results[i].second[TO_ERASE_VIRTUAL_LEN_0], (double)results[i].second[VIRTUAL_LEN_0], topologies);				outputPercent(outputDirectory + "/analysis/" + layerName, string("VirtualArcsToErase1"), numNodes, (double)results[i].second[TO_ERASE_VIRTUAL_LEN_1], (double)results[i].second[VIRTUAL_LEN_1], topologies);				outputPercent(outputDirectory + "/analysis/" + layerName, string("VirtualArcsToErase2"), numNodes, (double)results[i].second[TO_ERASE_VIRTUAL_LEN_2], (double)results[i].second[VIRTUAL_LEN_2], topologies);								outputPercent(outputDirectory + "/analysis/" + layerName, string("VirtualArcsErased0"), numNodes, (double)results[i].second[ERASED_VIRTUAL_LEN_0], results[i].second[TO_ERASE_VIRTUAL_LEN_0], topologies);				outputPercent(outputDirectory + "/analysis/" + layerName, string("VirtualArcsErased1"), numNodes, (double)results[i].second[ERASED_VIRTUAL_LEN_1], results[i].second[TO_ERASE_VIRTUAL_LEN_1], topologies);				outputPercent(outputDirectory + "/analysis/" + layerName, string("VirtualArcsErased2-2"), numNodes, (double)results[i].second[ERASED_VIRTUAL_LEN_2_2], results[i].second[TO_ERASE_VIRTUAL_LEN_2], topologies);				outputPercent(outputDirectory + "/analysis/" + layerName, string("VirtualArcsErased2-1"), numNodes, (double)results[i].second[ERASED_VIRTUAL_LEN_2_1], results[i].second[TO_ERASE_VIRTUAL_LEN_2], topologies);			}						// cout << "Nodi Attivi Layer " << i << ": " << activeNodes[i] << " / " << totalNodes[i] << ")" << endl;			out = new ofstream((outputDirectory + "/analysis/" + layerName + "/ActiveNodes.dat").c_str(), ios::app);			*out << numNodes << " " << ((double)activeNodes[i] / (double)topologies) << endl;			out->close();			delete(out);		}				return 1;	}	else if (algorithm == "clusters") {				cout << "Analyze CLUSTERS:" << endl;				// Calculate Clusters.		colorsLayer results;		map<string, int> nodes;				analyze_clusters(resultFile, results, nodes);				// La mappa dei colori è la seguente:		// black: clusterHead.		// gray: gateway.		// white: normal.		for (colorsLayer::iterator l = results.begin(); l != results.end(); l++) {			for (Colors::iterator c = (l->second).begin(); c != (l->second).end(); c++) {				string fileName;				if (c->first == "black") {					fileName = "ClusterHeads";				}				else if (c->first == "gray") {					fileName = "Gateways";				}				else if (c->first == "white") {					fileName = "NormalNodes";				}								string layerName = l->first;								prepareDestination(outputDirectory, layerName);				ofstream out((outputDirectory + "/analysis/" + l->first + "/" + fileName + ".dat").c_str(), ios::app);				out << nodes[l->first] << " " << c->second << endl;								out.close();			}		}		return 1;	}	else if (algorithm == "dca-degree") {				cout << "Analyze DEGREE:" << endl;				map<int, int> degree_id;		map<int, int> degree_degree;		map<int, int> degree_altro;				analyze_degree(topologyDirectory, numNodes, degree_id, degree_degree, degree_altro);		cout << "Degree Difference Distribution for Degree - ID (" << numNodes << " nodi):" << endl;		long total = 0;		for (map<int, int>::iterator i = degree_altro.begin(); i != degree_altro.end(); i++)			total += i->second;		for (map<int, int>::iterator i = degree_altro.begin(); i != degree_altro.end(); i++)			cout << i->first << "\t" << ((float)i->second / (float)total * 100) << endl;				cout << "----------------------------------------------------------------" << endl;				cout << "Degree Distribution for ID (" << numNodes << " nodi):" << endl;		total = 0;		for (map<int, int>::iterator i = degree_id.begin(); i != degree_id.end(); i++)			total += i->second;		for (map<int, int>::iterator i = degree_id.begin(); i != degree_id.end(); i++)			cout << i->first << "\t" << ((float)i->second / (float)total * 100) << endl;				cout << "----------------------------------------------------------------" << endl;				cout << "Degree Distribution for Degree (" << numNodes << " nodi):" << endl;		total = 0;		for (map<int, int>::iterator i = degree_degree.begin(); i != degree_degree.end(); i++)			total += i->second;		for (map<int, int>::iterator i = degree_degree.begin(); i != degree_degree.end(); i++)			cout << i->first << "\t" << ((float)i->second / (float)total * 100) << endl;				return 1;	}		return 0;}int main(int argc, char * argv[]){	use_zipped = false;		if (parseFlags(argc, argv) == 0)		usage();}

⌨️ 快捷键说明

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