Sunday, May 29, 2011

AI- Simple Implementation of Uninformed Search Strategies - Part I

The first class in my code is Node.cs which represents the node as a data structure in the state space. Each node has some attributes such as depth, cost, state, and parent node. The state attribute is defined according to a physical configuration within the problem state space. My code is simply search for a number in the state space of positive numbers so the state here is defined simply as an integer number.
Lets explore the Node class by the following snippet:


// class Node.cs
class Node
    {
      public  int depth;
      public  int State;
      public  int Cost;
      public  Node Parent;
 // Parent Node  which has depth =0 and parent = null;
      public Node (int State)
        {
              this.State = State;
              this.Parent = null;
              this.depth = 0;
        }
// another form of Node Costructor which accepts only the State;
      public Node(int State)
        {
            this.State = State;
        }
            // this form of Generalization of Node Constructor which accept any node root or ordinary node;
      public Node(int State,Node Parent)
        {
            this.State = State;
            this.Parent = Parent;
            if (Parent == null)
                this.depth = 0;
              else
                this.depth = Parent.depth + 1;
        
        }
     // this form of Generalization of Node Constructor which accept any node root or ordinary node and  accept the cost of each node;
      public Node(int State, Node Parent, int Cost)
        {
            this.State = State;
            this.Parent = Parent;
            this.Cost = Cost;
            if (Parent == null)
               this.depth = 0; 
              else
               this.depth = Parent.depth + 1; 
            
                
        }
    }

No comments:

Post a Comment