Category : adjacency-matrix

I have an adjacency matrix for a graph. And I need to output all the cycles in this graph. How can I do this using dfs? void al_dfs(int tmp_vertex,int** Graph,vector<int>& color,int number,vector<int>& result){ color[tmp_vertex] = 1; for(int i = 0;i<number;i++){ if((color[i] == 0)){ al_dfs(i,Graph,color,number,result); result.push_back(i); }; if((color[i] == 1)){ for(int i = 0;i< result.size();i++) cout ..

Read more

In the boost graph library, there are two popular functions to read in graphs from a file: boost::read_graphviz(), and boost::read_graphml(), for the GraphViz and the GraphML format, respectively. Now both read generically to any type of boost::adjacency_list<…>, as they are derived from the Mutable Graph concept: #include <string> #include <fstream> #include <boost/graph/adjacency_list.hpp> #include <boost/graph/adjacency_matrix.hpp> #include ..

Read more

Here is my Graph class which contains adjacency list: typedef std::vector<std::list<unsigned int>> AdjacencyList; class Graph { public: Graph(size_t vertices); // to test // Constructs a ‘Graph’ object, // expecting a pointer to the ‘AdjacencyList’ // and the number of vertices Graph(std::shared_ptr<AdjacencyList> adjListPtr, int vertices); // to test // Constructs a ‘Graph’ object from ‘AdjacencyMatrix’ object ..

Read more

Trying to take an adjacency relation with this input format {(1,2),(1,5),(2,1),(2,3),(3,2),(3,4),(4,3),(4,5),(5,1),(5,4)} and print a adjacency matrix. My goal was to check for digits using isdigit() and then take the 2 numbers and update my matrix in those indexes. My matrix still results with all 0’s. To test input. 6 as nodes and enter the above ..

Read more