/* Explanation-Based Generalization (EBG) in Picat v3. This is a port of the program minihyper.pl in I. Bratko, "Prolog Programming for Artificial Intelligence", 4th edn., Pearson Education / Addison-Wesley 2012 Page 621ff (Figures 25.6, 25.7) This is the gift example from figure 25.6. This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import ebg_v3. main => go. % example from page 624 and 625 go ?=> load_gifts, ebg($gives(john,john,chocolate),$gives(X,Y,Z),Condition), number_vars([X,Y,Z]), println(condition=Condition), nl. go => true. % another example from page 624 go2 ?=> load_gifts, ebg($gives(john,annie,tennis_racket),$gives(X,Y,Z),Condition), number_vars([X,Y,Z]), println(condition=Condition), nl. go2 => true. % Figure 25.6 Two problem definitions for explanation-based generalization. % For compatibility with some Prologs the following predicates % are defined as dynamic: % :- dynamic gives/3, would_please/2, would_comfort/2, feels_sorry_for/2, % go/3, move/2, move_list/2. % A domain theory: about gifts % hakank: Load predicates to bp context load_gifts :- bp.assertz($(gives( Person1, Person2, Gift) :- likes( Person1, Person2), would_please( Gift, Person2))), bp.assertz($(gives( Person1, Person2, Gift) :- feels_sorry_for( Person1, Person2), would_comfort( Gift, Person2))), bp.assertz($(would_please( Gift, Person) :- needs( Person, Gift))), bp.assertz($(would_comfort( Gift, Person) :- likes( Person, Gift))), bp.assertz($(feels_sorry_for( Person1, Person2) :- likes( Person1, Person2), sad( Person2))), bp.assertz($(feels_sorry_for( Person, Person) :- sad( Person))). % Operational predicates operational( likes( _, _)). operational( needs( _, _)). operational( sad( _)). % An example situation likes( john, annie). likes( annie, john). likes( john, chocolate). needs( annie, tennis_racket). sad( john). % % Another domain theory: about lift movement % % go( Level, GoalLevel, Moves) if % % list of moves Moves brings lift from Level to GoalLevel % go( Level, GoalLevel, Moves) :- % move_list( Moves, Distance), % A move list and distance travelled % Distance =:= GoalLevel - Level. % move_list( [], 0). % move_list( [Move1 | Moves], Distance + Distance1) :- % move_list( Moves, Distance), % move( Move1, Distance1). % move( up, 1). % move( down, -1). % operational( A =:= B).