public void AddedToSortedOpenList(StateNode IN_state_node)
        {
            IN_state_node.mTailly = null;
            bool add_result = this.mOpenSortedList.Add(IN_state_node);

            if (false == add_result)
            {
                SortedSet <StateNode> view_sn    = this.mOpenSortedList.GetViewBetween(IN_state_node, IN_state_node);
                StateNode             found_node = view_sn.Min;
                if (null == found_node.mTailly)
                {
                    found_node.mTailly = new LinkedList <StateNode>();
                }
                found_node.mTailly.AddLast(IN_state_node);
                //StateNode to_next_node_in_chain_of_found_node = found_node.mNextNodeWithSameHeuristic;
                //to_next_node_in_chain_of_found_node can be null, but it does not matter
                //found_node.mNextNodeWithSameHeuristic = IN_state_node;
                //IN_state_node.mNextNodeWithSameHeuristic = to_next_node_in_chain_of_found_node;

                //while (null != to_find_the_last_node_in_chain_of_found_node.mNextNodeWithSameHeuristic)
                //{
                //    to_find_the_last_node_in_chain_of_found_node = to_find_the_last_node_in_chain_of_found_node.mNextNodeWithSameHeuristic;
                //}
                //to_find_the_last_node_in_chain_of_found_node.mNextNodeWithSameHeuristic = IN_state_node;
                //if (to_find_the_last_node_in_chain_of_found_node.Equals(IN_state_node))
                //{
                //    //something wrong
                //    int bp = 0;
                //}
            }
        }
Example #2
0
        private void ResetTree()
        {
            State root_state = this.mRootNode.InnerState;

            this.mRootNode            = null;
            this.mRootNode            = StateNode.CreateNewRootNode(root_state, new LoopKiller());
            this.mCurrentVisitingNode = null;
            this.mLoopKiller.Reset();
            StateTree.smVisitedNodesCount = 0;
        }
 public StateNode PopFromOpenStack()
 {
     if (null != this.mOpenList.First)
     {
         StateNode top = this.mOpenList.First.Value;
         this.mOpenList.RemoveFirst();
         return(top);
     }
     else
     {
         return(null);
     }
 }
Example #4
0
        private VisitResult HIIDFSVisitNextNode(int until_level)
        {
            this.mCurrentVisitingNode = this.mLoopKiller.PollMinFromSortedOpenList();    //poll the smaller one

            if (null == this.mCurrentVisitingNode)
            {
                return(VisitResult.VisitedNodeExceededMaxLevel);
            }
            else
            {
                if (this.mCurrentVisitingNode.Level > until_level)
                {
                    //something wrong
                }
                smVisitedNodesCount++;
                this.mCurrentVisitingNode.ToBeVisited();
                if (true == this.mCurrentVisitingNode.InnerState.Goal)
                {
                    //reached the goal node
                    return(VisitResult.VisitedNodeGoal);
                }
                else
                {
                    //if (!this.mCurrentVisitingNode.Children.Any())
                    //{
                    //    this.mCurrentVisitingNode.Branch();
                    //}
                    //else
                    //{
                    //    int bp = 0;
                    //    //something wrong;
                    //}
                    if (until_level > this.mCurrentVisitingNode.Level)
                    {
                        List <StateNode> lst_children_node_of_current_node = this.mCurrentVisitingNode.BranchChildren();
                        foreach (StateNode sn in lst_children_node_of_current_node)
                        {
                            this.mLoopKiller.AddedToSortedOpenList(sn);         //it doesn't matter whether it is used as stack or queue.
                        }
                    }
                    return(VisitResult.VisitedNodeNotAGoal);
                }
            }
        }
        public StateNode PollMinFromSortedOpenList()
        {
            StateNode min_sn = this.mOpenSortedList.Min;

            if (null != min_sn)
            {
                LinkedList <StateNode> tailly_min_sn = min_sn.mTailly;
                if (null != tailly_min_sn)
                {
                    StateNode new_min_sn = tailly_min_sn.First.Value;
                    tailly_min_sn.RemoveFirst();
                    if (new_min_sn.mTailly == null)         //this if-else is just for debug.
                    {
                        if (true == tailly_min_sn.Any())
                        {
                            new_min_sn.mTailly = tailly_min_sn;
                        }
                        else
                        {
                            new_min_sn.mTailly = null;
                        }
                    }
                    else
                    {
                        //something wrong
                        int bp = 0;
                    }
                    this.mOpenSortedList.Remove(min_sn);
                    bool add_result = this.mOpenSortedList.Add(new_min_sn);
                    if (false == add_result)
                    {
                        //something wrong
                        int bp = 0;
                    }
                }
                else
                {
                    //if min_sn is the only one with the value in mOpenSortedList, just remove it after polling.
                    this.mOpenSortedList.Remove(min_sn);
                }
                min_sn.mTailly = null;
            }
            return(min_sn);
        }
