Boost Graph read_graphml & dynamic vertex properties

…衆ロ難τιáo~ 提交于 2019-12-11 05:23:46

问题


I have use the boost graph library and read in a graph from a graphml such as this:

<?xml version="1.0" encoding="UTF-8"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"  
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
   http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
    <graph id="G" edgedefault="directed">
        <node id="A"/>
        <node id="B"/>
        <edge id="0" source="A" target="B">
    </graph>
</graphml>

I have the following C++ function:

using namespace boost;
typedef adjacency_list<vecS, vecS, directedS> BoostGraphType;
typedef dynamic_properties BoostDynamicProperties;

BoostGraphType& g = ...;
BoostDynamicProperties& dp = ...;
read_graphml(is, g, dp);

// get the property map for vertex indices
typedef property_map<BoostGraphType, vertex_index_t>::type IndexMap;
IndexMap index_map = get(vertex_index, g);

typedef graph_traits<BoostGraphType>::vertex_iterator vertex_iter;
for (auto vp = vertices(g); vp.first != vp.second; ++vp.first)
{
    size_t index = index_map[*vp.first];
    // How do I get the id of the node?
}

How can I extract the id of each node, resp. associate the boost vertex_index and "id"-graphml-tag?

Alternatively, how can I identify or map the vertices in my boost graph structure to the vertices in my GraphML file?

来源:https://stackoverflow.com/questions/15433492/boost-graph-read-graphml-dynamic-vertex-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!