CN107145949B - Multi-core real-time rule reasoning method - Google Patents

Multi-core real-time rule reasoning method Download PDF

Info

Publication number
CN107145949B
CN107145949B CN201710308370.5A CN201710308370A CN107145949B CN 107145949 B CN107145949 B CN 107145949B CN 201710308370 A CN201710308370 A CN 201710308370A CN 107145949 B CN107145949 B CN 107145949B
Authority
CN
China
Prior art keywords
node
queue
memory
rule
instance
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201710308370.5A
Other languages
Chinese (zh)
Other versions
CN107145949A (en
Inventor
乔颖
徐超
王宏安
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Institute of Software of CAS
Original Assignee
Institute of Software of CAS
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Institute of Software of CAS filed Critical Institute of Software of CAS
Priority to CN201710308370.5A priority Critical patent/CN107145949B/en
Publication of CN107145949A publication Critical patent/CN107145949A/en
Application granted granted Critical
Publication of CN107145949B publication Critical patent/CN107145949B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N5/00Computing arrangements using knowledge-based models
    • G06N5/04Inference or reasoning models
    • G06N5/046Forward inferencing; Production systems
    • G06N5/047Pattern matching networks; Rete networks

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Evolutionary Computation (AREA)
  • Artificial Intelligence (AREA)
  • Computing Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Mathematical Physics (AREA)
  • Software Systems (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)
  • Multi Processors (AREA)

Abstract

The invention provides a multi-core real-time rule inference method which is suitable for a RETE network, wherein the RETE network comprises a α network and a β network, the β network consists of α nodes, one α node corresponds to one constraint of a condition element Ci, the β network consists of β nodes, and one β node represents a logic combination of different condition elements.

Description

Multi-core real-time rule reasoning method
Technical Field
The invention belongs to the technical field of rule systems and real-time, and particularly relates to a multi-core real-time rule reasoning method.
Background
Rule reasoning can express the domain knowledge as rules, and through matching of the rules and facts, the rules are triggered and executed, so that automatic decision making is carried out. It has been widely used in various expert systems for medical diagnosis, geological exploration, intelligent decision making, etc.
In recent years, Real-Time Systems are required to have strong reasoning capability, collect external environment data through a series of sensors, monitor a continuous event stream, identify scenes needing attention from the collected external environment data, and make automatic decisions so as to perform actions in Real Time in response to the identified scenes, so rule reasoning also begins to be applied to Real-Time Systems such as production process monitoring, high-speed train online fault diagnosis, grid self-healing control, and financial transaction risk early warning.since Real-Time Systems have Time constraints, tasks in the Systems need to be completed before their deadlines, and thus, rules in GRE reasoning must also have deadlines.7. in the present invention, the Time interval between the Time when all data associated with a certain rule is received by the system and the completion of actions defined by the rule is defined as the delay of the rule, and the upper limit of the rule delay is defined as the deadlines of the rule is specified by the algorithm when the temperature monitoring of the rule is over the system, the fire monitoring system is over the fire, the fire alarm system is monitored by the system, the algorithm 26, the algorithm finds that the fire occurrence of the fire is specified by the algorithm 26, the fire occurrence of the fire detection system 26, the fire detection system 54, the algorithm 26, the fire detection system 7 is specified by the algorithm 26, the fire detection system 7 is specified by the algorithm, the fire detection system, the fire detection.
Meanwhile, with the wide application of the multi-core processor, the hardware environment in which the rule runs is often a computer with the multi-core processor. However, the current rule reasoning system does not consider the hardware operating environment and does not fully utilize the characteristics of the multi-core processor, thereby influencing the performance of rule reasoning.
Disclosure of Invention
Aiming at the defects of the prior art of the rule reasoning system, the invention provides a multi-core real-time rule reasoning method which can complete the matching of the rule and the data under the multi-core operating environment and enable the rule to be executed before the deadline as far as possible.
In the present invention, RETE networks are created compiled according to a user-defined rule set R (the concept and principle of RETE networks are specified in R.B. Doorenbos, "Production Matching for L. age L arriving Systems," technical report CS-95-113, School of Computer Science, Carnegie Mellon Univ, 1995), and a RETE network includes α networks and L networks. in RETE networks, rules are expressed in the form of IF C1 ^ C2 ^ … ^ Cn THENA, where 1 ≦ n is called a condition element (condition), the condition element Ci may be matched with a fact (fact), a fact is composed of a type name and several attribute-attribute values, which is expressed in the form of (attribute 1x1) (attr2x2) (… (Ci) and a fact is expressed by a type name) and several attribute-attribute values, which are expressed in a set of a special attribute (attribute), which is expressed as a value of a special attribute of (No. 1 × 465) in a special attribute (No. 8) where each of a special attribute is expressed as a special attribute (No. 8) and No. 8. c.5. a special attribute (No. 8) is expressed in a special attribute (No. 8) where each special attribute is expressed as a special attribute (No. 8. c.5) corresponding to a special attribute (No. 8) which is expressed in a special attribute (94. c.8) where a special attribute (No. 8) is expressed in a special attribute (No. 94) where a special attribute (No. 2. c.8) is expressed in a special attribute (No. 2 No. 8) where a special attribute (No. 2 No. 8, where a special attribute is expressed in a special attribute (No. 8. a special attribute, where a special attribute is expressed in a special attribute (special attribute is expressed in a special attribute (special attribute, where a special attribute is expressed in a special attribute (special number of network) where a special number of a special number.
Aiming at the defects, the technical scheme adopted by the invention is as follows:
a multi-core real-time rule reasoning method is applicable to RETE networks, wherein the RETE networks comprise α networks and β networks, the α networks consist of α nodes, one α node corresponds to one constraint of a condition element Ci, the β networks consist of β nodes, one β node represents a logic combination of different condition elements, and the method comprises the following steps:
1) according to the input fact X, determining α nodes corresponding to the type of the fact X in the RETE network by using a CPU core;
2) filtering according to the constraint corresponding to the α node, and if the test is passed, storing the fact X in the α memory (alpha memory) to become AM (alpha match);
3) transferring AM to the β node succeeding the α node to form a compute instance and place it in the instance queue of the β node succeeding the α node, if the β node succeeding the α node is not activated, activating the β node succeeding the α node and placing it in β activation queue Q;
4) when the remaining CPU cores are idle and the β activation queue Q is not empty, selecting a β node with the highest priority from the β activation queue Q and recording the node as a node B, taking out a calculation example from an example queue of the node B, performing a variable consistency test on the calculation example according to a test function bound on the node B, if the test is passed, judging whether the node B is a termination node (namely a node without a subsequent node), if the test is passed, indicating that a corresponding rule is successfully matched once, triggering the rule, and executing actions defined by the rule, if the test is not passed, generating a new calculation example, adding the calculation example into an example queue of a subsequent β node of the node B, calculating the priority of the subsequent β node, and putting the priority of the subsequent β node into the β activation queue Q, and if the test is not passed, not generating a new calculation example and stopping the operation;
5) step 4) is executed circularly until the instance queue of the node B is empty, the node B is deleted from the β activation queue Q;
6) step 4) and step 5) are executed in a loop until the β activation queue Q is empty.
Further, the RETE network is created according to a user-defined rule set R compilation, and the steps include:
a. creating a Root node Root;
b. taking a rule Ri (i is more than or equal to 1 and less than or equal to M), wherein the rule Ri has a conditional element C1 … Ci … Cn;
c. sequentially taking out a condition element Ci (i is more than or equal to 1 and less than or equal to n) of Ri according to the sequence of the condition elements in the rule Ri, checking the type name TypeName of the condition element Ci, if the condition element Ci is a new type, adding a α node and taking the node as a current node, otherwise, finding a corresponding α node and taking the node as the current node, sequentially taking out all constraints in the Ci, if a α node corresponding to the taken-out constraint already exists, updating the current node to a corresponding α node, otherwise, newly building a α node and taking the node as a successor of the current node, and then updating the current node to a newly built α node;
d. checking the constraint of Ci and the previously extracted conditional element C1 … C (i-1) and generating a corresponding β node, wherein the left input of the β node is the previous β node (the previous β node is the β node corresponding to C1 ^ … ^ C (i-1)), and the right input is the α memory generated by the current Ci;
e. repeating c-d until all condition elements are processed;
f. and repeating b-e until all rules are processed.
Further, the α network and the β network jointly complete communication through one β active queue Q and an instance queue of β node, and the β node of β network includes left input, right input, one instance queue, left-memory (left-memory), right-memory (right-memory) and output.
Further, when an β node has an input (left input or right input), the β node is activated, the β node priorities are calculated, and placed in the β activation queue Q in descending order of priority.
Further, the α memory stores in step 2) are of a type that conforms to all corresponding α node constraints.
Further, the calculation example in the step 3) is in the form of (β -id, AM, left-memory), wherein β -id represents the identity of a node β succeeding the α node, left-memory is left storage corresponding to the node β -id and stores Partial matches (Partial Match, PM), and the Partial matches are formed by combining AMs through Join operation by the node β -id.
Further, the β node priority calculating method in step 4) includes:
Figure BDA0001286415210000041
wherein R is a rule set; deadlines (Ri) represent the deadline for a rule Ri (1. ltoreq. i.ltoreq.M); k is a weight value, which can be obtained by expert experience; path (B, d) represents the path length from node B to its reachable terminating node d (i.e., the node without the successor node) in the RETE network; d is the set of terminating nodes reachable by node B in the RETE network; and the smaller P (B), the greater the priority.
Further, when the node B is not a terminating node in step 4), the following steps are performed:
4-1) taking out a calculation example from the example queue of the node B;
4-2) if the calculation example form taken out is (B, AM, left-memory) (namely generated by α network), firstly, storing the AM into the right-memory of the node B, traversing the PM in the left-memory one by one according to the test function bound on the node B, checking the consistency with the variable in the AM, if the test is passed, generating a new partial matching PM, and generating a new calculation example on the subsequent β node, otherwise, not generating partial matching and stopping the operation;
4-3) if the extracted calculation example is in the form of (B, PM, right-memory) (namely generated by β network), firstly storing the PM into the left-memory of the node B, traversing the AMs in the right-memory one by one according to the test function bound on the node B, checking the consistency with the variable in the PM, if the test is passed, generating a new partial matching PM, and generating a new calculation example on the subsequent β node, otherwise, not generating partial matching and stopping the operation;
4-4) storing the new calculation instances generated on the successor β node in steps 4-2) and 4-3) in the instance queue of the successor β node, and calculating the priority of the successor β node, placing them in the β activation queue Q in descending order of priority.
Further, the new calculation instance in step 4) is in the form of (β × PM, right-memory), where β × is the identity of the node β succeeding the node B, PM is the partial match generated by the node B, and right-memory is the right store of the node β ″.
The invention has the beneficial effects that: the invention provides a multi-core real-time rule reasoning method, which ensures that the matching and the execution of rules are completed as far as possible within the rule deadline, and is suitable for a real-time system, thereby improving the intelligent degree of the real-time system. The method has the advantages that:
1. by utilizing the characteristics of the multi-core processor, the α network and the β network correspond to different threads and are distributed to be executed on different cores, communication is completed between a plurality of threads of the α network and a plurality of threads of the β network through one instance queue of β activation queue Q and β nodes, and the concurrency and the efficiency of rule matching are effectively improved.
2. By adding left-memory, right-memory and an instance queue into β nodes, the calculation of β nodes has no influence on predecessor and successor nodes, the performance of multiple cores is further utilized, different CPU cores can process β networks in parallel, communication among threads corresponding to β networks is completed by β activated queue Q and the instance queue of relevant β nodes, and therefore the accuracy of inference results when β networks are processed by different cores in parallel is guaranteed.
3. The processed β nodes are selected according to β node priorities, the larger the priority is, the more the processor is occupied preferentially, rules with short rule deadlines can be processed preferentially, and therefore the real-time performance of rule reasoning is improved.
Drawings
FIG. 1 is a schematic diagram of a RETE network and β node structural model according to an embodiment of the present invention;
FIG. 2 is a β thread execution flow diagram of the present invention.
Detailed Description
In order to make the aforementioned and other features and advantages of the invention more comprehensible, embodiments accompanied with figures are described in detail below.
The present invention creates a RETE network from a user defined rule set R compilation, and the RETE network includes α networks and β networks, where α network consists of α nodes, β network consists of β nodes, and α network and β network together complete the communication through one β active queue Q and an instance queue of β nodes.
Assuming that the user-defined rule set is R, where each rule is denoted as Ri (1 ≦ i ≦ M), the specific steps of establishing the RETE network include:
a. creating a Root node Root;
b. taking out a rule Ri (setting Ri conditional element C1 … Ci … Cn);
c. sequentially taking out a condition element Ci (i is more than or equal to 1 and less than or equal to n) of Ri according to the sequence of the condition elements in the rule Ri, checking the type name TypeName of the condition element Ci, if the condition element Ci is a new type, adding a α node and taking the node as a current node, otherwise, finding a corresponding α node and taking the node as the current node, sequentially taking out all constraints in the Ci, if a α node corresponding to the taken-out constraint already exists, taking the node as the current node, otherwise, newly building a α node and serving as a successor of the current node, and then updating the current node into a newly built α node;
d. checking the constraint of Ci and the previously extracted conditional element C1 … C (i-1) and generating a corresponding β node, wherein the left input of the β node is a previous β node (in this case, the previous β node corresponds to C1A … A C (i-1), the left input of the first β node is Root), and the right input is the α memory generated by the current Ci;
e. repeating c-d until all condition elements are processed;
f. and repeating b-e until all rules are processed.
Please refer to fig. 1, which is a schematic diagram of a RETE network and a β node structure model according to an embodiment of the present invention, where the α network is a Trie tree structure and mainly functions to parse input data into internal objects (which may be an object of C + + class), and after a α node checks attributes of the objects, the objects are cached in a α memory of a corresponding α node to form an am.5390 network α node includes two inputs (left input and right input), an instance queue, two stores (left-right, right-left) and output α node compares the inputs and the corresponding stores one by one (Join operation) to generate a partially matched PM and transfers the partially matched PM to a subsequent α node to form a computation instance, and then places the partially matched PM into an instance queue of the subsequent α node. α node has a left input (PM) to be compared with an AM-right-left-right in the β node, and tests consistency of the partially matched PM (compare) with an AM of the right-left-right-left (left-right) in the α node to perform consistency test on the corresponding PM.
The invention firstly divides α network and β network to be delivered to different thread processing, each CPU core corresponds to a thread, the thread for processing α network is called α thread, the thread for processing β 0 network is called β 1 thread, the invention mainly relates to β 2 thread, β 3 thread stores β 4 node and β 5 node as an input and corresponding β as a calculation example, namely (β, left-memory) or (β, right-memory), different β threads can process different β nodes at the same time, thereby concurrently processing β network.
The α thread is responsible for constant testing of attributes of the same type of fact, placing the fact into α memory in the corresponding α node the present invention assigns a α thread.
1) According to the invention, according to the constant test of checking X attributes, such as checking X.name ═ jack' or X.age >20, and the like, the corresponding α node in the RETE network is finally found and stored in a α memory of the α node to be AM, and the AM only contains a fact, namely X.
2) The AM is passed to the node β succeeding the α node and then forms a calculation instance of the form (β -id, AM, left-memory), where β -id is the identity of the β node succeeding the α node, left-memory is the left store to which node β -id corresponds, and is a linked list structure, each element of the linked list is a partial match.
3) The compute instance (β -id, AM, left-memory) is placed in the instance queue in node β -id, if node β -id is first placed in the instance queue, node β -id is simultaneously activated and the priority of node β -id is computed and placed β in the activation queue Q.
4) Steps 1) to 3) are executed in a loop until there is no fact.
The β thread is responsible for performing variable consistency tests on attributes between different types of facts, and places the generated partial matching PM into the corresponding β node storage or triggering rules, please refer to fig. 2, which is an execution flow diagram of the β thread of the present invention, the present invention allocates the remaining threads to β threads, and the specific steps include:
1) when β active queue Q is not empty and β thread is idle, β thread selects β node from β active queue Q with the highest priority and not processed by other β threads, and marks as node B, fetches the first compute instance of the instance queue on node B, and processes the compute instance S by the β thread;
2) β when a right input is generated, i.e. a computation instance (B, AM, left-memory) generated by α network, the AM is first put into the right-memory of node B, then the PMs in the left-memory are traversed one by one according to the test function bound to node B, the consistency with the variables in the AM is checked, for example, the PM in the left-memory is a partial match of C1 a C2, the right input of node B corresponds to C3, the AM corresponds to C3, if the PM passes the test, e.g., C1.63id ═ C3.num or C2.age > C3.age, it is determined whether node B is a termination node, if node B is a termination node, it indicates that the corresponding rule matches once successfully, the rule is triggered, the action defined by the rule is executed, if node B is not a termination node, a new partial match PM is generated (C1 a C4), if the PM is generated by a subsequent PM generation operation, the PM generation is not performed by a subsequent PM generation operation of node B — 368, if the node B is a new partial match, the node B is generated by a post-PM generation operation, if the node B is a post-generation operation is not generated by a post-PM generation operation, the node B — 369, and the node B is stored in the post operation of the node B — n-PM generation operation, wherein the node B is stored as a post operation, the post operation of node B — n-PM generation operation, the post operation is stored in the post operation;
3) β thread the selected calculation instance S, if it is left input generation, namely β network generated calculation instance (B, PM, right-memory), firstly put PM into left-memory of node B, then similar to 1) operation, according to the test function bound in node B, go through AM in right-memory one by one, check consistency with variable in PM, if passing test, judge whether node B is termination node, if node B is termination node, indicate that corresponding rule matches successfully once, trigger the rule, and execute the action defined by the rule, if node B is not termination node, generate new partial matching PM, and generate new calculation instance (β, PM, right-memory) on node B successor β node, if not, do not generate partial matching and stop this operation.
4) In both step 1) and step 2) above, a new partially matching PM may be generated and passed to node β (i.e., node β subsequent to node B) to form a computation instance in the form of (β 0, PM, right-memory). this newly formed computation instance is placed in the instance queue at node β. if node β is not in the activation queue Q at β, i.e., the instance queue at node β is initially empty, node β is now said to be activated, and node β needs to be placed in β activation queue Q based on priority, otherwise it is simply placed at the end of the instance queue at node β.
5) Steps 1) to 4) are performed in a loop, whether the instance queue of the node B is empty or not is judged, and if the instance queue of the node B is empty, the node B is deleted from the β activation queue Q.
6) Steps 1) to 5) are executed in a loop until the β activation queue Q is empty.
The calculation method of the β node priority comprises the following steps:
Figure BDA0001286415210000071
wherein R is a rule set; deadlines (Ri) represent the deadline for a rule Ri ((1. ltoreq. i.ltoreq.M)); k is a weight value, which can be obtained by expert experience; path (B, d) represents the path length from node B to its reachable terminating node d (i.e., the node without the successor node) in the RETE network; d is the set of terminating nodes reachable by node B in the RETE network; and the smaller P (B), the greater the priority.
The method of the present invention is further described below with reference to 2 specific rules and associated data.
Figure BDA0001286415210000081
The two rules respectively correspond to R1 and R3 in FIG. 1, and there are 5 β nodes in total, that is, B1-B5, and B1 and B2 are shared nodes of the two rules, wherein B1 and B4 do not need to do any test, B2 needs to check whether the values corresponding to attr1 of C1 and C2 are equal, B3 needs to check whether the value corresponding to attr1 of C3 is equal to the value corresponding to attr2 of C1, B5 needs to check whether the value corresponding to attr1 of C3 is equal to the value corresponding to attr2 of C4, and if the data corresponding to the rules meet various tests, the time corresponding to the last arrived data and the corresponding alarm time should meet the deadline requirement.
All data can be considered to arrive at the same time and table 1 is only one possible execution order.
Table 1: data execution order
Data of Corresponding β node
f1:(C1(attr1 10)(attr2 15)) B1
f2:(C2(attr1 10)(attr2 10)) B2
f3:(C4(attr1 15)(attr2 15)) B4
f4:(C3(attr1 15)(attr2 25)) B3,B5
(1) All data arrives in α memory at the same time, the corresponding β node has right inputs, i.e., compute instances, which are stored in the instance queue of the corresponding β node in chronological order, and the β node is also activated, so the instance queue of each β node is as shown in table 2.
TABLE 2 example queue for β node
β node Instance queue Left-memory Right-memory P(B)
B1 f1 Null Null 0
B2 f2 Null Null 50
B3 f4 Null Null 450
B4 f3 Null Null 100
B5 f4 Null Null 150
Wherein P (B) is obtained according to the following formula:
Figure BDA0001286415210000091
for example, if K is 50 and B2 belongs to both R1 and R2, then
Figure BDA0001286415210000092
There are 2 available termination nodes from B2, the path lengths from B2 to these two termination nodes are 2 and 3, respectively, so p (B) 200-50 x 3-50, and the priority calculation for the remaining β nodes is similar, so the activation queue at this time is prioritized as B1>B2>B4>B5>B3。
(2) Thread 1 selects B1 processing from β active queue Q, thread 2 selects B2 processing from β active queue Q thread 1 processes B1, since there is no test function in B1, and B1 does not need to store f1 in B1, so f1 is passed directly to the successor β node B2 as the partial match f1^ and stored in the instance queue of B2 at this time, thread 2 fetches f2 from the B2 instance queue, puts the right-memory of B2, traverses the partial matches in the left-memory of B2, compares one by one, while the left-memory of B2 is still empty, so this calculation does not produce a new calculation instance at this time, each β node's instance queue is as shown in Table 3.
TABLE 3 example queue for β node
β node Instance queue Left-memory Right-memory P(B)
B1 Air conditioner Null Null
B2 f1^ Null f2^ 50
B3 f4 Null Null 450
B4 f3 Null Null 100
B5 f4 Null Null 150
(3) Thread 1 selects B2 processing from β active queue Q, thread 2 selects B3 processing from β active queue Q thread 1 fetches the head of line element f1 of the B2 instance queue, the left-memory stored in B2, because f1 is the left input, the elements in the right-memory in B2 are compared one by one (f 2), a new partial match is generated by testing f1 f2, then the partial match is passed to the next β node and placed into the instance queues of B3 and B4 thread 2 fetches f4 and places into the right-memory of B3, because f4 is the right input, the elements in the left-memory in B3 are compared one by one, the left-memory of the current B3 is empty, so no new compute instances are generated, the table queue for each instance β at this moment is as shown in Table 4.
Table 4 example queue for β node
β node Instance queue Left-Memory Right-memory P(B)
B1 Air conditioner Null Null
B2 Air conditioner f1^ f2^
B3 f1^f2 Null Null 450
B4 f3,f1^f2 Null Null 100
B5 f4 Null Null 150
(4) Thread 1 selects B4 processing from β activation queue Q, thread 2 selects B5 processing from β activation queue Q. thread 1 fetches f3 and puts it into the right-memory of B4 because f3 is the right input, the elements in the left-memory of B4 are compared one by one, now the left-memory of B4 is empty, so no new compute instance is generated.thread 2 fetches f4 in B5 and puts it into the right-memory of B5, now the left-memory of B5 is also empty, so no new compute instance is generated.
Table 5 example queue of β node
β node Instance queue Left-memory Right-memory P(B)
B1 Air conditioner Null Null
B2 Air conditioner f1^ f2^
B3 f1^f2 Null Null 450
B4 f1^f2 Null f3^ 100
B5 Null f4^
(5) Thread 1 selects f4 from the instance queue of B4, thread 2 selects B4 from the active queue Q of 4 to process, thread 1 fetches f4, puts f4 into the left-memory of B4, because f4 is the left input, it is necessary to compare elements in the right-memory of B4 one by one (f4), because B4 has no test function, it is necessary to generate a new partial match f4, put into the instance queue of the succeeding 4 node B4, thread 2 fetches f4 on B4, because it is the left input, it is necessary to compare elements in the right-memory of B4 one by one (f4), the test function of B4 checks whether the attr of f4 and the attr 4 f4 are equal, because each succeeding 4 passes the test table 4, and whether the test of the succeeding 4 is successful.
β node's example queue
β node Instance queue Left-memory Right-memory P(B)
B1 Air conditioner Null Null
B2 Air conditioner f1^f2 f2^
B3 Air conditioner Null Null
B4 Air conditioner f1^f2 f3^
B5 f1^f2^f3 Null f4^ 200
(6) Thread 1 takes out f1^ f2^ f3 on B5, matches the right-memory (f4^) on B5 one by one, and the matching is successful, so the reasoning is successful once, at this moment, the example queue of each β node is shown in Table 7.
Table 7 example queue for β node
β node Instance queue Left-memory Right-memory P(B)
B1 Air conditioner Null Null
B2 Air conditioner f1^f2 f2^
B3 Air conditioner Null Null
B4 Air conditioner f1^f2 f3^
B5 Air conditioner Null f4^
The above embodiments are only for illustrating the technical solution of the present invention and not for limiting the same, and a person skilled in the art can make modifications or equivalent substitutions to the technical solution of the present invention without departing from the spirit and scope of the present invention, and the scope of the present invention should be determined by the claims.

