adjacency graph from dictionary

Topics: graph
Jul 26, 2009 at 11:10 AM

Hello,

I have a dictionary where the key is the vertex and the value is an array of adjacent vertices.

How this dictionary can be transformed to graph?

Thanks

Coordinator
Jul 26, 2009 at 2:49 PM

It's documented here: http://quickgraph.codeplex.com/Wiki/View.aspx?title=Creating%20Graphs&referringTitle=Home

Jul 27, 2009 at 5:18 PM

Sorry but:

Dictionary<int, int[]> adjacencyGraph = ...; // vertex -> target edges
var graph = adjacencyGraph.ToDelegateVertexAndEdgeListGraph(
  adjacencyGraph,
  kv => new SEdge(kv.Key, kv.Value) // map key value pairs to SEdge
  );

doesn't work.

I tried also:

var graph = channelsListeners.ToDelegateVertexAndEdgeListGraph(
  kv => new SEdge<uint>(kv.Key, kv.Value) // map key value pairs to SEdge
  );

But the SEdge wants <uint,uint> and I have <uint,uint[]>

Please suggest.

Thank you!

Jul 30, 2009 at 10:52 PM

Dear Pelikhan,

Example says:

Dictionary<int, int[]> adjacencyGraph = ...; // vertex -> target edges

Probably it should be:

Dictionary<int, int[]> adjacencyGraph = ...; // vertex -> target vertices

 

There should be something other instead of SEdge which can handle  int, int[], not int,int.

Please correct the example xor

please point to my mistake.

 

Thank you very much!

Coordinator
Jul 31, 2009 at 3:43 AM
Edited Jul 31, 2009 at 3:44 AM

Oops error in the docs. This is more accurate:

var graph = adjacencyGraph.ToDelegateVertexAndEdgeListGraph(
  adjacencyGraph,
  kv => Array.ConvertAll(kv.Value, v => new SEdge<int>(kv.Key, v)) // map key value pairs to an enumeration of SEdge
 );

Jul 31, 2009 at 8:23 PM

Pelikhan,

Could you please provide working example? The

var graph = adjacencyGraph.ToDelegateVertexAndEdgeListGraph(
  adjacencyGraph,
  kv => Array.ConvertAll(kv.Value, v => new SEdge<int>(kv.Key, v)) // map key value pairs to an enumeration of SEdge
 );

doesn't work.

Thanks.

Coordinator
Aug 1, 2009 at 4:59 PM

I've updated the docs. You need to use a SEquatableEdge instead.