Rule Engine (1): inference engine and Rule Engine

Source: Internet
Author: User
ArticleDirectory
    • Question proposal
    • Inference Engine and Rule Engine
Question proposal

Assume that:

A company produces two models of devices, m {M1, M2}. Both models support four features: f {F1, F2, F3, F4 }, however, what functions are available depends on the factory settings. Before leaving the factory, you need to perform various tests on the device. Currently, five tests are defined: t {T1, T2, T3, T4, and T5}. Which tests depend on the model. Each test on each device has a requirement for the latest execution date D, depending on the test item to be executed by the device.

Due to business needs, the relationships between devices of each model and the items to be tested and D will change frequently. For example, one of the rules is:

Test Item rules:

If M = m1, exec (T1, T2, T5)

If M = m2 and M. hasfunction (F1), exec (T2, T3)

If M = m2 and M. hasfunction (F2), exec (T4, T5)

If M = m2 and M. hasfunction (F3), exec (T3, T4)

If M = m2 and M. hasfunction (F4), exec (T1, T3)

Test Time rules (where D indicates the number of days, for example, 3 indicates that the latest execution date is 3 days later) follow the rules from the highest priority to the bottom:

If M. Todo (T1), D = 3

If M. Todo (T2), D = 7

If M. Todo (T3), D = 10

If M. Todo (T4), D = 12

If M. Todo (T5), D = 14

 

The function is to obtain the test item and test time for each device based on the given rules and a group of devices.

 

Even if you do not consider the changes in rules, it is very tedious and tedious to implement such business rules. To avoid frequent deployment, rules must be defined and configured in some form and cannot be implemented by hard coding. (Of course, I have nothing to say if you adopt the osgi architecture and regularly update the bundle of the rule ).

Inference Engine and Rule Engine

The problem in the above example is a typical reasoning problem: based on the existing knowledge, analyze the actual situation and give a conclusion. IfProgramThis program is called the inference engine ). Inference engine is the core module of an Expert System (an expert system is a branch of Artificial Intelligence.

 

The inference engine uses different control policies based on different knowledge representation. Common types include neural networks, case-based and rule-based inference engines. Rule-based inference engines are easy to understand, acquire, and manage, and are widely used. This type of reasoning engine is called the rule engine ".

In the rule engine, knowledge is expressed as rules, and the situation to be analyzed is defined as fact ). The storage in the memory is called production memory and working memory, for example:

Rules and facts are input parameters accepted by the rule engine, and the Rule Engine itself consists of two components: Pattern matcher and agenda. Pattern matcher finds matched rules based on facts, and Agenda manages the execution sequence of the rules selected by patternmatcher. In the periphery, an execution engine is also responsible for executing specific operations based on the Rules output by agenda.

Among them, pattern matcher is the core of Rule Engine reasoning. In contrast to human thinking, the rule engine also has two ways of reasoning: Forward-chaining and backward-chaining ).

Positive reasoning is also called the embedding method. It is driven by facts. It starts from an initial fact and constantly applies rules to draw conclusions. First, select a rule in the Candidate queue to enable the rule for reasoning, and record the conclusion as the evidence for the next reasoning. Repeat this process until no available rules can be selected or the required solutions are obtained.

Reverse reasoning is also called induction. It is driven by goals. First, a hypothesis is put forward, and then evidence that supports this assumption is sought. If all the required evidence can be found, the original hypothesis is correct; if no evidence is found in any case, it means that the original hypothesis is not true. A new hypothesis is required.

 

The rule engine is a relatively simple inference engine. It can be used as a component to penetrate into the application system, so that business decisions can be made from applications.CodeAnd use a predefined rule language to write business decisions. The benefits of using the rule engine are:
1. Avoid recompilation and redeployment problems caused by changes in business rules;
2. Use Declarative Programming methods to greatly improve the readability of Business Rule code;
3. Developers do not need to pay too much attention to the business logic (determine what happened according to various situations), but can focus on the application logic (what kind of processing will happen when something happens)

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.