Пример #1
0
        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");
        }
		/// <summary>
		/// A height first search algorithm on a directed graph
		/// </summary>
		/// <param name="g">The graph to traverse</param>
		/// <exception cref="ArgumentNullException">g is null</exception>
		public HeightFirstSearchAlgorithm(IBidirectionalVertexListGraph g)
		{
			if (g == null)
				throw new ArgumentNullException("g");
			this.visitedGraph = g;
			this.colors = new VertexColorDictionary();
		}
Пример #3
0
        public static FilteredVertexAndEdgeListGraph FilteredFsm()
        {
            AdjacencyGraph g = Fsm();

            // 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 g.Vertices)
            {
                if (pred.Test(v))
                    vertexColors[v]=GraphColor.Black;
                else
                    vertexColors[v]=GraphColor.White;
            }

            IVertexPredicate vp = new NoBlackVertexPredicate(vertexColors);
            IEdgePredicate ep = new EdgePredicate(
                new KeepAllEdgesPredicate(),
                vp
                );
            return new FilteredVertexAndEdgeListGraph(g,
                ep,
                vp
                );
        }
		/// <summary>
		/// Create a undirected dfs algorithm
		/// </summary>
		/// <param name="g">Graph to search on.</param>
        public UndirectedDepthFirstSearchAlgorithm(IBidirectionalVertexAndEdgeListGraph g)
        {
			if(g == null)
				throw new ArgumentNullException("g");
			visitedGraph = g;
			edgeColors=new EdgeColorDictionary();
			colors = new VertexColorDictionary();
		}
 public DepthFirstSearchAlgorithm(IVertexListGraph g)
 {
     this.maxDepth = 0x7fffffff;
     if (g == null)
     {
         throw new ArgumentNullException("g");
     }
     this.visitedGraph = g;
     this.colors = new VertexColorDictionary();
 }
 public BreadthFirstSearchAlgorithm(IVertexListGraph g)
 {
     if (g == null)
     {
         throw new ArgumentNullException("g");
     }
     this.m_VisitedGraph = g;
     this.m_Colors = new VertexColorDictionary();
     this.m_Q = new VertexBuffer();
 }
 public CyclePoppingRandomTreeAlgorithm(IVertexListGraph g)
 {
     this.visitedGraph = null;
     this.colors = new VertexColorDictionary();
     this.edgeChain = new NormalizedMarkovEdgeChain();
     this.successors = new VertexEdgeDictionary();
     this.rnd = new Random((int) DateTime.Now.Ticks);
     if (g == null)
     {
         throw new ArgumentNullException("g");
     }
     this.visitedGraph = g;
 }
