HAL: a fast matching algorithm

Source: Internet
Author: User

(Note: This article references from P.-y.leeanda.m.k.cheng, "Hal:a faster Match algorithm", IEEE Trans. Knowledge and Data eng.,vol.14,no.5,sept./  Oct. 2002.) HAL: Fast matching algorithm one, Introduction

The generation system of forward inference has been applied in various fields. The basic structure of these production systems is divided into three parts. The first part is the inference engine of the control rule. The second section is a working memory that consists of all the facts or assertions to resolve the problem. The third part is the rule set, and each rule consists of LHS and RHS. Where LHS consists of one or more fact-related conditions, RHS is the operation of elements in working memory. The following figure is an example of rules and working memory in a OPS5

In the figure above, p shows the beginning of a rule, Rule-one is the name of the rule. Class_x is the name of the class where the facts are. A pointed "^" indicates a property in the class. "Al" is the name of the attribute. "< >" indicates that it is a variable name.

Typically, a production system is usually the following matching process:

1. Match: The conditions in the rule match the facts in the working memory, and all conditions are matched and the successful rule is instantiated and entered into the conflict set.

2, select (SELECT): Through some kind of conflict policy, select a rule instantiation in the conflict set.

3, Execution (ACT): The action of the selected rule will be executed, it is possible to change the working memory element state.

The state of working memory in the production system rarely changes during the forward inference operation. Therefore, many algorithms attach great importance to restricting the link operation in the matching process, so as to prevent all the facts and the combination of all the rules to match the problem. This is mainly done by maintaining a matching network of each rule separately. The nodes in these networks all store the relevant facts. When elements in working memory are deleted or added, the nodes are updated accordingly, but no matching network is recompiled. However, the current algorithm still has a combinatorial problem, and the match is treated as a NP-hard problem (Np-hard).

McDermott et al. It is considered that the process of establishing a matching network is much less expensive in a production system than a matching test. The Rete and treat algorithms are focused primarily on the fact space in working memory, and Matchbox focuses on the binding values of variables and variables in the binding space rather than the conditions and facts. Matchbox still uses the composite network structure in the binding space. The combination properties of these matching algorithms greatly affect the execution speed of the production system.

This paper introduces a new algorithm called heuristic-annotation-Connection (Heuristically-annotated-linkage, HAL), which supports link matching, but does not perform Cartesian product matching. The rule node provides a feedback message to establish a heuristic association with the relevant type node about the fact instantiation. When the fact set in working memory changes, and the new node content partially matches the conditional element, the corresponding rule is fired by a class node or intermediate node. The HAL supports equality condition matching, negative condition matching, and unequal condition matching (<). The HAL mainly uses heuristic information for classes, not rules, because in a program, rules are defined more than classes. The number of classes is generally fixed, and as the program changes, the number of rules generally changes. Based on class definition, a global fixed-traversal-distance matching support structure is sufficient, and in other matching algorithms, a matching support structure is established for each rule.

The HAL uses the following matching procedure:

Pretreatment (preprocessing)

Rules and classes are transformed into three-class nodes: Rule nodes, class nodes, and intermediate nodes (intermediate nodes). The intermediate node is between the rule node and the class node. The phase of preprocessing is similar to the local matching network which establishes the rules in the traditional matching stage. Preprocessing assumes that neither the rule nor the class definition will change. The rule node contains pointers that directly point to the related class node.

1. Select (select)

Nodes that contain facts that are fully matched to the rule will enter the conflict set. The rule instantiation selects a rule action execution according to the conflict policy.

2. Operation (operate)

The action performed according to the rule action is likely to change the contents of the related class node.

3. Excitation (stimulate)

The modified class node may fire the rule node associated with it, or the associated intermediate node.

The above three operations (1,2,3) are cycled until no related class node is executed, or a termination instruction is encountered. two, various matching algorithms

The following example is used to describe the rete,treat, and matchbox matching process.

Rete establishes a local network that includes alpha and beta memory for each rule. The depth and width of the network are proportional. The top of the network is the Alpha Memory node, which holds the tokens of the partial matching criteria element. The remaining network nodes are beta nodes that hold the tokens of the conditional element variable bindings and connections. As shown in the following figure.

Compared to Rete, the treat network only establishes a local alpha node for each rule. The alpha nodes in the treat are more responsible than the Rete, and the alpha nodes are divided into three parts. The old (OID) node, the newly added (new-add) node, and the newly deleted (new-delete) node. When a new fact is inserted in the Alpha node, a search is thrown that can cause a change in the set of conflicts. The following figure

Because of the combination characteristics of these matching algorithms (combinatorial nature), the matching time is likely to be very long. Rules with more conditions, the match time becomes very long. The redundant data in the node further exacerbates the situation. Using heuristics between nodes, the HAL algorithm introduces a feedback mechanism which reduces the time to determine whether a rule is matched and solves the problem of matching time. Meanwhile, a global matching network is introduced to eliminate the problem of data redundancy in local support matching networks. three, Hal algorithm

