%% heuristics.lp = %% bwplan_choice.lp + new initial state, new goal state + heuristics %% Section 9.3 %% Last Modified: 2/4/14 %% Heuristics for the blocks world: %% -- Don't put blocks into the same location %% -- Only consider moving blocks that are out of place %% -- Give priority to actions that increase the number of blocks %% -- placed in the right position block(b0). block(b1). block(b2). block(b3). block(b4). block(b5). block(b6). block(b7). block(b8). block(b9). block(b10). block(b11). block(b12). block(b13). block(b14). block(b15). block(b16). location(X) :- block(X). location(t). fluent(inertial, on(B,L)) :- block(B), location(L). fluent(defined, above(B,L)) :- block(B), location(L). action(put(B,L)) :- block(B), location(L), B != L. #const n = 9. step(0..n). holds(on(B,L),I+1) :- occurs(put(B,L),I), I < n. -holds(on(B,L2),I) :- holds(on(B,L1),I), location(L2), L1 != L2. -holds(on(B2,B),I) :- holds(on(B1,B),I), block(B), block(B2), B1 != B2. holds(above(B2,B1),I) :- holds(on(B2,B1),I). holds(above(B2,B1),I) :- holds(on(B2,B),I), holds(above(B,B1),I). -occurs(put(B,L),I) :- location(L), holds(on(B1,B),I). -occurs(put(B1,B),I) :- block(B1), block(B), holds(on(B2,B),I). %% CWA for Defined Fluents -holds(F,I) :- fluent(defined,F), step(I), not holds(F,I). %% General Inertia Axiom holds(F,I+1) :- fluent(inertial,F), holds(F,I), not -holds(F,I+1), I < n. -holds(F,I+1) :- fluent(inertial,F), -holds(F,I), not holds(F,I+1), I < n. %% CWA for Actions -occurs(A,I) :- action(A), step(I), not occurs(A,I). %% Initial Situation: %% holds(on(B,L),I): a block B is on location L at step I. holds(on(b0,t),0). holds(on(b3,b0),0). holds(on(b2,b3),0). holds(on(b1,t),0). holds(on(b4,b1),0). holds(on(b5,t),0). holds(on(b6,b5),0). holds(on(b7,b6),0). % New Blocks: holds(on(b8,b4),0). holds(on(b9,t),0). holds(on(b10,b9),0). holds(on(b11,b10),0). holds(on(b12,b11),0). holds(on(b13,b12),0). holds(on(b14,t),0). holds(on(b16,b14),0). holds(on(b15,b16),0). %% If block B is not known to be on location L at step 0, %% then we assume it is not. -holds(on(B,L),0) :- block(B), location(L), not holds(on(B,L),0). %% Simple Planning Module: success :- goal(I), I <= n. :- not success. 1{occurs(Action,I): action(Action)}1 :- step(I), not goal(I), I < n. %%%%%%%%%%%%%% %% Heuristics %%%%%%%%%%%%%% %% Don't put blocks into the same location: :- holds(on(B,L),I), occurs(put(B,L),I). %% Only consider moving blocks that are out of place: in_place(B,I) :- subgoal(on(B,B1),true), holds(on(B,B1),I), in_place(B1,I). %in_place(B,I) :- subgoal(on(B,t),true), % holds(on(B,t),I). in_place(t,I) :- step(I). :- in_place(B,I), occurs(put(B,L),I). %% Give priority to actions that increase the number of blocks placed %% in the right position: good_move(B,L,I) :- subgoal(on(B,L),true), in_place(L,I), -occupied(L,I), -occupied(B,I). occupied(B,I) :- block(B), holds(on(B1,B),I). -occupied(t,I) :- step(I). -occupied(B,I) :- block(B), step(I), not occupied(B,I). exists_good_move(I) :- good_move(B,L,I). :- exists_good_move(I), occurs(put(B,L),I), not good_move(B,L,I). %% Subgoals: subgoal(on(b4,t),true). subgoal(on(b1,b4),true). subgoal(on(b15,b1),true). subgoal(on(b3,t),true). subgoal(on(b2,b3),true). subgoal(on(b0,b2),true). subgoal(on(b8,b0),true). subgoal(on(b5,t),true). subgoal(on(b6,b5),true). subgoal(on(b7,b6),true). subgoal(on(b9,t),true). subgoal(on(b10,b9),true). subgoal(on(b11,b10),true). subgoal(on(b12,b11),true). subgoal(on(b13,b12),true). subgoal(on(b14,t),true). subgoal(on(b16,b14),true). %% New goal: goal(I) :- holds(on(b4,t),I), holds(on(b1,b4),I), holds(on(b15,b1),I), holds(on(b3,t),I), holds(on(b2,b3),I), holds(on(b0,b2),I), holds(on(b8,b0),I), holds(on(b5,t),I), holds(on(b6,b5),I), holds(on(b7,b6),I), holds(on(b9,t),I), holds(on(b10,b9),I), holds(on(b11,b10),I), holds(on(b12,b11),I), holds(on(b13,b12),I), holds(on(b14,t),I), holds(on(b16,b14),I). #show occurs/2.