Boost logo

Boost Users :

Subject: Re: [Boost-users] [Serialization][BGL] problem serializing an edge
From: Cedric Laczny (cedric.laczny_at_[hidden])
Date: 2010-07-19 18:51:55

Hi Irek,

as far as I can see from the example and the error message, the error seems to
be that there is no operator<< implemented for the edge_descriptor. So the
serialization does not know how it should save this instance of an edge
_descriptor. Same problem as when working with std::cout and custom classes
that have no operator<< defined.
I remember having encountered issues when first working with boost::serialize
and boost graph lib. However, I don't exactly remember what the problems
where. In any case, I managed to sucessfully serialize a graph with custom
Vertex and Edge-Properties. You're adjacency_list is a rather straight-forward
example and thus should work well. At least as long as you don't want to
do/store more complex things with your vertices/edges ;)
What I used there was the operator& instead of operator<<.
So perhaps you might give it a try.

Also you might be interested in the code:
#include <iostream>
#include <fstream>
#include "Graph.hpp"
#include "Properties.hpp"
#include <boost/graph/adj_list_serialize.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>

using namespace boost;

int main(int argc, char** argv)
        typedef Graph<VertexProperties, EdgeProperties> MyGraph;
        std::list< std::pair< VertexProperties, VertexProperties> > v_props;
        v_props.push_back(std::make_pair(VertexProperties("a", "type_of_a"),
VertexProperties("b", "type_of_b")));
        MyGraph G(v_props);
        //Serialize it!
        std::ofstream ofs("./serialize_out.dat");
        archive::text_oarchive oa(ofs);
        oa & G;

        //DEserialize it!!!
        std::ifstream ifs("./serialize_in.dat");
        archive::text_iarchive ia(ifs);
        MyGraph g;
        ia & g;
        Graph<VertexProperties, EdgeProperties>::Vertex v = g.getFirstVertex();
        std::cout << (( << std::endl;

        return 0;

There's not much of a difference to your example about it, except for the
operator& and the custom Graph<>-class. I have not defined the operator&
anywhere, so it might very well work for your problem out-of-the-box also.
If it doesn't please let the mailinglist, and thus me, know.



On Monday, 19. July 2010 21:17:14 Ireneusz Szcześniak wrote:
> Hi,
> I have a problem serializing an edge in a graph. This is my test case:
> #include <iostream>
> #include <boost/archive/text_oarchive.hpp>
> #include <boost/graph/adj_list_serialize.hpp>
> using namespace std;
> using namespace boost;
> int
> main()
> {
> typedef adjacency_list<listS, vecS, undirectedS> Graph;
> typedef graph_traits<Graph>::edge_descriptor Edge;
> Graph g;
> Edge e;
> boost::archive::text_oarchive oa(cout);
> oa << g;
> oa << e;
> return 0;
> }
> Compilation with gcc version 4.4.1 returns this error:
> /usr/include/boost/serialization/access.hpp:109: error: ‘class
> boost::detail::edge_desc_impl<boost::undirected_tag, unsigned int>’
> has no member named ‘serialize’
> I would appreciate it if someone could point out what the problem is
> and how to fix it.
> Thanks,
> Irek

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at