erster Einstieg in boost::graph



  • Hallo,

    ich sitze gerade über dem Buch "The Boost Graph Library" und verstehe nur Bahnhof.

    Dabei brauche ich im Prinzip nur einen ganz billigen Baum. Jede Kante und jeder Knoten kommen nur einmal vor und Schleifen sind verboten. Z.B.:

    f
       / 
      c
     / \
    a   e
     \ 
      b
       \
        d
    

    Was ist bei boost::graph zu tun das ich eine Klasse a in meinen Graphen g nach obigen Bedingungen bekomme?

    Gruß, Goran



  • Helfen dir die Tutorials nicht weiter?



  • kein Stück 😕



  • Wenn man das Beispiel aus der "Quick-Tour" umwandelt, müsste das nicht deinen Baum ergeben?

    #include <iostream>                  // for std::cout
    #include <utility>                   // for std::pair
    #include <algorithm>                 // for std::for_each
    #include <boost/graph/graph_traits.hpp>
    #include <boost/graph/adjacency_list.hpp>
    #include <boost/graph/dijkstra_shortest_paths.hpp>
    
    using namespace boost;
    
    int main(int,char*[])
    {
        // create a typedef for the Graph type
        typedef adjacency_list<vecS, vecS, bidirectionalS> Graph;
    
        // Make convenient labels for the vertices
        enum { A, B, C, D, E, N };
        const int num_vertices = N;
        const char* name = "ABCDE";
    
        // writing out the edges in the graph
        typedef std::pair<int, int> Edge;
        Edge edge_array[] = { Edge(A,B), Edge(B,D), Edge(A,C), Edge(C,E), Edge(C,F) };
        const int num_edges = sizeof(edge_array)/sizeof(edge_array[0]);
    
        // declare a graph object
        Graph g(num_vertices);
    
        // add the edges to the graph object
        for (int i = 0; i < num_edges; ++i)
          add_edge(edge_array[i].first, edge_array[i].second, g);
    
        return 0;
    }
    

    Ist auch schon lange her, dass ich das letzte mal was mit boost.graph gemacht hab und fande die Bibliothek auch ziemlich unintuitiv.

    Und soweit ich weiß gibt man bei den Graphen hier immer nur die Kanten an, die Menge der Knoten ergibt sich dann halt aus den Kanten.


Anmelden zum Antworten