Boost logo

Boost Users :

Subject: [Boost-users] How to create a Graph with BOOST Bib (e.g. adjacency_list)?
From: Konstantin Silav (SugarRay21_at_[hidden])
Date: 2010-01-22 07:52:13


Hallo,

im hardly tring to create a Graph after I parsed an XML File with Nodes (Junction) and Edges.

They are stored in Lists as objects from class Junction resp. Edges.

Junctions stored ones more in Hash Map (boost::unordered_map) for search convenience.


[cpp]class Junction {
public:
    Junction();
    Junction(int id, float x, float y);

    int getId();
    float getX();
    float getY();

private:
    unsigned int id;
    float x, y;
};
[/cpp]


and


[cpp]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
};
[/cpp]

How do i now create the Graph from it? Nodes have to have the Properties like  "id", "x" and "y" and Edges "id".

Should I use my classes or structures? like here:

http://www.boost.org/doc/libs/1_41_0/libs/graph/doc/bundles.html

Is it possible with adjacency_list?


[cpp]
struct Junction_str {
    int id;
    float x, y;
};

struct Edge_str {
    string id;
};[/cpp]


I started with:


[cpp]

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;
//

[/cpp]

How do i initialise the Graph?
[cpp]
MyGraphType map; //or
MyGraphType map(JunctionList.size());
[/cpp]

 

How do i add edge from list?
We have to lists and one hash map:
[cpp]
typedef boost::unordered_map<int, Junction> hashmap;
hashmap junction_map;

list <Junction> JunctionList;
list <Junction>::iterator IterJ;

list <Edge> EdgeList;
list <Edge>::iterator IterE;[/cpp]

 

Great Thanx to all

  

Haiti-Nothilfe! Helfen Sie per SMS: Sende UIHAITI an die Nummer 81190.   
Von 5 Euro je SMS (zzgl. SMS-Gebühr) gehen 4,83 Euro an UNICEF.

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net