Claims (8)

1. A multi-core real-time rule reasoning method is applicable to RETE networks, wherein the RETE networks comprise α networks and β networks, the α networks consist of α nodes, one α node corresponds to one constraint of a condition element Ci, the β networks consist of β nodes, one β node represents a logic combination of different condition elements, and the method comprises the following steps:
1) according to the input fact X, determining α nodes corresponding to the type of the fact X in the RETE network by using a CPU core;
2) filtering according to the constraint corresponding to the α node, and if the test is passed, storing the fact X in a α memory to be AM;
3) transferring AM to the β node succeeding the α node to form a compute instance and place it in the instance queue of the β node succeeding the α node, if the β node succeeding the α node is not activated, activating the β node succeeding the α node and placing it in β activation queue Q;
4) when the remaining CPU cores are idle and the β activation queue Q is not empty, selecting a β node with the highest priority from the β activation queue Q and recording the node as a node B, taking out a calculation example from an example queue of the node B, performing a variable consistency test on the calculation example according to a test function bound on the node B, judging whether the node B is a termination node or not if the calculation example passes the test, indicating that a corresponding rule is successfully matched once, triggering the rule and executing actions defined by the rule, if the calculation example does not pass the test, generating a new calculation example, adding the calculation example into an example queue of a subsequent β node of the node B, calculating the priority of the subsequent β node, and putting the priority of the subsequent β node into the β activation queue Q;
the β node priority calculation method comprises the following steps:
Figure FDA0002480796420000011
wherein R is a rule set; deadlines (Ri) represent rules Ri, 1. ltoreq. i.ltoreq.M deadline; k is a weight value, which can be obtained by expert experience; path (B, d) represents the path length from node B to its reachable terminating node d in the RETE network; d is the set of terminating nodes reachable by node B in the RETE network; and the smaller P (B), the greater the priority;
5) step 4) is executed circularly until the instance queue of the node B is empty, the node B is deleted from the β activation queue Q;
6) step 4) and step 5) are executed in a loop until the β activation queue Q is empty.
2. The method of claim 1, wherein the RETE network is created from a user-defined rule set R compilation, comprising the steps of:
a. creating a Root node Root;
b. taking a rule Ri, wherein i is more than or equal to 1 and less than or equal to M, and the rule Ri has conditional elements C1 … Ci … Cn;
c. sequentially taking out a condition element Ci of Ri according to the sequence of the condition elements in the rule Ri, wherein i is more than or equal to 1 and less than or equal to n, checking the type name TypeName, if the condition element is a new type, adding a α node, and taking the node as a current node, otherwise, finding a corresponding α node, and taking the node as the current node, sequentially taking out all constraints in Ci, if a α node corresponding to the taken-out constraint already exists, updating the current node to a corresponding α node, otherwise, newly building a α node as a successor of the current node, and then updating the current node to a newly built α node;
d. checking the constraint of Ci and the previously fetched conditional element C1 … C (i-1), and generating a corresponding β node, wherein the left input of the β node is the previous β node, and the right input is α memory generated by the current Ci;
e. repeating c-d until all condition elements are processed;
f. and repeating b-e until all rules are processed.
3. The method of claim 1, wherein the α network and the β network collectively complete communication through one β Activate queue Q and an instance queue of the β node, and wherein the β node of the β network includes a left input, a right input, one instance queue, a left store, a right store, and an output.
4. The method of claim 3 wherein when an β node has input, the β node is activated, the β node priorities are calculated, and placed in the β activation queue Q in descending order of priority.
5. The method of claim 1, wherein said α memory stores in step 2) are of a type that conforms to all corresponding α node constraints.
6. The method as claimed in claim 1, wherein the computation instance in step 3) is in the form of (β -id, AM, left-memory), wherein β -id represents the identity of β node succeeding the α node, left-memory is left storage corresponding to node β -id, storing partial match, which is node β -id combining AM by Join operation.
7. The method as claimed in claim 1, wherein the following steps are performed in step 4) when the node B is not a terminating node:
4-1) taking out a calculation example from the example queue of the node B;
4-2) if the calculation example form taken out is (B, AM, left-memory), firstly storing the AM into the right-memory of the node B, traversing the PM in the left-memory one by one according to the test function bound on the node B, checking the consistency with the variable in the AM, if the test is passed, generating a new partial matching PM, and generating a new calculation example on the subsequent β node, otherwise, not generating partial matching and stopping the operation;
4-3) if the calculation example form taken out is (B, PM, right-memory), firstly storing the PM into the left-memory of the node B, traversing the AMs in the right-memory one by one according to the test function bound on the node B, checking the consistency with the variable in the PM, if the test is passed, generating a new partial matching PM, and generating a new calculation example on the subsequent β node, otherwise, not generating partial matching and stopping the operation;
4-4) storing the new calculation instances generated on the successor β node in steps 4-2) and 4-3) in the instance queue of the successor β node, and calculating the priority of the successor β node, placing them in the β activation queue Q in descending order of priority.
8. The method of claim 1 wherein the new instance of computation in step 4) is of the form (β x, PM, right-memory), where β x is the identity of the β node that is subsequent to the node B, PM is the partial match generated by the node B, and right-memory is the right store of node β x.
CN201710308370.5A 2017-05-04 2017-05-04 Multi-core real-time rule reasoning method Active CN107145949B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710308370.5A CN107145949B (en) 2017-05-04 2017-05-04 Multi-core real-time rule reasoning method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710308370.5A CN107145949B (en) 2017-05-04 2017-05-04 Multi-core real-time rule reasoning method

