예제 #1
0
        /// <inheritdoc />
        int IReadonlyDirectedGraph.CountIncomingHeavyEdges(NodeId node)
        {
            int count = 0;

            foreach (var edge in m_graph.GetIncomingEdges(node))
            {
                if (!edge.IsLight && m_nodeFilter.WasVisited(edge.OtherNode))
                {
                    count++;
                }
            }

            return(count);
        }
예제 #2
0
        private void TestGraphSerializationPerformCommonValidations(DirectedGraph graph, NodeId[] nodes, IReadonlyDirectedGraph sourceGraph)
        {
            XAssert.AreEqual(graph.NodeCount, nodes.Length);
            XAssert.AreEqual(graph.EdgeCount, 12);

            XAssert.IsTrue(graph.IsSinkNode(nodes[0]));
            XAssert.IsTrue(graph.IsSinkNode(nodes[1]));
            XAssert.IsTrue(graph.IsSinkNode(nodes[2]));
            XAssert.IsTrue(graph.IsSinkNode(nodes[3]));
            XAssert.IsTrue(graph.IsSinkNode(nodes[4]));
            XAssert.IsTrue(graph.IsSourceNode(nodes[7]));
            XAssert.IsTrue(graph.IsSourceNode(nodes[10]));
            XAssert.IsTrue(graph.IsSourceNode(nodes[11]));

            XAssert.IsFalse(graph.IsSourceNode(nodes[6]));
            XAssert.IsFalse(graph.IsSinkNode(nodes[6]));

            foreach (var node in sourceGraph.Nodes)
            {
                XAssert.IsTrue(EdgeSetEqual(new HashSet <Edge>(sourceGraph.GetOutgoingEdges(node)), new HashSet <Edge>(graph.GetOutgoingEdges(node))));
                XAssert.IsTrue(EdgeSetEqual(new HashSet <Edge>(sourceGraph.GetIncomingEdges(node)), new HashSet <Edge>(graph.GetIncomingEdges(node))));
            }

            VerifyNodeHeights(graph, nodes);

            var succOfNode9 = new HashSet <Edge>(graph.GetOutgoingEdges(nodes[9]));

            XAssert.IsTrue(
                EdgeSetEqual(
                    succOfNode9,
                    new HashSet <Edge>
            {
                new Edge(nodes[6]),
                new Edge(nodes[3]),
                new Edge(nodes[4])
            }));

            var predOfNode8 = new HashSet <Edge>(graph.GetIncomingEdges(nodes[8]));

            XAssert.IsTrue(
                EdgeSetEqual(
                    predOfNode8,
                    new HashSet <Edge>
            {
                new Edge(nodes[10]),
                new Edge(nodes[11])
            }));
        }
예제 #3
0
        private void VisitTransitiveClosure(
            Queue <NodeId> queue,
            VisitationTracker visitedNodes,
            VisitNode visitNodeDependencies,
            VisitNode visitNodeDependents,
            bool dependencies,
            bool dependents)
        {
            Contract.Assert(visitNodeDependencies == null || dependencies);
            Contract.Assert(visitNodeDependents == null || dependents);

            while (queue.Count != 0)
            {
                var node = queue.Dequeue();

                if (dependencies)
                {
                    if (visitNodeDependencies == null || visitNodeDependencies(node))
                    {
                        foreach (Edge inEdge in m_dataflowGraph.GetIncomingEdges(node))
                        {
                            if (visitedNodes.MarkVisited(inEdge.OtherNode))
                            {
                                queue.Enqueue(inEdge.OtherNode);
                            }
                        }
                    }
                }

                if (dependents)
                {
                    if (visitNodeDependents == null || visitNodeDependents(node))
                    {
                        foreach (Edge outEdge in m_dataflowGraph.GetOutgoingEdges(node))
                        {
                            if (visitedNodes.MarkVisited(outEdge.OtherNode))
                            {
                                queue.Enqueue(outEdge.OtherNode);
                            }
                        }
                    }
                }
            }
        }