简体   繁体   中英

boost serialization of graph property map

I am attempting to serialize a boost::graph with the following definitions:

 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'

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"

/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

#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.

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.

In order to serialize an object of any class, the class must provide a serialize() template function. Apparently the type adj_list_edge_property_map does not have that function. 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. Then instead of serializing weightMap, you serialize W.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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