
Prolog program for block world problem series#
Here 10 Ohm and 40 Ohm resistors are in parallel, then that is in series with 12 Ohm, and the equivalent resistor of the lower half is parallel with 30 Ohm. If R1 and R2 are in Parallel, then equivalent resistor Re = (R1 * R2)/(R1 + R2). If R1 and R2 are in Series, then equivalent resistor Re = R1 + R2. At first, we will try to get the result by hand, then try to see whether the result is matching with the prolog output or not. We have to find the equivalent resistance of this network. Let us consider the following circuit to understand this concept −
Prolog program for block world problem how to#
In this section, we will see how to write a prolog program that will help us find the equivalent resistance of a resistive circuit. Program find_max(X, Y, X) :- X >= Y, !.find_max(X, Y, Y) :- X Y. Similarly find_min(X,Y,Min) takes X and Y values, and store the minimum value into the Min variable. This takes X and Y values, and stores the maximum value into the Max. First, we will create two predicates, find_max(X,Y,Max). Here we will see one Prolog program, that can find the minimum of two numbers and the maximum of two numbers. Verify whether a line segment is horizontal, vertical or oblique compiling D:/TP Prolog/Sample_Codes/monkey_ for byte code.D:/TP Prolog/Sample_Codes/monkey_ compiled, 17 lines read - 2167 bytes written, 19 ms(31 ms) yes| ?- canget(state(atdoor, onfloor, atwindow, hasnot)).true ?yes| ?- trace.The debugger will first creep - showing everything (trace)yes| ?- canget(state(atdoor, onfloor, atwindow, hasnot)).In the following chapter, we are going to discuss basic prolog examples to −įind the equivalent resistance of a resistive circuit 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. In this prolog example, we will see one very interesting and famous problem, The Monkey and Banana Problem.
