コード例 #1
0
        public int CompareTo(object other)
        {
            if (other == null)
            {
                return(1);
            }

            HeuristicNode <T> otherHeuristicNode = other as HeuristicNode <T>;

            return(this.CompareTo(otherHeuristicNode));
        }
コード例 #2
0
        public SearchResult <T> Search()
        {
            T state = Problem.InitialState;
            HeuristicNode <T> node = new HeuristicNode <T>(state, 1);

            if (Problem.GoalTest(state))
            {
                return(new SearchResult <T>(node));
            }
            PriorityQueue.Push(node);
            OpenList.Add(state);

            while (!PriorityQueue.IsEmpty)
            {
                node  = PriorityQueue.Pop();
                state = node.State;
                ClosedList.Add(state);
                foreach (IAction <T> action in Problem.Actions(state))
                {
                    HeuristicNode <T> childNode = node.ChildNode(Problem, action, Heuristic);
                    T childState = childNode.State;
                    if (ClosedList.Contains(childState) || OpenList.Contains(childState))
                    {
                        if (PriorityQueue.Contains(childNode) && childNode.HeuristicCost > node.HeuristicCost)
                        {
                            PriorityQueue.Push(childNode);
                            OpenList.Add(childState);
                        }
                    }

                    if (!ClosedList.Contains(childState) && !OpenList.Contains(childState))
                    {
                        if (Problem.GoalTest(childState))
                        {
                            return(new SearchResult <T>(childNode));
                        }
                        PriorityQueue.Push(childNode);
                        OpenList.Add(childState);
                    }
                }
            }
            return(new SearchResult <T>(null));
        }
コード例 #3
0
 public int CompareTo(HeuristicNode <T> other)
 {
     return(this.HeuristicCost.CompareTo(other.HeuristicCost));
 }