Tải bản đầy đủ (.pdf) (2 trang)

Bài tập trí tuệ nhân tạo state space search

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (119.14 KB, 2 trang )

Artificial Intelligence (2014-2015)
Lab 2
STATE SPACE SEARCH
1. OBJECTIVE
The objectives of Lab 2 are (1) to introduce the Prolog’s powerful concept of compound term;
and (2) to do the complete solution of state search space illustrated by the means of the 8-puzzle
problem (3) and to practice your java programming skills.
2. EXPERIMENT
2.1. Compound terms
Compound term is a Prolog concept used to describe combined and structured concepts. In
Listing 1, what we want to imply in the first fact is “MU is a football club whose jersey color is
red” and the second “Chelsea is yet another football club whose jersey color is blue.”
red(club(mu)).
blue(club(chelsea)).

Here we have club(mu) and club(chelsea) are some compound terms used by the predicates
red and blue respectively. Unification and resolution, the two great things coining the power of
Prolog, can be applied on the compound terms as well as if on atoms. Listing 2 introduces some
attempts to find the best player in red and blue jerseys.
bestplayer(mu,ronaldo).
bestplayer(chelsea,terry).

Who is the best player?
bestredplayer(X):-red(club(Y)),bestplayer(Y,X).
bestblueplayer(X):-blue(club(Y)),bestplayer(Y,X).

Try the following queries and observe the results.
bestredplayer(X)
bestblueplayer(X)

2.2. Search solution for the 8-puzzle problem


OK, now we try to solve the first basic toy AI problem, the 8-puzzle one. No, “we” does not
include you, but… we only. Your job is to take into consideration the search.pl and setting.pl
files. All are done in there.
The principle is to use two stacks (or queues, it depends) named open and closed in the
working memory of Prolog. Then, in search.pl, we have implemented the following things:
- path: it retracts one state out of open, put all of children of the state into closed. If open is
empty but the goal is still not reached, it will display the failure message. Otherwise, the goal is
displayed.

CuuDuongThanCong.com

/>

- checkgoal: It checks if the first state in open is the goal or not.
- get_children: It generates all of children of the parameter in order to put them into open.
- addToOpen: It put a state to the open. Depending on the algorithm used, the corresponding
predicate is invoked.
- move: It moves from the current state to another, provided that neither open and closed are
not empty.
- go: the first predicate to be run.
In file setting.pl, we define problem-specified features, which include the following:
- The KB of possible legal moves. For example:
move(state([X1,X2,X3,X4,0,X6,X7,X8,X9]), state([X1,0,X3,X4,X2,X6,X7,X8,X9])) means
that we can move the blank up in the current state (0 represents the blank tile).
- algorithm(dfs): It indicates the search algorithm. One may want replace dfs by brfs.
- mywrite: Write out a state.
- go_p and isGoal: They define the initial state and the goal respectively.
3. EXERCISES
3.1. Try to run the 8-puzzle program successfully. Change the first initial and goal and observe
the results.

3.2. Modify the file setting.pl to solve the water-jug problem (you should not touch the
search.pl file).
3.3. Use Java to solve the water-jug problem.
4. SUBMISSIONS
There is no writing submission required. Students run their solutions at their workstations and
answer questions from instructors to get marked.
-- End --

CuuDuongThanCong.com

/>


×