Esempio n. 1
0
        // TODO: adjust for traversal direction
        private IEnumerable <SimpleTreeNode <T> > GetBreadthFirstEnumerable(TreeTraversalDirection TraversalDirection)
        {
            if (TraversalDirection == TreeTraversalDirection.BottomUp)
            {
                var stack = new Stack <SimpleTreeNode <T> >();
                foreach (var item in GetBreadthFirstEnumerable(TreeTraversalDirection.TopDown))
                {
                    stack.Push(item);
                }
                while (stack.Count > 0)
                {
                    yield return(stack.Pop());
                }
                yield break;
            }

            var queue = new Queue <SimpleTreeNode <T> >();

            queue.Enqueue(this);

            while (0 < queue.Count)
            {
                SimpleTreeNode <T> node = queue.Dequeue();

                foreach (SimpleTreeNode <T> child in node.Children)
                {
                    queue.Enqueue(child);
                }

                yield return(node);
            }
        }
        public SimpleTreeNode <T> Add(T Value)
        {
            SimpleTreeNode <T> Node = new SimpleTreeNode <T>(Parent);

            Node.Value = Value;
            return(Node);
        }
Esempio n. 3
0
        // TODO: adjust for traversal direction
        private IEnumerable <SimpleTreeNode <T> > GetBreadthFirstEnumerable(TreeTraversalDirection TraversalDirection)
        {
            if (TraversalDirection == TreeTraversalDirection.BottomUp)
            {
                var stack = new Stack <SimpleTreeNode <T> >();
                foreach (var item in GetBreadthFirstEnumerable(TreeTraversalDirection.TopDown))
                {
                    stack.Push(item);
                }
                while (stack.Count > 0)
                {
                    yield return(stack.Pop());
                }
                yield break;
            }

            var queue = new Queue <SimpleTreeNode <T> >();

            queue.Enqueue(this);

            while (queue.Count > 0)
            {
                GridSolver.MoveCount++;

                SimpleTreeNode <T> node = queue.Dequeue();

                foreach (SimpleTreeNode <T> child in node.Children)
                {
                    queue.Enqueue(child);
                }

                if (queue.Count % 1000 == 0)
                {
                    Log.Debug("Queue size: {QueueSize}", queue.Count);
                }

                yield return(node);
            }
        }
Esempio n. 4
0
        public IEnumerable <SimpleTreeNode <T> > GetPriorityFirstEnumerable(IComparer <SimpleTreeNode <T> > comparer)
        {
            var queue = new PriorityQueue <SimpleTreeNode <T> >(comparer);

            queue.Add(this);

            while (queue.Count > 0)
            {
                GridSolver.MoveCount++;

                SimpleTreeNode <T> node = queue.Take();

                foreach (SimpleTreeNode <T> child in node.Children)
                {
                    queue.Add(child);
                    if (queue.Count % 1000 == 0)
                    {
                        Log.Debug("Queue size: {QueueSize}", queue.Count);
                    }
                }

                yield return(node);
            }
        }
 public new SimpleTreeNode <T> Add(SimpleTreeNode <T> Node)
 {
     base.Add(Node);
     Node.Parent = Parent;
     return(Node);
 }
 public SimpleTreeNodeList(SimpleTreeNode <T> Parent)
 {
     this.Parent = Parent;
 }
Esempio n. 7
0
 public SimpleTreeNode(SimpleTreeNode <T> Parent)
 {
     this.Parent = Parent;
     Children    = new SimpleTreeNodeList <T>(this);
 }
Esempio n. 8
0
 public SimpleTreeNode(SimpleTreeNode <T> Parent, SimpleTreeNodeList <T> Children)
 {
     this.Parent     = Parent;
     this.Children   = Children;
     Children.Parent = this;
 }
Esempio n. 9
0
 public int CompareTo(SimpleTreeNode <T> other)
 {
     return(other.Value.CompareTo(Value));
 }