Beispiel #1
0
 public int GetNextActionsCount(IAction action)
 {
     if (action == null)
     {
         throw new ArgumentNullException("action");
     }
     return(_graph.OutDegree(action));
 }
Beispiel #2
0
        public void OutDegreeSumEqualsEdgeCount([PexAssumeNotNull] IBidirectionalGraph <string, Edge <string> > graph)
        {
            int edgeCount = graph.EdgeCount;
            int degCount  = 0;

            foreach (string v in graph.Vertices)
            {
                degCount += graph.OutDegree(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));
        }
Beispiel #4
0
        public void OutDegreeSumEqualsEdgeCount <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.OutDegree(vertex);
            }

            Assert.AreEqual(edgeCount, degCount);
        }
        private void OutDegreeSumEqualsEdgeCount <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.OutDegree(v);
            }

            Assert.Equal(edgeCount, degCount);
        }
Beispiel #6
0
        private double CalcSequenceWeights(IBidirectionalGraph <Cluster <TSeq>, ClusterEdge <TSeq> > tree, ClusterEdge <TSeq> edge, double curWeight,
                                           Stack <Cluster <TSeq> > nodeStack, Dictionary <Cluster <TSeq>, Profile <TSeq, TItem> > profiles)
        {
            double length = edge.Length;

            if (tree.IsOutEdgesEmpty(edge.Target))
            {
                TSeq   seq    = edge.Target.DataObjects.First();
                double weight = curWeight + length;
                profiles[edge.Target] = CreateProfile(seq, weight);
                return(weight);
            }

            nodeStack.Push(edge.Target);
            double lengthPart = length / tree.OutDegree(edge.Target);
            double maxWeight  = double.MinValue;

            foreach (ClusterEdge <TSeq> childEdge in tree.OutEdges(edge.Target))
            {
                maxWeight = Math.Max(maxWeight, CalcSequenceWeights(tree, childEdge, curWeight + lengthPart, nodeStack, profiles));
            }
            return(maxWeight);
        }
Beispiel #7
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));
 }
        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));
        }
Beispiel #9
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));
        }