Example #6
0
 //uninformed DFS
 private VisitResult DFSVisitNextNode()
 {
     this.mCurrentVisitingNode = this.mLoopKiller.PopFromOpenStack();
     this.mCurrentVisitingNode.ToBeVisited();
     if (true == this.mCurrentVisitingNode.InnerState.Goal)
     {
         //reached the goal node
         return(VisitResult.VisitedNodeGoal);
     }
     else
     {
         //this.mCurrentVisitingNode.Branch();
         List <StateNode> lst_children_node_of_current_node = this.mCurrentVisitingNode.BranchChildren();
         foreach (StateNode sn in lst_children_node_of_current_node)
         {
             this.mLoopKiller.PushToOpenStack(sn);
         }
         return(VisitResult.VisitedNodeNotAGoal);
     }
 }
Example #7
0
        private LoopKiller mLoopKiller;         //but closelist will be useless for this class.

        public StateTree(State root_node_state)
        {
            this.mLoopKiller = new LoopKiller();
            this.mRootNode   = StateNode.CreateNewRootNode(root_node_state, new LoopKiller());
        }
Example #8
0
        private VisitResult IIDFSVisitNextNode(int until_level)
        {
            this.mCurrentVisitingNode = this.mLoopKiller.PopFromOpenStack();
            if (null == this.mCurrentVisitingNode)
            {
                return(VisitResult.VisitedNodeExceededMaxLevel);
            }
            else
            {
                if (this.mCurrentVisitingNode.Level > until_level)
                {
                    //something wrong
                    int bp = 0;
                }
                smVisitedNodesCount++;
                this.mCurrentVisitingNode.ToBeVisited();
                if (true == this.mCurrentVisitingNode.InnerState.Goal)
                {
                    //reached the goal node
                    return(VisitResult.VisitedNodeGoal);
                }
                else
                {
                    //if (!this.mCurrentVisitingNode.Children.Any())
                    //{
                    //    this.mCurrentVisitingNode.Branch();
                    //}
                    //else
                    //{
                    //    int bp = 0;
                    //    //something wrong;
                    //}
                    if (until_level > this.mCurrentVisitingNode.Level)
                    {
                        List <StateNode> lst_children_node_of_current_node = this.mCurrentVisitingNode.BranchChildren();
                        foreach (StateNode sn in lst_children_node_of_current_node)
                        {
                            this.mLoopKiller.PushToOpenStack(sn);
                        }
                    }
                    return(VisitResult.VisitedNodeNotAGoal);
                }
            }
            #region deprecated code

            /*
             * if (until_level >= this.mCurrentVisitingNode.Level)
             * {
             *  smVisitedNodesCount++;
             *  this.mCurrentVisitingNode.ToBeVisited();
             *  if (true == this.mCurrentVisitingNode.InnerState.Goal)
             *  {
             *      //reached the goal node
             *      return VisitResult.VisitedNodeGoal;
             *  }
             *  else
             *  {
             *      if (!this.mCurrentVisitingNode.Children.Any())
             *      {
             *          this.mCurrentVisitingNode.Branch();
             *      }
             *      else
             *      {
             *          int bp = 0;
             *          //something wrong;
             *      }
             *      if (until_level > this.mCurrentVisitingNode.Level)
             *      {
             *          List<StateNode> lst_children_node_of_current_node = this.mCurrentVisitingNode.Children;
             *          foreach (StateNode sn in lst_children_node_of_current_node)
             *          {
             *              this.mLoopKiller.PushToOpenStack(sn);
             *          }
             *      }
             *      return VisitResult.VisitedNodeNotAGoal;
             *  }
             * }
             * else
             * {
             *  //this.mLoopKiller.PushToOpenStack(this.mCurrentVisitingNode);
             *  return VisitResult.VisitedNodeExceededMaxLevel;
             * }
             * */
            #endregion
        }
 public void PushToOpenStack(StateNode IN_state_node)
 {
     this.mOpenList.AddFirst(IN_state_node);
 }
        //public StateNode PollSmallestFromOpenList()     //depricated due to bad performance.
        //{
        //    if (true == this.mOpenList.Any())
        //    {
        //        var smallest_node = this.mOpenList.First;
        //        var iterator_node = this.mOpenList.First.Next;
        //        while (null != iterator_node)
        //        {
        //            if (iterator_node.Value < smallest_node.Value)
        //            {
        //                smallest_node = iterator_node;
        //            }
        //            iterator_node = iterator_node.Next;

        //        }
        //        StateNode smallest_value = smallest_node.Value;
        //        this.mOpenList.Remove(smallest_node);
        //        return smallest_value;
        //    }
        //    else
        //    {
        //        return null;
        //    }
        //}

        public void OfferToOpenQueue(StateNode IN_state_node)
        {
            this.mOpenList.AddLast(IN_state_node);
        }