Пример #8
0
		/// <summary>
		/// A depth first search algorithm on a directed graph
		/// </summary>
		/// <param name="g">The graph to traverse</param>
		/// <param name="colors">vertex color map</param>
		/// <exception cref="ArgumentNullException">g or colors are null</exception>
		public NeighborDepthFirstSearchAlgorithm(
			IBidirectionalVertexListGraph g, 
			VertexColorDictionary colors
			)
		{
			if (g == null)
				throw new ArgumentNullException("g");
			if (colors == null)
				throw new ArgumentNullException("Colors");

			this.visitedGraph = g;
			this.colors = colors;
		}
		/// <summary>
		/// Builds a new Bellman Ford searcher.
		/// </summary>
		/// <param name="g">The graph</param>
		/// <param name="weights">Edge weights</param>
		/// <exception cref="ArgumentNullException">Any argument is null</exception>
		/// <remarks>This algorithm uses the <seealso cref="BreadthFirstSearchAlgorithm"/>.</remarks>
		public BellmanFordShortestPathAlgorithm(
			IVertexAndEdgeListGraph g, 
			EdgeDoubleDictionary weights
			)
		{
			if (weights == null)
				throw new ArgumentNullException("Weights");

			m_VisitedGraph = g;
			m_Colors = new VertexColorDictionary();
			m_Weights = weights;
			m_Distances = new VertexDoubleDictionary();
			m_Predecessors = new VertexVertexDictionary();
		}
 public HeightFirstSearchAlgorithm(IBidirectionalVertexListGraph g, VertexColorDictionary colors)
 {
     this.maxDepth = 0x7fffffff;
     if (g == null)
     {
         throw new ArgumentNullException("g");
     }
     if (colors == null)
     {
         throw new ArgumentNullException("Colors");
     }
     this.visitedGraph = g;
     this.colors = colors;
 }
		/// <summary>
		/// Builds a new Dijsktra searcher.
		/// </summary>
		/// <param name="g">The graph</param>
		/// <param name="weights">Edge weights</param>
		/// <exception cref="ArgumentNullException">Any argument is null</exception>
		/// <remarks>This algorithm uses the <seealso cref="BreadthFirstSearchAlgorithm"/>.</remarks>
		public DijkstraShortestPathAlgorithm(
			IVertexListGraph g, 
			EdgeDoubleDictionary weights
			)
		{
			if (g == null)
				throw new ArgumentNullException("g");
			if (weights == null)
				throw new ArgumentNullException("Weights");

			this.visitedGraph = g;
			this.colors = new VertexColorDictionary();
			this.distances = new VertexDoubleDictionary();
			this.weights = weights;
			this.vertexQueue = null;
		}
 public DagShortestPathAlgorithm(IVertexListGraph g, EdgeDoubleDictionary weights)
 {
     if (g == null)
     {
         throw new ArgumentNullException("g");
     }
     if (weights == null)
     {
         throw new ArgumentNullException("Weights");
     }
     this.m_VisitedGraph = g;
     this.m_Colors = new VertexColorDictionary();
     this.m_Distances = new VertexDoubleDictionary();
     this.m_Predecessors = new VertexVertexDictionary();
     this.m_Weights = weights;
 }
        /// <summary>
        /// Builds a new Dijsktra searcher.
        /// </summary>
        /// <param name="g">The graph</param>
        /// <param name="weights">Edge weights</param>
        /// <exception cref="ArgumentNullException">Any argument is null</exception>
        /// <remarks>This algorithm uses the <seealso cref="BreadthFirstSearchAlgorithm"/>.</remarks>
        public DijkstraShortestPathAlgorithm(
            IVertexListGraph g,
            EdgeDoubleDictionary weights
            )
        {
            if (g == null)
                throw new ArgumentNullException("g");
            if (weights == null)
                throw new ArgumentNullException("Weights");

            m_VisitedGraph = g;
            m_Colors = new VertexColorDictionary();
            m_Distances = new VertexDoubleDictionary();
            m_Predecessors = new VertexVertexDictionary();
            m_Weights = weights;
            m_VertexQueue = null;
        }
 public BreadthFirstSearchAlgorithm(IVertexListGraph g, VertexBuffer q, VertexColorDictionary colors)
 {
     if (g == null)
     {
         throw new ArgumentNullException("g");
     }
     if (q == null)
     {
         throw new ArgumentNullException("Stack Q is null");
     }
     if (colors == null)
     {
         throw new ArgumentNullException("Colors");
     }
     this.m_VisitedGraph = g;
     this.m_Colors = colors;
     this.m_Q = q;
 }
Пример #15
0
		/// <summary>Constructs a maximum flow algorithm.</summary>
		/// <param name="g">Graph to compute maximum flow on.</param>
		/// <param name="capacities">edge capacities</param>
		/// <param name="reversedEdges">reversed edge map</param>
		/// <exception cref="ArgumentNullException"><paramref name="g"/> or
		/// <paramref name="capacities"/> or <paramref name="reversedEdges"/> is a null
		/// reference.
		/// </exception>
		public MaximumFlowAlgorithm(
			IVertexListGraph g,
			EdgeDoubleDictionary capacities,
			EdgeEdgeDictionary reversedEdges
			)
		{
			if (g==null)
				throw new ArgumentNullException("g");
			if (capacities==null)
				throw new ArgumentNullException("capacities");
			if (reversedEdges==null)
				throw new ArgumentNullException("reversedEdges");
		
			this.visitedGraph=g;
			this.capacities=capacities;
			this.reversedEdges=reversedEdges;
		
			this.predecessors=new VertexEdgeDictionary();
			this.residualCapacities=new EdgeDoubleDictionary();
			this.colors = new VertexColorDictionary();
        }
