Given two lists `As` and `Bs`, `substitute/4` will substitute every term `A` in `As` with `B` to produce `Bs`. Substitute(on(Block, _), Source, on(Block, Destination), Target). Perform(Source, move(Block, Destination), Target) :. This clause is responsible for changing the `Source` state into the `Target` state by performing an `Action`. nothing in on `Destination`.Īction(State, move(Block, Destination)) :-Īction(, move(a, q)). `Destination` is free to move to in this state. All actions are of the form `move(Block, Destination)`.Ī action `move(Block, Destination)` is legal ifģ. This clause is responsible for determining the legal actions in a state. In this section we will take a look at the definition of these clauses. With the above considerations it is not garantueed that Prolog can find a solution. The `strips/4` clause is defined in terms of `action/2` and `perform/3`. Blocks world is > one of the most famous planning domains in. Strips(Initial, Final, Plan) :- strips(Initial, Final,, Plan).ĭeepening_strips(1, Initial, Final, Visited, Plan).ĭeepening_strips(Bound, Initial, Final, Visited, Plan) :-īounded_strips(Bound, Initial, Final, Visited, Plan).ĭeepening_strips(Successor, Initial, Final, Visited, Plan).īounded_strips(Bound, Initial, Final, Visited, ) :-īounded_strips(Predecessor, Intermediate, Final,, Actions). Since Prolog out of the box does a depth first search, we are not guaranteed to find the shortest plan first. In general we will favor shorter plans over longer plans. In order to prevent the revisiting intermediate states, we keep track of the visited intermediate states. The reason for this is that Prolog would happily move a to b, and back again ad infinitum. In that case we perform any legal action to an intermediate state and try to reach the `Final` state from there. The `strips/3` clause does the heavy lifting of coming up with a plan. Solve(Initial, Final, Plan) :- strips(Initial, Final, Plan). We delegate the actual solving to our implementation of STRIPS. We will introduce a top-level term that allows us to come up with a plan to go from an `Initial` state to a `Final` state. "p", "q", "r".Īs an example the state above is represented as "a", "b", "c", and `Y` can either be a block or a place on the table, e.g. We will represent a state in the blocks world as a list of terms `on(X, Y)`. Our world has three blocks: a, b, c, and three places on the table: p, q, r. Moreover, some kinds of blocks cannot have other blocks stacked on top of them. Because of this, any blocks that are, at a given time, under another block cannot be moved. Only one block may be moved at a time: it may either be placed on the table or placed atop another block. The goal is to build one or more vertical stacks of blocks. For a base, you should begin with a simple prolog code for simple blocks world at the end of this part. A set of wooden blocks of various shapes and colors sitting on a table. Engineering Computer Science Computer Science questions and answers PART3 - Prolog - Blocks World. The standard layout is defined in Figure 1. Several prolog information blocks have been defined. Code to allocate stack space is not required in the Language Environment prolog see Figure 1. A block or internal procedure is found by R15 pointing to an area saved in the DSA. > one of the most famous planning domains in artificial intelligence. The prolog information exists for every block or internal procedure. > an automated planner developed by Richard Fikes and Nils Nilsson part_K_rows(,_,) :- !.Īpplying part_K_rows/3 to the original sudoku matrix, then transposing each of the resulting row partitions and applying part_K_rows/3 to each of them will produce the required list of "box" lists.This notebook explores () Stanford Research Institute Problem Solver. To do so only requires a further predicate to "partition" a matrix into groups of K rows apiece. Using you same design as before, you would also need a predicate to repackage the sudoku matrix into a list of "box" lists. Note however for a generalized sudoku matrix of size K²xK², you also have "all different" entries in each "box" of size KxK tiling the matrix. The idea is to create a new "first row" by pulling the head off each existing row, then recurse on the list of "leftover" tails. Here's some simple Prolog to transpose a matrix in list-of-lists representation.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |