• No se han encontrado resultados

As noted above, variations on the basic scheme for forward-chaining are possible. Where variables are used in rules, the conclusions may be performed using just the first set of instantiations that are found — this is single instantiation. Alternatively, the conclusions may be performed repeatedly using all possible instantiations — this is multiple instantiation. The difference between the two approaches is shown in Figure 2.3. As an example, consider the following pair of rules:

/* Rule 2.20 */

IF control valve ?x is open THEN flow rate in tube ?x is high Find all sets of instantiations

of variables

Fire conclusion for each set of instantiations Build conflict set

Select rule to fire

Find one set of instantiations of variables

Fire conclusion for that set of instantiations Build conflict set

Select rule to fire Conflict set empty? Stop no yes Conflict set empty? Stop no yes (a) (b)

Figure 2.3 Alternative forms of forward-chaining: (a) multiple instantiation of variables

/* Rule 2.21 */

IF flow rate in tube ?x is high THEN close control valve ?x

Suppose that we start with two facts:

control valve 1 is open control valve 2 is open

Under multiple instantiation, each rule would fire once, generating conclusions in the following order:

flow rate in tube 1 is high flow rate in tube 2 is high close control valve 1 close control valve 2

If the conflict resolution strategy gives preference to Rule 2.21 over Rule 2.20, a different firing order would occur under single instantiation. Each cycle of the inference engine would result in a rule firing on a single instantiation of the variable x. After four cycles, conclusions would have been generated in the following order:

flow rate in tube 1 is high close control valve 1

close control valve 2 flow rate in tube 1 is high close control valve 1 flow rate in tube 2 is high close control valve 2 flow rate in tube 1 is high close control valve 1 flow rate in tube 2 is high (a) (b)

Figure 2.4 Applying Rules 2.20 and 2.21: (a) multiple instantiation is a breadth-first process

flow rate in tube 2 is high close control valve 2

Multiple instantiation is a breadth-first approach to problem solving and single instantiation is a depth-first approach, as illustrated in Figure 2.4. The practical implications of the two approaches are discussed in Chapters 11 and 14.

2.7.2 Rete algorithm

The scheme for forward-chaining shown in Figure 2.2 contains at least one source of inefficiency. Once a rule has been selected from the conflict set and fired, the conflict set is thrown away and the process starts all over again. This is because firing a rule alters the fact base, so that a different set of rules may qualify for the conflict set. A new conflict set is therefore drawn up by re- examining the condition parts of all the available rules. In most applications, the firing of a single rule makes only slight changes to the fact base and hence to the membership of the conflict set. Therefore, a more efficient approach would be to examine only those rules whose condition is affected by changes made to the fact base on the previous cycle. The Rete (pronounced “ree-tee”) algorithm [1, 2] is one way of achieving this.

The principle of the Rete algorithm can be shown by a simple example, using the following rule:

/* Rule 2.22*/

IF ?p is a pipe of bore ?b AND ?v is a valve of bore ?b THEN ?p and ?v are compatible

Prior to running the system, the condition parts of all the rules are assembled into a Rete network, where each node represents an atomic condition, i.e., one that contains a simple test. There are two types of nodes — alpha nodes can be satisfied by a single fact, whereas beta nodes can only be satisfied by a pair of facts. The condition part of Rule 2.22 would be broken down into two alpha nodes and one beta node:

D1: find a pipe D2: find a valve

E1: the bore of each must be equal

The Rete network for this example is shown in Figure 2.5. Suppose that, initially, the only relevant fact is:

Node D1 would be satisfied, and so the fact would be passed on to node E1. However, node E1 would not be satisfied as it has received no information from node D2. The fact that there is a pipe of bore 100mm would remain stored at node E1. Imagine now that, as a result of firing other rules, the following fact is derived:

v1 is a valve of bore 100mm

This fact satisfies node D2 and is passed on to node E1. Node E1 is satisfied by the combination of the new fact and the one that was already stored there. Thus, Rule 2.22 can be added to the conflict set without having to find a pipe again (the task of node D1).

A full Rete network would contain nodes representing the subconditions of all the rules in the rule base. Every time a rule is fired, the altered facts would be fed into the network and the changes to the conflict set generated. Where rules contain identical subconditions, nodes can be shared, thereby avoiding duplicated testing of the conditions. In an evaluation of some commercially available artificial intelligence toolkits that use forward- chaining, those that incorporated the Rete algorithm were found to offer substantial improvements in performance [3].

α1: find a pipe

α2: find a valve

β1:

each item has the same bore

new facts

The rule is added to the conflict set if a fact passes node β1

Documento similar