Exemple #1
0
        /// <summary>
        /// Main method where the program execution starts
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            Node startNode = new Node();
            Node goalNode  = new Node();

            //Prompts the user to enter start state and goal state
            Console.WriteLine("Enter the start state:");
            startNode.State = CheckInput();
            Console.WriteLine("Enter the goal state:");
            goalNode.State = CheckInput();

            startNode.PathCost = 0;
            startNode.Parent   = null;

            Node bestNode = new Node();

            //Create an object of AStarProgram and call the AStar algorithm
            AStarProgram astar = new AStarProgram();

            bestNode = astar.AStar(startNode, goalNode);

            //Used a stack to display the path of solution
            Stack <Node> result = new Stack <Node>();

            if (bestNode != null)
            {
                while (bestNode.Parent != null)
                {
                    result.Push(bestNode);
                    bestNode = bestNode.Parent;
                }
            }
            else
            {
                //if bestnode is null then display
                Console.WriteLine("Solution does not exist");
            }

            //Print the solution, Number of nodes generated and nodes expanded
            Console.WriteLine("Number of Nodes in solution path : " + result.Count());
            Node tempNode = new Node();

            startNode.PrintState();
            Console.WriteLine();
            while (result.Count != 0)
            {
                tempNode = result.Pop();
                tempNode.PrintState();
                Console.WriteLine();
            }
            Console.WriteLine(); Console.WriteLine();
            Console.WriteLine("Number of Nodes generated : " + AStarProgram.noOfNodesGenerated);
            Console.WriteLine("Number of Nodes Expanded : " + AStarProgram.noOfNodesExpanded);
            Console.Read();
        }
Exemple #2
0
        /// <summary>
        /// Main method where the program execution starts
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            Node startNode = new Node();
            Node goalNode = new Node();

            //Prompts the user to enter start state and goal state
            Console.WriteLine("Enter the start state:");
            startNode.State = CheckInput();
            Console.WriteLine("Enter the goal state:");
            goalNode.State = CheckInput();

            startNode.PathCost = 0;
            startNode.Parent = null;

            Node bestNode = new Node();

            //Create an object of AStarProgram and call the AStar algorithm
            AStarProgram astar = new AStarProgram();
            bestNode = astar.AStar(startNode, goalNode);

            //Used a stack to display the path of solution
            Stack<Node> result = new Stack<Node>();
            if (bestNode != null)
            {
                while (bestNode.Parent != null)
                {
                    result.Push(bestNode);
                    bestNode = bestNode.Parent;
                }
            }
            else
            {
                //if bestnode is null then display
                Console.WriteLine("Solution does not exist");
            }

            //Print the solution, Number of nodes generated and nodes expanded
            Console.WriteLine("Number of Nodes in solution path : " + result.Count());
            Node tempNode = new Node();
            startNode.PrintState();
            Console.WriteLine();
            while (result.Count != 0)
            {
                tempNode = result.Pop();
                tempNode.PrintState();
                Console.WriteLine();
            }
            Console.WriteLine(); Console.WriteLine();
            Console.WriteLine("Number of Nodes generated : " + AStarProgram.noOfNodesGenerated);
            Console.WriteLine("Number of Nodes Expanded : " + AStarProgram.noOfNodesExpanded);
            Console.Read();
        }