Code generation method and device and computer program product

Through the signal segmentation processing and probability distribution analysis of the intelligent connected vehicle monitoring system, the logical rule sequence is optimized, and the coupling and resource allocation of the code generation process in the existing technology is solved, and the computing efficiency and resource utilization of the system are improved.

CN120469672APending Publication Date: 2025-08-12GUANGZHOU AUTOMOBILE GROUP CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510553546.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-28
Publication Date
2025-08-12

Smart Images

  • Figure CN120469672A_ABST
    Figure CN120469672A_ABST
Patent Text Reader

Abstract

The invention discloses a code generation method and device and a computer program product, and the method comprises the steps: carrying out the segmentation processing of a target signal, and obtaining a plurality of signal segmentation values; calculating the probability of each signal segment value to obtain a probability distribution relation; on the basis of the probability distribution relationship, performing sequential optimization on conditional expressions in a logic rule arranged by the user; and automatically generating codes according to the optimized logic rule sequence. By establishing a dynamic optimization mechanism based on signal segmentation probability distribution, the calculation efficiency and the resource utilization rate of the intelligent networked automobile monitoring system are remarkably improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of intelligent connected vehicles, and in particular to a code generation method, device, and computer program product, and the device and computer program product. Background Art

[0002] In the current mainstream technology solutions for big data monitoring of intelligent connected vehicles, users construct monitoring rule logic through visual orchestration tools (such as drag-and-drop interfaces or structured configuration tables). The system then converts the rule topology into executable code through a predefined syntax mapping mechanism. The core process is as follows: users configure monitoring rule parameters (including data source fields, calculation operators, threshold conditions, etc.) in the orchestration interface. The system then uses the rule parsing engine to map these configurations to pre-set code templates, ultimately generating distributed computing code that meets the target execution environment.

[0003] However, the above-mentioned existing technologies have the following defects: First, there is a strong coupling relationship between the orchestration interface and the code template, which requires that the parameter types, operator functions and logical order configured by the user must completely match the code template syntax, resulting in limited flexibility in rule expression; Second, the code generation process lacks the ability to semantically analyze and optimize the rule logic, and is unable to perform equivalent conversion or execution order optimization on user-defined monitoring rules, resulting in redundant computing, unreasonable resource allocation and other problems in the generated code in distributed computing scenarios. Summary of the Invention

[0004] The technical problem to be solved by the embodiments of the present invention is to provide a code generation method, device and computer program product, device and computer program product to automatically optimize and adjust the order of logical rules to improve code running efficiency.

[0005] To solve the above technical problems, the present invention provides a code generation method, which is characterized by comprising the following steps:

[0006] Perform segmentation processing on the target signal to obtain multiple signal segmentation values;

[0007] Calculate the probability of each signal segment value and obtain the probability distribution relationship;

[0008] Based on the probability distribution relationship, sequentially optimize the conditional expressions in the logic rules arranged by the user;

[0009] Automatically generate code according to the optimized logical rule sequence.

[0010] Preferably, the sequential optimization of the conditional expressions in the user-arranged logic rules based on the probability distribution relationship specifically includes:

[0011] For multiple conditional expressions connected by the logical AND operator, the execution order is rearranged in ascending order of the probability of the signal segment values they contain.

[0012] Preferably, the method further comprises: maintaining the original branch structure of the conditional expression connected by the logical OR operator.

[0013] Preferably, the calculating the probability of each signal segment value includes:

[0014] Extract historical data of target signals according to preset periods;

[0015] Counting the number of occurrences of each signal segment value in the historical data;

[0016] The probability of the target signal segment value is obtained by dividing the number of occurrences of the target signal segment value by the sum of the number of occurrences of each segment value of the target signal.

[0017] Preferably, the probability distribution relationship is reflected in the form of a probability statistical table, which includes the vehicle series name, signal name, signal segment value and its corresponding probabilities.

[0018] Preferably, the segmentation processing of the target signal to obtain multiple signal segmentation values specifically includes:

[0019] For continuous-valued signals, when the difference between the maximum and minimum values exceeds the preset threshold, segmentation is performed according to step size = ceil((maximum value - minimum value) / segment number threshold); when the difference does not exceed the preset threshold, the interval [minimum value, maximum value] is evenly divided by step size 1, and the number of segments is equal to the maximum value - minimum value, and does not exceed the segment number threshold;

