I want to create an xml-file out of my Boost Graph... So I'm using the write_graphml Function with dynamic_properties. Everything is fine, I get a file, but there are wrong source- and target- ID's in the edge structs (in the generated file).

Here an example:

<node id="n1">
  <data key="key0">vertex_7</data>
  <data key="key2">bf88aa63-bff1-5c04-8daf-37a5e31981f6</data>
  <data key="key6">12.5</data>
  <data key="key7">7.5</data>
<edge id="e1" source="n1" target="n2">
  <data key="key1">edge_4_5</data>
  <data key="key3">26c512cb-46d8-5eb5-8021-2aac9f492227</data>
  <data key="key4">45844430-f1ea-5355-b7ce-eb566fe89256</data>
  <data key="key5">ecac63d6-e531-5ce8-9578-13cb63d040de</data>

In the edge struct there is the wrong source ID - it should be the ID of Vertex 4 (source="n0") not 7 (source="n1")

Can anybody help me? Or even give me a hint to figure out what is going wrong?

I even tried to create a property map by myself to set the UUID as the (vertex- & source-/target-)ID's, but that changed nothing, there are still false source- and target-ID's in the edge struct.

//boost graph definitions
struct vertex
    float x;
    float y;
    std::string name;
    std::string uuid;

struct edge 
    std::string source_v_uuid;
    std::string dest_v_uuid;
    std::string name;
    std::string uuid;

typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, vertex, edge> my_graph;     

//function to save graph as xml-file
void BoostGraphGenerator::saveBoostGraphAsML(my_graph graph)

     // create file
     std::ofstream ofs(filename);

     // create dynamic properties for function write_graphml
     boost::dynamic_properties dyn_p;
     // fill vertex properties
     dyn_p.property("name", get(&vertex2::name, graph));
     dyn_p.property("x-value", get(&vertex2::x, graph));
     dyn_p.property("y-value", get(&vertex2::y, graph));
     dyn_p.property("uuid", get(&vertex2::uuid, graph));
     // fill edge properties
     dyn_p.property("name", get(&edge2::name, graph));
     dyn_p.property("v-src-uuid", get(&edge2::source_v_uuid, graph));
     dyn_p.property("v-dest-uuid", get(&edge2::source_v_uuid, graph));
     dyn_p.property("uuid", get(&edge2::uuid, graph));

     write_graphml(ofs, graph, dyn_p, true);
//   auto map = get(&vertex2::uuid, graph);
//   write_graphml(ofs, graph, map, dyn_p, true);

0 Answers