Knowledge Representation & Reasoning

2. Logic-based knowledge representation and reasoning

2.3. Inferring a popcorn making plan

In this section, we introduce an axiomatization of the popcorn world, which allows us to derive a sequence of actions that achieves a subgoal of the popcorn making plan. We leave the specification of remaining axioms as an exercise to the reader. Let us consider the action sequence

  1. Put(Pot01, StoveCenter),
  2. Pour(Bowl01, Pot01),
  3. TurnKnob(switch(StoveCenter)),
  4. Wait(3),
  5. Put(Plate01, TableTopLeft),
  6. Pour(Pot01, Plate01).
We want to model actions and states in a way, such that a robot agent is able to automatically derive this action sequence as a plan that achieves its goal of having made popcorn in the kitchen environment and having served it on a plate. The initial state of the environment shall be

location(Bowl01 , S_0) = CounterTopRight
location(Pot01, S_0) = ShelfRight
location(Plate01, S_0) = ShelfLeft
in(Corn01, Bowl01, S_0)
\lnot switchedOn(StoveCenter, S_0)
\lnot popped(Corn01, S_0)

i.e., the unpopped corn is in the bowl on the right counter top, the cooking pot is in the right shelf, the plate in the left shelf, and the stove is switched off. Let the goal be that the corn has popped and is on a plate on one of the counter tops, i.e.,

\exists c,p,s. type(c, Corn) \land popped(c, s) \land type(p, Plate) \nonumber
\land in(c, p, s) \land location(p,s) \in{TabletopLeft,TabletopRight}.

By using existentially quantified entities, we have made the goal specification independent of specific instance names in the model.

In the previous section, we already provided a model of the Put action, which we can reuse so we move on and create a model of Pouring. The Pour(f,t) action denotes the transfer of a substance contained from a source container f to a destination container t. For simplicity, we will assume here that any container can hold exactly one unit of volume, and that Pour will cause a complete transfer, i.e., there will not be any leftovers in the source container after pouring. As preconditions, we require the destination container to be empty and unobstructed. Unobstructed means that the container is not covered by anything (like a lid), and that there is sufficient free space above its opening such that the pouring can be performed. Obviously, in our popcorn world, a container is only unobstructed if it is located at one of the counter tops or the stove, and there is nothing on top of it, i.e.,

\forall o, s. unobstructed(o,s) \Leftrightarrow location(o,s) \in {CounterTopLeft, CounterTopRight, StoveCenter}
\land\lnot(\exists o'. on(o',o,s)).

We can now define the preconditions, under which pouring is possible, as

\forall f, t, s. (type(f, Container) \land type(t, Container)
\land\exists c_1. in(c_1,f,s) \land \lnot(\exists c_2. in(c_2,t,s))
\land accessible(f,s) \land unobstructed(t,s)) \Rightarrow possible(Pour(f,t),s),

i.e., both f and t must be containers, f must be non-empty and accessible, and t must be empty and unobstructed. As postconditions, Pour will cause the contents of the source container to be in the destination container, whereas it ceases being in the source container:

\forall a,t,f,c,s. possible(a,s) \Rightarrow
(in(c, t, do(a,s)) \Leftrightarrow a = Pour(f,t) \land in(c,f,s)
\lor (in(c,t,s) \land\lnot(\exists t'. t' \neq t \land a = Pour(f,t'))),

The most interesting part of our popcorn example is the event when the corn pops. It is so interesting because it involves not only actions that transform the world state, but also physical and chemical processes that are captured in logical axioms. We will model the process in three parts: (1) the functionality of a switch, (2) the functionality of a stove, and (3) the popping process.

The core functionality of a switch is to toggle the state of an electrical device d in a situation s between switchedOn and \lnot switchedOn. We introduce a TurnKnob(k) action, which operates on a knob and flips an electrical device's state. It is possible to execute TurnKnob(k) if  k is a knob and belongs to an electrical device:

\forall k, s. (type(k, Knob) \land\exists d. switch(d) = k \land type(d, ElectricalDevice))
\Rightarrow possible(TurnKnob(k),s),

where switch(d) is a function denoting the switch of an electrical device. TurnKnob(k) will change the state of the device it belongs to from \lnot switchedOn(d,s) to switchedOn(d, do(TurnKnob(k),s)), and back:

\forall a, d, s. possible(a,s) \Rightarrow
(switchedOn(d, do(a,s)) \Leftrightarrow a = TurnKnob(switch(d)) \land\lnot switchedOn(d,s)
\lor switchedOn(d,s) \land a \neq TurnKnob(switch(d))),

When a stove is switched on, everything on its top will be exposed to heat. We can capture this introducing a fluent heated(o,s),

\forall o,s. heated(o,s) \Leftrightarrow \exists c,l. type(l,Stove) \land switchedOn(l,s)
\land location(c,l,s) \land (c = o \lor in(o,c,s) \land type(c, CookingPot)).

Note that in this formula, we have also modeled the heat conductivity of cooking pots, such that everything inside a pot will also be exposed to heat, when the pot is on a stove and the stove is switched on.

The final missing step in our world model is the popping process of the corn. In order for the corn to pop, it must be exposed to heat for 3 minutes. In a real-world setting, it would be desirable if a robot agent were able to spend the time until the corn has popped more useful, but for now we assume that it bridges this idle time with waiting. To this end, we introduce an action Wait(t), during which the agent sleeps for the given amount of time. First, let us specify that it is always possible to wait and do nothing:

\forall t, s. possible(Wait(t), s)

Time consuming processes like cooking or boiling can be elegantly modeled as postconditions of a waiting action, given that the world model satisfies certain conditions. In our example, we can state that the corn will have popped as a result of waiting for three minutes in a situation in which the corn is exposed to heat, i.e.,

\forall a,c,s. possible(a,s) \Rightarrow
(popped(c, do(a,s)) \Leftrightarrow a = Wait(3) \land heated(c,s) \land\lnot popped(c,s)
\land type(c, Corn) \lor popped(c,s).

Note that, in this case, there is no negative effect in the state successor axiom as the property of having popped is irreversible.

Starting from the initial state, it can be proven that our goal state in Equation can be reached by the action sequence

do(Pour(Pot01, Plate01),
do(Put(Plate01, TabletopLeft),
do(Wait(3)),
do(TurnKnob(switch(StoveCenter)),
do(Pour(Bowl01, Pot01),
do(Put(Pot01, StoveCenter),S_0))))))

Note that this solution is not unique. There are many alternative action sequences that achieve the goal state and many other ways of modelling the actions and processes one can think of. In kR&R, there is an entire subfield called qualitative physics and qualitative process theory that addresses this problem. A more thorough introduction to this field is beyond the scope of this chapter. We refer the interested reader to Brachman, Levesque 1985.