I just tried to use your code to read a graphml file. I compile
graphml.cpp myself and have it linked to my executable.
Boost version is 1.33.1.
My code looks like this:
// system headers
#include <string>
#include <iostream>
#include <fstream>
// Boost graph library, including LEDA wrapper
// #include <boost/graph/leda_graph.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/dynamic_property_map.hpp>
// graph_tool: graphml reader
#include "graphml.hpp"
struct VertexProperties
{
float x;
float y;
};
struct EdgeProperties
{
float length;
};
int main()
{
using namespace boost;
using namespace std;
typedef adjacency_list<vecS, vecS, directedS, VertexProperties,
Graph;
Graph g;
dynamic_properties dp;
dp.property("coord1", get(&VertexProperties::x, g));
dp.property("coord2", get(&VertexProperties::y, g));
dp.property("length", get(&EdgeProperties::length, g));
std::ifstream in;
in.open(options.inputgraph.c_str(), ios::in);
read_graphml(in, g, dp);
}
options.inputgraph is a file that looks like this:
<?xml version="1.0"?>
<graphml
xmlns="http://graphml.graphdrawing.org/xmlns/1.0rc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns/1.0rc
graphml-structure-1.0rc.xsd
http://graphml.graphdrawing.org/xmlns/1.0rc
graphml-attributes-1.0rc.xsd"
>
<key id="k0" for="node" attr.name="coord1" attr.type="double">
<desc>First coordinate</desc>
<default>0</default>
</key>
<key id="k1" for="node" attr.name="coord2" attr.type="double">
<desc>Second coordinate</desc>
<default>0</default>
</key>
<key id="k2" for="edge" attr.name="length" attr.type="double">
<desc>Distance</desc>
<default>1</default>
</key>
<graph edgedefault="directed">
<node id="n0">
<data key="k0">1.71661e-05</data>
<data key="k1">0.636771</data>
</node>
[and so on ...]
When running my program, I get:
$ ./separator -f test -i planar100k.graphml
terminate called after throwing an instance of 'boost::bad_any_cast'
what(): boost::bad_any_cast: failed conversion using boost::any_cast
Aborted
If that's helpful, here is an gdb backtrace:
(gdb) r
Starting program:
/amd.home/home/jmueller/separator_devel/separator_jens/separator -f test
-i planar100k.graphml
[Thread debugging using libthread_db enabled]
[New Thread -1211508544 (LWP 4229)]
terminate called after throwing an instance of 'boost::bad_any_cast'
what(): boost::bad_any_cast: failed conversion using boost::any_cast
Program received signal SIGABRT, Aborted.
[Switching to Thread -1211508544 (LWP 4229)]
0xffffe410 in __kernel_vsyscall ()
(gdb) bt
#0 0xffffe410 in __kernel_vsyscall ()
#1 0xb7ce47d0 in raise () from /lib/libc.so.6
#2 0xb7ce5ea3 in abort () from /lib/libc.so.6
#3 0xb7ee63a0 in __gnu_cxx::__verbose_terminate_handler () from
/usr/lib/libstdc++.so.6
#4 0xb7ee3dc5 in std::set_unexpected () from /usr/lib/libstdc++.so.6
#5 0xb7ee3e02 in std::terminate () from /usr/lib/libstdc++.so.6
#6 0xb7ee3f3a in __cxa_throw () from /usr/lib/libstdc++.so.6
#7 0x080526d2 in boost::any_cast<std::string> (operand=@0xbfefc2a8) at
/usr/include/boost/throw_exception.hpp:39
#8 0x08053040 in
boost::detail::dynamic_property_map_adaptor<boost::bundle_property_map<boost::adjacency_list<boost::vecS,
boost::vecS, boost::directedS, VertexProperties, EdgeProperties,
boost::no_property, boost::listS>, unsigned int, VertexProperties,
>::put (this=0x8070a20, in_key=@0xbfefc2ac,
in_value=@0xbfefc2a8) at
/usr/include/boost/dynamic_property_map.hpp:149
#9 0x080553fc in boost::put<unsigned int, double> (name=@0x807513c,
dp=@0xbfefdcd8, key=@0xbfefc31c, value=@0xbfefc350)
at /usr/include/boost/dynamic_property_map.hpp:303
#10 0x0805f17c in
boost::mutate_graph_impl<boost::adjacency_list<boost::vecS, boost::vecS,
boost::directedS, VertexProperties, EdgeProperties, boost::no_property,
boost::listS> >::set_vertex_property (this=0xbfefd9dc, name=@0x807513c,
vertex=@0xbfefc3e4, value=@0xbfefc49c, value_type=@0x807515c)
at graphml.hpp:203
#11 0x08063729 in graphml_reader::handle_property (this=0xbfefd8f4,
key_id=@0xbfefc4a4, descriptor=@0xbfefc4a0, is_vertex=true,
value=@0xbfefc49c)
at graphml.cpp:365
#12 0x080643db in graphml_reader::handle_vertex (this=0xbfefd8f4,
v=@0xbfefc528) at graphml.cpp:293
#13 0x080659db in graphml_reader::on_start_element
(user_data=0xbfefd8f4, c_name=0x80751a0 "node", atts=0x8072fd8) at
graphml.cpp:152
#14 0xb7f1935c in XML_ParserCreate () from /usr/lib/libexpat.so.1
#15 0xb7f19e2d in XML_ParserCreate () from /usr/lib/libexpat.so.1
#16 0xb7f1aee4 in XML_ParserCreate () from /usr/lib/libexpat.so.1
#17 0xb7f1bdb5 in XML_ParserCreate () from /usr/lib/libexpat.so.1
#18 0xb7f1362b in XML_ParseBuffer () from /usr/lib/libexpat.so.1
#19 0xb7f1c292 in XML_Parse () from /usr/lib/libexpat.so.1
#20 0x0806649d in graphml_reader::run (this=0xbfefd8f4, in=@0xbfefdb0c)
at graphml.cpp:68
#21 0x08060058 in boost::read_graphml (in=@0xbfefdb0c, g=@0xbfefd9dc) at
graphml.cpp:408
#22 0x08051899 in boost::read_graphml<boost::adjacency_list<boost::vecS,
boost::vecS, boost::directedS, VertexProperties, EdgeProperties,
boost::no_property, boost::listS> > (in=@0xbfefdb0c, g=@0xbfefdcfc,
dp=@0xbfefdcd8) at graphml.hpp:235
#23 0x0804fe26 in main (argc=5 '\005', argv=0xbfefe054) at separator.cpp:328
Any help's appreciated, thanks.