|
22 | 22 | }, |
23 | 23 | { |
24 | 24 | "cell_type": "code", |
25 | | - "execution_count": 1, |
| 25 | + "execution_count": 29, |
26 | 26 | "metadata": {}, |
27 | 27 | "outputs": [], |
28 | 28 | "source": [ |
|
48 | 48 | }, |
49 | 49 | { |
50 | 50 | "cell_type": "code", |
51 | | - "execution_count": 2, |
| 51 | + "execution_count": 30, |
52 | 52 | "metadata": {}, |
53 | 53 | "outputs": [], |
54 | 54 | "source": [ |
|
78 | 78 | }, |
79 | 79 | { |
80 | 80 | "cell_type": "code", |
81 | | - "execution_count": 3, |
| 81 | + "execution_count": 31, |
82 | 82 | "metadata": {}, |
83 | 83 | "outputs": [], |
84 | 84 | "source": [ |
|
103 | 103 | }, |
104 | 104 | { |
105 | 105 | "cell_type": "code", |
106 | | - "execution_count": 4, |
| 106 | + "execution_count": 32, |
107 | 107 | "metadata": {}, |
108 | 108 | "outputs": [], |
109 | 109 | "source": [ |
|
132 | 132 | }, |
133 | 133 | { |
134 | 134 | "cell_type": "code", |
135 | | - "execution_count": 5, |
| 135 | + "execution_count": 33, |
136 | 136 | "metadata": {}, |
137 | 137 | "outputs": [], |
138 | 138 | "source": [ |
|
152 | 152 | }, |
153 | 153 | { |
154 | 154 | "cell_type": "code", |
155 | | - "execution_count": 6, |
| 155 | + "execution_count": 34, |
156 | 156 | "metadata": {}, |
157 | 157 | "outputs": [ |
158 | 158 | { |
|
170 | 170 | " At(Sibiu)]" |
171 | 171 | ] |
172 | 172 | }, |
173 | | - "execution_count": 6, |
| 173 | + "execution_count": 34, |
174 | 174 | "metadata": {}, |
175 | 175 | "output_type": "execute_result" |
176 | 176 | } |
|
190 | 190 | }, |
191 | 191 | { |
192 | 192 | "cell_type": "code", |
193 | | - "execution_count": 7, |
| 193 | + "execution_count": 35, |
194 | 194 | "metadata": {}, |
195 | 195 | "outputs": [], |
196 | 196 | "source": [ |
|
246 | 246 | }, |
247 | 247 | { |
248 | 248 | "cell_type": "code", |
249 | | - "execution_count": 8, |
| 249 | + "execution_count": 36, |
250 | 250 | "metadata": {}, |
251 | 251 | "outputs": [], |
252 | 252 | "source": [ |
|
267 | 267 | }, |
268 | 268 | { |
269 | 269 | "cell_type": "code", |
270 | | - "execution_count": 9, |
| 270 | + "execution_count": 37, |
271 | 271 | "metadata": {}, |
272 | 272 | "outputs": [], |
273 | 273 | "source": [ |
|
284 | 284 | }, |
285 | 285 | { |
286 | 286 | "cell_type": "code", |
287 | | - "execution_count": 10, |
| 287 | + "execution_count": 38, |
288 | 288 | "metadata": {}, |
289 | 289 | "outputs": [], |
290 | 290 | "source": [ |
|
307 | 307 | }, |
308 | 308 | { |
309 | 309 | "cell_type": "code", |
310 | | - "execution_count": 15, |
| 310 | + "execution_count": 39, |
311 | 311 | "metadata": {}, |
312 | 312 | "outputs": [], |
313 | 313 | "source": [ |
|
323 | 323 | }, |
324 | 324 | { |
325 | 325 | "cell_type": "code", |
326 | | - "execution_count": 16, |
| 326 | + "execution_count": 40, |
327 | 327 | "metadata": {}, |
328 | 328 | "outputs": [ |
329 | 329 | { |
|
348 | 348 | }, |
349 | 349 | { |
350 | 350 | "cell_type": "code", |
351 | | - "execution_count": 17, |
| 351 | + "execution_count": 41, |
352 | 352 | "metadata": {}, |
353 | 353 | "outputs": [], |
354 | 354 | "source": [ |
|
372 | 372 | }, |
373 | 373 | { |
374 | 374 | "cell_type": "code", |
375 | | - "execution_count": 18, |
| 375 | + "execution_count": 42, |
376 | 376 | "metadata": {}, |
377 | 377 | "outputs": [ |
378 | 378 | { |
|
381 | 381 | "True" |
382 | 382 | ] |
383 | 383 | }, |
384 | | - "execution_count": 18, |
| 384 | + "execution_count": 42, |
385 | 385 | "metadata": {}, |
386 | 386 | "output_type": "execute_result" |
387 | 387 | } |
|
390 | 390 | "airCargo.goal_test()" |
391 | 391 | ] |
392 | 392 | }, |
| 393 | + { |
| 394 | + "cell_type": "markdown", |
| 395 | + "metadata": {}, |
| 396 | + "source": [ |
| 397 | + "It has now achieved its goal." |
| 398 | + ] |
| 399 | + }, |
| 400 | + { |
| 401 | + "cell_type": "markdown", |
| 402 | + "metadata": {}, |
| 403 | + "source": [ |
| 404 | + "## Spare Tire Problem:\n" |
| 405 | + ] |
| 406 | + }, |
| 407 | + { |
| 408 | + "cell_type": "markdown", |
| 409 | + "metadata": {}, |
| 410 | + "source": [ |
| 411 | + "It is basically the problem of changing a flat tire. The goal is to have a \n", |
| 412 | + "good spare tire properly mounted onto the car's axle, where the initial state \n", |
| 413 | + "has a flat tire on the axle and a good spare tire in the trunk. Let us now \n", |
| 414 | + "define an object of `spare-tire` problem:" |
| 415 | + ] |
| 416 | + }, |
393 | 417 | { |
394 | 418 | "cell_type": "code", |
395 | | - "execution_count": null, |
| 419 | + "execution_count": 43, |
396 | 420 | "metadata": {}, |
397 | 421 | "outputs": [], |
398 | 422 | "source": [ |
399 | | - "It has now achieved its goal." |
| 423 | + "spareTire = spare_tire()" |
| 424 | + ] |
| 425 | + }, |
| 426 | + { |
| 427 | + "cell_type": "markdown", |
| 428 | + "metadata": {}, |
| 429 | + "source": [ |
| 430 | + "Now, before taking any actions, we will check the `spareTire` if it has \n", |
| 431 | + "completed the goal it is required to do:" |
| 432 | + ] |
| 433 | + }, |
| 434 | + { |
| 435 | + "cell_type": "code", |
| 436 | + "execution_count": 44, |
| 437 | + "metadata": {}, |
| 438 | + "outputs": [ |
| 439 | + { |
| 440 | + "name": "stdout", |
| 441 | + "output_type": "stream", |
| 442 | + "text": [ |
| 443 | + "False\n" |
| 444 | + ] |
| 445 | + } |
| 446 | + ], |
| 447 | + "source": [ |
| 448 | + "print(spareTire.goal_test())" |
| 449 | + ] |
| 450 | + }, |
| 451 | + { |
| 452 | + "cell_type": "markdown", |
| 453 | + "metadata": {}, |
| 454 | + "source": [ |
| 455 | + "As we can see, it hasn't completed the goal. Now, we define the sequence of\n", |
| 456 | + "actions that it should take in order to mount the spare tire onto the car's axle. Then the `spareTire` acts on each of them." |
| 457 | + ] |
| 458 | + }, |
| 459 | + { |
| 460 | + "cell_type": "code", |
| 461 | + "execution_count": 45, |
| 462 | + "metadata": {}, |
| 463 | + "outputs": [], |
| 464 | + "source": [ |
| 465 | + "solution = [expr(\"Remove(Flat, Axle)\"),\n", |
| 466 | + " expr(\"Remove(Spare, Trunk)\"),\n", |
| 467 | + " expr(\"PutOn(Spare, Axle)\")]\n", |
| 468 | + "\n", |
| 469 | + "for action in solution:\n", |
| 470 | + " spareTire.act(action)" |
| 471 | + ] |
| 472 | + }, |
| 473 | + { |
| 474 | + "cell_type": "markdown", |
| 475 | + "metadata": {}, |
| 476 | + "source": [ |
| 477 | + "As the `spareTire` has taken all the steps it needed in order to achieve the goal, we can now check if it has acheived its goal:" |
| 478 | + ] |
| 479 | + }, |
| 480 | + { |
| 481 | + "cell_type": "code", |
| 482 | + "execution_count": 46, |
| 483 | + "metadata": {}, |
| 484 | + "outputs": [ |
| 485 | + { |
| 486 | + "name": "stdout", |
| 487 | + "output_type": "stream", |
| 488 | + "text": [ |
| 489 | + "True\n" |
| 490 | + ] |
| 491 | + } |
| 492 | + ], |
| 493 | + "source": [ |
| 494 | + "print(spareTire.goal_test())" |
| 495 | + ] |
| 496 | + }, |
| 497 | + { |
| 498 | + "cell_type": "markdown", |
| 499 | + "metadata": {}, |
| 500 | + "source": [ |
| 501 | + "It has now successfully achieved its goal i.e, to have a good spare tire mounted onto the car's axle" |
| 502 | + ] |
| 503 | + }, |
| 504 | + { |
| 505 | + "cell_type": "markdown", |
| 506 | + "metadata": {}, |
| 507 | + "source": [ |
| 508 | + "## Three Block Tower Problem:" |
| 509 | + ] |
| 510 | + }, |
| 511 | + { |
| 512 | + "cell_type": "markdown", |
| 513 | + "metadata": {}, |
| 514 | + "source": [ |
| 515 | + "This problem's domain consists of a set of cube-shaped blocks sitting on a table.The blocks can be stacked, but only one block can fit directly on top of another. A robot arm can pick up a block and move it to another position, either on the table or on top of another block. The arm can pick up only one block at a time, so it can't pick up a block that has another one on it. The goal will always be to build one or more stacks of blocks.In our case, the number of blocks are three. Let's start by defining an object of `three_block_tower` problem:" |
| 516 | + ] |
| 517 | + }, |
| 518 | + { |
| 519 | + "cell_type": "code", |
| 520 | + "execution_count": 47, |
| 521 | + "metadata": {}, |
| 522 | + "outputs": [], |
| 523 | + "source": [ |
| 524 | + "threeBlockTower = three_block_tower()" |
400 | 525 | ] |
| 526 | + }, |
| 527 | + { |
| 528 | + "cell_type": "markdown", |
| 529 | + "metadata": {}, |
| 530 | + "source": [ |
| 531 | + "Now, before taking any actions, we will check the `threeBlockTower` if it has \n", |
| 532 | + "completed the goal it is required to do:" |
| 533 | + ] |
| 534 | + }, |
| 535 | + { |
| 536 | + "cell_type": "code", |
| 537 | + "execution_count": 48, |
| 538 | + "metadata": {}, |
| 539 | + "outputs": [ |
| 540 | + { |
| 541 | + "name": "stdout", |
| 542 | + "output_type": "stream", |
| 543 | + "text": [ |
| 544 | + "False\n" |
| 545 | + ] |
| 546 | + } |
| 547 | + ], |
| 548 | + "source": [ |
| 549 | + "print(threeBlockTower.goal_test())" |
| 550 | + ] |
| 551 | + }, |
| 552 | + { |
| 553 | + "cell_type": "markdown", |
| 554 | + "metadata": {}, |
| 555 | + "source": [ |
| 556 | + "As we can see, it hasn't completed the goal. Now, we define the sequence of\n", |
| 557 | + "actions that it should take in order to build a stack of three blocks. Then the `threeBlockTower` acts on each of them." |
| 558 | + ] |
| 559 | + }, |
| 560 | + { |
| 561 | + "cell_type": "code", |
| 562 | + "execution_count": 49, |
| 563 | + "metadata": {}, |
| 564 | + "outputs": [], |
| 565 | + "source": [ |
| 566 | + "solution = [expr(\"MoveToTable(C, A)\"),\n", |
| 567 | + " expr(\"Move(B, Table, C)\"),\n", |
| 568 | + " expr(\"Move(A, Table, B)\")]\n", |
| 569 | + "\n", |
| 570 | + "for action in solution:\n", |
| 571 | + " threeBlockTower.act(action)" |
| 572 | + ] |
| 573 | + }, |
| 574 | + { |
| 575 | + "cell_type": "markdown", |
| 576 | + "metadata": {}, |
| 577 | + "source": [ |
| 578 | + "As the `threeBlockTower` has taken all the steps it needed in order to achieve the goal, we can now check if it has acheived its goal:" |
| 579 | + ] |
| 580 | + }, |
| 581 | + { |
| 582 | + "cell_type": "code", |
| 583 | + "execution_count": 50, |
| 584 | + "metadata": {}, |
| 585 | + "outputs": [ |
| 586 | + { |
| 587 | + "name": "stdout", |
| 588 | + "output_type": "stream", |
| 589 | + "text": [ |
| 590 | + "True\n" |
| 591 | + ] |
| 592 | + } |
| 593 | + ], |
| 594 | + "source": [ |
| 595 | + "print(threeBlockTower.goal_test())" |
| 596 | + ] |
| 597 | + }, |
| 598 | + { |
| 599 | + "cell_type": "markdown", |
| 600 | + "metadata": {}, |
| 601 | + "source": [ |
| 602 | + "It has now successfully achieved its goal i.e, to build a stack of three blocks." |
| 603 | + ] |
| 604 | + }, |
| 605 | + { |
| 606 | + "cell_type": "code", |
| 607 | + "execution_count": null, |
| 608 | + "metadata": {}, |
| 609 | + "outputs": [], |
| 610 | + "source": [] |
401 | 611 | } |
402 | 612 | ], |
403 | 613 | "metadata": { |
|
0 commit comments