%% morphing_vehicles.lp %% Last Modified: 3/16/14 %% Additional Exercise for Chapter 8 %% Recall the vehicle hierarchy from Section 5.4.2 in which we had a %% vehicle, Darling, that could be both a sub and a car. %% In this problem, instead of simply belonging to two categories at %% once, the vehicle morphs from one mode into another; hence, the %% properties inherited by Darling are fluents. %% %% --------- %% Exercise: %% --------- %% Consider an action "morph" turning an object from a car to a sub, etc. %% For simplicity, assume that an object can only belong to one class %% at a time and that morphing only occurs between leaf classes. %% Describe the following vehicle hierarchy and action morph in ASP. %% %% vehicle %% / | \ %% land_vehicle sea_vehicle air_vehicle %% | | | %% car sub plane %% %% Initially, Darling is a car and the Narwhal is a sub. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% #const n = 1. class(car). class(sub). class(plane). class(land_vehicle). class(sea_vehicle). class(air_vehicle). class(vehicle). vehicle_mode(car). vehicle_mode(sub). vehicle_mode(plane). object(narwhal). object(darling). %% Fluents: fluent(inertial, is_a(O,C)) :- object(O), class(C). fluent(defined, member(O,C)) :- object(O), class(C). %% Action: action(morph(O,C)) :- object(O), vehicle_mode(C). step(0..n). % Description of subclass links: is_subclass(sub,sea_vehicle). is_subclass(car,land_vehicle). is_subclass(plane,air_vehicle). is_subclass(air_vehicle,vehicle). is_subclass(sea_vehicle,vehicle). is_subclass(land_vehicle,vehicle). %% Subclass Relation: subclass(C1,C2) :- is_subclass(C1,C2). subclass(C1,C2) :- is_subclass(C1,C3), subclass(C3,C2). -subclass(C1,C2) :- class(C1), class(C2), not subclass(C1,C2). %% Laws: % morph(O,C) causes is_a(O,C) holds(is_a(O,C),I2) :- occurs(morph(O,C),I1), I2 = I1 + 1, I1 < n. % -is_a(O,C2) if is_a(O,C1), C1 != C2 -holds(is_a(O,C2),I) :- holds(is_a(O,C1),I), class(C2), C1 != C2. % member(X,C) if is_a(X,C) holds(member(X,C),I) :- holds(is_a(X,C),I). % member(X,C) if is_a(X,C0), subclass(C0,C) holds(member(X,C),I) :- holds(is_a(X,C0),I), subclass(C0,C). %% Inertia Axioms: holds(F,I2) :- fluent(inertial, F), holds(F,I1), not -holds(F,I2), I2 = I1 + 1, I1 < n. -holds(F,I2) :- fluent(inertial, F), -holds(F,I1), not holds(F,I2), I2 = I1 + 1, I1 < n. %% CWA for Defined Fluents: -holds(F,I) :- fluent(defined, F), step(I), not holds(F,I). %% CWA for Actions -occurs(A,I) :- action(A), step(I), not occurs(A,I). %% Initial State: holds(is_a(narwhal,sub),0). holds(is_a(darling, car),0). occurs(morph(darling,sub),0).