What is it?

.NET graph operations library (PROTOTYPE)

Hello world!

static void HelloWorld() {
	var graph = new AdjacencyGraph<int,NamedEdge<int>>();

	var v1 = graph.AddVertex();
	var v2 = graph.AddVertex();

	var edge = graph.AddEdge(v1,v2);

	foreach(int vertex in graph.Vertices) {
		Console.WriteLine("Vertex " + vertex);
	}
	
	foreach(NamedEdge<int> edge in graph.Edges) {
		Console.WriteLine("Edge " + edge);
	}
}

Creating graphs

        // graph with standard vertex and edge types
	var graph = new AdjacencyGraph<UserVertex,UserEdge<UserVertex>>();

        // vertex is of type int
	var graph = new AdjacencyGraph<int,UserEdge<int>>();

        // custom vertex type; MyVertex1 extends VertexBase
	var graph = new AdjacencyGraph<MyVertex1,UserEdge<MyVertex>>();

Graph operations

        bool isPlanar = graph.IsPlanar(); // checking for planarity

        bool isPlanar = graph.IsConnected();
        bool isPlanar = graph.IsBiconnected();

        var embeddedGraph = graph.Embed(); // embed graph in plane

Straight line drawing

        var layout = embeddedGraph.StraightLinePresentation();
	
	foreach(var vertex in embeddedGraph.Vertices) {
		var position = layout.GetPosition(vertex);
		Console.WriteLine("(X,Y)=" + position);
	}

Rectangular drawing

       var layout = embeddedGraph.RectangularPresentation(topLeft, topRight, bottomRight, bottomLeft);

Orthogonal drawing

	var layout = embeddedGraph.OrthogonalPresentation();
	
	foreach(var edge in embeddedGraph.Edges) {
		Console.WriteLine("Edge bends from source to target are: ");
		
		foreach(var bendPosition in layout.GetEdgeBends(edge)) {
			Console.WriteLine("(X,Y)=" + layout.GetPosition(bendPosition));
		}
	}

Related projects

Pigale http://pigale.sourceforge.net
QuickGraph http://www.codeplex.com/quickgraph

Last edited Mar 20, 2009 at 12:22 PM by tivadj, version 6