[0020] For an enumerated value signal, the segment value is a discrete set of all possible values.

[0021] Preferably, the signal value segment smaller than the minimum value is (-∞, minimum value), and the signal value segment greater than the maximum value is (maximum value +1, +∞).

[0022] The present invention also provides a code generating device, comprising:

[0023] A segmentation module is used to process the target signal in segments to obtain multiple signal segmentation values;

[0024] A calculation module is used to calculate the probability of each signal segment value and obtain the probability distribution relationship;

[0025] An optimization module, configured to sequentially optimize the conditional expressions in the logic rules arranged by the user based on the probability distribution relationship;

[0026] The generation module is used to automatically generate code according to the optimized logical rule sequence.

[0027] The present invention also provides a code generating device, comprising:

[0028] one or more processors;

[0029] Memory;

[0030] One or more application programs, wherein the one or more application programs are stored in the memory and configured to be executed by the one or more processors, and the one or more application programs are configured to execute the code generation method.

[0031] The present invention also provides a computer program product, comprising computer instructions, wherein the computer instructions instruct a computer device to execute operations corresponding to the method.

[0032] The implementation of this invention has the following beneficial effects: By establishing a dynamic optimization mechanism based on the probability distribution of signal segments, the invention significantly improves the computational efficiency and resource utilization of intelligent connected vehicle monitoring systems. Specifically, based on the full set of historical data, the probability of occurrence of each signal segment value is calculated to form a dynamically updateable probability distribution relationship, providing a data-driven decision-making basis for logic optimization. A probability-driven conditional expression reordering strategy utilizes the short-circuiting nature of logic to prioritize low-probability conditions, effectively reducing invalid computational branches and significantly reducing the average computational effort of complex monitoring rules. This significantly improves the real-time and economic performance of the system in complex vehicle monitoring scenarios. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0034] Figure 1 This is a flowchart of a code generation method according to an embodiment of the present invention. DETAILED DESCRIPTION

[0035] The following descriptions of the embodiments refer to the accompanying drawings to illustrate specific embodiments in which the present invention may be implemented.

[0036] Please refer to Figure 1 As shown, the first embodiment of the present invention provides a code generation method, comprising the following steps:

[0037] Perform segmentation processing on the target signal to obtain multiple signal segmentation values;

[0038] Calculate the probability of each signal segment value and obtain the probability distribution relationship;

[0039] Based on the probability distribution relationship, sequentially optimize the conditional expressions in the logic rules arranged by the user;

[0040] Automatically generate code according to the optimized logical rule sequence.

[0041] It can be seen from the above steps that the embodiment of the present invention significantly improves the resource efficiency and execution performance of code generation by processing signals in segments, calculating probability distribution, and optimizing the order of logic rules based on the segmented processing.

[0042] Specifically, the embodiment of the present invention first performs segmentation processing on the target signal involved in the user-programmed logic rule. The segmentation method varies depending on the type of the target signal:

[0043] (1) Segmented processing of continuous-valued signals

[0044] The minimum and maximum values of continuous-valued signals are derived from the DBC file (CAN bus signal definition file). For example, the physical value range of automotive sensor signals (such as vehicle speed and temperature) is 0, and the maximum value of the SigX signal is 125. Based on the difference between the maximum and minimum values, the segmentation method is divided into the following two categories:

[0045] a. When the maximum value - minimum value ≤ 100: directly divide evenly

[0046] That is, the interval [minimum value, maximum value] is divided equally by a step size of 1, and the number of segments is equal to the maximum value - minimum value.

[0047] For example, the minimum value of the signal SigX is 0, and the maximum value is 56; then the segments are [0, 1), [1, 2), ..., [55, 56), for a total of 56 segments.

[0048] b. When the maximum value - minimum value > 100: Dynamically adjust the step size

[0049] Calculate the step size as step = ceil((maximum - minimum) / 100). Divide the interval [minimum, maximum] by the step size, starting from the minimum and ending at the maximum, with a maximum number of segments ≤ 100. Setting an upper limit of 100 segments can control computing resources and avoid the loss of statistical efficiency caused by excessive segmentation. By rounding up the segment size, the number of segments does not exceed 100, even if the maximum and minimum values differ significantly.

