Boost logo

Boost Users :

Subject: Re: [Boost-users] [Serialization][BGL] problem serializing an edge
From: Cedric Laczny (cedric.laczny_at_[hidden])
Date: 2010-07-20 13:43:30


Hi Irek,

you did not mention if you tried the operator& instead of operator<<.
I could imagine that the fact, that you are using nested properties might
impose problems to the operator<<. However, I am not sure if this can be fixed
by using operator&, but it could be worth a try.

Best,

Cedric

On Tuesday, 20. July 2010 19:03:23 Ireneusz Szcześniak wrote:
> Hi Cedric,
>
> Thanks for your response. My graph in my code is actually a bit more
> complicated than what I gave in my example. This is what I'm actually
> using:
>
> typedef
> adjacency_list <vecS, vecS, undirectedS,
> property<vertex_name_t, string,
> property<vertex_distance_t, vector<int>,
> property<vertex_predecessor_t, vector<Vertex>,
> property<vertex_bundle_t, vector<my_class> > > > >,
> property<edge_weight_t, int,
> property<edge_weight2_t, int> > >
> Graph;
>
> I have many data structures that have edge_descriptors as their
> fields, and I wouldn't like to refactor them only to make them vertex
> or edge properties.
>
> I agree that the reason for the compilation error is that the
> Serialization library doesn't know how to serialize an
> edge_descriptor. I don't know why the serialization code for the
> adjacency list doesn't deliver the serialization code for the
> edge_description. Should I write the serialization code for the
> edge_descriptor? If so, then how?
>
> I would appreciate it, if someone could fix the initial example, so
> that it compiles:
>
> #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;
> }
>
>
> Thanks,
> Irek
>
> > 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 << ((g.properties(v)).type) << 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.
> >
> > Best,
> >
> > Cedric
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net