c++ - Using vertex_name when reading a GraphML file with Boost Graph -
i trying load simple graphml file such each vertex has vertex name stored in graphml. can change graphml, important thing have access vertex_name code afterwards.
here's minimal example extract still shows problem:
#include <iostream> #include <string> #include <fstream> #include <boost/graph/adjacency_list.hpp> #include <boost/graph/graphml.hpp> int main() { using namespace boost; typedef adjacency_list<vecs, vecs, directeds,property<vertex_name_t,std::string> > boostgraphtype; typedef dynamic_properties boostdynamicproperties; std::string fn = "simple.graphml"; std::ifstream is(fn.c_str()); if (!is.is_open()) { std::cout << "loading file '" << fn << "'failed." << std::endl; throw "could not load file."; } boostgraphtype g; boostdynamicproperties dp ; const std::string vn = "vertex_name"; dp.property(vn,get(vertex_name,g)); read_graphml(is, g, dp); (auto vp = vertices(g); vp.first != vp.second; ++vp.first) { std::cout << "index '" << get(vertex_index,g,*vp.first) << "' "; std::cout << "name '" << get(vertex_name,g,*vp.first) << "'" << std::endl; } return 0; }
i using the following graphml test file:
<?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"> <key id="d0" for="node" attr.name="vertex_name" attr.type="string"/> <graph id="g" edgedefault="directed"> <node id="a"> <data key="d0">a</data> </node> <node id="b"> <data key="d0">b</data> </node> <edge id="0" source="a" target="b"/> </graph> </graphml>
read_graphml throws exception helpful message (e.what()):
parse error: unrecognized type "
it seems problem related vertex_name association (which got comment previous question of mine).
if remove
<data key="d0">a</data>
from node, works.
however, need able identify vertices vertex_name.
how can fix parses graphml , not throw? doing wrong?
your code works when run it.
>wilbert.exe index '0' name 'a' index '1' name 'b'
this using boost v1.52 on windows 7
Comments
Post a Comment