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

📄 shivautility.cc

📁 clustering for ns-2 simulation
💻 CC
字号:
/** * Copyright (c) 2006 Michele Mastrogiovanni. * *   Licensed under the Apache License, Version 2.0 (the "License"); *   you may not use this file except in compliance with the License. *   You may obtain a copy of the License at * *       http://www.apache.org/licenses/LICENSE-2.0 * *   Unless required by applicable law or agreed to in writing, software *   distributed under the License is distributed on an "AS IS" BASIS, *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *   See the License for the specific language governing permissions and *   limitations under the License. * */ #include "ShivaUtility.h"static class ShivaUtilityClass : public TclClass {public:    ShivaUtilityClass() : TclClass("Utility/SHIVA") {}    TclObject* create(int , const char*const* ) {        return(new ShivaUtility());    }} class_shiva_utility;void ShivaUtility::dump(){	BackboneUtility::dump();		// DEBUG	cerr << "----------------------" << endl;	cerr << "Mapping Arcs" << endl;	for (map<Arc, NodeList>::iterator n = mappingArcs.begin(); n != mappingArcs.end(); n++) {		cerr << n->first.first << "\t" << n->first.second;		for (NodeList::iterator i = n->second.begin(); i != n->second.end(); i++)			cerr << "\t" << *i;		cerr << endl;	}		cerr << "Virtual Arcs" << endl;	for (int i = 0; i < 3; i++) {		for (Arcs::iterator arc = virtualArcs[i].begin(); arc != virtualArcs[i].end(); arc++)			cerr << arc->first << "\t" << arc->second << endl;	}	cerr << "Virtual Arcs Erased" << endl;	for (int i = 0; i < 3; i++) {		for (Arcs::iterator arc = virtualArcsErased[i].begin(); arc != virtualArcsErased[i].end(); arc++)			cerr << arc->first << "\t" << arc->second << endl;	}	cerr << "----------------------" << endl;		//	// Stampa il numero totale di archi virtuali che contengono	// 0, 1 o 2 nodi gateway.	//	cout << virtualArcs[0].size() << " ";	cout << virtualArcs[1].size() << " ";	cout << virtualArcs[2].size() << " ";	cout << virtualArcsErased[0].size() << " ";	cout << virtualArcsErased[1].size() << " ";	cout << virtualArcsErased[2].size() << " ";	cerr << "Archi Rilevati: " << (virtualArcs[0].size() + virtualArcs[1].size() + virtualArcs[2].size()) << endl;	cerr << "Archi Da Eliminare: " << (virtualArcsErased[0].size() + virtualArcsErased[1].size() + virtualArcsErased[2].size()) << endl;	int reallyErased[4];		reallyErased[3] = 0;		for (int i = 0; i < 3; i++) {		reallyErased[i] = 0;		// Scorre la lista degli archi di una certa lunghezza da eliminare.		for (Arcs::iterator arc = virtualArcsErased[i].begin();			 arc != virtualArcsErased[i].end();			 arc++) {						// Per ognuno di questi archi nel mapping ritrova la lista dei 			// nodi che c'è fra i due estremi: se almeno un nodo fra i due			// estremi non è colorato, l'arco è eliminato veramente. Altrimenti			// resta.									int decolored = 0;						for (NodeList::iterator node = mappingArcs[*arc].begin(); 				 node != mappingArcs[*arc].end();				 node++)				if (find(coloredGateways.begin(), coloredGateways.end(), *node) == coloredGateways.end())					decolored++;			if (decolored == i)				reallyErased[i]++;			if ((i == 2) && (decolored == 1))				reallyErased[3]++;		}	}		cout << reallyErased[0] << " ";	cout << reallyErased[1] << " ";	cout << reallyErased[2] << " ";	cout << reallyErased[3] << " ";		cerr << "Archi Eliminati Effettivi: " << (reallyErased[0] + reallyErased[1] + reallyErased[2]) << endl;	cerr << "Archi Lunghi 2 con un solo gateway off: " << reallyErased[3] << endl;		cout << endl;}void ShivaUtility::addVirtualArc(NodeAddress a, NodeAddress b, NodeList members){	if (a > b) {		NodeAddress tmp = b;		b = a;		a = tmp;	}	// DEBUG	/*	cout << a << "\t" << b;	for (NodeList::iterator n = members.begin(); n != members.end(); n++)		cout << "\t" << *n;	cout << endl;	 */		Arc arc(a, b);	virtualArcs[members.size()].insert(arc);		// DEBUG	/*	bool exists = false;	if (mappingArcs.find(arc) != mappingArcs.end())		exists = true;	int size_before = mappingArcs[arc].size();	for (NodeList::iterator n = members.begin(); n != members.end(); n++)		mappingArcs[arc].insert(*n);	if (exists && (size_before != mappingArcs[arc].size())) {		cout << "ERRORE: ho memorizzato un arco diverso da quello di partenza: " << endl;		cout << arc.first << " - " << arc.second << endl;	}	*/			mappingArcs[arc] = members;}void ShivaUtility::eraseVirtualArc(NodeAddress a, NodeAddress b, int size){	if (a > b) {		NodeAddress tmp = b;		b = a;		a = tmp;	}		virtualArcsErased[size].insert(Arc(a, b));}void ShivaUtility::colorNode(NodeAddress node){	coloredGateways.insert(node);}

⌨️ 快捷键说明

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