///////////////////////////////////////////////////////////////// // GraphAlgorithms.cpp - Algorithms on graph structures // // ver 1.0 // // ----------------------------------------------------------- // // copyright © Jim Fawcett, 2012 // // All rights granted provided that this notice is retained // // ----------------------------------------------------------- // // Jim Fawcett, CST 4-187, Syracuse University, 315 443 3948 // // Summer Projects, 2012 // // Win7, Visual Studio 2010 // ///////////////////////////////////////////////////////////////// #include "GraphAlgorithms.h" #include "..\GraphPersistence\GraphIO.h" using namespace DirectedGraph; #ifdef TEST_GRAPHALGORITHMS class TestFunctor : public IFunctor { public: TestFunctor() { std::cout << "\n "; } ~TestFunctor() { std::cout << "\n"; } void operator()(Vertex& v) { static size_t count = 0; if(++count != 1) std::cout << ", "; std::cout << v.value(); } }; void DemoGraph() { GraphIO gio; Graph g; gio.ReadGraph(g, "DemoGraph.xml"); std::cout << "\n Demonstrating Graph " << g.name(); std::cout << "\n ---------------------" << std::string(g.name().size()+1, '-'); foreach(g, Display(g)); std::cout << "\n"; std::cout << "\n ids of vertices with no parents:"; std::cout << "\n ----------------------------------"; std::vector> noParents = vertsWithNoParents(g); std::cout << "\n "; for(size_t i=0; i algo; Graph cond; Components comp = algo.createCondensedGraph(g, cond); for(size_t i=0; i(cond)); std::cout << "\n"; std::cout << "\n Topologically sorted condensed graph vertices:"; std::cout << "\n ------------------------------------------------"; std::vector orderedVertices = algo.topoSort(cond); std::cout << "\n "; for(size_t i=0; i g; GraphIO gio; if(!gio.ReadGraph(g, SrcFile)) { std::cout << "\n can't read " << SrcFile << "\n\n"; } Display display(g); foreach(g, display); std::cout << "\n"; std::cout << "\n Vertices with no Parents:"; std::cout << "\n ---------------------------"; std::vector> VertsWNP; VertsWNP = vertsWithNoParents(g); for(size_t i=0; i(g, TestFunctor()); std::cout << "\n"; DemoGraph(); std::cout << "\n\n"; } #endif