Topology / ALM-Compiler

A Java implementation of the ALM language that compiles to the SPARC variant of Answer Set Programming (ASP).
Apache License 2.0
0 stars 1 forks source link

CALM bug? -- #18

Closed zhangyuanlin closed 6 years ago

zhangyuanlin commented 6 years ago

In

                    impossible occurs(X) if
                        instance(X,cook_toast_side),
                        toast(X) = T1,
                        instance(Y,cook_toast_side),
                        toast(Y) = T2,
                        instance(Z,cook_toast_side),
                        toast(Z) = T3,
                        T1 != T2,
                        T2 != T3,
                        T1 != T3.

cook_toast_side is an action sort. It is ok in first instance(...), but complained in the second instance(...). For specific error message and program, see below.

Error message

ErrorID: CND008
Message: Term  [cook_toast_side at (45:35)] has not been declared as a function term or a constant for any sort.

The program


system description simple_french_toast
    theory french_toast
        module cooking_toast
            sort declarations
                things :: universe
                % NEW a good example for using Herbrand function
                % to represent two sides of a toast.
                toasts :: things
                sides :: things

                cook_toast_side :: actions
                    attributes
                        toast : toasts
                        side : sides

            function declarations
                fluents
                    basic
                        total is_side_cooked : toasts * sides -> booleans
                    defined
                        toasted : toasts -> booleans
            axioms
                dynamic causal laws
                    occurs(X) causes is_side_cooked(T, S) if 
                                    instance(X,cook_toast_side), 
                                    toast(X) = T, 
                                    side(X) = S.

                executability conditions
                    impossible occurs(X) if 
                                        instance(X,cook_toast_side), 
                                        is_side_cooked(T, S),
                                        toast(X) = T, 
                                        side(X) = S.
                    % NEW it is not possible to cook both sides at the same time
                    %impossible occurs(X) if
                    %   instance(X,cook_toast_side), toast(X) = Tx, side(X) = Sx,
                    %   occurs(Y), instance(Y,cook_toast_side), toast(Y) = Tx, side(Y) = Sy,
                    %   Sx != Sy.

                    %cannot cook more than two toasts at a time
                    impossible occurs(X) if
                        instance(X,cook_toast_side),
                        toast(X) = T1,
                        instance(Y,cook_toast_side),
                        toast(Y) = T2,
                        instance(Z,cook_toast_side),
                        toast(Z) = T3,
                        T1 != T2,
                        T2 != T3,
                        T1 != T3.

                function definitions
                    toasted(T) if is_side_cooked(T,S1), is_side_cooked(T,S2),S1 != S2.

structure toastbread
    instances
        t1 in toasts
        s1t1,s2t1 in sides
        toasting_bread(T,S) in cook_toast_side
                toast = T
                side = S

planning problem
max steps 3

history
% initially all three blocks b1 to b3 are on table
observed(is_side_cooked(t1,s1t1),false, 0).
observed(is_side_cooked(t1,s2t1),false, 0).
% observed(is_side_cooked(t1,s2t1),true, 1).

% Our goal is to have b1 on b2, b2 on b3 and b3 on table.
goal = {toasted(t1)}
zhangyuanlin commented 6 years ago

Maybe it is an ambiguity in ALM as described in the paper. The following is from paper


An executability condition for actions is an expression of the form
                        impossible occurs(a) if instance(a, c), cond
where a is a variable or an object constant, c is the sort actions or a subsort of it, 
and cond is a collection of literals and expressions of the form occurs(t) or ¬occurs(t) 
where t is a variable or an object constant of the sort actions. 
The law says that an occurrence of an action a of the sort c is impossible 
when condition cond holds.
anuradha252 commented 6 years ago

can occurrence of one action depend on the occurrence of another in the executability condition? from what I read from above I seem to understand that cond can include the occurrence of another action. is that correct?

zhangyuanlin commented 6 years ago

I think so.

zhangyuanlin commented 6 years ago

The specification of executability condition does seem to allow any other literals. I am not sure if that is intentional or an overlook.

zhangyuanlin commented 6 years ago

Sorry, a correct reading could be: it allows all kinds of literals as well as expressions using occurs. So the specification is good.

Topology commented 6 years ago

calm.jar is updated. the above program is now producing final answer sets. I did not check if the answer set was correct.