Пример #16
0
 /// <summary>
 /// Construct the edge predicate with the edge color map
 /// </summary>
 /// <param name="edgeColors">edge color map</param>
 /// <remarks>
 /// The vertex color map must be initialize for the graph edges.
 /// </remarks>
 public NoBlackVertexPredicate(VertexColorDictionary vertexColors)
 {
     if (vertexColors == null)
         throw new ArgumentNullException("vertexColors");
     m_VertexColors = vertexColors;
 }
Пример #17
0
        private void depthFirstSearchAlgorithmItem_Click(object sender, System.EventArgs e)
        {
            if (this.netronPanel.Graph==null)
                throw new Exception("Generate a graph first");

            // clear colors
            ResetVertexAndEdgeColors();

            // create algorithm
            this.edgeColors=new EdgeColorDictionary();
            foreach(IEdge edge in this.netronPanel.Graph.Edges)
                this.edgeColors[edge]=GraphColor.White;

            this.vertexColors = new VertexColorDictionary();
            DepthFirstSearchAlgorithm dfs = new DepthFirstSearchAlgorithm(
                this.netronPanel.Graph,
                this.vertexColors);

            // create tracer
            LayoutAlgorithmTraverVisitor tracer = new LayoutAlgorithmTraverVisitor(this.netronPanel.Populator);

            // link to algo
            dfs.RegisterTreeEdgeBuilderHandlers(tracer);
            dfs.RegisterVertexColorizerHandlers(tracer);

            dfs.TreeEdge +=new EdgeEventHandler(dfs_TreeEdge);
            dfs.BackEdge +=new EdgeEventHandler(dfs_BackEdge);
            dfs.ForwardOrCrossEdge +=new EdgeEventHandler(dfs_ForwardOrCrossEdge);

            // add handler to tracers
            tracer.UpdateVertex +=new ShapeVertexEventHandler(tracer_UpdateVertex);
            tracer.UpdateEdge +=new ConnectionEdgeEventHandler(tracer_UpdateEdge);

            // running algorithm
            Thread thread = new Thread(new ThreadStart(dfs.Compute));
            thread.Start();
        }
        /// <summary>
        /// BreadthFirstSearch searcher contructor
        /// </summary>
        /// <param name="g">Graph to visit</param>
        /// <param name="Q">Vertex buffer</param>
        /// <param name="colors">Vertex color map</param>
        public BreadthFirstSearchAlgorithm(
            IVertexListGraph g,
            VertexBuffer Q,
            VertexColorDictionary colors
            )
        {
            if (g == null)
                throw new ArgumentNullException("g");
            if (Q == null)
                throw new ArgumentNullException("Stack Q is null");
            if (colors == null)
                throw new ArgumentNullException("Colors");

            m_VisitedGraph = g;
            m_Colors = colors;
            m_Q = Q;
        }
Пример #19
0
        /// <summary>
        /// A depth first search algorithm on a directed graph
        /// </summary>
        /// <param name="g">The graph to traverse</param>
        /// <param name="colors">vertex color map</param>
        /// <exception cref="ArgumentNullException">g or colors are null</exception>
        public DepthFirstSearchAlgorithm(
            IVertexListGraph g,
            VertexColorDictionary colors
            )
        {
            if (g == null)
                throw new ArgumentNullException("g");
            if (colors == null)
                throw new ArgumentNullException("Colors");

            m_VisitedGraph = g;
            m_Colors = colors;
        }
