Wie erzeugt man einen Graph mit BOOST Bib (z.B. adjacency_list)?



  • Hallo,
    nach dem Parsen einer XML Datei, habe ich die Knoten (Junction) und Kanten (Edges) als Objekte der Klasse Junction bzw. Edges in jeweils einer Liste gespeichert.
    Knoten noch mal in einer Hash Map (boost::unordered_map) gespeichert.

    class Junction {
    public:
        Junction();
        Junction(int id, float x, float y);
    
        int getId();
        float getX();
        float getY();
    
    private:
        unsigned int id;
        float x, y;
    };
    

    und

    class Edge {
    public:
        Edge();
        Edge(string id, int from, int to);
    
        string getId();
        int getFrom();
        int getTo();
    
    private:
        string id;
        int from, to; //Ids von Anfangs- und Ende-Junction
    };
    

    Wie erzeuge ich damit einen Graphen, so dass Knoten über Eigenschaften (Properties) "id", "x" und "y" und Kanten über "id" verfügen?
    Soll ich weiter meine Klassen oder doch Struct, wie hier benutzen?

    struct Junction_str {
        int id;
        float x, y;
    };
    
    struct Edge_str {
        string id;
    };
    

    Mein Anfang sieht so aus:

    typedef boost::adjacency_list<
    boost::listS, // edge container type
    boost::vecS, // vertex container type
    boost::bidirectionalS,
    Junction, // vertex properties :: oder doch Junction_str
    Edge // edge properties :: oder doch Edge_str
    > MyGraphType;
    //geht das überhaupt so mit den Klassen?
    

    Wie initialisiere ich einen Graphen?

    MyGraphType map; //oder
    MyGraphType map(JunctionList.size());
    

    Wie füge ich jetzt die Kanten bzw. die Knoten hinzu???
    Zur Verfügung stehen 3 Speicherstruckturen:

    typedef boost::unordered_map<int, Junction> hashmap;
    hashmap junction_map;
    
    list <Junction> JunctionList;
    list <Junction>::iterator IterJ;
    
    list <Edge> EdgeList;
    list <Edge>::iterator IterE;
    

Anmelden zum Antworten