Binary serialization of a Graph

Topics: graph, serialization
Apr 23, 2008 at 9:19 PM
Is it possible to use a Binary Serializer in order to store a Graph ?

I have a AdjacencyGraph(Of String, Edge(Of String))

I've try to serialize it using BinaryFormater and i managed to serialize the graph to disk using the following code (VB) :

Private Shared _serializerBin As BinaryFormatter = New BinaryFormatter

Using stream As New FileStream(DataFilePath, FileMode.Create)
_serializerBin.Serialize(stream, graph)
End Using

Although i face problems to deserialize the graph from disk :

If File.Exists(DataFilePath) Then
Using stream As New FileStream(DataFilePath, FileMode.Open)
Dim tmpGraph As AdjacencyGraph(Of String, Edge(Of String)) = TryCast(_serializerBin.Deserialize(stream), AdjacencyGraph(Of String, Edge(Of String)))
End Using

End If

The error is : A first chance exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll

Any ideas ?

Apr 25, 2008 at 8:13 PM
I just noticed that the last Source code supports binary serialization of Bidirectional graphs.

I just did a test and succesfully serialized/deserialized a sample graph of type : BidirectionalGraph(Of String, TaggedEdge(Of String, String))

Is there any possibility to have serialization for non Bidirectional graphs ?
I want only to have a graph with nodes and edges without directions (and probably keep the distance between nodes to the edge) . which is the best graph type to use ?
Apr 30, 2008 at 4:05 PM
There's the UndirectedGraph, I don't think it has been made 'serializable' yet.