Sample projects for displaying graph using C#

Apr 17, 2009 at 8:47 AM
Edited Apr 17, 2009 at 8:48 AM
Can you please post a sample project using Dijkstra's alogrithm and display an image as an output ? You had mentioned that we can use Glee, AGL and others but post a sample.

How do I generate a graph or Image after this ? I would need the code. Thanks

Sample C# Code - 

 

AdjacencyGraph<string, Edge<string>> graph = new AdjacencyGraph<string, Edge<string>>(true);

            // Add some cities to the graph
            graph.AddVertex("A");
            graph.AddVertex("B");
            graph.AddVertex("C");
            graph.AddVertex("D");
            graph.AddVertex("E");
            graph.AddVertex("F");
            graph.AddVertex("G");
            graph.AddVertex("H");
            graph.AddVertex("I");
            graph.AddVertex("J");

            // Create the streets (<string> -> the edge is identified by a string value)
            Edge<string> a_e = new Edge<string>("A", "E");
            Edge<string> e_f = new Edge<string>("E", "F");
            Edge<string> f_g = new Edge<string>("F", "G");
            Edge<string> g_h = new Edge<string>("G", "H");

            // Add the streets
            graph.AddEdge(a_e);
            graph.AddEdge(e_f);
            graph.AddEdge(f_g);
            graph.AddEdge(g_h);

            // Define some lengths to the streets
            Dictionary<Edge<string>, double> edgeCost = new Dictionary<Edge<string>, double>(graph.EdgeCount);
            edgeCost.Add(a_e, 1);
            edgeCost.Add(e_f, 1);
            edgeCost.Add(f_g, 1);
            edgeCost.Add(g_h, 1);
    
            DijkstraShortestPathAlgorithm<string, Edge<string>> dijkstra = new DijkstraShortestPathAlgorithm<string, Edge<string>>(graph, AlgorithmExtensions.GetIndexer<Edge<string>, double>(edgeCost));

            // Attach a Vertex Predecessor Recorder Observer to give us the paths
            QuickGraph.Algorithms.Observers.VertexPredecessorRecorderObserver<string, Edge<string>> predecessorObserver = new QuickGraph.Algorithms.Observers.VertexPredecessorRecorderObserver<string, Edge<string>>();
            predecessorObserver.Attach(dijkstra);

            // attach a distance observer to give us the shortest path distances
            VertexDistanceRecorderObserver<string, Edge<string>> distObserver = new VertexDistanceRecorderObserver<string, Edge<string>>(AlgorithmExtensions.GetIndexer<Edge<string>, double>(edgeCost));
            distObserver.Attach(dijkstra);

            // Run the algorithm with A set to be the source
            dijkstra.Compute("A");

Coordinator
Apr 18, 2009 at 4:36 AM
See http://quickgraph.codeplex.com/Wiki/View.aspx?title=Visualization%20Using%20Glee
Apr 21, 2009 at 2:38 AM
Can you give in more details on using the Glee rendering please / Visualization? It would be a great sample for others as well, and understand it's from Glee side but a sample would be great.
Thanks
Jul 8, 2009 at 3:33 PM

All,

I encounter the same issue as buntybunty, I tried to have a visualization of a Dijkstra graph with Glee, but I can't figure out how to create this visualization (I success to visualize "simple" non weighted graphs).

I imagine the visualization should be based on :

VertexDistanceRecorderObserver<string, Edge<string>> distObserver

can you provide a small example in order to link to the sample you provide here :

http://quickgraph.codeplex.com/Wiki/View.aspx?title=Visualization%20Using%20Glee

 

Thanks