Пример #20
0
 /// <summary>
 /// A depth first search algorithm on a directed graph
 /// </summary>
 /// <param name="g">The graph to traverse</param>
 /// <exception cref="ArgumentNullException">g is null</exception>
 public DepthFirstSearchAlgorithm(IVertexListGraph g)
 {
     if (g == null)
         throw new ArgumentNullException("g");
     m_VisitedGraph = g;
     m_Colors = new VertexColorDictionary();
 }
        public ReportResult RunTests()
        {
            ReportResult result = new ReportResult();
            if (graph.VerticesCount == 0)
            {
                this.OnLog("No assembly to execute");
                result.UpdateCounts();
                return result;
            }

            this.OnLog("Sorting assemblies by dependencies");
            // create topological sort
            ArrayList sortedVertices = new ArrayList();
            TopologicalSortAlgorithm topo = new TopologicalSortAlgorithm(graph);
            topo.Compute(sortedVertices);
            if (sortedVertices.Count == 0)
                throw new InvalidOperationException("Cannot be zero");

            // set vertices colors
            this.OnLog("etting up fixture colors");
            VertexColorDictionary colors = new VertexColorDictionary();
            foreach (TestDomainVertex v in graph.Vertices)
                colors.Add(v, GraphColor.White);

            // execute each domain
            foreach (TestDomainVertex v in sortedVertices)
            {
                // if vertex color is not white, skip it
                GraphColor color = colors[v];
                if (color != GraphColor.White)
                {
                    this.OnLog("Skipping assembly {0} because dependent assembly failed", v.Domain.TestEngine.Explorer.AssemblyName);
                    // mark children
                    foreach (TestDomainVertex child in graph.AdjacentVertices(v))
                        colors[child] = GraphColor.Black;
                    continue;
                }

                this.OnLog("Loading {0}", v.Domain.TestEngine.Explorer.AssemblyName);

                ReportCounter counter = v.Domain.TestEngine.GetTestCount();
                this.OnLog("Found  {0} tests", counter.RunCount);
                this.OnLog("Running fixtures.");
                v.Domain.TestEngine.RunPipes();
                counter = v.Domain.TestEngine.GetTestCount();
                this.OnLog("Tests finished: {0} tests, {1} success, {2} failures, {3} ignored"
                    , counter.RunCount
                    , counter.SuccessCount
                    , counter.FailureCount
                    , counter.IgnoreCount
                    );

                result.Merge(v.Domain.TestEngine.Report.Result);

                if (counter.FailureCount != 0)
                {
                    // mark children as failed
                    colors[v] = GraphColor.Black;
                    foreach (TestDomainVertex child in graph.AdjacentVertices(v))
                        colors[child] = GraphColor.Black;
                }
                else
                {
                    // mark vertex as succesfull
                    colors[v] = GraphColor.Gray;
                }
            }

            result.UpdateCounts();
            MbUnit.Framework.Assert.IsNotNull(result);
            MbUnit.Framework.Assert.IsNotNull(result.Counter);

            this.OnLog("All Tests finished: {0} tests, {1} success, {2} failures, {3} ignored in {4} seconds"
                , result.Counter.RunCount
                , result.Counter.SuccessCount
                , result.Counter.FailureCount
                , result.Counter.IgnoreCount
                , result.Counter.Duration
                );

            return result;
        }
        /// <summary>
        /// Generates the dot code to be rendered with GraphViz
        /// </summary>
        /// <param name="outputFileName">output file name</param>
        /// <returns>corrected output file name</returns>
        /// <remarks>
        /// The output filename extension is automatically matched with the
        /// output file type.
        /// </remarks>
        public string Write(string outputFileName)
        {
            if (outputFileName == null)
                throw new ArgumentNullException("outputFileName");

            ClusterCount=0;
            m_StringWriter = new StringWriter();

            Output.WriteLine("digraph G {");

            String gf = GraphFormat.ToDot();
            if (gf.Length > 0)
                Output.WriteLine(gf);
            String vf = CommonVertexFormat.ToDot();
            if (vf.Length > 0)
                Output.WriteLine("node [{0}];",vf);
            String ef = CommonEdgeFormat.ToDot();
            if (ef.Length > 0)
                Output.WriteLine("edge [{0}];",ef);

            OnWriteGraph();

            // initialize vertex map
            VertexColorDictionary colors = new VertexColorDictionary();
            foreach(IVertex v in VisitedGraph.Vertices)
                colors[v]=GraphColor.White;
            EdgeColorDictionary edgeColors = new EdgeColorDictionary();
            foreach(IEdge e in VisitedGraph.Edges)
                edgeColors[e]=GraphColor.White;

            // write
            if (VisitedGraph is IClusteredGraph)
                WriteClusters(colors,edgeColors,VisitedGraph as IClusteredGraph);

            WriteVertices(colors,VisitedGraph.Vertices);
            WriteEdges(edgeColors,VisitedGraph.Edges);

            Output.WriteLine("}");

            return m_Dot.Run(ImageType,Output.ToString(), outputFileName);
        }
