📄 analyzer_sp.cpp
字号:
#include "analyzer_sp.h"/** * Questo file analizza gli shortest path e crea i file a partire dalla * cartella di destinazione passata come parametro. * E'possibile analizzare gli shortest path dei vari livelli dello stack * di simulazione. Le cartelle vengono create in base alla stringa che * descrive lo stack. */void analyze_sp(string topologyDirectory, string resultFile, int selectedLayer, Measure & sp_graph, Measure & sp_backbone, Measure & sp_inducted, string & layer_name, int & nodes_in_dump, bool exclude) { // Average graph, backbone, inducted; string topology, stack, layer, currentLayer; vector<string> layers; int i_tmp; unsigned int i; string s_tmp; string color; NodeList backbone_nodes; NodeList graph_nodes; Graph backbone; long tot_tmp, count_tmp; // Apre il file di risultato in lettura. istream * inFile; int degree = 0; int count = 0; if (use_zipped) inFile = new igzstream((resultFile + ".gz").c_str()); else inFile = new ifstream((resultFile).c_str()); cout << "Topology;Avg. SP Backbone;Avg. SP Inducted" << endl; // Inizia a leggere il file. while (*inFile >> topology >> stack) { cout << topology << ";"; // cout << "-------------------------------" << endl; // cout << "( " << topology << " ) - [" << stack << "]" << endl; // cout << "."; // cout.flush(); extractLayers(stack, layers); if (selectedLayer >= (int)layers.size()) { for (i = 0; i < layers.size(); i++) { skipLayer(inFile); } } else { for (i = 0; i < (unsigned int)selectedLayer; i++) { skipLayer(inFile); } { *inFile >> currentLayer; // cout << ", Layer: " << currentLayer; if ((currentLayer == "BACKBONE") || (currentLayer == "SHIVA") || (currentLayer == "CONNECTOR")) { // skip i dati in trasmissione dei nodi. *inFile >> i_tmp; for (int t = 0; t < (i_tmp + 2); t++) getline(*inFile, s_tmp, '\n'); *inFile >> i_tmp; int t; backbone_nodes.clear(); graph_nodes.clear(); for (t = 0; t < i_tmp; t++) { NodeList tmp_nodes; // Carica i colori dei nodi. readColor(inFile, color, tmp_nodes, false); if ((color == "black") || (color == "gray")) { for (NodeList::iterator n = tmp_nodes.begin(); n != tmp_nodes.end(); n++) { backbone_nodes.insert(*n); graph_nodes.insert(*n); } } else { for (NodeList::iterator n = tmp_nodes.begin(); n != tmp_nodes.end(); n++) { graph_nodes.insert(*n); } } } // Carica il backbone del grafo. loadFromDump(inFile, backbone); // print(backbone); // Calcola lo shortst_path_medio sul grafo e aggiungilo // al valore corrente. Measure shortest_path_backbone; shortest_path(backbone, shortest_path_backbone); sp_backbone = sp_backbone + shortest_path_backbone; // Carica il grafo della topologia in questione. // Induci sul grafo di partenza il backbone considerando // i nodi marcati di "black". // Calcola lo shortst_path_medio sul grafo indotto // e aggiungilo al valore corrente. Graph graph; changeToGraph(topology); string file = topologyDirectory + string("/") + topology; loadFromFile(file.c_str(), graph); nodes_in_dump = graph.size(); Measure shortest_path_inducted; shortest_path(graph, backbone_nodes, shortest_path_inducted); sp_inducted = sp_inducted + shortest_path_inducted; // cout << "Avg. SP Back;" << shortest_path_backbone.getAverage() << endl; cout << shortest_path_backbone.getAverage() << ";"; // cout << "Avg. SP Induct;" << shortest_path_inducted.getAverage() << endl; cout << shortest_path_inducted.getAverage(); // cout << "-------------------------------" << endl; // cout << endl; if (!exclude) { Measure shortest_path_graph; shortest_path(graph, graph_nodes, shortest_path_graph); sp_graph = sp_graph + shortest_path_graph; // Calculate shoretst path over the visibility graph. cout << shortest_path_graph.getAverage() << endl; } else cout << endl; } if ((currentLayer == "SHIVA") || (currentLayer == "CONNECTOR")) { getline(*inFile, s_tmp, '\n'); } } for (++i; i < layers.size(); i++) { skipLayer(inFile); } } // break; } // cout << (float)degree / ((float) count * nodes_in_dump) << endl; layer_name = string(""); // Save Name of layer. for (int l = 0; l <= selectedLayer; l++) { layer_name += layers[l]; if (l < selectedLayer) layer_name += string("-"); } delete(inFile);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -