include "../library-ontology"
include "../library"

module MBF;

% Monkey and Bananas: floor level

% An action may have a theme and may be executed by an agent.  To execute
% such an action, an agent has to be at the same place as the theme.

  import LOCAL;

  objects
    Monkey, Box: Thing;
    P1, P2, P3 : Place;

  actions
    Walk(Place); PushBox(Place);

  variables
    x: Thing;
    p: Place;

% Walk is a special case of library action Move.

  import MOVE;
    Move(Monkey,p) is Walk(p);

% PushBox(p) has all the properties of library action Move(Monkey,p)

  import MOVE;
    Move(Monkey,p) is PushBox(p);

% PushBox(p) also has all the properties of library action Move(Box,p)

  import MOVE;
    Move(Box,p) is PushBox(p);

% Actions cannot be executed concurrently.

  import NOCONCURRENCY;

  axioms
    Actor(Monkey, PushBox(p));
    Theme(Box, PushBox(p));



module MBS;

% Monkey and Bananas: how things are supported

  import MBF;

  objects
    Bananas:        Thing;
    Floor, Ceiling: Supporter;

% TopLocation(x) is the location of the things whose support is x.

  import TOP;

  actions
    ClimbOn; ClimbOff; GetBananas;

  variables
    x: Thing;
    p: Place;
    s: Supporter;

% GetBananas is a special case of library action Mount.

  import MOUNT;
    Mount(Bananas, Monkey) is GetBananas;

% ClimbOn and ClimbOff are special cases of library action MOUNT.

  import MOUNT;
    Mount(Monkey,Box) is ClimbOn; 

  import MOUNT;
    Mount(Monkey,Floor) is ClimbOff;

  axioms

    constraint Support(Box)=Floor;    
    constraint Support(Monkey)=Floor | Support(Monkey)=Box;



% This sort will be needed for the full description below
sorts
  Level;

module MB;

% Monkey and Bananas: full description

  import MBS;

  objects
    Lo, Hi: Level;

  fluents
    Elevation(Thing): simple(Level);
    TopLevel(Thing): staticallyDetermined(Level);

  variables
    x: Thing;
    f: Supporter;
    l: Level;

% To execute an action, an agent has to be at the same level as the theme.

  import LOCAL;
    Place is Level;
    Location(x) is Elevation(x);

% TopLevel(x) is the elevation of the things whose support is x.

  import TOP;
    Place is Level;
    Location(x) is Elevation(x);
    TopLocation(x) is TopLevel(x);

axioms

% Normally things are not tall: whatever is supported by x is at the same
% level as x.  (The default in module TOP.)  The box is an exception.
    TopLevel(Box)=Hi;

% Things directly supported by the floor are low and things directly
% supported by the ceiling are high.
    Elevation(x)=Lo if Support(x)=Floor;
    Elevation(x)=Hi if Support(x)=Ceiling;


%
%module MBD;
%
%% Monkey and Bananas: full description with defined fluents
%
%  import MB;
%
%  fluents
%    Hangs, HasBananas, OnBox:  staticallyDetermined;
%
%  axioms
%
%    default -Hangs, -HasBananas, -OnBox;
%
%    Hangs if Support(Bananas)=Ceiling,
%    HasBananas if Support(Bananas)=Monkey;
%    OnBox if Support(Monkey)=Box;
