|
15 | 15 | "cell_type": "code",
|
16 | 16 | "execution_count": 1,
|
17 | 17 | "metadata": {
|
| 18 | + "collapsed": true, |
18 | 19 | "scrolled": true
|
19 | 20 | },
|
20 | 21 | "outputs": [],
|
|
82 | 83 | },
|
83 | 84 | {
|
84 | 85 | "cell_type": "code",
|
85 |
| - "execution_count": null, |
| 86 | + "execution_count": 2, |
86 | 87 | "metadata": {
|
87 | 88 | "collapsed": true
|
88 | 89 | },
|
|
115 | 116 | "* `value(self, state)` : This acts as a bit of extra information in problems where we try to optimise a value when we cannot do a goal test."
|
116 | 117 | ]
|
117 | 118 | },
|
| 119 | + { |
| 120 | + "cell_type": "markdown", |
| 121 | + "metadata": {}, |
| 122 | + "source": [ |
| 123 | + "## NODE\n", |
| 124 | + "\n", |
| 125 | + "Let's see how we define a Node. Run the next cell to see how abstract class `Node` is defined in the search module." |
| 126 | + ] |
| 127 | + }, |
| 128 | + { |
| 129 | + "cell_type": "code", |
| 130 | + "execution_count": 7, |
| 131 | + "metadata": { |
| 132 | + "collapsed": true |
| 133 | + }, |
| 134 | + "outputs": [], |
| 135 | + "source": [ |
| 136 | + "%psource Node" |
| 137 | + ] |
| 138 | + }, |
| 139 | + { |
| 140 | + "cell_type": "markdown", |
| 141 | + "metadata": {}, |
| 142 | + "source": [ |
| 143 | + "The `Node` class has nine methods.\n", |
| 144 | + "\n", |
| 145 | + "* `__init__(self, state, parent, action, path_cost)` : This method creates a node. `parent` represents the the node that this is a successor of and `action` is the action required to get from the parent node to this node. `path_cost` is the cost to reach current node from parent node.\n", |
| 146 | + "\n", |
| 147 | + "* `__repr__(self)` : This returns the state of this node.\n", |
| 148 | + "\n", |
| 149 | + "* `__lt__(self, node)` : Given a `node`, this method returns `True` if the state of current node is less than the state of the `node`. Otherwise it returns `False`.\n", |
| 150 | + "\n", |
| 151 | + "* `expand(self, problem)` : This methods lists all the neighbouring(reachable in one step) nodes of current node. \n", |
| 152 | + "\n", |
| 153 | + "* `child_node(self, problem, action)` : Given an `action`, this methods returns the immediate neighbour that can be reached with that `action`.\n", |
| 154 | + "\n", |
| 155 | + "* `solution(self)` : This returns the sequence of actions required to reach this node from the root node. \n", |
| 156 | + "\n", |
| 157 | + "* `path(self)` : This returns a list of all the nodes that lies in the path from the root to this node.\n", |
| 158 | + "\n", |
| 159 | + "* `__eq__(self, other)` : This method returns `True` if the state of current node is equal to the other node. Else it returns `False`.\n", |
| 160 | + "\n", |
| 161 | + "* `__hash__(self)` : This returns the hash of the state of current node." |
| 162 | + ] |
| 163 | + }, |
118 | 164 | {
|
119 | 165 | "cell_type": "markdown",
|
120 | 166 | "metadata": {},
|
|
0 commit comments