/// <summary> /// Tests all actions for adjacencygraph and filtered graph. /// </summary> public void Test() { // The all action algorithms AdjacencyGraph g = GraphProvider.Fsm(); Console.WriteLine("Graph: {0} vertices, {1} edges, {2} eulerian trails", g.VerticesCount, g.EdgesCount, EulerianTrailAlgorithm.ComputeEulerianPathCount(g) ); // do layout EulerianTrailAlgorithm euler = CreateEulerianTrail(g); EdgeCollection temps = euler.AddTemporaryEdges(g); Console.WriteLine("Added {0} temporary edges", temps.Count); foreach (NamedEdge ne in temps) { ne.Name = "temporary"; } euler.Compute(); euler.RemoveTemporaryEdges(g); Console.WriteLine("Circuit: {0} edges", euler.Circuit.Count); foreach (NamedEdge e in euler.Circuit) { Console.WriteLine("{0}->{1} ({2})", (NamedVertex)e.Source, (NamedVertex)e.Target, e.Name ); } Console.WriteLine("Trails:"); foreach (EdgeCollection ec in euler.Trails( Traversal.FirstVertexIf(g.Vertices, new NameEqualPredicate("S0"))) ) { foreach (IEdge edge in ec) { Console.WriteLine("{0}->{1}, {2}", ((NamedVertex)edge.Source).Name, ((NamedVertex)edge.Target).Name, ((NamedEdge)edge).Name ); } Console.WriteLine(); } Console.WriteLine("Testing AdjacencyGraph"); TestAllActions(GraphProvider.Fsm(), @"../EdgeDfs"); // testing on filtered graph Console.WriteLine("Testing FilteredVertexAndEdgeListGraph"); TestAllActions(GraphProvider.FilteredFsm(), @"../FilteredEdgeDfs"); }
private void BasicFiltering() { BidirectionalGraph graph = GraphProvider.FileDependency(); DrawGraph(graph, "filedependency"); Console.WriteLine("Source vertices:"); foreach (NamedVertex v in graph.SelectVertices(Preds.SourceVertex(graph))) { Console.WriteLine("\t{0}", v.Name); } Console.WriteLine("Sink vertices:"); FilteredVertexEnumerable filteredVertices = new FilteredVertexEnumerable( graph.Vertices, Preds.SinkVertex(graph) ); foreach (NamedVertex v in filteredVertices) { Console.WriteLine("\t{0}", v.Name); } }
private void FilterFsm() { AdjacencyGraph graph = GraphProvider.Fsm(); // drawing the fsm DrawGraph(graph, "fsm"); // filtering // putting all black besides S4 // therefore all the edges touching s4 will be filtered out. VertexColorDictionary vertexColors = new VertexColorDictionary(); IVertexPredicate pred = new NameEqualPredicate("S4"); foreach (IVertex v in graph.Vertices) { if (pred.Test(v)) { vertexColors[v] = GraphColor.Black; } else { vertexColors[v] = GraphColor.White; } } IVertexPredicate vp = new NoBlackVertexPredicate(vertexColors); IEdgePredicate ep = new EdgePredicate( Preds.KeepAllEdges(), vp ); IVertexAndEdgeListGraph filteredGraph = new FilteredVertexAndEdgeListGraph(graph, ep, vp ); DrawGraph(filteredGraph, "fsmfiltered"); }