**3. The** *Rete* **algorithm**

As mentioned earlier in this chapter, the *Rete* matching algorithm is employed in the recognition stage the KBSs used by the CAA. It is proposed in [11], and is named after the latin word for "network".

The algorithm builds a graph out of the rules base of the KBS where each node has a special purpose. In the end, it avoids running through the entire facts base for each rule premise, every time a new fact arrives, by saving information about partial matches in some of its nodes [11].

The constructed graph has two portions: the alpha network, responsible for comparing the constants in the premises with the corresponding fields in the incoming fact; and the beta network, which checks for variable assignment consistency and maintenance of partial matches [10].

The nodes the compose the alpha network are the following [10]:

• *Root Node*: entry point for new facts;


The algorithm begins by expanding the graph. The pseudo-code for the expan-

*System Level Design and Conception of a System-on-a-Chip (SoC) for Cognitive Robotics*

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

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

*<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>

*<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*

�∈ *μAi*

sion step is given in Algorithm 1.

*DOI: http://dx.doi.org/10.5772/intechopen.98643*

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>

ð Þ *a* , *q*∈ *preconds b*ð Þg 5: *μsi*þ1 ð Þ *p*, *q* ∈*s*

**6: end procedure**

**Algorithm 1** Planning graph expansion

ð Þ *a* ∧*q*∈*effects*þð Þ! *b* ð Þ *a*, *b* ∈*μAi*þ1g

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

1: **procedure** SEARCh(*g*, *πi*, *i*)

4: **if** Π ¼ *Failure* **then** 5: **return** *Failure*

9: select any *p* ∈*g*

11: **if** *resolvers* ¼ ∅ **then** 12: **return** *Failure*

2: **if** *g* ¼ ∅ **then**

6: **end if** 7: **return** Π*:π<sup>i</sup>*

13: **end if**

16: end if

17: **end procedure**

2: **if** *i* ¼ 0 **then** 3: **return** ∅ 4: **end if**

7: **return** *π<sup>i</sup>* 8: **end if**

**93**

9: **return** *Failure* 10: **end procedure**

**Algorithm 3** Extract a plan. 1: **procedure** EXTRACT(*g*, *i*)

5: *π<sup>i</sup> Search g*ð Þ , ∅, *i* 6: **if** *π<sup>i</sup>* 6¼ *Failure* **then**

8: **else**

2

the functions Search (Algorithm 2) and Extract (Algorithm 3).

3: Π *Extract* ∪f g *preconds a*ð Þj∀*a*∈*π<sup>i</sup>* ð Þ , *i* � 1

10: *resolvers a*∈ *Ai* j*p*∈ *effects*þð Þ *a* ∧∀*b*∈*π<sup>i</sup>* : ð Þ *a*, *b*

14: nondeterministically choose *a*∈*resolvers* 15: **return** Search(*g* � *effects*þð Þ *a* , *πi*∪f g*a* , *i*)

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