Besides using the operation of the class, the HAL algorithm absorbs the advantages of other matching algorithms. The HAL algorithm establishes a global, fixed-height pseudo bidirectional network (global fixed-height Pseudobipartite Network). There are two types of nodes in this network, DB in the head and the bottom, there may be a third node between the two types of nodes, intermediate nodes. The characteristics of pseudo bidirectional network reduce the number of nodes in traditional treat algorithm. By introducing the intermediate node, the HAL algorithm also supports the binding space matching of the traditional Matchbox algorithm. At the same time, by introducing heuristic knowledge (such as the priority information of conditional value of rule matching), this algorithm is suitable for real-time system application. In addition, the cost of establishing and maintaining a support network is minimal, as there is only one global matching support network. The level of responsibility for the HAL network is largely determined by the number of classes, whereas in general the class is less than the number of rules. matching algorithm of 3.1 HAL algorithm

The matching process for the HAL algorithm:

1. Establish a global pseudo bidirectional network, establish a rule node for each rule, a class node for each class. For each rule, if the class involves a variable binding, an intermediate node is established for this rule. A rule contains a variable binding, there is a two-way communication link between its rule node and the intermediate node. There is no rule with variable bindings whose class nodes are directly connected to the rule node.

2. Iterate through all the facts that have not been checked or updated, select one of them. Check the class node for the class in this fact. If such a node is attached to an intermediate node, when the fact is added, the new factual information is sent to the intermediate node, and when the fact is deleted, the new factual information is sent to the intermediate node and the rule node. Go to step 3. If there is no intermediate node, check the test condition of the class node to see if it is satisfied. If satisfied, fire the appropriate rule node and go to step 4. If no new facts or changes are made, the algorithm terminates.

3. At each intermediate node, if the new bound value is not a fact of being monitored or is a deletion, all related class nodes are fired. If the newly added fact is a listening fact that this fact satisfies a set of variable bindings, the corresponding rule node is fired. Turn to step 4.

4. Check the newly added instantiation condition element or delete the information to determine if all the conditional elements are satisfied or partially unsatisfied. If all is met, the operation of the RHS section is performed. If the portion is not satisfied, modify the status of the corresponding conditional element. If you do not have a "stop" action, turn to step 2 or the end algorithm. 3.2 Matching Process example

Hal Pseudo Bidirectional Network

The example above in the HAL algorithm matches the following:

Add Facts (A 1). The middle node (XY) is triggered. Accordingly, the (X-y) node fires the B-node, and the B-node starts listening (b 1 *) to match rule 1.

Add Facts (A 2). The middle node (XY) is triggered. Accordingly, (X-y) triggers a B-node to listen (b 2 *) to match rule 1.

Add Facts (B 1 3). The intermediate node (XY) is triggered, triggering the C node to listen (c 3) to match rule 1.

Add Facts (B 3 5). The middle node (XY) is triggered, triggering a C node to listen (c 5) and triggering a node listener (a 3) to match.

Add Facts (B 3 7). Triggers the middle node (XY). Trigger C node Listening (c 7). 3.3 Discussion

One reason HAL is more suitable for real-time systems is that a-type match (type a matching) and type B matching are introduced in the algorithm. A type match is a successful match of the entire rule after an element in the rule has been successfully matched. All matches that do not belong to a type match are called B-type matches. In the HAL, only a type match needs to update the information of the three types of nodes in the global matching network, only the relevant local information should be passed between the two kinds of nodes in B type matching. In real time systems, a type of match is involved in assigning a higher priority than type B.

Hal achieves better performance because it streamlines the matching support structure to a single structure that uses a class definition rather than a rule definition.

One requirement of applying a production system to a real-time environment is that the response time of the production system should not exceed the limit set by the application. The HAL algorithm can be applied to the rule-based real-time system well by proper modification. A similar pseudo bidirectional network can be constructed by adding a class fourth node, the assertion node. You can determine the upper and lower limits of the allowable time at the rule matching execution stage.

For production programs that have as many class variables and rules as they are, the HAL runtime complexity may be the same as other rule-based representations. Also, because the bidirectional network that traverses the HAL is a constant, the HAL should allow faster. Generally, in many applications, the number of rules is more than the number of class variables, HAL in this case performance better. 3.4 Conclusion

The main feature of the HAL algorithm is the introduction of a global matching support network. The HAL absorbs the advantages of the existing algorithm while reducing the matching time. At the same time, the matching support network is reduced by minimizing redundant content. This is mainly through the establishment of relevant rules and classes of direct heuristic feedback channel. Compared to other matching algorithms, only one-way communication is used.

Future work depends on the performance of Hal in a large rule-based system, while looking at the changes in the performance of the HAL as the number of rules increases. Next, further optimize the OPS5 system and systems similar to OPS5. Finally, the HAL is fully and effectively applied to the rule-based system of OPS5 and clips.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.