繁体   English   中英

提升图属性图的序列化

[英]boost serialization of graph property map

我试图使用以下定义序列化boost :: graph:

 typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, boost::no_property,
                                  boost::property<boost::edge_weight_t, float> > mygraph_t;
    typedef boost::property_map<mygraph_t, boost::edge_weight_t>::type WeightMap;
    typedef mygraph_t::vertex_descriptor vertex;
    typedef mygraph_t::edge_descriptor edge_descriptor;


mygraph_t topoGraph;
WeightMap weightMap;

问题是由于我尝试序列化'weightMap'引起的

即使我包含了我认为合适的头文件:“boost / graph / adj_list_serialize.hpp”,它仍然没有出现以下错误消息

/usr/include/boost/serialization/access.hpp:118:9: error: ‘struct boost::adj_list_edge_property_map<boost::undirected_tag, float, float&, long unsigned int, boost::property<boost::edge_weight_t, float>, boost::edge_weight_t>’ has no member named ‘serialize’
         t.serialize(ar, file_version);
         ^

非常感谢您的帮助。

我无法重现它

这是一个在线工作的版本

住在Coliru

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/adj_list_serialize.hpp>

typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, boost::no_property,
                                          boost::property<boost::edge_weight_t, float> > mygraph_t;
typedef boost::property_map<mygraph_t, boost::edge_weight_t>::type WeightMap;
typedef mygraph_t::vertex_descriptor vertex;
typedef mygraph_t::edge_descriptor edge_descriptor;

#include <boost/archive/text_oarchive.hpp>
#include <iostream>

int main() {
    mygraph_t topoGraph;
    WeightMap weightMap;

    boost::archive::text_oarchive oa(std::cout);
    oa << topoGraph;
}

希望它能帮助你发现差异。 如果没有,您可能会遇到特定(旧)Boost版本的问题。

我想你错过了包含以下文件:

#include <boost/graph/adj_list_serialize.hpp>

此头文件包含必要的序列化方法,用于以非侵入模式加载/保存adjacency_list <...>对象。

为了序列化任何类的对象,该类必须提供serialize()模板函数。 显然,类型adj_list_edge_property_map没有该功能。 解决该问题的一种方法是创建一个存储该类型对象的包装类W,并添加W :: serialize(),它通过序列化weightMap的组件来实现。 然后序列化W而不是序列化weightMap。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM