Exemplo n.º 1
0
        public static void FillGraph(IGraph <int> graph, int levels, int descendants, int precedents)
        {
            var nodes = new Dictionary <int, QueueElement>();

            ValidateParameters(descendants, precedents);

            var parentQueue   = new Queue <QueueElement>();
            var childrenQueue = new LinkedList <QueueElement>();
            var rootNodeCount = NodesOnLevel(0, levels, descendants, precedents);

            for (var i = 0; i < rootNodeCount; i++) // add root's
            {
                EnqueueParent(parentQueue, GetOrCreateNode(nodes, nodes.Count));
            }

            var nodeCount = CalculateNodeCount(levels, descendants, precedents);

            while (graph.CountNodes < nodeCount || childrenQueue.Count != 0)
            {
                var parent        = DequeueFreeParent(parentQueue, descendants);
                var nextChildNode = DequeueFreeChild(childrenQueue, parent, precedents);
                if (nextChildNode == null)
                {
                    nextChildNode = GetOrCreateNode(nodes, nodes.Count);
                    EnqueueParent(parentQueue, nextChildNode);
                    EnqueueChild(childrenQueue, nextChildNode, precedents);
                }
                parent.Edges.Add(nextChildNode.Node);

                graph.AddSequence(new[] { parent.Node, nextChildNode.Node });
            }
        }
        public static void FillGraph(IGraph<int> graph, int levels, int descendants, int precedents)
        {
            var nodes = new Dictionary<int, QueueElement>();
            ValidateParameters(descendants, precedents);

            var parentQueue = new Queue<QueueElement>();
            var childrenQueue = new LinkedList<QueueElement>();
            var rootNodeCount = NodesOnLevel(0, levels, descendants, precedents);
            for (var i = 0; i < rootNodeCount; i++) // add root's
                EnqueueParent(parentQueue, GetOrCreateNode(nodes, nodes.Count));

            var nodeCount = CalculateNodeCount(levels, descendants, precedents);
            while (graph.CountNodes < nodeCount || childrenQueue.Count != 0)
            {
                var parent = DequeueFreeParent(parentQueue, descendants);
                var nextChildNode = DequeueFreeChild(childrenQueue, parent, precedents);
                if (nextChildNode == null)
                {
                    nextChildNode = GetOrCreateNode(nodes, nodes.Count);
                    EnqueueParent(parentQueue, nextChildNode);
                    EnqueueChild(childrenQueue, nextChildNode, precedents);
                }
                parent.Edges.Add(nextChildNode.Node);

                graph.AddSequence(new[] { parent.Node, nextChildNode.Node });
            }
        }
Exemplo n.º 3
0
        private IGraph Term()
        {
            IGraph graph = null;

            if (!_regexParser.More() || _regexParser.Peek.GrammarClass != RegularExpressionGrammarClass.Terminal && _regexParser.Peek.Value != "(")
            {
                return(graph);
            }

            graph = Factor();
            graph.AddSequence(Term());

            return(graph);
        }