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

📄 main.cpp

📁 clustering for ns-2 simulation
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include <iostream>#include <fstream>#include <stdlib.h>#include <sys/types.h>#include <sys/stat.h>#include <libgen.h>#include "gzstream.h"#include "graph.h"#include "shortest_path.h"#include "utility.h"#include "analyzer_strongness.h"#include "analyzer_sp.h"#include "analyzer_bytes.h"#include "analyzer_clusters.h"#include "analyzer_degree.h"#include "analyzer_backbone_property.h"#include "Measure.h"using namespace std;/** * This flag is true if result file is zipped. */bool use_zipped;/** * This method insure that a directory exists. */void prepareDirectory(const char * directory){	mkdir(directory, S_IRWXU | S_IRWXG | S_IRWXG);}/** * Output a dump result to a file. */void output(string fileName, int nodes, double value){	ofstream out(fileName.c_str(), ios::app);	out << nodes << " " << value << endl;	out.close();}/** * Output percent dump of a file and its normal distribution. * File has suffix "Percent". */void outputPercent(string outputFile, string propertyName, int nodes, double value, double total, int topologies) {	output(outputFile + "/" + propertyName + ".dat", nodes, value / (double)topologies);	output(outputFile + "/" + propertyName + "Percent.dat", nodes, value / total * 100);}/** * Create (if don't exists) a directory: * otuput/datas/layer/ */void prepareDestination(string & outputDirectory, string & layer){	prepareDirectory(outputDirectory.c_str());	prepareDirectory((outputDirectory + string("analysis")).c_str());	prepareDirectory((outputDirectory + string("analysis/") + layer).c_str());}/** * Usage */void usage(){	cout << "usage: analyzer -a analyzer [analyzer's options] [common-options]" << endl;	cout << endl;	cout << "Common options are:" << endl;	cout << "-r result_file				Dump File for a simulation" << endl;	cout << "-d topology_directory		Directory of Topology" << endl;	cout << "-o Output Directory		Output Directory" << endl;	cout << "-z							Dump File is zipped" << endl;	cout << endl;	cout << "Available Analyzers:" << endl;	cout << "> shortest-path" << endl;	cout << "> strongness" << endl;	cout << "> bytes" << endl;	cout << "> clusters" << endl;	cout << endl;	cout << "[\"shortest-path\"]" << endl;	cout << "* Calculate shortest path for a selected layer." << endl;	cout << "Options:" << endl;	cout << "-l layer		Layer Number" << endl;	cout << "-x				Exclude Calculation of Shortest Path on graph" << endl;	cout << endl;	cout << "[\"strongness\"]" << endl;	cout << "* Retrive strongness for a selected layer" << endl;	cout << "-l layer		Layer Number" << endl;	cout << "-t trial		Repetition in strongness calculation" << endl;	cout << endl;	cout << "[\"bytes\"]" << endl;	cout << "* Retrive bytes/msg transmitted in physic layer." << endl;	cout << "Options:" << endl;	cout << "-n Number Nodes			Number of nodes in simulations" << endl;	cout << endl;	cout << "[\"clusters\"]" << endl;	cout << "* Retrive gateway, clusterhead and common nodes of each layer" << endl;	cout << "Options:" << endl;	cout << "None" << endl;	cout << "[\"dca-degree\"]" << endl;	cout << "* Retrive gateway, clusterhead and common nodes of each layer" << endl;	cout << "Options:" << endl;	cout << "-n Nodes" << endl;	cout << "None" << endl;	cout << "[\"degree\"]" << endl;	cout << "* Retrive average degree of backbone of each layer" << endl;	cout << "Options:" << endl;	cout << "-l layer		Layer Number" << endl;	cout << "None" << endl;}int parseFlags(int argc, char * argv[]) {	bool result = true;	string algorithm, resultFile, topologyDirectory, outputDirectory;	int layer, trial, numNodes;		layer = trial = numNodes = -1;	bool exclude = false;	use_zipped = false;		while (result) {				int c = getopt(argc, argv, "a:r:d:o:l:t:n:xz");		if (c == EOF)			break;		switch (c) {						case 'x' :				exclude = true;				break;								// Algorithm.			case 'a' :				algorithm = string(optarg);				break;								// Common Options.			case 'r' :				resultFile = string(optarg);				break;			case 'd' :				topologyDirectory = string(optarg);				break;			case 'o' :				outputDirectory = string(optarg);				break;								// Trial			case 't' :				trial = atoi(optarg);				break;								// Layer			case 'l' :				layer = atoi(optarg);				break;							case 'n' :				numNodes = atoi(optarg);				break;							case 'z' :				use_zipped = true;				break;							default :				cout << "Option not recognized: " << ((char)optopt) << endl;				result = false;				break;		}	}		if (!result)		return 0;		if (algorithm == "shortest-path") {		if (layer < 0) {			cout << "Error Layer must be >= 0" << endl;			return 0;		}				// Calculate Shortest path.		Measure a;		Measure b;		Measure c;				string layer_name;		int nodes_in_dump;		analyze_sp(topologyDirectory,				   resultFile,				   layer - 1,				   a,				   b,				   c,				   layer_name,				   nodes_in_dump,				   exclude);		if (!exclude)			cout << "Avg Shortest Path Graph: " << a.getAverage() << endl;		cout << "Avg Shortest Path Backbone: " << b.getAverage() << endl;		cout << "Avg Shortest Path Inducted: " << c.getAverage() << endl;				// Save Results.		string destination = outputDirectory + "/analysis/" + layer_name + "/";				prepareDestination(outputDirectory, layer_name);				ofstream outShortestPathGraph((outputDirectory + "/analysis/ShortestPathGraph.dat").c_str(), ios::app);		ofstream outShortestPathBackbone((outputDirectory + "/analysis/" + layer_name + "/ShortestPathBackbone.dat").c_str(), ios::app);		ofstream outShortestPathInducted((outputDirectory + "/analysis/" + layer_name + "/ShortestPathInducted.dat").c_str(), ios::app);				if (!exclude)			outShortestPathGraph << nodes_in_dump << " " << a.getAverage() << endl;				outShortestPathBackbone << nodes_in_dump << " " << b.getAverage() << endl;		outShortestPathInducted << nodes_in_dump << " " << c.getAverage() << endl;				outShortestPathGraph.close();		outShortestPathBackbone.close();		outShortestPathInducted.close();				return 1;	}	else if (algorithm == "degree") {		if (layer < 0) {			cout << "Error Layer must be >= 0" << endl;			return 0;		}						// Calculate Shortest path.		Measure degree;		int count = 0;		string layer_name;				analyze_backbone_property(topologyDirectory,				   resultFile,				   layer - 1,				   degree,				   layer_name);

⌨️ 快捷键说明

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