Пример #23
0
        private void breadthFirstSearchItem_Click(object sender, System.EventArgs e)
        {
            if (this.netronPanel.Graph==null)
                throw new Exception("Generate a graph first");
            if (this.netronPanel.Populator==null)
                throw new Exception("Populator should not be null.");

            ResetVertexAndEdgeColors();

            // create algorithm
            this.edgeColors=new EdgeColorDictionary();
            foreach(IEdge edge in this.netronPanel.Graph.Edges)
                this.edgeColors[edge]=GraphColor.White;
            this.vertexColors = new VertexColorDictionary();
            BreadthFirstSearchAlgorithm bfs = new BreadthFirstSearchAlgorithm(
                this.netronPanel.Graph,
                new VertexBuffer(),
                this.vertexColors);

            // create tracer
            LayoutAlgorithmTraverVisitor tracer = new LayoutAlgorithmTraverVisitor(this.netronPanel.Populator);

            // link to algo
            bfs.RegisterTreeEdgeBuilderHandlers(tracer);
            bfs.RegisterVertexColorizerHandlers(tracer);

            bfs.TreeEdge +=new EdgeEventHandler(dfs_TreeEdge);
            bfs.NonTreeEdge+=new EdgeEventHandler(dfs_BackEdge);
            bfs.BlackTarget +=new EdgeEventHandler(dfs_ForwardOrCrossEdge);

            // add handler to tracers
            tracer.UpdateVertex +=new ShapeVertexEventHandler(tracer_UpdateVertex);
            tracer.UpdateEdge +=new ConnectionEdgeEventHandler(tracer_UpdateEdge);

            // running algorithm
            VertexMethodCaller vm=
                new VertexMethodCaller(
                    new ComputeVertexDelegate(bfs.Compute),
                    Traversal.FirstVertex(this.netronPanel.Graph)
                    );
            Thread thread = new Thread(new ThreadStart(vm.Run));
            thread.Start();
        }
        internal void WriteClusters(
            VertexColorDictionary colors,
            EdgeColorDictionary edgeColors,
            IClusteredGraph parent
            )
        {
            ++ClusterCount;
            foreach(IVertexAndEdgeListGraph g in parent.Clusters)
            {
                Output.Write("subgraph cluster{0}",ClusterCount.ToString());
                Output.WriteLine(" {");

                OnFormatCluster(g);

                if (g is IClusteredGraph)
                    WriteClusters(colors,edgeColors, g as IClusteredGraph);

                if (parent.Colapsed)
                {
                    // draw cluster
                    // put vertices as black
                    foreach(IVertex v in g.Vertices)
                    {
                        colors[v]=GraphColor.Black;

                    }
                    foreach(IEdge e in g.Edges)
                        edgeColors[e]=GraphColor.Black;

                    // add fake vertex

                }
                else
                {
                    WriteVertices(colors,g.Vertices);
                    WriteEdges(edgeColors,g.Edges);
                }

                Output.WriteLine("}");
            }
        }
Пример #25
0
        private void edgeDepthFirstSearchItem_Click(object sender, System.EventArgs e)
        {
            if (this.netronPanel.Graph==null)
                throw new Exception("Generate a graph first");
            if (this.netronPanel.Populator==null)
                throw new Exception("Populator should not be null.");

            ResetVertexAndEdgeColors();

            // create algorithm
            this.vertexColors=null;
            this.edgeColors = new EdgeColorDictionary();
            EdgeDepthFirstSearchAlgorithm edfs =
                new EdgeDepthFirstSearchAlgorithm(this.netronPanel.Graph,this.edgeColors);

            // create tracer
            LayoutAlgorithmTraverVisitor tracer = new LayoutAlgorithmTraverVisitor(this.netronPanel.Populator);

            // link to algo
            edfs.RegisterTreeEdgeBuilderHandlers(tracer);
            edfs.RegisterEdgeColorizerHandlers(tracer);

            // add handler to tracers
            tracer.UpdateVertex +=new ShapeVertexEventHandler(tracer_UpdateVertex);
            tracer.UpdateEdge +=new ConnectionEdgeEventHandler(tracer_UpdateEdge);

            // running algorithm
            Thread thread = new Thread(new ThreadStart(edfs.Compute));
            thread.Start();
        }
 internal void WriteVertices(VertexColorDictionary colors,
     IVertexEnumerable vertices)
 {
     foreach(IVertex v in vertices)
     {
         if(colors[v]==GraphColor.White)
         {
             OnWriteVertex(v);
             OnFormatVertex(v);
             colors[v]=GraphColor.Black;
         }
     }
 }