Click here to Skip to main content
15,886,110 members
Articles / Programming Languages / C#

QuickGraph: A 100% C# Graph Library with Graphviz Support

Rate me:
Please Sign up or sign in to vote.
4.86/5 (78 votes)
23 Apr 2007Zlib9 min read 1.2M   32.5K   360  
A generic directed graph library with a Graphviz Web Control Bonus!
In this article, you will learn about a 100% C# Generic Graph Library, an attempt to port the Boost Graph Library (BGL) from C++ to C#.
/// QuickGraph Library 
/// 
/// Copyright (c) 2003 Jonathan de Halleux
///
/// This software is provided 'as-is', without any express or implied warranty. 
/// 
/// In no event will the authors be held liable for any damages arising from 
/// the use of this software.
/// Permission is granted to anyone to use this software for any purpose, 
/// including commercial applications, and to alter it and redistribute it 
/// freely, subject to the following restrictions:
///
///		1. The origin of this software must not be misrepresented; 
///		you must not claim that you wrote the original software. 
///		If you use this software in a product, an acknowledgment in the product 
///		documentation would be appreciated but is not required.
///
///		2. Altered source versions must be plainly marked as such, and must 
///		not be misrepresented as being the original software.
///
///		3. This notice may not be removed or altered from any source 
///		distribution.
///		
///		QuickGraph Library HomePage: http://www.dotnetwiki.org
///		Author: Jonathan de Halleux


using System;

namespace QuickGraphNUnit.Generators
{
	using QuickGraph.Providers;
	using QuickGraph.Concepts;
	using QuickGraph.Concepts.Modifications;
	using QuickGraph.Concepts.Traversals;
	using QuickGraph.Representations;

	/// <summary>
	/// Description r�sum�e de AdjacencyGraphGenerator.
	/// </summary>
	public class BidirectionalGraphGenerator : 
		IGraphGenerator,
		IMutableGraphGenerator,
		IMutableIncidenceGraphGenerator,
		IIncidenceGraphGenerator,
		IVertexListGraphGenerator,
		IMutableEdgeListGraphGenerator
	{
		public BidirectionalGraph G
		{
			get
			{
				return new BidirectionalGraph(new VertexAndEdgeProvider(),true);
			}
		}

		public BidirectionalGraph ACyclicGraph
		{
			get
			{
				BidirectionalGraph g =  new BidirectionalGraph(new VertexAndEdgeProvider(),true);
				IVertex u = g.AddVertex();
				IVertex v = g.AddVertex();
				IVertex w = g.AddVertex();
				g.AddEdge(u,v);
				g.AddEdge(v,w);
				g.AddEdge(u,w);

				return g;
			}
		}

		public BidirectionalGraph CyclicGraph
		{
			get
			{
				BidirectionalGraph g =  new BidirectionalGraph(new VertexAndEdgeProvider(),true);
				IVertex u = g.AddVertex();
				IVertex v = g.AddVertex();
				IVertex w = g.AddVertex();
				g.AddEdge(u,v);
				g.AddEdge(v,w);
				g.AddEdge(w,u);

				return g;
			}
		}
		public IGraph Graph(bool pe)
		{
			return new BidirectionalGraph(new VertexAndEdgeProvider(),pe);
		}
		public IEdgeMutableGraph MutableGraph
		{
			get
			{
				return this.G;
			}
		}
		public IMutableIncidenceGraph MutableIncidenceGraph
		{
			get
			{
				
				return this.G;
			}
		}
		public IIncidenceGraph IncidenceGraph
		{
			get
			{
				return this.ACyclicGraph;
			}
		}
		public IMutableEdgeListGraph MutableEdgeListGraph
		{
			get
			{
				return this.ACyclicGraph;
			}
		}
		public IVertexListGraph VertexList
		{
			get
			{
				return this.ACyclicGraph;
			}
		}
		public int VertexListCount
		{
			get
			{
				return 3;
			}
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The zlib/libpng License


Written By
Engineer
United States United States
Jonathan de Halleux is Civil Engineer in Applied Mathematics. He finished his PhD in 2004 in the rainy country of Belgium. After 2 years in the Common Language Runtime (i.e. .net), he is now working at Microsoft Research on Pex (http://research.microsoft.com/pex).

Comments and Discussions