**Algorithm 1** Planning graph expansion

1: **procedure** EXPAND (*si*) ▷*si*: *<sup>i</sup>*-th state layer 2: *Ai*þ<sup>1</sup> *KBS:InferenceCycle si* ð Þ , *<sup>A</sup>* <sup>▷</sup>*A*: action profiles 3: *si*þ<sup>1</sup> ∪*Ai*þ1*:effects*<sup>þ</sup> 4: *<sup>μ</sup>Ai*þ1 ð Þ *<sup>a</sup>*, *<sup>b</sup>* <sup>∈</sup> *<sup>A</sup>*<sup>2</sup> *<sup>i</sup>*þ1, *<sup>a</sup>* 6¼ *<sup>b</sup>*<sup>j</sup> *Dependent a*ð Þ , *<sup>b</sup>* ∨∃ð Þ *<sup>p</sup>*, *<sup>q</sup>* <sup>∈</sup>*μsi* : *<sup>p</sup>*∈*preconds* ð Þ *a* , *q*∈ *preconds b*ð Þg 5: *μsi*þ1 ð Þ *p*, *q* ∈*s* 2 *<sup>i</sup>*þ1, *<sup>p</sup>* 6¼ *<sup>q</sup>*j∀ð Þ *<sup>a</sup>*, *<sup>b</sup>* <sup>∈</sup> *<sup>A</sup>*<sup>2</sup> *<sup>i</sup>*þ<sup>1</sup> : *<sup>p</sup>* <sup>∈</sup>*effects*<sup>þ</sup> ð Þ *a* ∧*q*∈*effects*þð Þ! *b* ð Þ *a*, *b* ∈*μAi*þ1g

**6: end procedure**

• *Constant Test Nodes* (CTN): compares constant fields of premises with

The beta network is composed by the following nodes [10]:

• *Production Nodes*: terminal nodes for full rule matches.

• *Beta Memories* (BM): stores partial matches produced in JNs; and

• *Alpha Memories* (AM): stores facts that successfully passed the tests in CTNs.

• *Join Nodes* (JN): perform tests that ensure variable assignment consistency

The cognitive level uses the *Graphplan* algorithm to generate the plans that the other levels should execute. Originally, the algorithm used a propositional knowledge representation, so this will be adopted here for the algorithm description. The

Mathematically, a planning problem may be stated as P ¼ <sup>Σ</sup>, *sj*, *<sup>g</sup>* , where <sup>Σ</sup> <sup>¼</sup> ð Þ *S*, *A*, *γ* is the problem domain (that comprises the set of states *S*, the set of actions *A* and a state transformation function *γ* ¼ *S* � *A* ! *S*), *s <sup>j</sup>* is the initial state and *g* is

Each action *a*∈ *A* has a set *prencond a*ð Þ of precondition propositions and a set *effects a*ð Þ¼ *effects*þð Þ *a* ∪ *effects*�ð Þ *a* of effects. The effects, in turn, may be broken down into two subsets: *effects*þð Þ *a* , the set of positive propositions (propositions to be added), and *effects*�ð Þ *a* , the set of negative propositions (propositions to be deleted). The applicability condition for an action *a*, in a given state *s*, may be written as *precond a*ð Þ⊆*s*. The new state produced by the application of *a* would be

Consider an action layer *Aj* and the propositional layer *Pj*�<sup>1</sup> preceding it. *Aj* contains all actions *a* such that *precond a*ð Þ⊆ *Pj*�1, and *Pj*�<sup>1</sup> all propositions *p* such that *p*∈*Pj*�1. The so called planning graph is the built by connecting elements in

• edges connecting a proposition *p* ∈*Pj*�<sup>1</sup> to an action *a*∈ *A <sup>j</sup>*;

• edges connecting an action *a*∈ *Aj* to a proposition *p*∈*Pj*�1, such that

• edges connecting an action *a*∈ *A <sup>j</sup>* to a proposition *p* ∈*Pj*�1, such that

If two actions *a*1, *a*<sup>2</sup> ∈ *A <sup>j</sup>* obey *effects*�ð Þ *a*<sup>1</sup> ∩ *precond a*ð Þ<sup>2</sup> ∪ *effects*þð Þ *a*<sup>2</sup>

<sup>¼</sup> <sup>∅</sup>, they a said to be *independent*; if not,

Propositions can also be *mutex*: *p* and *q* are *mutex* if every action in *A <sup>j</sup>* that adds *p* is *mutex* with every action in *Aj* that produces *q*, and there are no actions in *Aj* that adds both *p* and *q*. Also, if a precondition of an action is *mutex* with a precondition

<sup>¼</sup> <sup>∅</sup> and

corresponding ones in the current fact; and

*Robotics Software Design and Engineering*

inside a premise instance (partial match);

**4. The** *Graphplan* **algorithm**

the goal state.

rest of this section uses [12, 13] as references.

*γ*ð Þ¼ *s*, *a s* � *effects*� ð Þ ð Þ *a* ∪ *effects*þð Þ *a* .

*p* ∈*effects*þð Þ *a* (positive arc); and

*p* ∈*effects*�ð Þ *a* (negative arc).

*effects*�ð Þ *a*<sup>2</sup> ∩ *precond a*ð Þ<sup>1</sup> ∪ *effects*þð Þ *a*<sup>1</sup>

of another action, the actions are *mutex*.

**92**

they are *dependent*, or *mutually exclusive* (*mutex*).

*Pj*�<sup>1</sup> to elements in *Aj* by edges:

The expansion stops when the goal state *g* is detected in the state layer *si*. It then triggers a recursive search for non-*mutex* actions in all the preceding action layers that could have produced the goal state found in *si*. This procedure is composed by the functions Search (Algorithm 2) and Extract (Algorithm 3).

**Algorithm 2** Search for *non-mutex* actions.

```
1: procedure SEARCh(g, πi, i)
2: if g ¼ ∅ then
3: Π Extract ∪f g preconds að Þj∀a∈πi ð Þ , i � 1
4: if Π ¼ Failure then
5: return Failure
6: end if
7: return Π:πi
8: else
9: select any p ∈g
10: resolvers a∈ Ai jp∈ effectsþð Þ a ∧∀b∈πi : ð Þ a, b �∈ μAi

11: if resolvers ¼ ∅ then
12: return Failure
13: end if
14: nondeterministically choose a∈resolvers
15: return Search(g � effectsþð Þ a , πi∪f ga , i)
16: end if
```
17: **end procedure**

**Algorithm 3** Extract a plan.

```
1: procedure EXTRACT(g, i)
2: if i ¼ 0 then
3: return ∅
4: end if
5: πi Search gð Þ , ∅, i
6: if πi 6¼ Failure then
7: return πi
8: end if
9: return Failure
10: end procedure
```