Example #1
0
 /// <summary>
 /// Returns with the sources in the graph.
 /// </summary>
 /// <typeparam name="TVertex"></typeparam>
 /// <typeparam name="TEdge"></typeparam>
 /// <param name="g">The graph.</param>
 /// <returns>Returns with the sources in the graph.</returns>
 public static IEnumerable <TVertex> GetSources <TVertex, TEdge>(this IBidirectionalGraph <TVertex, TEdge> g)
     where TEdge : IEdge <TVertex>
 {
     return(from v in g.Vertices
            where g.InDegree(v) == 0
            select v);
 }
Example #2
0
 public int GetPrevActionsCount(IAction action)
 {
     if (action == null)
     {
         throw new ArgumentNullException("action");
     }
     return(_graph.InDegree(action));
 }
Example #3
0
        public void InDegreeSumEqualsEdgeCount([PexAssumeNotNull] IBidirectionalGraph <string, Edge <string> > graph)
        {
            int edgeCount = graph.EdgeCount;
            int degCount  = 0;

            foreach (string v in graph.Vertices)
            {
                degCount += graph.InDegree(v);
            }

            Assert.AreEqual(edgeCount, degCount);
        }
        public static void BidirectionalContainsEdgeAssertions(
            [NotNull] IBidirectionalGraph <int, IEdge <int> > graph,
            [NotNull] IEdge <int> e12,
            [NotNull] IEdge <int> f12,
            [CanBeNull] IEdge <int> e21,
            [CanBeNull] IEdge <int> f21)
        {
            Assert.AreEqual(0, graph.InDegree(1));
            Assert.AreEqual(1, graph.OutDegree(1));
            Assert.AreEqual(1, graph.InDegree(2));
            Assert.AreEqual(0, graph.OutDegree(2));
            Assert.AreEqual(1, graph.OutEdges(1).Count());
            Assert.AreEqual(1, graph.InEdges(2).Count());

            // e12 must be present in u, because we added it.
            Assert.IsTrue(graph.ContainsEdge(e12));

            // f12 is also in u, because e12 == f12.
            Assert.IsTrue(graph.ContainsEdge(f12));

            // e21 and f21 are not in u, because it's a directed graph.
            if (e21 != null)
            {
                Assert.IsFalse(graph.ContainsEdge(e21));
            }
            if (f21 != null)
            {
                Assert.IsFalse(graph.ContainsEdge(f21));
            }

            // There must be an edge between vertices 1, 2.
            Assert.IsTrue(graph.ContainsEdge(1, 2));

            // No edge between vertices 2, 1, because the graph is directed.
            Assert.IsFalse(graph.ContainsEdge(2, 1));

            // ContainsEdge(1, 3) raises contracts violation in IncidenceGraphContract, because 3 is not in the graph.
            // obviously no edge between vertices 1, 3, as vertex 3 is not even present in the graph.
            // Assert.IsFalse(g.ContainsEdge(1, 3));
        }
Example #5
0
        private static void AssertInDegreeSumEqualsEdgeCount <TVertex, TEdge>(
            [NotNull] IBidirectionalGraph <TVertex, TEdge> graph)
            where TEdge : IEdge <TVertex>
        {
            int totalInDegree = 0;

            foreach (TVertex vertex in graph.Vertices)
            {
                totalInDegree += graph.InDegree(vertex);
            }

            Assert.AreEqual(graph.EdgeCount, totalInDegree);
        }
Example #6
0
        public void InDegreeSumEqualsEdgeCount <TVertex, TEdge>(
            [NotNull] IBidirectionalGraph <TVertex, TEdge> graph)
            where TEdge : IEdge <TVertex>
        {
            int edgeCount = graph.EdgeCount;
            int degCount  = 0;

            foreach (TVertex vertex in graph.Vertices)
            {
                degCount += graph.InDegree(vertex);
            }

            Assert.AreEqual(edgeCount, degCount);
        }
        private void InDegreeSumEqualsEdgeCount <TVertex, TEdge>(
            IBidirectionalGraph <TVertex, TEdge> graph)
            where TEdge : IEdge <TVertex>
        {
            int edgeCount = graph.EdgeCount;
            int degCount  = 0;

            foreach (var v in graph.Vertices)
            {
                degCount += graph.InDegree(v);
            }

            Assert.Equal(edgeCount, degCount);
        }
Example #8
0
 public static int Degree <TVertex, TEdge>(this IBidirectionalGraph <TVertex, TEdge> graph,
                                           TVertex vertex, EdgeDirection direction)
     where TEdge : IEdge <TVertex>
 {
     return(direction == EdgeDirection.In ? graph.InDegree(vertex) : graph.OutDegree(vertex));
 }
 private Node GetRootNode()
 {
     return(this.visualGraph.Vertices.Where(node => visualGraph.InDegree(node) == 0).First());
 }
        public static void ContainsEdgeAssertions(IBidirectionalGraph<int, IEdge<int>> g,
            IEdge<int> e12,
            IEdge<int> f12,
            IEdge<int> e21,
            IEdge<int> f21)
        {
            Assert.AreEqual(0, g.InDegree(1));
            Assert.AreEqual(1, g.OutDegree(1));
            Assert.AreEqual(1, g.InDegree(2));
            Assert.AreEqual(0, g.OutDegree(2));
            Assert.AreEqual(1, g.OutEdges(1).Count());
            Assert.AreEqual(1, g.InEdges(2).Count());

            // e12 must be present in u, because we added it.
            Assert.IsTrue(g.ContainsEdge(e12));

            // f12 is also in u, because e12 == f12.
            Assert.IsTrue(g.ContainsEdge(f12));

            // e21 and f21 are not in u, because it's a directed graph.
            if (e21 != null) Assert.IsFalse(g.ContainsEdge(e21));
            if (f21 != null) Assert.IsFalse(g.ContainsEdge(f21));

            // there must be an edge between vertices 1, 2.
            Assert.IsTrue(g.ContainsEdge(1, 2));

            // no edge between vertices 2, 1, because the graph is directed.
            Assert.IsFalse(g.ContainsEdge(2, 1));

            // ContainsEdge(1, 3) raises contracts violation in IIncidenceGraphContract, because 3 is not in the graph.
            // obviously no edge between vertices 1, 3, as vertex 3 is not even present in the graph.
            // Assert.IsFalse(g.ContainsEdge(1, 3));
        }
Example #11
0
        public GraphStatistics(IMutableBidirectionalGraph <CyclicCluster, CondensedEdge <DisplayNode, DisplayEdge, CyclicCluster> > clusterGraph, IBidirectionalGraph <DisplayNode, DisplayEdge> simpleGraph)
        {
            ClusterSizeStatistics             = DiscreteStatisticsResult.Create(clusterGraph.Vertices, c => c.VertexCount);
            ClusterSortLayerStatistics        = DiscreteStatisticsResult.Create(clusterGraph.Vertices, c => c.SortLayer);
            ClusterSortLayerFromTopStatistics = DiscreteStatisticsResult.Create(clusterGraph.Vertices, c => c.SortLayerFromTop);

            NodeDependenciesStatistics = DiscreteStatisticsResult.Create(simpleGraph.Vertices.Select(v => new DisplayNodeAndEdges(v, simpleGraph)), v => simpleGraph.OutDegree(v.DisplayNode));
            NodeDependentsStatistics   = DiscreteStatisticsResult.Create(simpleGraph.Vertices.Select(v => new DisplayNodeAndEdges(v, simpleGraph)), v => simpleGraph.InDegree(v.DisplayNode));
        }