Skip to content

Commit 1e96cd1

Browse files
SkAdilinanorvig
authored andcommitted
Added Node in search.ipynb (#761)
1 parent ae4f1cf commit 1e96cd1

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

search.ipynb

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"cell_type": "code",
1616
"execution_count": 1,
1717
"metadata": {
18+
"collapsed": true,
1819
"scrolled": true
1920
},
2021
"outputs": [],
@@ -82,7 +83,7 @@
8283
},
8384
{
8485
"cell_type": "code",
85-
"execution_count": null,
86+
"execution_count": 2,
8687
"metadata": {
8788
"collapsed": true
8889
},
@@ -115,6 +116,51 @@
115116
"* `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."
116117
]
117118
},
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+
},
118164
{
119165
"cell_type": "markdown",
120166
"metadata": {},

0 commit comments

Comments
 (0)