[0050] For example, the minimum value of the signal SigX is 0, and the maximum value is 125; then the calculated step size is 2, and the segments are [0,2), [2,4), ..., [124,125), for a total of 63 segments.

[0051] It should be noted that regardless of the size of the difference, values outside the original range (such as <minimum or >maximum) are grouped separately. For example, values less than the minimum are grouped as (-∞, minimum) (such as (-∞, 0)), and values greater than the maximum are grouped as (maximum + 1, +∞) (such as (126, +∞)). This way, even if the signal exceeds the preset range (such as due to a sensor failure causing an abnormal value), it can still be classified into an independent segment, avoiding data loss.

[0052] The signal SigX is finally segmented into multiple signal segment values, that is, multiple value ranges: {(-∞,0),[0,2),[2,4),…,[124,125],(126,+∞)}.

[0053] (2) Segmented processing of enumeration value signals: use directly.

[0054] Each possible value of the enumerated value signal (such as "1", "3", "5") is directly treated as an independent segment without further segmentation.

[0055] For example, if the enumeration value of the signal Sig2 is “1”, “3”, and “5”, the segments are “1”, “3”, and “5”.

[0056] The segmented signal values (continuous value segments or enumerated values) will be used as statistical units for subsequent calculation of the probability of each segment value.

[0057] In an embodiment of the present invention, full data of each vehicle series on a certain day is regularly extracted and statistically analyzed to obtain the probability corresponding to each segment value of each signal, thereby obtaining the probability distribution relationship of each segment value of each signal of each vehicle series in the historical data.

[0058] Specifically, this embodiment of the present invention uses a full data extraction method. For example, on a specific day, all signal data from each vehicle series is fully extracted (e.g., by direct copying, exporting, importing, or using an API interface). This means that the complete signal records (e.g., sensor data, control signals, etc.) for all vehicles in that vehicle series on that day are obtained. For example, if vehicle series A contains 1,000 vehicles, the complete SigX records (e.g., vehicle speed signals) for all 1,000 vehicles on that day are extracted.

[0059] Probability distribution relationships must be based on sufficient historical data to reflect the long-term distribution of signal values (for example, to prevent outliers on a single day from affecting probability results). Therefore, the above-mentioned full data extraction is performed at fixed time intervals (for example, daily or weekly), thereby accumulating full data for each signal of each vehicle series to form historical data (for example, data from the past 30 days, the past week, etc.), and ensuring the timeliness of subsequent probability statistics.

[0060] As an example, the probability distribution relationship of an embodiment of the present invention can be expressed in the form of a probability statistical table. Specifically, the extracted full data is grouped by vehicle series name and signal name. For example, the SigX signal data and SigY signal data of vehicle series A, and the SigZ signal data of vehicle series B are processed independently. The vehicle series name refers to the vehicle series to which the signal belongs, and the signal name is the name of a signal within that vehicle series.

[0061] Then count the number of occurrences of each segment value (continuous value segment or enumeration value) for each signal:

[0062] (1) Continuous value signal: Count the number of occurrences of each segment value (such as [0,2)) in the historical data.

[0063] (2) Enumeration value signal: Count the number of times each enumeration value (such as "1", "3") appears in historical data.

[0064] According to the statistical number of occurrences, the probability of the target signal segment value is calculated = the number of occurrences of the target signal segment value ÷ the sum of the number of occurrences of each segment value of the target signal, that is:

[0065]

[0066] Among them, P(segment i ) is the probability of the i-th signal segment value, and n is the number of segments of the target signal.

[0067] Finally, a probability statistics table is constructed, as shown in the following table:

[0068]

[0069]

[0070] After obtaining the above probability distribution relationship, the conditional expression in the user-programmed logic rule is sequentially optimized. The conditional expression is an expression for logical judgment of the signal segment value, which includes the following three parts:

[0071] (1) Signal name (such as Sig1, Sig2);

[0072] (2) Operators (such as ==, >=, <, ∈);

[0073] (3) Comparison value (can be a discrete value set, such as {"1","3"}; can also be a continuous value interval, such as <128, ==122).

