WO2022001154A1 - 一种脚本化的智能电表事件判断解析方法 - Google Patents

一种脚本化的智能电表事件判断解析方法 Download PDF

Info

Publication number
WO2022001154A1
WO2022001154A1 PCT/CN2021/079250 CN2021079250W WO2022001154A1 WO 2022001154 A1 WO2022001154 A1 WO 2022001154A1 CN 2021079250 W CN2021079250 W CN 2021079250W WO 2022001154 A1 WO2022001154 A1 WO 2022001154A1
Authority
WO
WIPO (PCT)
Prior art keywords
node
matrix
logical
rows
judgment
Prior art date
Application number
PCT/CN2021/079250
Other languages
English (en)
French (fr)
Inventor
刘笑菲
张奔
刘国栋
敖鑫
张宏莉
李卓伟
于洪
杨加龙
Original Assignee
烟台东方威思顿电气有限公司
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 烟台东方威思顿电气有限公司 filed Critical 烟台东方威思顿电气有限公司
Publication of WO2022001154A1 publication Critical patent/WO2022001154A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/313Logic programming, e.g. PROLOG programming language
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q10/00Administration; Management
    • G06Q10/20Administration of product repair or maintenance
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q50/00Information and communication technology [ICT] specially adapted for implementation of business processes of specific business sectors, e.g. utilities or tourism
    • G06Q50/06Energy or water supply

