c++ - Extract the adjacency matrix from a BGL graph -


To remove the adjacency matrix, using Boost Graph Library From the built-in graph shown by either boost :: adjacency_list or boost :: adjacency_matrix . I want to use this matrix with boost :: numeric :: ublas to solve a system of linear equations together

The minimum example is:

  #include & lt; Boost / graph / adjacency_list.hpp & gt; #include & lt; Boost / graph / adjacency_matrix.hpp & gt; Using Namespace Boost; Typedef boost :: adjacency_list & lt; List, vcs, instructions & gt; ListGraph; Typedef boost :: adjacency_matrix & lt; Instructions S & gt; MatrixGraph; Int main () {ListGraph lg; Ad_Age (0, 1, LG); Ad_age (0, 3, LG); AD_Age (1, 2, LG); Ad_Age (2, 3, LG); // How do I get the distance of the Proximity Matrix LG? Matrix Graph Mg (3); Add_edge (0, 1, mg); Ad_ge (0, 3, mg); Ad_age (1, 2, mg); AD_Age (2, 3, mg); // How do I get matrix around Metami Magratti? }   

If a proximity can come in an efficient manner to obtain the matrix, then I must be very compelled. The solution is ideally suited to UBLAS. I wonder if there is any way to avoid walking through the whole graph.

The easiest way to change adjacency_list boost :: copy_graph

For Matrix Graph MG your code should be modified in the following form

  is in adjacency_matrix to use. # Include & lt; Boost / graph / copy.hpp & gt; # Include & lt; Cassert & gt; Using Namespace Boost; Typedef boost :: adjacency_list & lt; List, vcs, instructions & gt; ListGraph; Typedef boost :: adjacency_matrix & lt; Instructions S & gt; MatrixGraph; Int main () {ListGraph lg; Ad_Age (0, 1, LG); Ad_age (0, 3, LG); AD_Age (1, 2, LG); Ad_Age (2, 3, LG); // How do I get the distance of the Proximity Matrix LG? // How do I get matrix around Metami Magratti? Matrix Graph Mg (num_vertices (LG)); Promotion: copy_graph (LG, Mg); }   

Now, to use proximity matrix with ublas or similar, you can write a simple "access" class to make the silkt more consistent with ublas. We receive the previous snippet:

  template & lt; Class Graph & gt; Class Matrix Excerpt {Public: Type Chart Type Graph: Matrix Matrix; // in fact a vector & lt; Typiffef TypeName MATRICS :: CONSTITUTION CONSULTAREFER; Matrix accessor (con graph): m_g (g) {static_assert (boost :: isidmt; size_t, typename graph :: vertex_descriptor & gt; :: value, "vertex descriptor must be integer type"); } Const_reference operator () (size_t u, size_t v) const {returns m_g-> Get_edge (u, v); Const Graph * m_g; }; Zero usage_matrix (Const Metrics Graph & amp; MG) {matrix accessor & lt; Matrix graph & gt; Matr (& amp; mg); Insert throttle (matte (0, 1) == 1); Insert throttle (matte (0, 2) == 0); }   

If you have some edge-bundled properties near you, you may need to modify operator () in MatrixAvrier.

Depending on how much ULSAs you use, you can further refine the Matrix Accessor. For example, for a given head of a MatrixGraph, out_edge_iterator is actually an iterator on the matrix column; Matrix rows etc. can be understood as an offsetter.

Of course, the graph matrix is ​​irreversible and such should be used with care.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -