简体   繁体   English

提升图属性图的序列化

[英]boost serialization of graph property map

I am attempting to serialize a boost::graph with the following definitions: 我试图使用以下定义序列化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;

The problem is caused by my attempt to serialize the 'weightMap' 问题是由于我尝试序列化'weightMap'引起的

It is failing with the below error message even though I included what I believe to be the appropriate header file: "boost/graph/adj_list_serialize.hpp" 即使我包含了我认为合适的头文件:“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);
         ^

Thanks very much for any assistance. 非常感谢您的帮助。

I can't reproduce it 我无法重现它

Here's a version that works, online 这是一个在线工作的版本

Live On Coliru 住在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;
}

Hopefully it will help you spot a difference. 希望它能帮助你发现差异。 If not, you likely have a problem with a specific (old) version of Boost. 如果没有,您可能会遇到特定(旧)Boost版本的问题。

I think you have missed to include the following file: 我想你错过了包含以下文件:

#include <boost/graph/adj_list_serialize.hpp>

This header file contains necessary serialization methods for loading/saving an adjacency_list<...> object in a non-intrusive mode. 此头文件包含必要的序列化方法,用于以非侵入模式加载/保存adjacency_list <...>对象。

In order to serialize an object of any class, the class must provide a serialize() template function. 为了序列化任何类的对象,该类必须提供serialize()模板函数。 Apparently the type adj_list_edge_property_map does not have that function. 显然,类型adj_list_edge_property_map没有该功能。 One way to solve the problem is to create a wrapper class W that stores an object of that type, and add W::serialize() which is implemented by serializing components of the weightMap. 解决该问题的一种方法是创建一个存储该类型对象的包装类W,并添加W :: serialize(),它通过序列化weightMap的组件来实现。 Then instead of serializing weightMap, you serialize W. 然后序列化W而不是序列化weightMap。

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

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