Definitions

  • the invention relates to a method for judging an event of an intelligent electric meter, in particular to a method for judging and analyzing an event of an intelligent electric meter based on a script.
  • the event recording function is an important functional module of the smart meter, which can monitor the real-time working conditions of the power grid according to the judgment conditions preset by the user.
  • the pre-set judgment conditions for example, the voltage value exceeds a pre-set threshold T1
  • a series of actions are performed, such as event recording, sending an alarm signal and so on.
  • the logic for judging the occurrence of the event is: the voltage value is less than the threshold T1, and the current value is greater than the threshold T2; the logic for judging the end of the event is: the voltage value is greater than the threshold T3, or the current value is less than the threshold T4.
  • the invention proposes a scripted smart meter event judgment and analysis method, which aims to improve the analysis and running speed of logical expressions during event judgment.
  • a scripted smart meter event judgment and analysis method the steps are: constructing a logic script, each logic script corresponds to a smart meter event; the logic script includes a logic expression for judging events;
  • the logical expression includes logical units connected together by logical operators
  • Each of the logical units includes: a left variable address, a right variable address, an operator, a left variable address type and a right variable address type;
  • the address mapping is constructed according to the type of the variable, that is, the corresponding variable address type: for the function type, a general function template is established in advance; when taking the value of the variable, if the variable address type is the function type, the corresponding function template will be used according to the function template.
  • the variable address is converted to a function, and the result of the function's execution is used as the mapped value.
  • the address mapping is constructed according to the type of the variable, that is, the corresponding variable address type: for the single-byte, double-byte and four-byte data types of the memory, when the value of the variable is taken, the corresponding variable address is used as the physical address of the memory. , and start from the physical address to read data by byte length, and use the read data as the mapping value.
  • the address mapping is constructed according to the type of the variable, that is, the corresponding variable address type: for the RAM single-byte, double-byte and four-byte data types, when the value of the variable is taken, the corresponding variable address is used as the RAM address, and From this RAM address, data is read by byte length, and the read data is used as a mapping value.
  • the address mapping is constructed according to the type of the variable, that is, the corresponding variable address type: for the immediate data type—the data of this type is a constant stored in the flash of the microcontroller, and the data in the variable address is directly used as the mapping value.
  • the address mapping is constructed according to the type of the variable, that is, the corresponding variable address type: for the GPIO type, if it is a MCU platform where the data area and code area addresses do not overlap, the value on the MCU address bus pointed to by the variable address is used as a register. address, and take the corresponding register value as the mapping value; if it is a MCU with overlapping addresses in the data area and the code area, take the value on the MCU register address bus pointed to by the variable address as the register address, and take the corresponding register value as map value.
  • each logic script includes a first logic expression for judging whether the event occurs, a second logic expression for judging whether the event ends, and a callback function corresponding to the event.
  • the method for constructing the branch tree is: count the logical units appearing in the logical expression, obtain the information entropy corresponding to each logical unit, then sort the logical units according to the information entropy, and construct the branch tree according to the sorting.
  • Step 1 Count the logical units that appear in the corresponding logical expressions, and the repeated occurrences are only counted once; the number of logical units provided is n;
  • Step 2 The result of each logical unit is 0 and 1. 0 means logical false and 1 means logical true; arrange and combine the values of all possible logical units, there are 2 n cases in total; The combination forms a 2 n ⁇ n-dimensional matrix X, in which the elements of each row correspond to a value combination, and the elements of the i-th column correspond to the i-th logical unit;
  • Step 3 Substitute each row of the matrix X into a logical expression to perform a logical operation, and form a 2 n ⁇ 1-dimensional vector Y according to the row order of all the rows of the operation results;
  • Step 4 Combine X and Y according to the column direction, so that X and Y are combined into a matrix Z of 2 n ⁇ (n+1) dimensions;
  • Step 5 Calculate the information entropy of the first n columns of matrix Z respectively:
  • Step 5-1 For the i-th column, according to the different values of the elements of this column, divide the matrix Z into and Two matrices: Represents a matrix composed of rows where the i-th column of matrix Z is 1, and let the number of rows of the matrix be m; Represents a matrix composed of rows where the i-th column of matrix Z is 0, and let the number of rows of the matrix be n;
  • Step 5-2 according to the matrix and The different values of the last column, continue to be divided into and will be divided into and There are four matrices: representation matrix The matrix formed by the row whose last column value is 1 in , let the number of rows of the matrix be m 1 ; representation matrix The matrix formed by the row whose last column value is 0, let the number of rows of the matrix be m 2 ; representation matrix A matrix composed of rows whose last column is 1, let the number of rows of the matrix be n 1 ; representation matrix A matrix composed of rows whose last column is 0, let the number of rows of the matrix be n 2 ;
  • Step 5-3 Calculate the information entropy of the first n columns of matrix Z according to the information entropy formula, and use Entropy i to represent the information entropy of the i-th column of matrix Z, as follows:
  • Steps 5-6 Sort the calculated information entropy from small to large in absolute value.
  • step 6 of constructing the branch tree according to the sorting its specific steps are:
  • Step 6-1 Build n layers corresponding to logical units one-to-one in order of priority. Each layer is used to place Node nodes corresponding to the logical units of the layer, and each Node node corresponds to one node matrix H;
  • a Node node is established in the top first layer, and the matrix Z is used as the node matrix H corresponding to the Node node;
  • Step 6-2 For the currently traversed layer, traverse each Node node in the layer;
  • each Node node For each Node node, take its node matrix H, and suppose that the logical unit corresponding to this layer corresponds to the i-th column in matrix H, then according to the value of each row element in the i-th column of matrix H, divide H into a matrix and Represents a matrix composed of rows whose i-th column of matrix H is 1, and the number of rows of the matrix is set to be a; Represents a matrix composed of rows whose i-th column of matrix H is 0, and let the number of rows of the matrix be b;
  • representation matrix The matrix formed by the row whose last column value is 1 in , let the number of rows of the matrix be a 1 ; representation matrix A matrix composed of rows whose last column is 0, let the number of rows of the matrix be a 2 ; representation matrix A matrix composed of rows whose last column is 1, let the number of rows of the matrix be b 1 ; representation matrix A matrix composed of rows whose last column is 0, let the number of rows of the matrix be b 2 ;
  • both a 1 and a 2 are not 0, create a new Node in the next layer, and establish the path relationship between the current Node and the lower Node: when the logical unit value corresponding to the current Node is 1, the Node The node points to the lower Node node, and the current Node node's As the node matrix H of the lower node node, it is reserved for use when the lower node is traversed;
  • both b 1 and b 2 are not 0, create a new Node in the next layer, and establish the path relationship between the current Node and the lower Node: when the logical unit value corresponding to the current Node is 0, the Node The node points to the lower Node node, and the current Node node's As the node matrix H of the lower-level Node node, it is reserved for use when the lower-level node is traversed.
  • the path from the current Node node to a nearest leaf node is preferentially used as the next judgment branch.
  • steps 1 to 6 are performed on a computer platform whose performance is better than that of the smart meter microcontroller.
  • the present invention has the following beneficial effects: the method optimizes the logical expression for smart meter event judgment, carries out dynamic path optimization by means of statistical information entropy, constructs a corresponding branch tree, and then obtains based on the branch tree.
  • the optimized judgment rules are written into the single-chip microcomputer, and finally the analysis and judgment of the logic expression is completed in the single-chip computer, thereby improving the running speed of the logic expression.
  • Figure 1 is a flow chart for generating an event script.
  • FIG. 2 is a schematic diagram of a jump branch tree.
  • FIG. 3 is a flow chart of time script judgment.
  • FIG. 4 is a flow chart of generating a jump branch tree.
  • FIG. 5 is a schematic diagram of a jump branch tree judgment sequence.
  • This embodiment first takes the judgment of a flow loss event as an example, and the specific control requirements of the event are as follows:
  • the logic for judging the occurrence of an event is: the voltage value is less than the threshold T1, and the current value is greater than the threshold T2; the logic for judging the end of the event is: the voltage value is greater than the threshold T3, or the current value is less than the threshold T2.
  • the first part shown in Figure 1, generates event scripts.
  • the left variable address is represented by LVar
  • the right variable address is represented by RVar
  • the operator is represented by Op
  • the left variable address type is represented by LType
  • the right variable address type is represented by RType.
  • LType and RType are the same, and the values are as follows: (function type, memory single-byte data type, memory double-byte data type, memory four-byte data type, RAM single-byte data type, RAM double-byte data type type, RAM four-byte data type, immediate data type, GPIO type).
  • U32 indicates that the return data type is an unsigned 32-bit integer, function is the function name, and void indicates that the function does not accept incoming parameters.
  • the address map of the function type is represented as:
  • the meaning of the expression is: convert LVar or RVar into a function function defined by a general function template, pass in empty parameters, and use the converted function function execution result U32 type data as the mapping value.
  • MemChip-1Byte( ) means to read one byte of data starting from the specified physical address, and expand the read data into U32 type data as map values.
  • mapping method is similar to the memory single-byte data type, and will not be repeated.
  • the address mappings are:
  • (Byte_address)( ⁇ ) indicates that a value is used as a single-byte RAM address
  • *( ⁇ ) indicates that the data pointed to by the address in the parentheses is taken out
  • the final address mapping expands the taken value to U32 type as the mapping value .
  • mapping method is similar to the single-byte data type of the memory, and will not be repeated here.
  • the address mappings are:
  • this type is a constant stored in the flash of the microcontroller, and its address is mapped as:
  • bus_address( ) means to directly use LVar or RVar on the address bus of the single-chip microcomputer as the register address, and take the register value and expand it to U32 type data as the mapping value;
  • reg_bus_address( ⁇ ) means to directly use LVar or RVar on the register address bus of the microcontroller as the register address, and take the register value and expand it to U32 type data as the mapping value.
  • the judgment conditions include: the voltage value is less than the threshold T1; the current value is greater than the threshold T2; the voltage value is greater than the threshold T3; the current value is less than the threshold T2, a total of four Piece.
  • A (voltage value RAM address, threshold T1 memory address, ⁇ , RAM four-byte type, memory four-byte type);
  • C (voltage value RAM address, threshold T3 memory address, >, RAM four-byte type, memory four-byte type);
  • D (current value RAM address, threshold T2 memory address, ⁇ , RAM four-byte type, memory four-byte type).
  • the second part implements the analytical operation of the logical expression of the above script.
  • (G-1) Find the address type of the left variable.
  • the address type of the left variable RAM four-byte type.
  • the address mapping rule the address of the left variable is converted into actual data.
  • the mapping rule for the left variable address is: The left variable address is taken as the 4-byte RAM address, and the data corresponding to the address is taken out and converted to U32 type data;
  • the logical expression parsing rule is carried out according to the following steps:
  • each logical unit is 0 or 1, where 0 represents logical false and 1 represents logical true.
  • Combining the values of all logical units there are 2 n cases, where n is the number of logical units. Arrange all the value combinations to form a 2 n ⁇ n-dimensional matrix X, in which the elements of each row represent the values of each logical unit;
  • Entropy M 0.456
  • Entropy N 0.603
  • Entropy O 0.643
  • Entropy P 0.643
  • Entropy Q 0.635
  • Entropy R 0.641
  • (I-7) Determine the pre-judgment order of each logic unit according to the information entropy order calculated in (1-6), that is, the logic unit with the smaller absolute value of the information entropy is preferentially judged.
  • the priority order of judgment is: M, S, N, Q, R, O, P;
  • each layer is used to place Node nodes corresponding to the logical units of the layer, and each Node node Corresponds to a node matrix H;
  • a Node node is established in the top first layer, and the matrix Z is used as the node matrix H corresponding to the Node node;
  • each Node node For each Node node, take its node matrix H, and suppose that the logical unit corresponding to this layer corresponds to the i-th column in matrix H, then according to the value of each row element in the i-th column of matrix H, divide H into a matrix and Represents a matrix composed of rows whose i-th column of matrix H is 1, and the number of rows of the matrix is set to be a; Represents a matrix composed of rows whose i-th column of matrix H is 0, and let the number of rows of the matrix be b;
  • representation matrix The matrix formed by the row whose last column value is 1 in , let the number of rows of the matrix be a 1 ; representation matrix A matrix composed of rows whose last column is 0, let the number of rows of the matrix be a 2 ; representation matrix A matrix composed of rows whose last column is 1, let the number of rows of the matrix be b 1 ; representation matrix A matrix composed of rows whose last column is 0, let the number of rows of the matrix be b 2 ;
  • both a 1 and a 2 are not 0, create a new Node in the next layer, and establish the path relationship between the current Node and the lower Node: when the logical unit value corresponding to the current Node is 1, the Node The node points to the lower Node node, and the current Node node's As the node matrix H of the lower node node, it is reserved for use when the lower node is traversed;
  • both b 1 and b 2 are not 0, create a new Node in the next layer, and establish the path relationship between the current Node and the lower Node: when the logical unit value corresponding to the current Node is 0, the Node The node points to the lower Node node, and the current Node node's As the node matrix H of the lower node node, it is reserved for use when the lower node is traversed;
  • the worst case is a balanced binary tree.
  • the information entropy of all logical units is the same, the number of leaf nodes is 2 n-1 , and each leaf is reached. Nodes need to be judged n times, in this case, the optimization effect cannot be obtained by this method.
  • this method can significantly improve the judgment speed of actual logical expressions.
  • the final jump branch tree obtained by the example script of this step is shown in Figure 2.
  • Node represents a Node node
  • M 0 represents the logical unit M with a value of
  • M 1 represents the logical unit M with a value of 1, and the rest of the logical units are And so on
  • leaf node 0 indicates that the output value of the final logical expression is
  • leaf node 1 indicates that the output value of the final logical expression is 1;
  • the process of jumping the branch tree will not be changed. Therefore, the process of generating the jump branch tree in steps (I-1) to (I-8) can be carried out on a device with strong computing power such as a computer, while the dynamic judgment process of the jump branch tree is performed by the single chip microcomputer of the smart meter. on the platform.
  • the callback function CallBack is called according to the result to perform corresponding business actions, such as alarming and recording.

Landscapes

  • Engineering & Computer Science (AREA)
  • Business, Economics & Management (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Economics (AREA)
  • General Physics & Mathematics (AREA)
  • Human Resources & Organizations (AREA)
  • General Engineering & Computer Science (AREA)
  • Computing Systems (AREA)
  • Strategic Management (AREA)
  • Tourism & Hospitality (AREA)
  • Marketing (AREA)
  • General Business, Economics & Management (AREA)
  • Health & Medical Sciences (AREA)
  • Public Health (AREA)
  • Water Supply & Treatment (AREA)
  • Primary Health Care (AREA)
  • General Health & Medical Sciences (AREA)
  • Entrepreneurship & Innovation (AREA)
  • Operations Research (AREA)
  • Quality & Reliability (AREA)
  • Test And Diagnosis Of Digital Computers (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Debugging And Monitoring (AREA)

Abstract

一种脚本化的智能电表事件判断解析方法,步骤为:构建逻辑脚本,逻辑脚本包含用于进行事件判断的逻辑表达式;逻辑表达式包括通过逻辑运算符连接在一起的逻辑单元;构建与各逻辑表达式一一对应的分支树,分支树的判断结果与逻辑表达式一致;依据分支树的跳转结构生成判断代码,将判断代码写入到智能电表的单片机中,用于实现逻辑表达式的动态实时判断。本方法针对智能电表事件判断的逻辑表达式进行优化,通过统计信息熵的方式进行动态路径寻优,构建对应的分支树,然后基于分支树得到优化后的判断规则并写入到单片机中,最终在单片机中完成逻辑表达式的解析判断,从而提高了逻辑表达式的运行速度。

Description

一种脚本化的智能电表事件判断解析方法 技术领域
本发明涉及一种智能电表事件的判断方法,尤其是一种基于脚本的智能电表事件判断解析方法。
背景技术
事件记录功能是智能电表的一个重要功能模块,它可以根据用户预先设定好的判断条件,监测电网的实时工况。在满足预先设定好的判断条件时(比如,电压值超过一个预先设定的门限T1),进行一系列的动作,比如事件记录,发出报警信号等等。
随着用电设备的越来越复杂,用户对事件记录功能也提出了更复杂的要求,同时也出现了更多的组合条件。例如,针对同一个事件A,判断事件发生的逻辑为:电压值小于门限T1,并且电流值大于门限T2;判断事件结束的逻辑为:电压值大于门限T3,或者电流值小于门限T4。
针对普通的条件表达式,目前已公布的处理方式有:通过构造逻辑表达式的形式进行逻辑判断(参考公告号为CN108388653A的中国发明专利《变电站10kV出线开关分闸类型的识别方法》),根据最终的逻辑表达式输出的真假进行动作。
但是,现有技术中并未提及针对脚本化逻辑表达式的解析方式。如果按照常规的从左向右解析的方式进行,效率非常低。原因在于,单片机判断事件时,部分判断条件需要和外设交换数据,这种外部交换数据的过程通常比较耗时,按照经验值,和EEPROM存储器交换数 据耗时通常在毫秒级,和单总线器件(比如温度传感器DS18B20)交换数据通常在百毫秒级,和其他单片机系统交换数据甚至可以达到秒级。因此顺序解析的方法会耗费很长的时间。另一方面,由于逻辑表达式是根据用户需求自定义的,编译器无法参与逻辑表达式的速度优化,在一些极端情况下,这种处理速度甚至是无法忍受的,根本无法满足需求。
由于受到上述制约,在智能电表系统中,一般不直接使用逻辑表达式。比较通用的做法是:对每一种事件编写一个判断逻辑函数,当要求发生变更时,修改相应函数的代码逻辑。但是,不同的用户对事件部分的功能有不同的要求,每当用户的需求发生变更的时候,都需要更改代码、修改判断逻辑,这带来了很高的维护成本和测试成本。
发明内容
本发明提出了一种脚本化的智能电表事件判断解析方法,其目的是:提高事件判断时逻辑表达式的解析运行速度。
本发明技术方案如下:
一种脚本化的智能电表事件判断解析方法,步骤为:构建逻辑脚本,每条逻辑脚本对应一个智能电表事件;所述逻辑脚本包含用于进行事件判断的逻辑表达式;
所述逻辑表达式包括通过逻辑运算符连接在一起的逻辑单元;
每个所述逻辑单元包含:左变量地址,右变量地址,运算符,左变量地址类型以及右变量地址类型;
构建与各逻辑表达式一一对应的分支树,所述分支树的判断结果 与所述逻辑表达式一致;依据分支树的跳转结构生成判断代码,将判断代码写入到智能电表的单片机中,用于实现逻辑表达式的动态实时判断;
判断时,先获取各逻辑单元的输出值:对于各逻辑单元,基于地址映射的方式,根据左变量地址和左变量地址类型获取左变量的变量值,根据右变量地址和右变量地址类型获取右变量的变量值,再根据运算符完成左变量和右变量之间的运算,将布尔值类型的运算结果作为该逻辑单元的输出值;再进一步获得整个逻辑表达式的计算结果。
进一步的,依据变量的类型即对应的变量地址类型构建地址映射:对于函数类型,事先建立通用的函数模板;在取变量的值时,如果变量地址类型为函数类型,则依据函数模板将对应的变量地址转换为函数,并将该函数的执行结果作为映射值。
进一步的,依据变量的类型即对应的变量地址类型构建地址映射:对于存储器单字节、双字节和四字节数据类型,在取变量的值时,将对应的变量地址作为存储器的物理地址,并从该物理地址开始按字节长度读取数据,将该读取出的数据作为映射值。
进一步的,依据变量的类型即对应的变量地址类型构建地址映射:对于RAM单字节、双字节和四字节数据类型,在取变量的值时,将对应的变量地址作为RAM地址,并从该RAM地址开始按字节长度读取数据,将该读取出的数据作为映射值。
进一步的,依据变量的类型即对应的变量地址类型构建地址映射:对于立即数类型——该类型的数据是存储在单片机flash内部的常 量,直接将变量地址中的数据并作为映射值。
进一步的,依据变量的类型即对应的变量地址类型构建地址映射:对于GPIO类型,如果是数据区和代码区编址无重叠的单片机平台,则将变量地址指向的单片机地址总线上的值作为寄存器地址,并取对应的寄存器值作为映射值;如果是数据区和代码区编址有重叠的单片机,则将变量地址指向的单片机寄存器地址总线上的值作为寄存器地址,并取对应的寄存器值作为映射值。
进一步的,每条逻辑脚本包括一条判断事件是否发生的第一逻辑表达式和一条判断事件是否结束的第二逻辑表达式,还包括一个对应该事件的回调函数。
进一步的,在需要进行事件判断时,根据当前事件状态,查询事件对应的脚本的逻辑表达式,若当前事件状态是“发生”,则查询判断第二逻辑表达式,否则查询判断第一逻辑表达式;判断结束后,根据判断结果调用回调函数。
进一步的,构建分支树的方法为:统计逻辑表达式中所出现的逻辑单元,求取各逻辑单元所对应的信息熵,然后依据信息熵对逻辑单元排序,依据排序构建所述分支树。
进一步的,构建分支树的具体方法为:
步骤1、统计对应的逻辑表达式中所出现的逻辑单元,重复出现的只计一次;设有逻辑单元的数量为n;
步骤2、每个逻辑单元的结果取值为0、1两种情况,0表示逻辑假,1表示逻辑真;将所有可能存在的逻辑单元取值进行排列组合, 共有2 n种情况;将排列组合构成2 n×n维的矩阵X,其中每一行的元素分别对应一种取值组合情况,第i列的元素均对应第i个逻辑单元;
步骤3、将矩阵X的每一行分别代入逻辑表达式进行逻辑运算,将所有行的运算结果按矩阵X的行序组成2 n×1维的向量Y;
步骤4、将X,Y按照列方向进行组合,使X、Y组合成2 n×(n+1)维的矩阵Z;
步骤5、分别计算矩阵Z的前n列的信息熵:
步骤5-1、对于第i列,按该列元素的不同取值,将矩阵Z分成
Figure PCTCN2021079250-appb-000001
Figure PCTCN2021079250-appb-000002
两个矩阵:
Figure PCTCN2021079250-appb-000003
表示矩阵Z第i列取值为1的行所组成的矩阵,设该矩阵的行数为m;
Figure PCTCN2021079250-appb-000004
表示矩阵Z第i列取值为0的行所组成的矩阵,设该矩阵的行数为n;
步骤5-2、根据矩阵
Figure PCTCN2021079250-appb-000005
Figure PCTCN2021079250-appb-000006
最后一列的不同取值,继续将
Figure PCTCN2021079250-appb-000007
划分为
Figure PCTCN2021079250-appb-000008
Figure PCTCN2021079250-appb-000009
Figure PCTCN2021079250-appb-000010
划分为
Figure PCTCN2021079250-appb-000011
Figure PCTCN2021079250-appb-000012
共四个矩阵:
Figure PCTCN2021079250-appb-000013
表示矩阵
Figure PCTCN2021079250-appb-000014
中最后一列取值为1的行所组成的矩阵,设该矩阵的行数为m 1
Figure PCTCN2021079250-appb-000015
表示矩阵
Figure PCTCN2021079250-appb-000016
最后一列取值为0的行所组成的矩阵,设该矩阵的行数为m 2
Figure PCTCN2021079250-appb-000017
表示矩阵
Figure PCTCN2021079250-appb-000018
最后一列取值为1的行所组成的矩阵,设该矩阵的行数为n 1
Figure PCTCN2021079250-appb-000019
表示矩阵
Figure PCTCN2021079250-appb-000020
最后一列取值为0的行所组成的矩阵,设该矩阵的行数为n 2
步骤5-3、根据信息熵公式计算矩阵Z前n列各自的信息熵,以Entropy i表示矩阵Z第i列的信息熵,有:
Figure PCTCN2021079250-appb-000021
步骤5-6、将计算得到的信息熵按绝对值由小到大进行排序。
进一步的,依据排序构建所述分支树的步骤6,其具体步骤为:
步骤6-1、按优先级顺序由上至下构建n个与逻辑单元一一对应的分层,每个分层用于放置与该层的逻辑单元对应的Node节点,每个Node节点对应一个节点矩阵H;
在最上方的第一层中建立一个Node节点,将矩阵Z作为与该Node节点所对应的节点矩阵H;
由上至下遍历各个分层,对于每个分层,分别执行步骤6-2至步骤步骤6-4,完成分支树的构建;
步骤6-2、对于当前遍历到的分层,遍历该分层中的每个Node节点;
对于每个Node节点,取其节点矩阵H,设该层所对应的逻辑单元与矩阵H中的第i列对应,则根据矩阵H第i列中各行元素的取值,将H分为矩阵
Figure PCTCN2021079250-appb-000022
Figure PCTCN2021079250-appb-000023
Figure PCTCN2021079250-appb-000024
表示矩阵H第i列取值为1的行所组成的矩阵,设该矩阵的行数为a;
Figure PCTCN2021079250-appb-000025
表示矩阵H第i列取值为0的行所组成的矩阵,设该矩阵的行数为b;
然后根据矩阵
Figure PCTCN2021079250-appb-000026
Figure PCTCN2021079250-appb-000027
最后一列的不同取值,继续将
Figure PCTCN2021079250-appb-000028
划分为
Figure PCTCN2021079250-appb-000029
Figure PCTCN2021079250-appb-000030
Figure PCTCN2021079250-appb-000031
划分为
Figure PCTCN2021079250-appb-000032
Figure PCTCN2021079250-appb-000033
共四个矩阵:
Figure PCTCN2021079250-appb-000034
表示矩阵
Figure PCTCN2021079250-appb-000035
中最后一列取值为1的行所组成的矩阵,设该矩阵的行数为a 1
Figure PCTCN2021079250-appb-000036
表示矩阵
Figure PCTCN2021079250-appb-000037
最后一列取值为0的行所组成的矩阵,设该矩阵的行数为a 2
Figure PCTCN2021079250-appb-000038
表示矩阵
Figure PCTCN2021079250-appb-000039
最后一列取值为1的行所组成的矩阵,设该矩阵的行数为b 1
Figure PCTCN2021079250-appb-000040
表示矩阵
Figure PCTCN2021079250-appb-000041
最后一列取值为0的行所组成的矩阵,设该矩阵的行 数为b 2
步骤6-3、若a 1=0,新建一个结果值为0的叶子节点,并建立当前Node节点与该叶子节点之间的路径关系:当前Node节点对应的逻辑单元值为1时,该Node节点指向该叶子节点;
若a 2=0,新建一个结果值为1的叶子节点,并建立当前Node节点与该叶子节点之间的路径关系:当前Node节点对应的逻辑单元值为1时,该Node节点指向该叶子节点;
若a 1和a 2均不为0,则在下一层新建一个Node节点,并建立当前Node节点与该下层Node节点之间的路径关系:当前Node节点对应的逻辑单元值为1时,该Node节点指向该下层Node节点,并将当前Node节点的
Figure PCTCN2021079250-appb-000042
作为该下层Node节点的节点矩阵H,留作该下层节点被遍历到时使用;
步骤6-4、若b 1=0,新建一个结果值为0的叶子节点,并建立当前Node节点与该叶子节点之间的路径关系:当前Node节点对应的逻辑单元值为0时,该Node节点指向该叶子节点;
若b 2=0,新建一个结果值为1的叶子节点,并建立当前Node节点与该叶子节点之间的路径关系:当前Node节点对应的逻辑单元值为0时,该Node节点指向该叶子节点;
若b 1和b 2均不为0,则在下一层新建一个Node节点,并建立当前Node节点与该下层Node节点之间的路径关系:当前Node节点对应的逻辑单元值为0时,该Node节点指向该下层Node节点,并将当前Node节点的
Figure PCTCN2021079250-appb-000043
作为该下层Node节点的节点矩阵H,留作该下层节点 被遍历到时使用。
进一步的,生成跳转分支树后,按分支树从上至下的方向遍历所有Node节点,根据路径关系和叶子节点对应的结果值生成判断代码,将判断代码写入智能电表的单片机,用于完成动态实时判断。
进一步的,遍历分支树的所有Node节点生成判断代码时,对于当前Node节点,优先将从当前Node节点开始到一个最近的叶子节点的路径作为下一步的判断分支。
进一步的,所述步骤1至6在性能优于智能电表单片机的计算机平台上进行。
相对于现有技术,本发明具有以下有益效果:本方法针对智能电表事件判断的逻辑表达式进行优化,通过统计信息熵的方式进行动态路径寻优,构建对应的分支树,然后基于分支树得到优化后的判断规则并写入到单片机中,最终在单片机中完成逻辑表达式的解析判断,从而提高了逻辑表达式的运行速度。
附图说明
图1为生成事件脚本的流程图。
图2为跳转分支树的示意图。
图3为时间脚本判断流程图。
图4为生成跳转分支树的流程图。
图5为跳转分支树判断顺序的示意图。
具体实施方式
下面结合附图详细说明本发明的技术方案:
本实施例先以一个失流事件判断为例,该事件的具体控制要求如下:
判断事件发生的逻辑为:电压值小于门限T1,并且电流值大于门限T2;判断事件结束的逻辑为:电压值大于门限T3,或者电流值小于门限T2。
第一部分,如图1所示,生成事件脚本。
(A)定义逻辑单元。逻辑单元的组成元素包括:
(左变量地址,右变量地址,运算符,左变量地址类型,右变量地址类型)
为简化表示,以LVar表示左变量地址,以RVar表示右变量地址,以Op表示运算符(关系运算符和逻辑运算符),以LType表示左变量地址类型,以RType表示右变量地址类型。
其中,Op的取值如下:(≥,≤,<,>,=,≠,&,|),≥表示大于等于判断,≤表示小于等于判断,<表示小于判断,>表示大于判断,=表示等于判断,≠表示不等于判断,&表示逻辑与操作,|表示逻辑或操作。
LType和RType的取值范围相同,取值如下:(函数类型,存储器单字节数据类型,存储器双字节数据类型,存储器四字节数据类型,RAM单字节数据类型,RAM双字节数据类型,RAM四字节数据类型,立即数类型,GPIO类型)。
(B)为不同的数据类型建立地址映射:
(1)对于函数类型,建立通用函数模板,一个典型模板示例的伪代码如下:
U32 function(void);
其中,U32表示返回数据类型为无符号32位整数,function为函数名,void表示该函数不接受传入参数。
函数类型的地址映射表示为:
Figure PCTCN2021079250-appb-000044
该表达式的含义为:将LVar或者RVar转化成通用函数模板定义的函数function,传入参数为空,并将转换后的函数function执行结果U32类型的数据作为映射值。
(2)对于存储器单字节数据类型,该类型的地址映射表示为:
Figure PCTCN2021079250-appb-000045
该表达式的含义是:将LVar或者RVar值作为存储器的一个物理地址,MemChip-1Byte(·)表示从指定的物理地址开始读取一个字节的数据,将读取的数据扩展成U32类型的数据作为映射值。
(3)对于存储器双字节数据类型和存储器四字节数据类型,映射方式与存储器单字节数据类型类似,不再赘述,其地址映射分别为:
Figure PCTCN2021079250-appb-000046
(4)对于RAM单字节数据类型,该类型的地址映射表示为:
Figure PCTCN2021079250-appb-000047
其中,(Byte_address)(·)表示将一个数值作为一个单字节的RAM地址,*(·)表示将括号内的地址指向的数据取出,最终地址映射将取出的值扩展为U32类型作为映射值。
(5)对于RAM双字节数据类型和RAM四字节数据类型,映射方式与存储器单字节数据类型类似,不再赘述,其地址映射分别为:
Figure PCTCN2021079250-appb-000048
(6)对于立即数类型,该类型是存储在单片机flash内部的常量,其地址映射为:
Figure PCTCN2021079250-appb-000049
该表达式的含义为:直接将LVar或者RVar扩展成U32类型的数据并作为映射值。
(7)对于GPIO类型,其地址映射为:
Figure PCTCN2021079250-appb-000050
对于不同的单片机类型,GPIO地址映射不同,对于数据区和代码区编址无重叠的单片机,以STM32单片机为代表,使用
Figure PCTCN2021079250-appb-000051
bus_address(·)表示直接将单片机地址总线上LVar或者RVar作为寄存器地址,并取寄存器值,将其扩展为U32类型的数据作为映射值;对于数据区和代码区编址有重叠的单片机,以51单片机为代表,需显示的指定地址类型,使用
Figure PCTCN2021079250-appb-000052
reg_bus_address(·)表示直接将单片机寄存器地址总线上LVar或者RVar作为寄存器地址,并取寄存器值,将其扩展为U32类型的数据作为映射值。
(C)将每个判断条件根据地址映射关系转换为逻辑单元,在示例中,判断条件包括:电压值小于门限T1;电流值大于门限T2;电 压值大于门限T3;电流值小于门限T2共四个。
对应的逻辑单元分别为:
A=(电压值RAM地址,门限T1存储器地址,<,RAM四字节类型,存储器四字节类型);
B=(电流值RAM地址,门限T2存储器地址,>,RAM四字节类型,存储器四字节类型);
C=(电压值RAM地址,门限T3存储器地址,>,RAM四字节类型,存储器四字节类型);
D=(电流值RAM地址,门限T2存储器地址,<,RAM四字节类型,存储器四字节类型)。
(D)为简化表示,以字母A-Z表示逻辑单元的序号,根据判断逻辑将逻辑单元组合,则事件发生的组合逻辑为A&B(第一逻辑表达式),事件结束的组合逻辑为C|D(第二逻辑表达式),将事件发生的逻辑表达式与事件结束的逻辑表达式合并成一条逻辑脚本,以“$”分隔,即A&B$C|D。
(E)为每个事件增加回调函数,以CallBack表示,用于事件发生或者结束时进行相应的关联动作。
(F)将每个事件对应的逻辑单元,逻辑脚本,回调函数组合成一条完整的事件脚本:
逻辑单元:A B C D;
逻辑脚本:A&B$C|D
回调函数:CallBack。
第二部分,实现对上述脚本的逻辑表达式的解析运算。
(G)以逻辑单元A为例:A=(电压值RAM地址,门限T1存储器地址,<,RAM四字节类型,存储器四字节类型),逻辑单元的解析按照如下步骤进行:
(G-1)查找左变量地址类型,在本例中,左变量地址类型=RAM四字节类型,根据地址映射规则,将左变量地址转换为实际数据。在本例中,左变量地址的映射规则为:
Figure PCTCN2021079250-appb-000053
即将左变量地址作为4字节RAM地址,并取出该地址对应的数据,转换为U32类型数据;
(G-2)用与(G-1)同样的方法将右变量地址转换为U32类型数据;
(G-3)根据运算符类型将左右变量进行比较,在本例中,实际是将电压值与门限T1进行比较运算,若电压值>T1,则该逻辑单元输出1,否则输出0;
(H)如图3,在需要进行事件判断时,根据当前事件状态,查询事件对应的脚本的逻辑表达式,若当前事件状态是“发生”,则查询判断事件是否结束的逻辑表达式,本例中为:C|D;否则查询判断事件是否发生的逻辑表达式,本例中为:A&B。
(I)对步骤(H)中查询到的逻辑表达式进行解析,为保证最快判断速度,即以最少的判断次数使逻辑表达式输出最终的结果,逻辑表达式解析规则按照如下步骤进行:
前述示例中的逻辑表达式较为简单,主要用于描述脚本的结构, 不易清晰地展现出运行速度的差异。因此在后面的步骤中,以逻辑表达式M|N&(O|P)&(Q|R)|(Q&N)|S作为示例。其中,单个逻辑单元的逻辑结果依然是通过步骤(G)获得。
(I-1)如图4,统计逻辑表达式中所有逻辑单元的个数,不包含重复出现在逻辑表达式中的逻辑单元,在逻辑表达式中的逻辑单元个数共7个:M,N,O,P,Q,R,S;
(I-2)每个逻辑单元的结果取值为0、1两种情况,0表示逻辑假,1表示逻辑真。将所有逻辑单元的取值组合,则共有2 n种情况,其中n为逻辑单元的个数。将所有的取值组合进行排列,组成2 n×n维的矩阵X,其中每一行的元素分别代表各个逻辑单元的取值;
(I-3)将矩阵X的每一行代入逻辑表达式进行逻辑运算,将所有行的运算结果组成2 n×1维的向量Y;
(I-4)将X,Y按照列方向进行组合,使X、Y组合成2 n×(n+1)维的矩阵Z;
(I-5)分别计算矩阵Z的前n列的信息熵:
(I-5-1)根据Z第i列的不同取值,i=1,2,3,...,n,分成
Figure PCTCN2021079250-appb-000054
Figure PCTCN2021079250-appb-000055
两个矩阵:
Figure PCTCN2021079250-appb-000056
表示矩阵Z第i列取值为1的行所组成的矩阵,设该矩阵的行数为m;
Figure PCTCN2021079250-appb-000057
表示矩阵Z第i列取值为0的行所组成的矩阵,设该矩阵的行数为n;显然m+n=2 n
(I-5-2)根据矩阵
Figure PCTCN2021079250-appb-000058
Figure PCTCN2021079250-appb-000059
最后一列的不同取值(该列是向量Y的一部分),继续将
Figure PCTCN2021079250-appb-000060
划分为
Figure PCTCN2021079250-appb-000061
Figure PCTCN2021079250-appb-000062
Figure PCTCN2021079250-appb-000063
划分为
Figure PCTCN2021079250-appb-000064
Figure PCTCN2021079250-appb-000065
共四个矩阵:
Figure PCTCN2021079250-appb-000066
表示矩阵
Figure PCTCN2021079250-appb-000067
中最后一列取值为1的行所组成的矩阵,设 该矩阵的行数为m 1
Figure PCTCN2021079250-appb-000068
表示矩阵
Figure PCTCN2021079250-appb-000069
最后一列取值为0的行所组成的矩阵,设该矩阵的行数为m 2
Figure PCTCN2021079250-appb-000070
表示矩阵
Figure PCTCN2021079250-appb-000071
最后一列取值为1的行所组成的矩阵,设该矩阵的行数为n 1
Figure PCTCN2021079250-appb-000072
表示矩阵
Figure PCTCN2021079250-appb-000073
最后一列取值为0的行所组成的矩阵,设该矩阵的行数为n 2;显然:m 1+m 2=m,n 1+n 2=n;
(I-5-3)根据信息熵公式计算矩阵Z前n列各自的信息熵:
Figure PCTCN2021079250-appb-000074
以Entropy i表示矩阵Z第i列的信息熵,则有:
Figure PCTCN2021079250-appb-000075
(I-6)将计算得到的信息熵按绝对值由小到大进行排列,信息熵绝对值小的说明,如果先判断该列对应的逻辑单元,数据的有序性提高的最多。按照信息熵的计算方法,本例中各逻辑单元的信息熵的绝对值如下:
Entropy M=0.456,Entropy N=0.603,Entropy O=0.643,
Entropy P=0.643,Entropy Q=0.635,Entropy R=0.641,
Entropy S=0.456
按照值由小到大排列:
Entropy M=Entropy S>Entropy N>Entropy Q>Entropy R>Entropy O=Entropy P
(I-7)根据(I-6)中计算得到的信息熵顺序确定各逻辑单元的预先判断顺序,即优先判断信息熵绝对值小的逻辑单元。在本例中,判断的优先级顺序为:M、S、N、Q、R、O、P;
(I-8)根据判断的优先级构建跳转分支树,实现步骤如下:
(I-8-1)按优先级顺序由上至下构建n个与逻辑单元一一对应的分层,每个分层用于放置与该层的逻辑单元对应的Node节点,每个Node节点对应一个节点矩阵H;
在最上方的第一层中建立一个Node节点,将矩阵Z作为与该Node节点所对应的节点矩阵H;
由上至下遍历各个分层,对于每个分层,分别执行步骤(I-8-2)至步骤(I-8-4);
(I-8-2)对于当前遍历到的分层,遍历该分层中的每个Node节点;
对于每个Node节点,取其节点矩阵H,设该层所对应的逻辑单元与矩阵H中的第i列对应,则根据矩阵H第i列中各行元素的取值,将H分为矩阵
Figure PCTCN2021079250-appb-000076
Figure PCTCN2021079250-appb-000077
Figure PCTCN2021079250-appb-000078
表示矩阵H第i列取值为1的行所组成的矩阵,设该矩阵的行数为a;
Figure PCTCN2021079250-appb-000079
表示矩阵H第i列取值为0的行所组成的矩阵,设该矩阵的行数为b;
然后根据矩阵
Figure PCTCN2021079250-appb-000080
Figure PCTCN2021079250-appb-000081
最后一列的不同取值(该列是向量Y的一部分),继续将
Figure PCTCN2021079250-appb-000082
划分为
Figure PCTCN2021079250-appb-000083
Figure PCTCN2021079250-appb-000084
Figure PCTCN2021079250-appb-000085
划分为
Figure PCTCN2021079250-appb-000086
Figure PCTCN2021079250-appb-000087
共四个矩阵:
Figure PCTCN2021079250-appb-000088
表示矩阵
Figure PCTCN2021079250-appb-000089
中最后一列取值为1的行所组成的矩阵,设该矩阵的行数为a 1
Figure PCTCN2021079250-appb-000090
表示矩阵
Figure PCTCN2021079250-appb-000091
最后一列取值为0的行所组成的矩阵,设该矩阵的行数为a 2
Figure PCTCN2021079250-appb-000092
表示矩阵
Figure PCTCN2021079250-appb-000093
最后一列取值为1的行所组成的矩阵,设该矩阵的行数为b 1
Figure PCTCN2021079250-appb-000094
表示矩阵
Figure PCTCN2021079250-appb-000095
最后一列取值为0的行所组成的矩阵,设该矩阵的行数为b 2
(I-8-3)若a 1=0,说明在前面路径中其它节点取值的基础上,本逻辑单元结果为1时整个逻辑表达式的结果必为0,因此新建一个结果值为0的叶子节点,并建立当前Node节点与该叶子节点之间的路径关系:当前Node节点对应的逻辑单元值为1时,该Node节点指向该叶子节点;
若a 2=0,新建一个结果值为1的叶子节点,并建立当前Node节点与该叶子节点之间的路径关系:当前Node节点对应的逻辑单元值为1时,该Node节点指向该叶子节点;
若a 1和a 2均不为0,则在下一层新建一个Node节点,并建立当前Node节点与该下层Node节点之间的路径关系:当前Node节点对应的逻辑单元值为1时,该Node节点指向该下层Node节点,并将当前Node节点的
Figure PCTCN2021079250-appb-000096
作为该下层Node节点的节点矩阵H,留作该下层节点被遍历到时使用;
(I-8-4)若b 1=0,说明在前面路径中其它节点取值的基础上,本逻辑单元结果为0时整个逻辑表达式的结果必为0,因此新建一个结果值为0的叶子节点,并建立当前Node节点与该叶子节点之间的路径关系:当前Node节点对应的逻辑单元值为0时,该Node节点指向该叶子节点;
若b 2=0,新建一个结果值为1的叶子节点,并建立当前Node节点与该叶子节点之间的路径关系:当前Node节点对应的逻辑单元值为0时,该Node节点指向该叶子节点;
若b 1和b 2均不为0,则在下一层新建一个Node节点,并建立当前 Node节点与该下层Node节点之间的路径关系:当前Node节点对应的逻辑单元值为0时,该Node节点指向该下层Node节点,并将当前Node节点的
Figure PCTCN2021079250-appb-000097
作为该下层Node节点的节点矩阵H,留作该下层节点被遍历到时使用;
最后一层所有Node节点所指向的都是叶子节点。
按照步骤(I-8)得到的跳转分支树,最坏的情况是一棵平衡二叉树,此时所有的逻辑单元信息熵都相同,叶子节点的个数为2 n-1,到达每一个叶子节点都需要经过n次判断,这种情况下用本方法无法得到优化的效果。但实际应用中,所有逻辑单元信息熵都相同的情况非常少,因此本方法可以明显的提高实际逻辑表达式的判断速度。
本步骤的实例脚本最终得到的跳转分支树如图2所示,Node表示一个Node节点,M 0表示逻辑单元M取值为0,M 1表示逻辑单元M取值为1,其余逻辑单元以此类推;叶子节点0表示最终逻辑表达式的输出值为0,叶子节点1表示最终逻辑表达式的输出值为1;
(I-9)生成跳转分支树后,按分支树从上至下的方向遍历所有Node节点,根据路径关系和叶子节点对应的结果值生成判断代码,将判断代码写入智能电表的单片机,用于完成动态实时判断。
如图5,逻辑表达式的判断过程如下:
(I-9-1)从第一个Node节点开始,对应最上方的Node节点,向下遍历整棵分支树,按路径关系进行判断,优先将从当前Node节点开始到一个最近的叶子节点的路径作为下一步的判断分支。在本例中,最上方的Node节点到最近的叶子节点的分支是
Figure PCTCN2021079250-appb-000098
因此第一 步的判断的伪代码为:
If(M is 1)return 1
(I-9-2)如果逻辑单元的实际值不满足(I-9-1)中的判断条件,则继续向下遍历整颗树,找到下一个Node节点,依然优先将从当前Node节点开始到一个最近的叶子节点的路径作为下一步的判断分支。在本例中,第二步判断的伪代码为:
Else If(S is 1)return 1
(I-9-3)以此类推,直至遍历完所有的Node节点。
作为本方法的一个优选实例,由于逻辑表达式确定后,跳转分支树的过程不会再发生更改。因此,步骤(I-1)到(I-8)的生成跳转分支树的过程可以在电脑等运算能力较强的设备上进行,而跳转分支树的动态判断过程则在智能电表的单片机平台上进行。
逻辑表达式的最终逻辑结果计算完成后,根据结果调用回调函数CallBack进行相应的业务动作,比如报警、记录等。

Claims (7)

  1. 一种脚本化的智能电表事件判断解析方法,其特征在于:构建逻辑脚本,每条逻辑脚本对应一个智能电表事件;所述逻辑脚本包含用于进行事件判断的逻辑表达式;
    所述逻辑表达式包括通过逻辑运算符连接在一起的逻辑单元;
    构建与各逻辑表达式一一对应的分支树,所述分支树的判断结果与所述逻辑表达式一致;依据分支树的跳转结构生成判断代码,将判断代码写入到智能电表的单片机中,用于实现逻辑表达式的动态实时判断。
  2. 如权利要求1所述的脚本化的智能电表事件判断解析方法,其特征在于,构建分支树的方法为:统计逻辑表达式中所出现的逻辑单元,求取各逻辑单元所对应的信息熵,然后依据信息熵对逻辑单元排序,依据排序构建所述分支树。
  3. 如权利要求2所述的脚本化的智能电表事件判断解析方法,其特征在于,构建分支树的具体方法为:
    步骤1、统计对应的逻辑表达式中所出现的逻辑单元,重复出现的只计一次;设有逻辑单元的数量为n;
    步骤2、每个逻辑单元的结果取值为0、1两种情况,0表示逻辑假,1表示逻辑真;将所有可能存在的逻辑单元取值进行排列组合,共有2 n种情况;将排列组合构成2 n×n维的矩阵X,其中每一行的元素分别对应一种取值组合情况,第i列的元素均对应第i个逻辑单元;
    步骤3、将矩阵X的每一行分别代入逻辑表达式进行逻辑运算,将所有行的运算结果按矩阵X的行序组成2 n×1维的向量Y;
    步骤4、将X,Y按照列方向进行组合,使X、Y组合成2 n×(n+1)维的 矩阵Z;
    步骤5、分别计算矩阵Z的前n列的信息熵:
    步骤5-1、对于第i列,按该列元素的不同取值,将矩阵Z分成
    Figure PCTCN2021079250-appb-100001
    Figure PCTCN2021079250-appb-100002
    两个矩阵:
    Figure PCTCN2021079250-appb-100003
    表示矩阵Z第i列取值为1的行所组成的矩阵,设该矩阵的行数为m;
    Figure PCTCN2021079250-appb-100004
    表示矩阵Z第i列取值为0的行所组成的矩阵,设该矩阵的行数为n;
    步骤5-2、根据矩阵
    Figure PCTCN2021079250-appb-100005
    Figure PCTCN2021079250-appb-100006
    最后一列的不同取值,继续将
    Figure PCTCN2021079250-appb-100007
    划分为
    Figure PCTCN2021079250-appb-100008
    Figure PCTCN2021079250-appb-100009
    Figure PCTCN2021079250-appb-100010
    划分为
    Figure PCTCN2021079250-appb-100011
    Figure PCTCN2021079250-appb-100012
    共四个矩阵:
    Figure PCTCN2021079250-appb-100013
    表示矩阵
    Figure PCTCN2021079250-appb-100014
    中最后一列取值为1的行所组成的矩阵,设该矩阵的行数为m 1
    Figure PCTCN2021079250-appb-100015
    表示矩阵
    Figure PCTCN2021079250-appb-100016
    最后一列取值为0的行所组成的矩阵,设该矩阵的行数为m 2
    Figure PCTCN2021079250-appb-100017
    表示矩阵
    Figure PCTCN2021079250-appb-100018
    最后一列取值为1的行所组成的矩阵,设该矩阵的行数为n 1
    Figure PCTCN2021079250-appb-100019
    表示矩阵
    Figure PCTCN2021079250-appb-100020
    最后一列取值为0的行所组成的矩阵,设该矩阵的行数为n 2
    步骤5-3、根据信息熵公式计算矩阵Z前n列各自的信息熵,以Entropy i表示矩阵Z第i列的信息熵,有:
    Figure PCTCN2021079250-appb-100021
    步骤5-6、将计算得到的信息熵按绝对值由小到大进行排序。
  4. 如权利要求3所述的脚本化的智能电表事件判断解析方法,其特征在于,依据排序构建所述分支树的步骤6,其具体步骤为:
    步骤6-1、按优先级顺序由上至下构建n个与逻辑单元一一对应的分层,每个分层用于放置与该层的逻辑单元对应的Node节点,每个Node 节点对应一个节点矩阵H;
    在最上方的第一层中建立一个Node节点,将矩阵Z作为与该Node节点所对应的节点矩阵H;
    由上至下遍历各个分层,对于每个分层,分别执行步骤6-2至步骤步骤6-4,完成分支树的构建;
    步骤6-2、对于当前遍历到的分层,遍历该分层中的每个Node节点;对于每个Node节点,取其节点矩阵H,设该层所对应的逻辑单元与矩阵H中的第i列对应,则根据矩阵H第i列中各行元素的取值,将H分为矩阵
    Figure PCTCN2021079250-appb-100022
    Figure PCTCN2021079250-appb-100023
    表示矩阵H第i列取值为1的行所组成的矩阵,设该矩阵的行数为a;
    Figure PCTCN2021079250-appb-100024
    表示矩阵H第i列取值为0的行所组成的矩阵,设该矩阵的行数为b;
    然后根据矩阵
    Figure PCTCN2021079250-appb-100025
    Figure PCTCN2021079250-appb-100026
    最后一列的不同取值,继续将
    Figure PCTCN2021079250-appb-100027
    划分为
    Figure PCTCN2021079250-appb-100028
    Figure PCTCN2021079250-appb-100029
    Figure PCTCN2021079250-appb-100030
    划分为
    Figure PCTCN2021079250-appb-100031
    Figure PCTCN2021079250-appb-100032
    共四个矩阵:
    Figure PCTCN2021079250-appb-100033
    表示矩阵
    Figure PCTCN2021079250-appb-100034
    中最后一列取值为1的行所组成的矩阵,设该矩阵的行数为a 1
    Figure PCTCN2021079250-appb-100035
    表示矩阵
    Figure PCTCN2021079250-appb-100036
    最后一列取值为0的行所组成的矩阵,设该矩阵的行数为a 2
    Figure PCTCN2021079250-appb-100037
    表示矩阵
    Figure PCTCN2021079250-appb-100038
    最后一列取值为1的行所组成的矩阵,设该矩阵的行数为b 1
    Figure PCTCN2021079250-appb-100039
    表示矩阵
    Figure PCTCN2021079250-appb-100040
    最后一列取值为0的行所组成的矩阵,设该矩阵的行数为b 2
    步骤6-3、若a 1=0,新建一个结果值为0的叶子节点,并建立当前Node节点与该叶子节点之间的路径关系:当前Node节点对应的逻辑单元值为1时,该Node节点指向该叶子节点;
    若a 2=0,新建一个结果值为1的叶子节点,并建立当前Node节点与 该叶子节点之间的路径关系:当前Node节点对应的逻辑单元值为1时,该Node节点指向该叶子节点;
    若a 1和a 2均不为0,则在下一层新建一个Node节点,并建立当前Node节点与该下层Node节点之间的路径关系:当前Node节点对应的逻辑单元值为1时,该Node节点指向该下层Node节点,并将当前Node节点的
    Figure PCTCN2021079250-appb-100041
    作为该下层Node节点的节点矩阵H,留作该下层节点被遍历到时使用;
    步骤6-4、若b 1=0,新建一个结果值为0的叶子节点,并建立当前Node节点与该叶子节点之间的路径关系:当前Node节点对应的逻辑单元值为0时,该Node节点指向该叶子节点;
    若b 2=0,新建一个结果值为1的叶子节点,并建立当前Node节点与该叶子节点之间的路径关系:当前Node节点对应的逻辑单元值为0时,该Node节点指向该叶子节点;
    若b 1和b 2均不为0,则在下一层新建一个Node节点,并建立当前Node节点与该下层Node节点之间的路径关系:当前Node节点对应的逻辑单元值为0时,该Node节点指向该下层Node节点,并将当前Node节点的
    Figure PCTCN2021079250-appb-100042
    作为该下层Node节点的节点矩阵H,留作该下层节点被遍历到时使用。
  5. 如权利要求4所述的脚本化的智能电表事件判断解析方法,其特征在于:生成跳转分支树后,按分支树从上至下的方向遍历所有Node节点,根据路径关系和叶子节点对应的结果值生成判断代码,将判断代码写入智能电表的单片机,用于完成动态实时判断。
  6. 如权利要求5所述的脚本化的智能电表事件判断解析方法,其特征在于:遍历分支树的所有Node节点生成判断代码时,对于当前Node节点,优先将从当前Node节点开始到一个最近的叶子节点的路径作为下一步的判断分支。
  7. 如权利要求4至6任一所述的脚本化的智能电表事件判断解析方法,其特征在于:所述步骤1至6在性能优于智能电表单片机的计算机平台上进行。
PCT/CN2021/079250 2020-06-28 2021-03-05 一种脚本化的智能电表事件判断解析方法 WO2022001154A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202010598309.0A CN111767038B (zh) 2020-06-28 2020-06-28 一种脚本化的智能电表事件判断解析方法
CN202010598309.0 2020-06-28

Publications (1)

Publication Number Publication Date
WO2022001154A1 true WO2022001154A1 (zh) 2022-01-06

Family

ID=72722266

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/079250 WO2022001154A1 (zh) 2020-06-28 2021-03-05 一种脚本化的智能电表事件判断解析方法

Country Status (2)

Country Link
CN (1) CN111767038B (zh)
WO (1) WO2022001154A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114610288A (zh) * 2022-05-12 2022-06-10 之江实验室 基于阵列式解析基元结构的后端编译器实现方法及装置

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111767038B (zh) * 2020-06-28 2023-05-26 烟台东方威思顿电气有限公司 一种脚本化的智能电表事件判断解析方法

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103488524A (zh) * 2012-06-13 2014-01-01 北大方正集团有限公司 命令管理装置及其命令管理方法
CN110908640A (zh) * 2019-11-26 2020-03-24 京东数字科技控股有限公司 实现业务功能的方法和脚本引擎
CN111767038A (zh) * 2020-06-28 2020-10-13 烟台东方威思顿电气有限公司 一种脚本化的智能电表事件判断解析方法
CN111767037A (zh) * 2020-06-28 2020-10-13 烟台东方威思顿电气有限公司 一种脚本化的智能电表事件判断方法

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2019080091A1 (zh) * 2017-10-27 2019-05-02 华为技术有限公司 代码处理方法和设备

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103488524A (zh) * 2012-06-13 2014-01-01 北大方正集团有限公司 命令管理装置及其命令管理方法
CN110908640A (zh) * 2019-11-26 2020-03-24 京东数字科技控股有限公司 实现业务功能的方法和脚本引擎
CN111767038A (zh) * 2020-06-28 2020-10-13 烟台东方威思顿电气有限公司 一种脚本化的智能电表事件判断解析方法
CN111767037A (zh) * 2020-06-28 2020-10-13 烟台东方威思顿电气有限公司 一种脚本化的智能电表事件判断方法

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
ZHANG XIUSHEN , YANG WEI: "Research on an Expression Calculation Algorithm for Script Interpreter", JOURNAL OF SHANXI NORMAL UNIVERSITY(SOCIAL SCIENCE EDITION), vol. 39, 25 November 2012 (2012-11-25), pages 194 - 196, XP055883957 *
ZOU CHANGWEI , WANG LIN: "Coroutine and Scripted Mechanism for Embedded System", JOURNAL OF COMPUTER APPLICATIONS, vol. 34, no. 5, 10 May 2014 (2014-05-10), cn, pages 1408 - 1412, XP055883953, ISSN: 1001-9081, DOI: 10.11772/J.ISSN.1001-9081.2014.05.1408 *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114610288A (zh) * 2022-05-12 2022-06-10 之江实验室 基于阵列式解析基元结构的后端编译器实现方法及装置
CN114610288B (zh) * 2022-05-12 2022-09-16 之江实验室 基于阵列式解析基元结构的后端编译器实现方法及装置

Also Published As

Publication number Publication date
CN111767038B (zh) 2023-05-26
CN111767038A (zh) 2020-10-13

Similar Documents

Publication Publication Date Title
US11741014B2 (en) Methods and systems for handling data received by a state machine engine
US11599770B2 (en) Methods and devices for programming a state machine engine
Qin et al. Zero-shot action recognition with error-correcting output codes
WO2022001154A1 (zh) 一种脚本化的智能电表事件判断解析方法
US9886017B2 (en) Counter operation in a state machine lattice
CN1759393B (zh) 规则处理器和使用该规则处理器的方法
CN100511049C (zh) 用于对任意大小的正则表达式估值的方法和装置
CN111767037B (zh) 一种脚本化的智能电表事件判断方法
US11816493B2 (en) Methods and systems for representing processing resources
WO2021068683A1 (zh) 正则表达式生成方法、装置、服务器及计算机可读存储介质
WO2021047373A1 (zh) 基于大数据的列数据处理方法、设备及介质
CN117493622B (zh) 基于现场可编程阵列器件的字符串的查询方法和装置
EP3955256A1 (en) Non-redundant gene clustering method and system, and electronic device
CN113645137B (zh) 一种软件定义网络多级流表压缩方法及系统
CN110597876A (zh) 一种基于离线学习历史查询预测未来查询的近似查询方法
CN114610488A (zh) 基于负载均衡的数据采集方法、系统和电子设备
CN107861724B (zh) 快速适配dlms/cosem对象的脚本化编码方法
WO2024051163A1 (zh) 一种基于组合功能覆盖率的测试方法和系统
WO2017215030A1 (zh) 一种有查询功能的存储器及其查询方法
CN113486063A (zh) 电力物联网中流数据处理方法、装置及终端设备
Liu et al. Language and visual relations encoding for visual question answering
US20220004385A1 (en) Graphics processing unit
CN111125147B (zh) 基于扩展预计算模型和sql函数的超大集合分析方法及装置
CN118051438A (zh) 一种基于图神经网络的智能合约漏洞检测方法
Zhang Research on Malicious Code Detection Techniques Based on Data Mining and Machine Learning

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21832575

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 21832575

Country of ref document: EP

Kind code of ref document: A1

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 240523)

122 Ep: pct application non-entry in european phase

Ref document number: 21832575

Country of ref document: EP

Kind code of ref document: A1