[0074] For example: Conditional expression 1: Sig1∈("1","3""): determines whether the signal segment value of Sig1 is "1" or "3";

[0075] Conditional expression 2: Sig6<128: Determines whether the signal segment value of Sig6 is less than 128;

[0076] Conditional Expression 3: Sig7 == 122: Determine whether the signal segment value of Sig7 is equal to 122.

[0077] The logical rules arranged by the user are compound expressions that connect multiple conditional expressions through logical operators (such as && and ||).

[0078] Based on the probability distribution of each signal segment, we can analyze the trigger probability of each conditional expression, prioritize the condition with the lowest probability, and use the logical short-circuit property of logical operators to terminate invalid branches as early as possible, thereby reducing the overall computational effort. The trigger probability of each conditional expression is determined by the probability of its associated signal segment.

[0079] It can be understood that the logical short-circuit feature means that during the execution of a conditional expression, for sub-conditions connected by &&, if any condition is judged to be false, the subsequent conditions do not need to be executed; for sub-conditions connected by ||, if any condition is judged to be true, the subsequent conditions do not need to be executed. The embodiments of the present invention use probability-driven optimization, that is, low-probability conditions (i.e., conditions with a low probability of occurrence) are more likely to trigger a logical short-circuit during judgment, thereby reducing the computational complexity of subsequent conditions.

[0080] Take the passenger seat system fault monitoring rules programmed by the user as an example. The original rules are:

[0081] Sig1("1","3")&&Sig2>=11&&Sig3=="3"&&Sig4=="5"&&Sig5("2","4","5")&&Sig6<128&&Sig7==122||sig8>88

[0082] If, based on the probability distribution of each signal segment value, the probability of Sig1's signal segment value being 1 is 40%, the probability of Sig1's signal segment value being 3 is 20%, the probability of Sig6's signal segment value being <128 is 3.2%, and the probability of Sig7's signal segment value being 122 is 1.1%, and the triggering probability of each conditional expression is sorted from low to high (with the low probability condition in front), the logic rule is automatically optimized to:

[0083] Sig7==122&&Sig6<128&&Sig1("1","3")&&Sig2>=11&&Sig3=="3"&&Sig4=="5"&&Sig5("2","4","5")||sig8>88

[0084] As can be seen from the above, since the probability of Sig7 == 122 is the smallest, after automatically optimizing it to the first place, in most cases, only this one instruction in the rule needs to be calculated to complete the calculation, thereby greatly reducing server computing resources.

[0085] Finally, based on the optimized logical rules, the conditional expressions are converted into executable code for the target distributed computing framework through predefined syntax mapping rules, including: mapping logical operators to API calls supported by the framework, generating corresponding value range judgment logic according to the signal type, and injecting dynamically optimized logical rules; finally, the executable program is output to complete the automated deployment and operation of the logical rules.

[0086] Corresponding to the code generation method described in the first embodiment of the present invention, the second embodiment of the present invention further provides a code generation device, including:

[0087] A segmentation module is used to process the target signal in segments to obtain multiple signal segmentation values;

[0088] A calculation module is used to calculate the probability of each signal segment value and obtain the probability distribution relationship;

[0089] An optimization module, configured to sequentially optimize the conditional expressions in the logic rules arranged by the user based on the probability distribution relationship;

[0090] The generation module is used to automatically generate code according to the optimized logical rule sequence.

[0091] Corresponding to the code generation method described in the first embodiment of the present invention, the third embodiment of the present invention further provides a code generation device, including:

[0092] one or more processors;

[0093] Memory;

[0094] One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the one or more processors, and the one or more applications are configured to execute the code generation method described in the aforementioned embodiment 1 of the present invention.

[0095] Corresponding to the code generation method described in the aforementioned embodiment 1 of the present invention, embodiment 4 of the present invention further provides a computer program product, including computer instructions, which instruct a computer device to perform operations corresponding to the code generation method described in the aforementioned embodiment 1 of the present invention.

[0096] Preferably, the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor, or the processor may be any conventional processor. The processor is the control center of the device, and various parts of the device are connected using various interfaces and lines.

[0097] The memory mainly includes a program storage area and a data storage area, wherein the program storage area can store an operating system, an application program required for at least one function, etc., and the data storage area can store related data, etc. In addition, the memory can be a high-speed random access memory, or a non-volatile memory, such as a plug-in hard disk, a smart memory card (SmartMedia Card, SMC), a secure digital (Secure Digital, SD) card, and a flash card, etc., or the memory can also be other volatile solid-state storage devices.

[0098] It should be noted that the above-mentioned device may include but is not limited to a processor and a memory, which can be understood by those skilled in the art.

[0099] For the working principle and process of the above embodiment, please refer to the description of the above embodiment of the present invention, which will not be repeated here.

[0100] From the above description, it can be seen that compared with the existing technology, the beneficial effects of the present invention are as follows: by establishing a dynamic optimization mechanism based on the probability distribution of signal segments, the present invention significantly improves the computing efficiency and resource utilization of the intelligent connected vehicle monitoring system. Specifically, based on the statistics of the probability of occurrence of each signal segment value based on the full amount of historical data, a dynamically updateable probability distribution relationship is formed, providing a data-driven decision-making basis for logic optimization; through a probability-driven conditional expression reordering strategy, the logic short-circuit characteristic is utilized to prioritize the execution of low-probability conditions, effectively reducing invalid calculation branches, greatly reducing the average computational complexity of complex monitoring rules, and significantly improving the real-time and economic performance of the system in complex vehicle monitoring scenarios.

[0101] The above disclosure is merely a preferred embodiment of the present invention and is not intended to limit the scope of the present invention. Therefore, equivalent changes made according to the claims of the present invention are still within the scope of the present invention.

Claims

1. A code generation method, characterized in that: The following steps are involved: Perform segmentation processing on the target signal to obtain multiple signal segmentation values; Calculate the probability of each signal segment value and obtain the probability distribution relationship; Based on the probability distribution relationship, sequentially optimize the conditional expressions in the logic rules arranged by the user; Automatically generate code according to the optimized logical rule sequence.

2. The method according to claim 1, characterized in that The sequential optimization of the conditional expressions in the user-arranged logic rules based on the probability distribution relationship specifically includes: For multiple conditional expressions connected by the logical AND operator, the execution order is rearranged in ascending order of the probability of the signal segment values they contain.

3. The method according to claim 2, characterized in that Also includes: Keep the original branch structure of the conditional expression connected by the logical OR operator.

4. The method according to claim 1, wherein Calculating the probability of each signal segment value includes: Extract historical data of target signals according to preset periods; Counting the number of occurrences of each signal segment value in the historical data; The probability of the target signal segment value is obtained by dividing the number of occurrences of the target signal segment value by the sum of the number of occurrences of each segment value of the target signal.

5. The method according to claim 4, characterized in that The probability distribution relationship is reflected in the form of a probability statistics table, which includes the vehicle series name, signal name, signal segment value and its corresponding probability.

6. The method according to claim 1, characterized in that The target signal is segmented to obtain multiple signal segment values, specifically including: For continuous-valued signals, when the difference between the maximum and minimum values exceeds the preset threshold, segmentation is performed according to step size = ceil((maximum value - minimum value) / segment number threshold); when the difference does not exceed the preset threshold, the interval [minimum value, maximum value] is evenly divided by step size 1, and the number of segments is equal to the maximum value - minimum value, and does not exceed the segment number threshold; For an enumerated value signal, the segment value is a discrete set of all possible values.

7. The method according to claim 6, characterized in that The signal value segmentation is less than the minimum value (-∞, minimum value), and the signal value segmentation is greater than the maximum value (maximum value + 1, +∞).

8. A code generating device, characterized in that: include: A segmentation module is used to process the target signal in segments to obtain multiple signal segmentation values; A calculation module is used to calculate the probability of each signal segment value and obtain the probability distribution relationship; An optimization module, configured to sequentially optimize the conditional expressions in the logic rules arranged by the user based on the probability distribution relationship; The generation module is used to automatically generate code according to the optimized logical rule sequence.

9. A code generating device, characterized in that: include: one or more processors; Memory; One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the one or more processors, and the one or more applications are configured to execute the code generation method according to any one of claims 1 to 7.

10. A computer program product, characterized in that The method comprises computer instructions, wherein the computer instructions instruct a computer device to perform operations corresponding to the method according to any one of claims 1 to 7.