Publications (2)

Publication Number Publication Date
CN107145949A CN107145949A (en) 2017-09-08
CN107145949B true CN107145949B (en) 2020-07-21

Family

ID=59774423

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710308370.5A Active CN107145949B (en) 2017-05-04 2017-05-04 Multi-core real-time rule reasoning method

Country Status (1)

Country Link
CN (1) CN107145949B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110175676B (en) * 2019-04-28 2021-04-20 中国科学院软件研究所 High-performance rule matching method for memory-limited environment
CN112379645B (en) * 2020-10-23 2022-01-11 江苏大学 Drools rule engine-based internet-of-things management and control system and method for group-fed sow feeding station

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH06332703A (en) * 1993-05-26 1994-12-02 Toshiba Corp Condition collation processing method for rete network
US8315967B2 (en) * 2007-08-31 2012-11-20 Red Hat, Inc. Sequential mode in a Rete rule engine
CN104679790A (en) * 2013-12-03 2015-06-03 富士通株式会社 Distributed rule engine system, distributed rule engine construction method and rule processing method
CN105573737A (en) * 2014-10-30 2016-05-11 中国科学院声学研究所 Method for increasing operating efficiency of rule engines
CN106127306A (en) * 2016-06-17 2016-11-16 北京理工大学 A kind of high sharing Rete network construction method

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH06332703A (en) * 1993-05-26 1994-12-02 Toshiba Corp Condition collation processing method for rete network
US8315967B2 (en) * 2007-08-31 2012-11-20 Red Hat, Inc. Sequential mode in a Rete rule engine
CN104679790A (en) * 2013-12-03 2015-06-03 富士通株式会社 Distributed rule engine system, distributed rule engine construction method and rule processing method
CN105573737A (en) * 2014-10-30 2016-05-11 中国科学院声学研究所 Method for increasing operating efficiency of rule engines
CN106127306A (en) * 2016-06-17 2016-11-16 北京理工大学 A kind of high sharing Rete network construction method

