none
Serializing a Graph Structure Using Boost RRS feed

  • Question

  • Hi,

    I  would like to use boost to serialize my graph (it's in the boost adjacency list format)... I couldn't do it...

    I managed to serialize an array and some other structures as follows:

    int I[5] = {0,1,2,3,4};

    boost::archive::text_iarchive ia(file),

    ia << I;

    but that doesn't work with graph data in the boost adjacency list format... I also tried "SavingArchieve" template but couldn't do it... Any idea's please? or references?




    • Edited by NMKS Monday, December 23, 2013 1:32 PM
    Monday, December 23, 2013 1:22 PM

All replies

  • Hello,

    Please check the methods in the following links:

    How to serialize a graph structure?

    How to serialize type boost::labeled_graph

    The adjacency_list class implements a generalized adjacency list graph structure.

    Best Regards,

    Jane.

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, December 24, 2013 1:52 AM
  • Thanks for the reply...

    Actually, I went previously through those links...

    I couldn't find anything that helps me... even the boost documentation is not clear about this issue..

    Tuesday, December 24, 2013 6:41 AM
  • Hi,

    Thank you for your feedback.

    >>but that doesn't work with graph data in the boost adjacency list format

    Is there a possibility that  this issue is related to the memory  allocation?

    Please check the discussions in the following links:

    What is better, adjacency lists or adjacency matrices for graph problems in c++?

    Using C++ Boost's Graph Library

    Sincerely,

    Jane.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, December 25, 2013 9:36 AM
  • Thanks again for your reply...

    Actually, the problem is that when I write

    ia << g;

    where g is my graph... It gives me a compilation error that "serialize" should be a member function in my class... But there is not enough documentation on how to add this function... I just wish that I can see some code that does graph serialization...

    Wednesday, December 25, 2013 11:25 AM
  • Thanks again for your reply...

    Actually, the problem is that when I write

    ia << g;

    where g is my graph... It gives me a compilation error that "serialize" should be a member function in my class... But there is not enough documentation on how to add this function... I just wish that I can see some code that does graph serialization...

    Did you received any other compilation errors?

    Have you tried to debug this application with breakpoints?

    Could you please share more code and error message for further analysis?

    You can post sample code here or upload it on https://skydrive.live.com/ .

    Thanks for your understanding.

    Sincerely,

    Jane.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, December 26, 2013 1:50 AM
  • You need a structure or an interface to be able to serialize the data.  You already have the structure according to the title of the posting.  Your graph is an array of the structure type.  The standardize Net serialization method creates an XML format and a schema to save the data to a file or to transfer the data on a comm network.  Serialized data can be formatted data like XML or non formatted like a byte[].  XML adds a lot of overhead to the data which takes up a lot of space.  With large structures, it may be better to simply use convert the array to a byte[] especially if you structure is a fixed size (doesn't contain any pointers).  When using byte[] you may also want to add a CRC to the data structure to verify that the data isn't corrupted.  You can use BinaryWriter/BinaryReader to write and read the data to a file.

    jdweng

    Thursday, December 26, 2013 2:07 AM
  • Thanks for the replies... I really appreciate them...

    The following is my program... It creates the graph successfully... the problem occurs only when trying to serialize it (The lines marked with arrows <-----------------------)

    Note that if I write oa << I; where I is an array, it works...

    #include <iostream>

    #include <fstream>

    #include <boost/config.hpp>

    #include <boost/graph/adjacency_list.hpp>

    #include <boost/graph/graph_utility.hpp>

    #include <boost/property_map/property_map.hpp>

    #include <boost/archive/text_oarchive.hpp>

    #include <boost/archive/text_iarchive.hpp>

    #include <boost/graph/adj_list_serialize.hpp>

    using namespace std;

    using namespace boost;

    struct EdgeProperties

    {

            EdgeProperties(const int& w) : weight(w) { }

            int weight;

    };

    struct VertexProperties

    {

            int id;

            int weight;

    };

    int main()

    {

           typedef adjacency_list<vecS, listS, undirectedS,

                VertexProperties, EdgeProperties> Graph;

           const int V = 15;

           Graph g(V);

           int vnum = 0, num1, num2, num3;

           ifstream indata1, indata2;

           indata1.open("vertices_s_15.txt");

           indata2.open("edges_s_15.txt");

           if(!indata1 || !indata2)

                  cout << "One or more files are not found...\n";

           property_map<Graph, int VertexProperties::*>::type

                  id = get(&VertexProperties::id, g);

           property_map<Graph, int VertexProperties::*>::type

                  vweight = get(&VertexProperties::weight, g);

           property_map<Graph, int EdgeProperties::*>::type

                  eweight = get(&EdgeProperties::weight, g);

           graph_traits<Graph>::vertex_iterator vi, viend;

           graph_traits<Graph>::out_edge_iterator ei, eiend;

           // storing vertices values and weights from file

           for (boost::tie(vi,viend) = vertices(g); vi!=viend; ++vi)

           {

                  indata1 >> num1 >> num2;

                  id[*vi] = num1;

                  vweight[*vi] = num2;

           }

           // storing edges and their weights from file

           for(int i=0; i<V; i++)

           {

                  indata2 >> num1 >> num2 >> num3;

                  add_edge(vertex(num1, g), vertex(num2, g), EdgeProperties(num3), g);

           }

           //ofstream outdata("graph.txt"); <----------------------------

           //boost::archive::text_oarchive oa(outdata); <----------------

           //oa << g; <--------------------------------------------------

           indata1.close();

           indata2.close();

           //outdata.close(); <------------------------------------------

          

           return 0;

    }

    Thursday, December 26, 2013 8:37 AM
  • Hello,

    >>It creates the graph successfully... the problem occurs only when trying to serialize it

    Please check the following related links :

    A Quick Tour of the Boost Graph Library

    Serialization Tutorial

    Table of Contents: the Boost Graph Library

    In addition,please share the specific errors for further analysis.

    Sincerely,

    Jane.

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, December 27, 2013 8:51 AM
  • Thank you...

    I read the links... no success...

    The following are my errors:

    1. error C2039: 'serialize' : is not a member of 'VectorProperties'

    2. error C2039: 'serialize' : is not a member of 'EdgeProperties'

    As I said before, I don't know how to include 'serialize' in my structures, I can convert my structures to classes but still I don't know how to write 'serialize'...

    Sunday, December 29, 2013 7:32 AM