Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
"source": [
"It has now achieved its goal."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## The Spare Tire Problem"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's consider the problem of changing a flat tire of a car. \n",
"The goal is to mount a spare tire onto the car's axle, given that we have a flat tire on the axle and a spare tire in the trunk. "
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n",
" \"http://www.w3.org/TR/html4/strict.dtd\">\n",
"\n",
"<html>\n",
"<head>\n",
" <title></title>\n",
" <meta http-equiv=\"content-type\" content=\"text/html; charset=None\">\n",
" <style type=\"text/css\">\n",
"td.linenos { background-color: #f0f0f0; padding-right: 10px; }\n",
"span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }\n",
"pre { line-height: 125%; }\n",
"body .hll { background-color: #ffffcc }\n",
"body { background: #f8f8f8; }\n",
"body .c { color: #408080; font-style: italic } /* Comment */\n",
"body .err { border: 1px solid #FF0000 } /* Error */\n",
"body .k { color: #008000; font-weight: bold } /* Keyword */\n",
"body .o { color: #666666 } /* Operator */\n",
"body .ch { color: #408080; font-style: italic } /* Comment.Hashbang */\n",
"body .cm { color: #408080; font-style: italic } /* Comment.Multiline */\n",
"body .cp { color: #BC7A00 } /* Comment.Preproc */\n",
"body .cpf { color: #408080; font-style: italic } /* Comment.PreprocFile */\n",
"body .c1 { color: #408080; font-style: italic } /* Comment.Single */\n",
"body .cs { color: #408080; font-style: italic } /* Comment.Special */\n",
"body .gd { color: #A00000 } /* Generic.Deleted */\n",
"body .ge { font-style: italic } /* Generic.Emph */\n",
"body .gr { color: #FF0000 } /* Generic.Error */\n",
"body .gh { color: #000080; font-weight: bold } /* Generic.Heading */\n",
"body .gi { color: #00A000 } /* Generic.Inserted */\n",
"body .go { color: #888888 } /* Generic.Output */\n",
"body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */\n",
"body .gs { font-weight: bold } /* Generic.Strong */\n",
"body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */\n",
"body .gt { color: #0044DD } /* Generic.Traceback */\n",
"body .kc { color: #008000; font-weight: bold } /* Keyword.Constant */\n",
"body .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */\n",
"body .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */\n",
"body .kp { color: #008000 } /* Keyword.Pseudo */\n",
"body .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */\n",
"body .kt { color: #B00040 } /* Keyword.Type */\n",
"body .m { color: #666666 } /* Literal.Number */\n",
"body .s { color: #BA2121 } /* Literal.String */\n",
"body .na { color: #7D9029 } /* Name.Attribute */\n",
"body .nb { color: #008000 } /* Name.Builtin */\n",
"body .nc { color: #0000FF; font-weight: bold } /* Name.Class */\n",
"body .no { color: #880000 } /* Name.Constant */\n",
"body .nd { color: #AA22FF } /* Name.Decorator */\n",
"body .ni { color: #999999; font-weight: bold } /* Name.Entity */\n",
"body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */\n",
"body .nf { color: #0000FF } /* Name.Function */\n",
"body .nl { color: #A0A000 } /* Name.Label */\n",
"body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */\n",
"body .nt { color: #008000; font-weight: bold } /* Name.Tag */\n",
"body .nv { color: #19177C } /* Name.Variable */\n",
"body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */\n",
"body .w { color: #bbbbbb } /* Text.Whitespace */\n",
"body .mb { color: #666666 } /* Literal.Number.Bin */\n",
"body .mf { color: #666666 } /* Literal.Number.Float */\n",
"body .mh { color: #666666 } /* Literal.Number.Hex */\n",
"body .mi { color: #666666 } /* Literal.Number.Integer */\n",
"body .mo { color: #666666 } /* Literal.Number.Oct */\n",
"body .sa { color: #BA2121 } /* Literal.String.Affix */\n",
"body .sb { color: #BA2121 } /* Literal.String.Backtick */\n",
"body .sc { color: #BA2121 } /* Literal.String.Char */\n",
"body .dl { color: #BA2121 } /* Literal.String.Delimiter */\n",
"body .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */\n",
"body .s2 { color: #BA2121 } /* Literal.String.Double */\n",
"body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */\n",
"body .sh { color: #BA2121 } /* Literal.String.Heredoc */\n",
"body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */\n",
"body .sx { color: #008000 } /* Literal.String.Other */\n",
"body .sr { color: #BB6688 } /* Literal.String.Regex */\n",
"body .s1 { color: #BA2121 } /* Literal.String.Single */\n",
"body .ss { color: #19177C } /* Literal.String.Symbol */\n",
"body .bp { color: #008000 } /* Name.Builtin.Pseudo */\n",
"body .fm { color: #0000FF } /* Name.Function.Magic */\n",
"body .vc { color: #19177C } /* Name.Variable.Class */\n",
"body .vg { color: #19177C } /* Name.Variable.Global */\n",
"body .vi { color: #19177C } /* Name.Variable.Instance */\n",
"body .vm { color: #19177C } /* Name.Variable.Magic */\n",
"body .il { color: #666666 } /* Literal.Number.Integer.Long */\n",
"\n",
" </style>\n",
"</head>\n",
"<body>\n",
"<h2></h2>\n",
"\n",
"<div class=\"highlight\"><pre><span></span><span class=\"k\">def</span> <span class=\"nf\">spare_tire</span><span class=\"p\">():</span>\n",
" <span class=\"sd\">"""[Figure 10.2] SPARE-TIRE-PROBLEM</span>\n",
"\n",
"<span class=\"sd\"> A problem involving changing the flat tire of a car</span>\n",
"<span class=\"sd\"> with a spare tire from the trunk.</span>\n",
"\n",
"<span class=\"sd\"> Example:</span>\n",
"<span class=\"sd\"> >>> from planning import *</span>\n",
"<span class=\"sd\"> >>> st = spare_tire()</span>\n",
"<span class=\"sd\"> >>> st.goal_test()</span>\n",
"<span class=\"sd\"> False</span>\n",
"<span class=\"sd\"> >>> st.act(expr('Remove(Spare, Trunk)'))</span>\n",
"<span class=\"sd\"> >>> st.act(expr('Remove(Flat, Axle)'))</span>\n",
"<span class=\"sd\"> >>> st.goal_test()</span>\n",
"<span class=\"sd\"> False</span>\n",
"<span class=\"sd\"> >>> st.act(expr('PutOn(Spare, Axle)'))</span>\n",
"<span class=\"sd\"> >>> st.goal_test()</span>\n",
"<span class=\"sd\"> True</span>\n",
"<span class=\"sd\"> >>></span>\n",
"<span class=\"sd\"> """</span>\n",
" <span class=\"k\">return</span> <span class=\"n\">PlanningProblem</span><span class=\"p\">(</span><span class=\"n\">init</span><span class=\"o\">=</span><span class=\"s1\">'Tire(Flat) & Tire(Spare) & At(Flat, Axle) & At(Spare, Trunk)'</span><span class=\"p\">,</span>\n",
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
" <span class=\"n\">goals</span><span class=\"o\">=</span><span class=\"s1\">'At(Spare, Axle) & At(Flat, Ground)'</span><span class=\"p\">,</span>\n",
" <span class=\"n\">actions</span><span class=\"o\">=</span><span class=\"p\">[</span><span class=\"n\">Action</span><span class=\"p\">(</span><span class=\"s1\">'Remove(obj, loc)'</span><span class=\"p\">,</span>\n",
" <span class=\"n\">precond</span><span class=\"o\">=</span><span class=\"s1\">'At(obj, loc)'</span><span class=\"p\">,</span>\n",
" <span class=\"n\">effect</span><span class=\"o\">=</span><span class=\"s1\">'At(obj, Ground) & ~At(obj, loc)'</span><span class=\"p\">),</span>\n",
" <span class=\"n\">Action</span><span class=\"p\">(</span><span class=\"s1\">'PutOn(t, Axle)'</span><span class=\"p\">,</span>\n",
" <span class=\"n\">precond</span><span class=\"o\">=</span><span class=\"s1\">'Tire(t) & At(t, Ground) & ~At(Flat, Axle)'</span><span class=\"p\">,</span>\n",
" <span class=\"n\">effect</span><span class=\"o\">=</span><span class=\"s1\">'At(t, Axle) & ~At(t, Ground)'</span><span class=\"p\">),</span>\n",
" <span class=\"n\">Action</span><span class=\"p\">(</span><span class=\"s1\">'LeaveOvernight'</span><span class=\"p\">,</span>\n",
" <span class=\"n\">precond</span><span class=\"o\">=</span><span class=\"s1\">''</span><span class=\"p\">,</span>\n",
" <span class=\"n\">effect</span><span class=\"o\">=</span><span class=\"s1\">'~At(Spare, Ground) & ~At(Spare, Axle) & ~At(Spare, Trunk) & </span><span class=\"se\">\\</span>\n",
"<span class=\"s1\"> ~At(Flat, Ground) & ~At(Flat, Axle) & ~At(Flat, Trunk)'</span><span class=\"p\">)])</span>\n",
"</pre></div>\n",
"</body>\n",
"</html>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"psource(spare_tire)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**At(obj, loc):** object **'obj'** is at location **'loc'**.\n",
"\n",
"**~At(obj, loc):** object **'obj'** is _not_ at location **'loc'**.\n",
"\n",
"**Tire(t):** Declare a tire of type **'t'**.\n",
"\n",
"Let us now define an object of `spare_tire` problem:"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"spareTire = spare_tire()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Before taking any actions, we will check if `spare_tire` has reached its goal:"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n"
]
}
],
"source": [
"print(spareTire.goal_test())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As we can see, it hasn't completed the goal. \n",
"We now define a possible solution that can help us reach the goal of having a spare tire mounted onto the car's axle. \n",
"The actions are then carried out on the `spareTire` PlanningProblem.\n",
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
"\n",
"The actions available to us are the following: Remove, PutOn\n",
"\n",
"**Remove(obj, loc):** Remove the tire **'obj'** from the location **'loc'**.\n",
"\n",
"**PutOn(t, Axle):** Attach the tire **'t'** on the Axle.\n",
"\n",
"**LeaveOvernight():** We live in a particularly bad neighborhood and all tires, flat or not, are stolen if we leave them overnight.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"solution = [expr(\"Remove(Flat, Axle)\"),\n",
" expr(\"Remove(Spare, Trunk)\"),\n",
" expr(\"PutOn(Spare, Axle)\")]\n",
"\n",
"for action in solution:\n",
" spareTire.act(action)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
}
],
"source": [
"print(spareTire.goal_test())"
]
},
{
"cell_type": "markdown",
"source": [
"This is a valid solution.\n",
"<br>\n",
"Another possible solution is"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": true
},
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
"spareTire = spare_tire()\n",
"\n",
"solution = [expr('Remove(Spare, Trunk)'),\n",
" expr('Remove(Flat, Axle)'),\n",
" expr('PutOn(Spare, Axle)')]\n",
"\n",
"for action in solution:\n",
" spareTire.act(action)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
}
],
"source": [
"print(spareTire.goal_test())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Notice that both solutions work, which means that the problem can be solved irrespective of the order in which the `Remove` actions take place, as long as both `Remove` actions take place before the `PutOn` action."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We have successfully mounted a spare tire onto the axle."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Three Block Tower Problem"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This problem's domain consists of a set of cube-shaped blocks sitting on a table. \n",
"The blocks can be stacked, but only one block can fit directly on top of another.\n",
"A robot arm can pick up a block and move it to another position, either on the table or on top of another block. \n",
"The arm can pick up only one block at a time, so it cannot pick up a block that has another one on it. \n",
"The goal will always be to build one or more stacks of blocks. \n",
"In our case, we consider only three blocks.\n",
"The particular configuration we will use is called the Sussman anomaly after Prof. Gerry Sussman."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's take a look at the definition of `three_block_tower()` in the module."
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n",
" \"http://www.w3.org/TR/html4/strict.dtd\">\n",
"\n",
"<html>\n",
"<head>\n",
" <title></title>\n",
" <meta http-equiv=\"content-type\" content=\"text/html; charset=None\">\n",
" <style type=\"text/css\">\n",
"td.linenos { background-color: #f0f0f0; padding-right: 10px; }\n",
"span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }\n",
"pre { line-height: 125%; }\n",
"body .hll { background-color: #ffffcc }\n",
"body { background: #f8f8f8; }\n",
"body .c { color: #408080; font-style: italic } /* Comment */\n",
"body .err { border: 1px solid #FF0000 } /* Error */\n",
"body .k { color: #008000; font-weight: bold } /* Keyword */\n",
"body .o { color: #666666 } /* Operator */\n",
"body .ch { color: #408080; font-style: italic } /* Comment.Hashbang */\n",
"body .cm { color: #408080; font-style: italic } /* Comment.Multiline */\n",
"body .cp { color: #BC7A00 } /* Comment.Preproc */\n",
"body .cpf { color: #408080; font-style: italic } /* Comment.PreprocFile */\n",
"body .c1 { color: #408080; font-style: italic } /* Comment.Single */\n",
"body .cs { color: #408080; font-style: italic } /* Comment.Special */\n",
"body .gd { color: #A00000 } /* Generic.Deleted */\n",
"body .ge { font-style: italic } /* Generic.Emph */\n",
"body .gr { color: #FF0000 } /* Generic.Error */\n",
"body .gh { color: #000080; font-weight: bold } /* Generic.Heading */\n",
"body .gi { color: #00A000 } /* Generic.Inserted */\n",
"body .go { color: #888888 } /* Generic.Output */\n",
"body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */\n",
"body .gs { font-weight: bold } /* Generic.Strong */\n",
"body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */\n",
"body .gt { color: #0044DD } /* Generic.Traceback */\n",
"body .kc { color: #008000; font-weight: bold } /* Keyword.Constant */\n",
"body .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */\n",
"body .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */\n",
"body .kp { color: #008000 } /* Keyword.Pseudo */\n",
"body .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */\n",
"body .kt { color: #B00040 } /* Keyword.Type */\n",
"body .m { color: #666666 } /* Literal.Number */\n",
"body .s { color: #BA2121 } /* Literal.String */\n",
"body .na { color: #7D9029 } /* Name.Attribute */\n",
"body .nb { color: #008000 } /* Name.Builtin */\n",
"body .nc { color: #0000FF; font-weight: bold } /* Name.Class */\n",
"body .no { color: #880000 } /* Name.Constant */\n",
"body .nd { color: #AA22FF } /* Name.Decorator */\n",
"body .ni { color: #999999; font-weight: bold } /* Name.Entity */\n",
"body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */\n",
"body .nf { color: #0000FF } /* Name.Function */\n",
"body .nl { color: #A0A000 } /* Name.Label */\n",
"body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */\n",
"body .nt { color: #008000; font-weight: bold } /* Name.Tag */\n",
"body .nv { color: #19177C } /* Name.Variable */\n",
"body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */\n",
"body .w { color: #bbbbbb } /* Text.Whitespace */\n",
"body .mb { color: #666666 } /* Literal.Number.Bin */\n",
"body .mf { color: #666666 } /* Literal.Number.Float */\n",
"body .mh { color: #666666 } /* Literal.Number.Hex */\n",
"body .mi { color: #666666 } /* Literal.Number.Integer */\n",
"body .mo { color: #666666 } /* Literal.Number.Oct */\n",
"body .sa { color: #BA2121 } /* Literal.String.Affix */\n",
"body .sb { color: #BA2121 } /* Literal.String.Backtick */\n",
"body .sc { color: #BA2121 } /* Literal.String.Char */\n",
"body .dl { color: #BA2121 } /* Literal.String.Delimiter */\n",
"body .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */\n",
"body .s2 { color: #BA2121 } /* Literal.String.Double */\n",
"body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */\n",
"body .sh { color: #BA2121 } /* Literal.String.Heredoc */\n",
"body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */\n",
"body .sx { color: #008000 } /* Literal.String.Other */\n",
"body .sr { color: #BB6688 } /* Literal.String.Regex */\n",
"body .s1 { color: #BA2121 } /* Literal.String.Single */\n",
"body .ss { color: #19177C } /* Literal.String.Symbol */\n",
"body .bp { color: #008000 } /* Name.Builtin.Pseudo */\n",
"body .fm { color: #0000FF } /* Name.Function.Magic */\n",
"body .vc { color: #19177C } /* Name.Variable.Class */\n",
"body .vg { color: #19177C } /* Name.Variable.Global */\n",
"body .vi { color: #19177C } /* Name.Variable.Instance */\n",
"body .vm { color: #19177C } /* Name.Variable.Magic */\n",
"body .il { color: #666666 } /* Literal.Number.Integer.Long */\n",
"\n",
" </style>\n",
"</head>\n",
"<body>\n",
"<h2></h2>\n",
"\n",
"<div class=\"highlight\"><pre><span></span><span class=\"k\">def</span> <span class=\"nf\">three_block_tower</span><span class=\"p\">():</span>\n",
" <span class=\"sd\">"""</span>\n",
"<span class=\"sd\"> [Figure 10.3] THREE-BLOCK-TOWER</span>\n",
"\n",
"<span class=\"sd\"> A blocks-world problem of stacking three blocks in a certain configuration,</span>\n",
"<span class=\"sd\"> also known as the Sussman Anomaly.</span>\n",
"<span class=\"sd\"> Example:</span>\n",
"<span class=\"sd\"> >>> from planning import *</span>\n",
"<span class=\"sd\"> >>> tbt = three_block_tower()</span>\n",
"<span class=\"sd\"> >>> tbt.goal_test()</span>\n",
"<span class=\"sd\"> False</span>\n",
"<span class=\"sd\"> >>> tbt.act(expr('MoveToTable(C, A)'))</span>\n",
"<span class=\"sd\"> >>> tbt.act(expr('Move(B, Table, C)'))</span>\n",
"<span class=\"sd\"> >>> tbt.goal_test()</span>\n",
"<span class=\"sd\"> False</span>\n",
"<span class=\"sd\"> >>> tbt.act(expr('Move(A, Table, B)'))</span>\n",
"<span class=\"sd\"> >>> tbt.goal_test()</span>\n",
"<span class=\"sd\"> True</span>\n",
"<span class=\"sd\"> >>></span>\n",
"<span class=\"sd\"> """</span>\n",
"\n",
" <span class=\"k\">return</span> <span class=\"n\">PlanningProblem</span><span class=\"p\">(</span><span class=\"n\">init</span><span class=\"o\">=</span><span class=\"s1\">'On(A, Table) & On(B, Table) & On(C, A) & Block(A) & Block(B) & Block(C) & Clear(B) & Clear(C)'</span><span class=\"p\">,</span>\n",
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
" <span class=\"n\">goals</span><span class=\"o\">=</span><span class=\"s1\">'On(A, B) & On(B, C)'</span><span class=\"p\">,</span>\n",
" <span class=\"n\">actions</span><span class=\"o\">=</span><span class=\"p\">[</span><span class=\"n\">Action</span><span class=\"p\">(</span><span class=\"s1\">'Move(b, x, y)'</span><span class=\"p\">,</span>\n",
" <span class=\"n\">precond</span><span class=\"o\">=</span><span class=\"s1\">'On(b, x) & Clear(b) & Clear(y) & Block(b) & Block(y)'</span><span class=\"p\">,</span>\n",
" <span class=\"n\">effect</span><span class=\"o\">=</span><span class=\"s1\">'On(b, y) & Clear(x) & ~On(b, x) & ~Clear(y)'</span><span class=\"p\">),</span>\n",
" <span class=\"n\">Action</span><span class=\"p\">(</span><span class=\"s1\">'MoveToTable(b, x)'</span><span class=\"p\">,</span>\n",
" <span class=\"n\">precond</span><span class=\"o\">=</span><span class=\"s1\">'On(b, x) & Clear(b) & Block(b)'</span><span class=\"p\">,</span>\n",
" <span class=\"n\">effect</span><span class=\"o\">=</span><span class=\"s1\">'On(b, Table) & Clear(x) & ~On(b, x)'</span><span class=\"p\">)])</span>\n",
"</pre></div>\n",
"</body>\n",
"</html>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"psource(three_block_tower)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**On(b, x):** The block **'b'** is on **'x'**. **'x'** can be a table or a block.\n",
"\n",
"**~On(b, x):** The block **'b'** is _not_ on **'x'**. **'x'** can be a table or a block.\n",
"\n",
"**Block(b):** Declares **'b'** as a block.\n",
"\n",
"**Clear(x):** To indicate that there is nothing on **'x'** and it is free to be moved around.\n",
"\n",
"**~Clear(x):** To indicate that there is something on **'x'** and it cannot be moved.\n",
" \n",
" Let us now define an object of `three_block_tower` problem:"
"cell_type": "code",
"execution_count": 25,
"metadata": {
"collapsed": true
},
"outputs": [],
"threeBlockTower = three_block_tower()"
"Before taking any actions, we will check if `threeBlockTower` has reached its goal:"
"cell_type": "code",
"execution_count": 26,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n"
]
}
],
"print(threeBlockTower.goal_test())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As we can see, it hasn't completed the goal. \n",
"We now define a sequence of actions that can stack three blocks in the required order. \n",
"The actions are then carried out on the `threeBlockTower` PlanningProblem.\n",
"The actions available to us are the following: MoveToTable, Move\n",
"\n",
"**MoveToTable(b, x): ** Move box **'b'** stacked on **'x'** to the table, given that box **'b'** is clear.\n",
"\n",
"**Move(b, x, y): ** Move box **'b'** stacked on **'x'** to the top of **'y'**, given that both **'b'** and **'y'** are clear.\n"
"execution_count": 27,
"metadata": {
"collapsed": true
},
"solution = [expr(\"MoveToTable(C, A)\"),\n",
" expr(\"Move(B, Table, C)\"),\n",
" expr(\"Move(A, Table, B)\")]\n",
"\n",
"for action in solution:\n",
" threeBlockTower.act(action)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As the `three_block_tower` has taken all the steps it needed in order to achieve the goal, we can now check if it has acheived its goal."
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
}
],
"print(threeBlockTower.goal_test())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"It has now successfully achieved its goal i.e, to build a stack of three blocks in the specified order."
"The `three_block_tower` problem can also be defined in simpler terms using just two actions `ToTable(x, y)` and `FromTable(x, y)`.\n",
"The underlying problem remains the same however, stacking up three blocks in a certain configuration given a particular starting state.\n",
"Let's have a look at the alternative definition."
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
"text/html": [
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n",
" \"http://www.w3.org/TR/html4/strict.dtd\">\n",
"\n",
"<html>\n",
"<head>\n",
" <title></title>\n",
" <meta http-equiv=\"content-type\" content=\"text/html; charset=None\">\n",
" <style type=\"text/css\">\n",
"td.linenos { background-color: #f0f0f0; padding-right: 10px; }\n",
"span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }\n",
"pre { line-height: 125%; }\n",
"body .hll { background-color: #ffffcc }\n",
"body { background: #f8f8f8; }\n",
"body .c { color: #408080; font-style: italic } /* Comment */\n",
"body .err { border: 1px solid #FF0000 } /* Error */\n",
"body .k { color: #008000; font-weight: bold } /* Keyword */\n",
"body .o { color: #666666 } /* Operator */\n",
"body .ch { color: #408080; font-style: italic } /* Comment.Hashbang */\n",
"body .cm { color: #408080; font-style: italic } /* Comment.Multiline */\n",
"body .cp { color: #BC7A00 } /* Comment.Preproc */\n",
"body .cpf { color: #408080; font-style: italic } /* Comment.PreprocFile */\n",
"body .c1 { color: #408080; font-style: italic } /* Comment.Single */\n",
"body .cs { color: #408080; font-style: italic } /* Comment.Special */\n",
"body .gd { color: #A00000 } /* Generic.Deleted */\n",
"body .ge { font-style: italic } /* Generic.Emph */\n",
"body .gr { color: #FF0000 } /* Generic.Error */\n",
"body .gh { color: #000080; font-weight: bold } /* Generic.Heading */\n",
"body .gi { color: #00A000 } /* Generic.Inserted */\n",
"body .go { color: #888888 } /* Generic.Output */\n",
"body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */\n",
"body .gs { font-weight: bold } /* Generic.Strong */\n",
"body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */\n",
"body .gt { color: #0044DD } /* Generic.Traceback */\n",
"body .kc { color: #008000; font-weight: bold } /* Keyword.Constant */\n",
"body .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */\n",
"body .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */\n",
"body .kp { color: #008000 } /* Keyword.Pseudo */\n",
"body .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */\n",
"body .kt { color: #B00040 } /* Keyword.Type */\n",
"body .m { color: #666666 } /* Literal.Number */\n",
"body .s { color: #BA2121 } /* Literal.String */\n",
"body .na { color: #7D9029 } /* Name.Attribute */\n",
"body .nb { color: #008000 } /* Name.Builtin */\n",
"body .nc { color: #0000FF; font-weight: bold } /* Name.Class */\n",
"body .no { color: #880000 } /* Name.Constant */\n",
"body .nd { color: #AA22FF } /* Name.Decorator */\n",
"body .ni { color: #999999; font-weight: bold } /* Name.Entity */\n",
"body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */\n",
"body .nf { color: #0000FF } /* Name.Function */\n",
"body .nl { color: #A0A000 } /* Name.Label */\n",
"body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */\n",
"body .nt { color: #008000; font-weight: bold } /* Name.Tag */\n",
"body .nv { color: #19177C } /* Name.Variable */\n",
"body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */\n",
"body .w { color: #bbbbbb } /* Text.Whitespace */\n",
"body .mb { color: #666666 } /* Literal.Number.Bin */\n",
"body .mf { color: #666666 } /* Literal.Number.Float */\n",
"body .mh { color: #666666 } /* Literal.Number.Hex */\n",
"body .mi { color: #666666 } /* Literal.Number.Integer */\n",
"body .mo { color: #666666 } /* Literal.Number.Oct */\n",
"body .sa { color: #BA2121 } /* Literal.String.Affix */\n",
"body .sb { color: #BA2121 } /* Literal.String.Backtick */\n",
"body .sc { color: #BA2121 } /* Literal.String.Char */\n",
"body .dl { color: #BA2121 } /* Literal.String.Delimiter */\n",
"body .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */\n",
"body .s2 { color: #BA2121 } /* Literal.String.Double */\n",
"body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */\n",
"body .sh { color: #BA2121 } /* Literal.String.Heredoc */\n",
"body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */\n",
"body .sx { color: #008000 } /* Literal.String.Other */\n",
"body .sr { color: #BB6688 } /* Literal.String.Regex */\n",
"body .s1 { color: #BA2121 } /* Literal.String.Single */\n",
"body .ss { color: #19177C } /* Literal.String.Symbol */\n",
"body .bp { color: #008000 } /* Name.Builtin.Pseudo */\n",
"body .fm { color: #0000FF } /* Name.Function.Magic */\n",
"body .vc { color: #19177C } /* Name.Variable.Class */\n",
"body .vg { color: #19177C } /* Name.Variable.Global */\n",
"body .vi { color: #19177C } /* Name.Variable.Instance */\n",
"body .vm { color: #19177C } /* Name.Variable.Magic */\n",
"body .il { color: #666666 } /* Literal.Number.Integer.Long */\n",
"\n",
" </style>\n",
"</head>\n",
"<body>\n",
"<h2></h2>\n",
"\n",
"<div class=\"highlight\"><pre><span></span><span class=\"k\">def</span> <span class=\"nf\">simple_blocks_world</span><span class=\"p\">():</span>\n",
" <span class=\"sd\">"""</span>\n",
"<span class=\"sd\"> SIMPLE-BLOCKS-WORLD</span>\n",
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
"<span class=\"sd\"> A simplified definition of the Sussman Anomaly problem.</span>\n",
"\n",
"<span class=\"sd\"> Example:</span>\n",
"<span class=\"sd\"> >>> from planning import *</span>\n",
"<span class=\"sd\"> >>> sbw = simple_blocks_world()</span>\n",
"<span class=\"sd\"> >>> sbw.goal_test()</span>\n",
"<span class=\"sd\"> False</span>\n",
"<span class=\"sd\"> >>> sbw.act(expr('ToTable(A, B)'))</span>\n",
"<span class=\"sd\"> >>> sbw.act(expr('FromTable(B, A)'))</span>\n",
"<span class=\"sd\"> >>> sbw.goal_test()</span>\n",
"<span class=\"sd\"> False</span>\n",
"<span class=\"sd\"> >>> sbw.act(expr('FromTable(C, B)'))</span>\n",
"<span class=\"sd\"> >>> sbw.goal_test()</span>\n",
"<span class=\"sd\"> True</span>\n",
"<span class=\"sd\"> >>></span>\n",
"<span class=\"sd\"> """</span>\n",
"\n",
" <span class=\"k\">return</span> <span class=\"n\">PlanningProblem</span><span class=\"p\">(</span><span class=\"n\">init</span><span class=\"o\">=</span><span class=\"s1\">'On(A, B) & Clear(A) & OnTable(B) & OnTable(C) & Clear(C)'</span><span class=\"p\">,</span>\n",
" <span class=\"n\">goals</span><span class=\"o\">=</span><span class=\"s1\">'On(B, A) & On(C, B)'</span><span class=\"p\">,</span>\n",
" <span class=\"n\">actions</span><span class=\"o\">=</span><span class=\"p\">[</span><span class=\"n\">Action</span><span class=\"p\">(</span><span class=\"s1\">'ToTable(x, y)'</span><span class=\"p\">,</span>\n",
" <span class=\"n\">precond</span><span class=\"o\">=</span><span class=\"s1\">'On(x, y) & Clear(x)'</span><span class=\"p\">,</span>\n",
" <span class=\"n\">effect</span><span class=\"o\">=</span><span class=\"s1\">'~On(x, y) & Clear(y) & OnTable(x)'</span><span class=\"p\">),</span>\n",
" <span class=\"n\">Action</span><span class=\"p\">(</span><span class=\"s1\">'FromTable(y, x)'</span><span class=\"p\">,</span>\n",
" <span class=\"n\">precond</span><span class=\"o\">=</span><span class=\"s1\">'OnTable(y) & Clear(y) & Clear(x)'</span><span class=\"p\">,</span>\n",
" <span class=\"n\">effect</span><span class=\"o\">=</span><span class=\"s1\">'~OnTable(y) & ~Clear(x) & On(y, x)'</span><span class=\"p\">)])</span>\n",
"</pre></div>\n",
"</body>\n",
"</html>\n"
],
"<IPython.core.display.HTML object>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**On(x, y):** The block **'x'** is on **'y'**. Both **'x'** and **'y'** have to be blocks.\n",
"**~On(x, y):** The block **'x'** is _not_ on **'y'**. Both **'x'** and **'y'** have to be blocks.\n",
"**OnTable(x):** The block **'x'** is on the table.\n",
"**~OnTable(x):** The block **'x'** is _not_ on the table.\n",
"\n",
"**Clear(x):** To indicate that there is nothing on **'x'** and it is free to be moved around.\n",
"\n",
"**~Clear(x):** To indicate that there is something on **'x'** and it cannot be moved.\n",
"\n",
"Let's now define a `simple_blocks_world` prolem."
"execution_count": 30,
"metadata": {
"collapsed": true
},
"simpleBlocksWorld = simple_blocks_world()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Before taking any actions, we will see if `simple_bw` has reached its goal."
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As we can see, it hasn't completed the goal. \n",
"We now define a sequence of actions that can stack three blocks in the required order. \n",
"The actions are then carried out on the `simple_bw` PlanningProblem.\n",
"The actions available to us are the following: MoveToTable, Move\n",
"**ToTable(x, y): ** Move box **'x'** stacked on **'y'** to the table, given that box **'y'** is clear.\n",
"\n",
"**FromTable(x, y): ** Move box **'x'** from wherever it is, to the top of **'y'**, given that both **'x'** and **'y'** are clear.\n"
"execution_count": 32,
"metadata": {
"collapsed": true
},
"solution = [expr('ToTable(A, B)'),\n",
" expr('FromTable(B, A)'),\n",
" expr('FromTable(C, B)')]\n",
"\n",
"for action in solution:\n",
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As the `three_block_tower` has taken all the steps it needed in order to achieve the goal, we can now check if it has acheived its goal."
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
"print(simpleBlocksWorld.goal_test())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"It has now successfully achieved its goal i.e, to build a stack of three blocks in the specified order."
{
"cell_type": "markdown",
"metadata": {},
"source": [
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This problem requires us to acquire a carton of milk, a banana and a drill.\n",
"Initially, we start from home and it is known to us that milk and bananas are available in the supermarket and the hardware store sells drills.\n",
"Let's take a look at the definition of the `shopping_problem` in the module."
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
"outputs": [
{
"data": {
"text/html": [
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n",
" \"http://www.w3.org/TR/html4/strict.dtd\">\n",
"\n",
"<html>\n",
"<head>\n",
" <title></title>\n",
" <meta http-equiv=\"content-type\" content=\"text/html; charset=None\">\n",
" <style type=\"text/css\">\n",
"td.linenos { background-color: #f0f0f0; padding-right: 10px; }\n",
"span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }\n",
"pre { line-height: 125%; }\n",
"body .hll { background-color: #ffffcc }\n",
"body { background: #f8f8f8; }\n",
"body .c { color: #408080; font-style: italic } /* Comment */\n",
"body .err { border: 1px solid #FF0000 } /* Error */\n",
"body .k { color: #008000; font-weight: bold } /* Keyword */\n",
"body .o { color: #666666 } /* Operator */\n",
"body .ch { color: #408080; font-style: italic } /* Comment.Hashbang */\n",
"body .cm { color: #408080; font-style: italic } /* Comment.Multiline */\n",
"body .cp { color: #BC7A00 } /* Comment.Preproc */\n",
"body .cpf { color: #408080; font-style: italic } /* Comment.PreprocFile */\n",
"body .c1 { color: #408080; font-style: italic } /* Comment.Single */\n",
"body .cs { color: #408080; font-style: italic } /* Comment.Special */\n",
"body .gd { color: #A00000 } /* Generic.Deleted */\n",
"body .ge { font-style: italic } /* Generic.Emph */\n",
"body .gr { color: #FF0000 } /* Generic.Error */\n",
"body .gh { color: #000080; font-weight: bold } /* Generic.Heading */\n",
"body .gi { color: #00A000 } /* Generic.Inserted */\n",
"body .go { color: #888888 } /* Generic.Output */\n",
"body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */\n",
"body .gs { font-weight: bold } /* Generic.Strong */\n",
"body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */\n",
"body .gt { color: #0044DD } /* Generic.Traceback */\n",
"body .kc { color: #008000; font-weight: bold } /* Keyword.Constant */\n",
"body .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */\n",
"body .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */\n",
"body .kp { color: #008000 } /* Keyword.Pseudo */\n",
"body .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */\n",
"body .kt { color: #B00040 } /* Keyword.Type */\n",
"body .m { color: #666666 } /* Literal.Number */\n",
"body .s { color: #BA2121 } /* Literal.String */\n",
"body .na { color: #7D9029 } /* Name.Attribute */\n",
"body .nb { color: #008000 } /* Name.Builtin */\n",
"body .nc { color: #0000FF; font-weight: bold } /* Name.Class */\n",
"body .no { color: #880000 } /* Name.Constant */\n",
"body .nd { color: #AA22FF } /* Name.Decorator */\n",
"body .ni { color: #999999; font-weight: bold } /* Name.Entity */\n",
"body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */\n",
"body .nf { color: #0000FF } /* Name.Function */\n",
"body .nl { color: #A0A000 } /* Name.Label */\n",
"body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */\n",
"body .nt { color: #008000; font-weight: bold } /* Name.Tag */\n",
"body .nv { color: #19177C } /* Name.Variable */\n",
"body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */\n",
"body .w { color: #bbbbbb } /* Text.Whitespace */\n",
"body .mb { color: #666666 } /* Literal.Number.Bin */\n",
"body .mf { color: #666666 } /* Literal.Number.Float */\n",
"body .mh { color: #666666 } /* Literal.Number.Hex */\n",
"body .mi { color: #666666 } /* Literal.Number.Integer */\n",
"body .mo { color: #666666 } /* Literal.Number.Oct */\n",
"body .sa { color: #BA2121 } /* Literal.String.Affix */\n",
"body .sb { color: #BA2121 } /* Literal.String.Backtick */\n",
"body .sc { color: #BA2121 } /* Literal.String.Char */\n",
"body .dl { color: #BA2121 } /* Literal.String.Delimiter */\n",
"body .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */\n",
"body .s2 { color: #BA2121 } /* Literal.String.Double */\n",
"body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */\n",
"body .sh { color: #BA2121 } /* Literal.String.Heredoc */\n",
"body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */\n",
"body .sx { color: #008000 } /* Literal.String.Other */\n",
"body .sr { color: #BB6688 } /* Literal.String.Regex */\n",
"body .s1 { color: #BA2121 } /* Literal.String.Single */\n",
"body .ss { color: #19177C } /* Literal.String.Symbol */\n",
"body .bp { color: #008000 } /* Name.Builtin.Pseudo */\n",
"body .fm { color: #0000FF } /* Name.Function.Magic */\n",
"body .vc { color: #19177C } /* Name.Variable.Class */\n",
"body .vg { color: #19177C } /* Name.Variable.Global */\n",
"body .vi { color: #19177C } /* Name.Variable.Instance */\n",
"body .vm { color: #19177C } /* Name.Variable.Magic */\n",
"body .il { color: #666666 } /* Literal.Number.Integer.Long */\n",
"\n",
" </style>\n",
"</head>\n",
"<body>\n",
"<h2></h2>\n",
"\n",
"<div class=\"highlight\"><pre><span></span><span class=\"k\">def</span> <span class=\"nf\">shopping_problem</span><span class=\"p\">():</span>\n",
" <span class=\"sd\">"""</span>\n",
"<span class=\"sd\"> SHOPPING-PROBLEM</span>\n",
"<span class=\"sd\"> A problem of acquiring some items given their availability at certain stores.</span>\n",
"\n",
"<span class=\"sd\"> Example:</span>\n",
"<span class=\"sd\"> >>> from planning import *</span>\n",
"<span class=\"sd\"> >>> sp = shopping_problem()</span>\n",
"<span class=\"sd\"> >>> sp.goal_test()</span>\n",
"<span class=\"sd\"> False</span>\n",
"<span class=\"sd\"> >>> sp.act(expr('Go(Home, HW)'))</span>\n",
"<span class=\"sd\"> >>> sp.act(expr('Buy(Drill, HW)'))</span>\n",
"<span class=\"sd\"> >>> sp.act(expr('Go(HW, SM)'))</span>\n",
"<span class=\"sd\"> >>> sp.act(expr('Buy(Banana, SM)'))</span>\n",
"<span class=\"sd\"> >>> sp.goal_test()</span>\n",
"<span class=\"sd\"> False</span>\n",
"<span class=\"sd\"> >>> sp.act(expr('Buy(Milk, SM)'))</span>\n",
"<span class=\"sd\"> >>> sp.goal_test()</span>\n",
"<span class=\"sd\"> True</span>\n",
"<span class=\"sd\"> >>></span>\n",
"<span class=\"sd\"> """</span>\n",
"\n",