Non-Patent Citations (4)

* Cited by examiner, † Cited by third party
Title
Improving Rete Algorithm to Enhance Performance of Rule Engine Systems;Ding Xiao等;《201O International Conference On Computer Design And Appliations》;20101231;第3卷;第572-575页 *
Summary Instance: Scalable Event Priority Determination Engine for Large Scale Distributed Event-based System;Ruisheng Shi等;《2012 IEEE Ninth International Conference on Services Computing》;20121231;第400-406页 *
一种分布式规则引擎的实现方法;朱思远等;《软件》;20151231;第36卷(第12期);第158-161、170页 *
基于Rete算法的多Agent的实时协同推理;冯梅等;《计算机科学》;20030430;第30卷(第4期);第139-142页 *

Also Published As

Publication number Publication date
CN107145949A (en) 2017-09-08

Similar Documents

Publication Publication Date Title
CN107239335B (en) Job scheduling system and method for distributed system
Lomuscio et al. An approach to reachability analysis for feed-forward relu neural networks
US20200097333A1 (en) Scalable task scheduling systems and methods for cyclic interdependent tasks using semantic analysis
CN105164639B (en) Control being executed by computing system for task
WO2018140885A1 (en) Memory side acceleration for deep learning parameter updates
Liu et al. Rule engine based on improvement rete algorithm
CN107145949B (en) Multi-core real-time rule reasoning method
US8914775B2 (en) Dynamic and intelligent partial computation management for efficient parallelization of software analysis in a distributed computing environment
Alian et al. Test case reduction techniques-survey
WO2022077907A1 (en) Adversarial attack detection method, system and device, and computer-readable storage medium
CN117273954B (en) Stock right relation penetration method, device and equipment based on large-scale relation map
CN112202617A (en) Resource management system monitoring method and device, computer equipment and storage medium
CN110175676B (en) High-performance rule matching method for memory-limited environment
Pavlenko et al. Criterion of cyber-physical systems sustainability
Xie et al. Fairness testing of machine learning models using deep reinforcement learning
Tsai et al. Integrated adaptive reasoning testing framework with automated fault detection
Singh et al. Modeling and prediction of performability of safety critical computer based systems using Petri nets
CN111814981B (en) Distributed real-time rule inference scheduling method
CN113328467A (en) Probability voltage stability evaluation method, system, terminal device and medium
CN108845927A (en) A kind of screening technique and device of test case
Shady et al. A hyper-heuristic framework using GP for dynamic job shop scheduling problem
Csar et al. Computing the Schulze Method for Large-Scale Preference Data Sets.
Biere et al. Experimenting with SAT solvers in Vampire
Haque et al. An automated tool for MC/DC test data generation
Chivilikhin et al. Test-based extended finite-state machines induction with evolutionary algorithms and ant colony optimization

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant