Does UndirectedGraph<int, Edge<int>> support Serialization

Topics: algorithm, graph, serialization
Nov 23, 2009 at 9:17 AM
Edited Nov 24, 2009 at 6:32 AM

 

Hi,

I am new in QuickGraph and trying to Serialize and Deserialize the

UndirectedGraph<int, Edge<int>>

 

By Using

     GraphMLExtensions.DeserializeFromGraphML< .

My question is does

UndirectedGraph<int, Edge<int>>

support Serialization and Deserialization. If yes can any one help me out the way.

Some previous tries and errors:

//Serialize
SerializationExtensions.SerializeToBinary(graphToSerialize, BiniaryGraph);

//Deserialize
UndirectedGraph<int, Edge<int>> DeserializedToGraph = (UndirectedGraph<int, Edge<int>>)SerializationExtensions.DeserializeFromBinary<int, Edge<int>, UndirectedGraph<int, Edge<int>>>(BiniaryGraph);

Errors:

It throws "key not found" in

//dijkstra is ==> UndirectedDijkstraShortestPathAlgorithm<int, Edge<int>> dijkstra = new UndirectedDijkstraShortestPathAlgorithm<int, Edge<int>>(DeserializeGraph, DeserializeEdge);
dijkstra.Compute(source);

Hope i will be benefited from this discussion.

Thanks
Barman

 

 

Nov 24, 2009 at 7:22 AM

Hi,

I've tried using the GraphMLSerializer but I'm currently having problems with the deserialization process. I'm using the UndirectedGraph

Below are some snip of code

//Here is the graph initialization
UndirectedGraph<int, Edge<int>> graph;
graph = new UndirectedGraph<int, Edge<int>>(true);

//It goes through loops and add Edges
Edge<int> localEdge = new Edge<int>(source, destination);  //source and destination are EdgeAtLocation
graph.AddEdge(localEdge);

//Here is the serialization code. It is working fine and create xml file
XmlWriter writer = XmlWriter.Create("graph.xml");
GraphMLExtensions.SerializeToGraphML<int, Edge<int>, UndirectedGraph<int, Edge<int>>>(graphToSerialize, writer);
writer.Close();

//Here is the deserialization code. It is generating error
IdentifiableVertexFactory<int> vertexFactory;
IdentifiableEdgeFactory<int, Edge<int>> edgeFactory;
UndirectedGraph<int, Edge<int>> DeserializedToGraph;
XmlReader reader = XmlReader.Create("graph.xml");
GraphMLExtensions.DeserializeFromGraphML<int, Edge<int>, UndirectedGraph<int, Edge<int>>>(DeserializedToGraph, reader, vertexFactory, edgeFactory);
reader.Close();
return DeserializedToGraph;

 

ERROR:

Error    1          The type 'QuickGraph.UndirectedGraph<int,QuickGraph.Edge<int>>' cannot be used as type parameter 'TGraph' in the generic type or method 'QuickGraph.Serialization.GraphMLExtensions.DeserializeFromGraphML<TVertex,TEdge,TGraph>(TGraph, System.Xml.XmlReader, QuickGraph.IdentifiableVertexFactory<TVertex>, QuickGraph.IdentifiableEdgeFactory<TVertex,TEdge>)'. There is no implicit reference conversion from 'QuickGraph.UndirectedGraph<int,QuickGraph.Edge<int>>' to 'QuickGraph.IMutableVertexAndEdgeListGraph<int,QuickGraph.Edge<int>>'.         D:\SUDIP WORKING FOLDER\RnD\SHORTEST PATH\Quickgraph\DijkstraDesktop\Dijkstra2.0\Dijkstra2.0\serialization.cs    67        13            Dijkstra2.0

 

I also tried other process for serilization and deserilization which also generate "The given key was not present in the dictionary" details are posted in my previous discussion.

It will be really appreciate if any one help on this.

Coordinator
Nov 29, 2009 at 12:46 AM

Never tried. I will investigate.

Coordinator
Nov 29, 2009 at 3:58 AM

It seems that you are mixing issues here: the key not present in dictionary is thrown from the dijkstra algorithm not the serialization code.

UndirectedGraph can be serialized. Do you have a repro? If so, open an issue on this problem.

Dec 1, 2009 at 10:38 AM
Edited Dec 2, 2009 at 7:27 AM

Pelikhan,

 

Thank you for your response. Here is the overall scenario. I am generating a route from shape file data using dijkstra algorithm and undirected graph object. This is working but it is providing me severe performance problems. I planned to prepare and serialize a set of undirected graph object and edge factory object so that I can deserialize the same for routing and hopefully resolve the performance issue.

 

First, I tried to use .NET serialization and deserialization for these two objects. When I tried this approach, the serialization and deserialization seems to happen but upon using the deserialized undirected graph object and edgeCost object, I get "The given key was not present in the dictionary" error.

 

Second, I tried to do serialization and deserialization using GraphML options in QuickGraph but received the following error below.

 

The type 'QuickGraph.UndirectedGraph<int,QuickGraph.Edge<int>>' cannot be used as type parameter 'TGraph' in the generic type or method 'QuickGraph.Serialization.GraphMLExtensions.DeserializeFromGraphML<TVertex,TEdge,TGraph>(TGraph, System.Xml.XmlReader, QuickGraph.IdentifiableVertexFactory<TVertex>, QuickGraph.IdentifiableEdgeFactory<TVertex,TEdge>)'. There is no implicit reference conversion from 'QuickGraph.UndirectedGraph<int,QuickGraph.Edge<int>>' to 'QuickGraph.IMutableVertexAndEdgeListGraph<int,QuickGraph.Edge<int>>'.

 

I have created a small sample to shows these issues. Any input in this regard will be very helpful. If you feel I should take a completely different approach for the performance problem, please let me know.

Download Link Sample Code: http://download898.mediafire.com/6ioeexbjmdyg/mynyjju0zjz/Serialization.zip or http://www.mediafire.com/?mynyjju0zjz

 

 

Regards,

Sudip