Monday, May 30, 2011

Part IV: Uniform Cost Search

v      Uniform Cost Search

public static void Uniform_Cost_Search(Node Start,Node Goal)
        {
            GetSucc x = new GetSucc();
            ArrayList children = new ArrayList();
            PriorityQueue Fringe = new PriorityQueue();
            Fringe.Enqueue(Start);
            while (Fringe.Count != 0)
            {
                Node Parent = (Node)Fringe.Dequeue();
                Console.WriteLine("Node {0} Visited with Cost {1} ", Parent.State,Parent.Cost);
                if (Parent.State == Goal.State)
                {
                    Console.WriteLine();
                    Console.WriteLine("Find Goal   " + Parent.State);
                    break;
                }//end if
                children = x.GetSussessor(Parent.State,Parent);
                for (int i = 0; i < children.Count; i++)
                {
                    Fringe.Enqueue((Node)children[i]);
                }//end for
                
            }//end while 
        
        }// end method