#include "GraphManager.h" #include "Command.h" using std::ostream; using std::endl; GraphManager * GraphManager::Instance() { if (_instance == 0) _instance = new GraphManager(); return _instance; } void GraphManager::printGraph() const { cout << endl << "THE GRAPH: " << endl; cout << graph << endl; } bool GraphManager::isClass(const string& this_class) const { vector::const_iterator ptr = find(classList.begin(), classList.end(), this_class); return ( ptr != classList.end() ); } void GraphManager::printClassList() const { int count = 1; for ( vector::const_iterator ptr = classList.begin(); ptr != classList.end(); ++ptr ) { cout << count++ << ". " << *ptr << endl; } } void GraphManager::findCycles() { BuildStrongComponents cmd(graph); cmd.execute(); components = cmd.getCycles(); //cmd.printReverseDfsNumbering(); } void GraphManager::printTotalEdgeCount() const { graph.printEdgeCount (); cout << "Nested classes: " << nestedClassCount << endl; } void GraphManager::printEdgeCount(const Graph& thegraph) const { thegraph.printEdgeCount (); } void GraphManager::printCycles() const { int count = 0; cout << endl; for ( list::const_iterator ptr = components.begin(); ptr != components.end(); ++ptr ) { Graph graph = (*ptr); cout << ++count << ". THE NEW CLUSTER: " << endl; cout << graph; graph.printEdgeCount(); cout << endl; } } void GraphManager::buildGraph(const string & fn) { BuildGraphCommand cmd(fn); cmd.execute(); nestedClassCount = cmd.getNestedClassCount(); } void GraphManager::printComponentSummary() const { int count = components.size(); cout << "The number of components is: " << count << endl; int i = 1; int singletons = 0; for ( list::const_iterator ptr = components.begin(); ptr != components.end(); ++ptr ) { cout << "Component: " << i++ << " has "; cout << ptr->numberOfNodes() << " nodes " << endl; if ( ptr->numberOfNodes() == 1) ++singletons; } cout << "SINGLETONS: " << singletons << endl; } void GraphManager::breakCycles() { model.setWeights(); for ( list::const_iterator ptr = components.begin(); ptr != components.end(); ++ptr ) { int count = ptr->numberOfNodes(); if ( count > 1) { BreakCyclesCommand cmd(model, *ptr); cmd.execute(); edgesRemoved = cmd.getEdgesRemoved(); } } cout << "Number of required break calls: " << BreakCyclesCommand::getBreakCount() << endl; } void GraphManager::printEdgesRemoved() const { cout << endl << "THE GRAPH OF EDGES REMOVED: " << endl; cout << edgesRemoved << endl; }// printEdgesRemoved void GraphManager::buildGPrime() { GPrime = graph; for ( list< list >::const_iterator ptr = edgesRemoved.getAdjList().begin(); ptr != edgesRemoved.getAdjList().end(); ++ptr ) { list::const_iterator ptr2 = ptr->begin(); string src = ptr2->getName(); ++ptr2; while (ptr2 != ptr->end()) { Edge edge(src, ptr2->getName(), ptr2->getEdgeType()); GPrime.remEdge(edge); indegrees[ptr2->getName()] -= 1; ++ptr2; }// while }// for }// buildGPrime void GraphManager::printGPrime() const { cout << endl << "GPRIME: " << endl; cout << GPrime << endl; }// printGPrime void GraphManager::findOrder() { FindOrderCommand cmd(GPrime, indegrees); cmd.execute(); order = cmd.getOrder(); }// findOrder void GraphManager::printOrder() { cout << "Result of Reverse Topological Sort: "; while (!order.empty()) { cout << order.top(); if (order.size() >= 2) cout << ", "; order.pop(); }// while cout << endl; }// printOrder void GraphManager::printIndegrees() const { for ( map::const_iterator ptr = indegrees.begin(); ptr != indegrees.end(); ++ptr ) { cout << "Indegree of " << ptr->first << ": " << ptr->second << endl; }// for }// printIndegrees int GraphManager::incrIndegree(const string& name) { indegrees[name] += 1; return (indegrees[name]); }// incrIndegree