![]() Program move(state(middle,onbox,middle,hasnot), grasp, state(middle,onbox,middle,has)).move(state(P,onfloor,P,H), climb, state(P,onbox,P,H)).move(state(P1,onfloor,P1,H), drag(P1,P2), state(P2,onfloor,P2,H)).move(state(P1,onfloor,B,H), walk(P1,P2), state(P2,onfloor,B,H)).canget(state(_,_,_,has)).canget(State1) :- move(State1,_,State2), canget(State2). When we have reached to the state ‘ has>’, this indicates ‘ has banana’. ![]() Here we pass a state, so this will perform move predicate from one state to another using different actions, then perform canget() on state 2. Monkey can move from one place to another using walk or move clauses.Īnother predicate will be canget(). The push or drag operation moves the block from one place to another. on top state), by performing the action climb. has not state), then using the grasp action, it will change from has not state to have state.įrom the floor, it can move to the top of the block (i.e. When the block is at the middle, and monkey is on top of the block, and monkey does not have the banana (i.e. We have some predicates that will move from one state to another state, by performing action. We will create some predicates as follows − Now, let us see how we can solve this using Prolog. When the monkey is on the block, and block is at the center, then the monkey can get the bananas. So the vertical position of the monkey will be changed. If monkey and the block both are on the floor, and block is at the center, then the monkey can climb up on the block. If the block position is not at the center, then monkey can drag it to the center. From the above image, we can see that both the monkey and the block are on the floor. Monkey can reach the block, if both of them are at the same level. Below are few observations in this case − So if the monkey is clever enough, he can come to the block, drag the block to the center, climb on it, and get the banana. The monkey wants the banana, but cannot reach it. There is a block (or chair) present in the room near the window. Problem StatementĪ hungry monkey is in a room, and he is near the door.īananas have been hung from the center of the ceiling of the room. Here is the answer from prolog: 24 ?- plan().In this prolog example, we will see one very interesting and famous problem, The Monkey and Banana Problem. In this way we get unified G when dealing with goal_state. That means instead of generating all possible goal_states, we first try every reachable positions and then check if they are goal states. with plan(L) :- initial_state(I), reachable(I,L,G), goal_state(G). I solve the problem by replacing plan(L) :- initial_state(I), goal_state(G), reachable(I,L,G). Plan(L) :- initial_state(I), goal_state(G), reachable(I,L,G). ![]() The whole program is like this: %Initial states Is there any way that can help me get rid of the infinite loop? The first element here are aways move(a,b) since the program get infinite loop in satisfying move(d, area2). ![]() X = īut when I have more than one goals, say goal_state(S):- located_on(a,b,S),located_on(d,area2,S)., the fluents I get get stuck in one of its goals: ?- goal_state(X). The problem is that, when I have only one goal, say goal_state(S):- located_on(a,b,S), I can get all possible fluents S: ?- goal_state(X). We can know where each blocks are according to fluents(their action history). After each action, we add the action into the third parameter fluent.įor example, if we move a to b, then move b to c, then move c to d, the fluent would be. The fluent starts at empty list which means no action has been done yet. The third parameter of located_on is situations(fluents), which indicates the action history. ![]() The goal_state is where we want the blocks to be. The predicate located_on tells us the locations of blocks according to the fluents. This is a block world problem which is going to move the blocks where we want them to be. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |