Subway signal control method and device, electronic equipment and storage medium
By constructing an expression binary tree to parse control rules and evaluate them in real time, the problem of strong coupling between rules and code in traditional railway signal control systems is solved, realizing flexible and efficient subway signal control and improving the system's response efficiency and reliability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CRSC URBAN RAIL TRANSIT TECH CO LTD
- Filing Date
- 2026-03-24
- Publication Date
- 2026-06-19
AI Technical Summary
In traditional railway signal control systems, hard-coded control methods result in strong coupling between rules and code, poor flexibility, difficulty in adapting to the rapidly changing needs of subway systems, high maintenance costs, poor scalability, and poor readability.
The control rules are parsed using an expression binary tree structure. By acquiring the control rule set, an expression binary tree is constructed. Device data is collected in real time and recursively evaluated to trigger control commands. This decouples the control logic from the code and supports flexible modification and expansion.
It improves the flexibility and response efficiency of the subway signal control system, reduces maintenance costs, enhances system readability and reliability, and supports rule reuse and rapid response.
Smart Images

Figure CN122232695A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of train control technology, and in particular to a subway signal control method, device, electronic equipment, and storage medium. Background Technology
[0002] Traditional railway signal control systems typically implement control logic using hard-coding. In this approach, control rules are directly written into the program source code, and the relationship between the system's control logic and equipment states is established through fixed programming. When the subway system needs to add stations, introduce new control rules, or modify existing rules, developers must modify the source code, recompile, test, and deploy the entire system. The system executes corresponding control commands by directly reading equipment state variables and making corresponding control logic decisions.
[0003] However, hard-coded control methods suffer from problems such as poor flexibility due to strong coupling between rules and code. Summary of the Invention
[0004] This invention provides a subway signal control method, device, electronic equipment, and storage medium to solve the problem of poor flexibility caused by strong coupling between rules and code in existing hard-coded control methods.
[0005] This invention provides a subway signal control method, comprising: Obtain the control rule set of the subway system; the control rule set contains at least one control rule consisting of a control instruction and a logical expression. The logical expression is parsed to construct an expression binary tree corresponding to the control rule; the leaf nodes of the expression binary tree are used to associate device state variables, and the non-leaf nodes are used to associate logical operators. The system collects equipment operation data of the subway system in real time and updates the equipment status variables with the equipment operation data. Based on the device state variables, the expression binary tree is recursively evaluated to obtain the complete operation result of the logical expression; Based on the complete calculation result of the logical expression, the control instruction corresponding to the logical expression is triggered.
[0006] According to a subway signal control method provided by the present invention, the step of recursively evaluating the expression binary tree based on the equipment state variables to obtain the complete computation result of the logical expression includes: Starting from the root node of the expression binary tree, if the current node is a leaf node, read the real-time value from the device operation data as the node value based on the device status variable associated with the leaf node. If the current node is a non-leaf node, logical operations are performed on the node return values of the child nodes under the non-leaf node according to the logical operators associated with the non-leaf node to obtain the calculation result of the current node. Based on the calculation result of the root node, the complete calculation result is obtained.
[0007] According to a subway signal control method provided by the present invention, the step of performing logical operations on the node return values of the child nodes under the non-leaf nodes based on the logical operators associated with the non-leaf nodes to obtain the calculation result of the current node includes: When the logical operator is logical AND, the value of the left subtree is calculated first. If the value of the left subtree is false, the calculation of the right subtree is stopped, and false is returned directly as the calculation result of the current node. When the logical operator is logical OR, the value of the left subtree is calculated first. If the value of the left subtree is true, the calculation of the right subtree is stopped, and true is returned directly as the calculation result of the current node.
[0008] According to a subway signal control method provided by the present invention, the step of parsing the logical expression and constructing an expression binary tree corresponding to the control rule includes: Traverse the string elements in the logical expression and identify the operands and operators in the string elements; Based on the operands, the operand stack is pushed onto the stack to obtain the updated operand stack; Based on the aforementioned operators and operator precedence rules, the top element of the operator stack is compared to determine the pop operator. Based on the pop operator and the corresponding number of operands extracted from the update operand stack, a subtree node is constructed and the subtree node is backfilled into the update operand stack; Repeat the steps of traversal, updating the operand stack, element comparison, and subtree construction and backfilling until the logical expression is traversed and the expression binary tree is constructed.
[0009] According to a subway signal control method provided by the present invention, the operator priority rule includes the priority order of at least one of the following operators: parentheses, logical NOT, logical AND, and logical OR. The step of comparing the top element of the operator stack based on the operators and operator precedence rules to determine the pop operator includes: If the priority of the operator is less than or equal to the priority of the operator at the top of the stack, the operator at the top of the stack is determined as the pop operator.
[0010] According to a subway signal control method provided by the present invention, the equipment state variables adopt a standardized three-level structure identifier, which includes equipment type, equipment identifier and state attribute; The real-time acquisition of equipment operation data of the subway system and the updating of the equipment operation data to the equipment status variables include: Parse the source device information in the device operation data; Based on the three-level structure identifier, regular expression matching or string mapping is performed to locate the corresponding device object in memory and update the status attribute value of the device object. The binary tree of the expression is re-evaluated only when the device state variable contained in the logical expression changes.
[0011] The present invention also provides a subway signal control device, comprising: The acquisition unit acquires the control rule set of the subway system; the control rule set contains at least one control rule consisting of a control instruction and a logical expression. The binary tree construction unit parses the logical expression and constructs the expression binary tree corresponding to the control rule; the leaf nodes of the expression binary tree are used to associate device state variables, and the non-leaf nodes are used to associate logical operators. The status update unit collects the equipment operation data of the subway system in real time and updates the equipment operation data to the equipment status variables; The arithmetic unit recursively evaluates the expression binary tree based on the device state variables to obtain the complete computation result of the logical expression; The control unit triggers the control command corresponding to the logical expression based on the complete calculation result of the logical expression.
[0012] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the subway signal control method as described above.
[0013] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the metro signal control method as described above.
[0014] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the metro signal control method as described above.
[0015] The metro signal control method, device, electronic equipment, and storage medium provided by this invention acquire a set of control rules containing control instructions and logical expressions, and parse it into an expression binary tree; update the associated equipment state variables by collecting equipment operation data in real time, and recursively evaluate the binary tree to trigger control instructions. This realizes the transformation of traditional hard-coded control logic into dynamic parsing and evaluation based on expression binary trees, which can flexibly, efficiently, and accurately handle complex logic nesting, and improve the response efficiency and reliability of the metro signal control system. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0017] Figure 1 This is one of the flowcharts of the subway signal control method provided in the embodiments of the present invention; Figure 2 This is the second flowchart of the subway signal control method provided by the present invention; Figure 3 This invention provides a subway signal control device. Figure 4 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation
[0018] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0019] It should be noted that all actions involving the acquisition of signals, information, or data in this application are carried out in compliance with the relevant data protection laws and policies of the country where the application is located, and with the authorization granted by the owner of the relevant device.
[0020] To address the aforementioned problems, embodiments of the present invention provide a subway signal control method to achieve efficient, accurate, and flexible subway control. Figure 1 This is one of the flowcharts illustrating the subway signal control method provided in this embodiment of the invention, such as... Figure 1As shown, this method can be executed by electronic devices such as a subway signal control system, onboard controller, or ground area controller. The following description uses the subway signal control system as the executing entity, and the method includes: Step 110: Obtain the control rule set of the subway system; the control rule set contains at least one control rule consisting of a control instruction and a logical expression.
[0021] Here, the control rule set refers to a collection of files or data packages that define the operating logic of the subway system. It is not source code hard-coded in the program, but a collection of rules that exists in the form of an independent configuration file, such as XML or other structured text formats.
[0022] Furthermore, the control rules here are the smallest units that constitute the rule set, used to describe under what conditions a certain action is triggered. Each control rule consists of two core elements: first, a control instruction, which represents the specific action or operation that the system needs to perform, such as opening the car wash door, locking the route, or sending a departure signal; second, a logical expression, which represents the combination of conditions that must be met to trigger the instruction, usually composed of Boolean logic relations.
[0023] Specifically, during the startup initialization phase or upon receiving a hot update request, the configuration file stored on the local or remote server is read. By identifying each rule defined in the configuration file, the action identifier on the left-hand side of the rule is recognized as a control instruction, and the condition description on the right-hand side of the rule is recognized as a logical expression.
[0024] It should be noted that traditional railway signal control systems, which use hard-coding to implement control logic, have the following limitations: First, poor flexibility and scalability; control rules are tightly coupled with program code, requiring source code modifications for every rule change, making it unsuitable for the frequently changing operational needs of subway systems. Second, high maintenance costs; control logic is scattered across different code modules, requiring maintenance personnel to understand the entire system's code structure to make modifications, increasing the risk of errors. Third, long deployment cycles; the entire software development cycle is required from rule changes to actual deployment, failing to meet the rapid response requirements of subway operations. Fourth, poor readability; control rules are expressed in program code, making it difficult for non-programmers such as signal engineers to understand and verify the correctness of the control logic. Fifth, poor reusability; similar control logic across different stations cannot be reused, requiring separate coding implementation for each station's control rules.
[0025] Understandably, by combining control commands and logical expressions in a declarative manner, non-programmers can intuitively understand and modify business logic without delving into the underlying code. This completely decouples business logic from program code, eliminating the need for recompiling and deploying code when modifying or adding subway control rules, greatly improving the system's flexibility and maintainability. Specific effects include: First, significantly improved configuration flexibility; control rules can be adjusted by modifying configuration files without modifying program code, shortening the change cycle. Second, reduced maintenance costs; rule configuration files can be directly understood and modified without needing to deeply understand the program code structure. Third, improved scalability; adding new control rules only requires adding the corresponding rule entry to the configuration file, without recompiling and deploying. Fourth, improved rule readability and verifiability; rules are presented in a logical expression form close to natural language, facilitating understanding and verification of logical correctness. Fifth, support for rule reuse; similar control logic can be reused by copying and modifying rule configurations, improving development efficiency. Sixth, improved reliability; understandably, the rule parsing and evaluation engine has undergone rigorous testing, avoiding logical errors that may occur in hard-coded rules.
[0026] Step 120: Parse the logical expression to construct the expression binary tree corresponding to the control rule.
[0027] The leaf nodes of the expression binary tree are used to associate device state variables, and the non-leaf nodes are used to associate logical operators.
[0028] Here, the expression binary tree refers to a data structure used for processing logical operations. It converts linear string expressions into a tree structure to facilitate traversal and evaluation. Leaf nodes are the terminal nodes in the tree structure that have no child nodes. In this embodiment, these nodes represent specific input conditions, i.e., device state variables. Here, device state variables are memory mappings of physical equipment or logical states in the subway system, such as the occupancy status of a track section or the stationary status of a train.
[0029] In addition, non-leaf nodes here refer to intermediate nodes in the tree structure that have child nodes. They represent logical operators used to connect and process the values of leaf nodes. Common logical operators include logical AND, logical OR, logical NOT, etc.
[0030] Specifically, the built-in parsing engine can be used to perform lexical and syntactic analysis on the logical expression in string form obtained in step 110. Then, the parsing engine identifies the operands and operators representing device state variables in the expression, reorganizes them into a tree structure according to their operation precedence, and gradually builds subtrees through the CombineBTree operation to finally generate a complete binary tree of the expression.
[0031] In this process, all operands can be placed at the bottom level of the binary tree as leaf nodes, and all operators can be placed at the top level as parent nodes, thus constructing an expression binary tree that can fully express the original logical meaning. It should be noted that the process of constructing the binary tree realizes the transformation from textual logic to executable computational logic.
[0032] Step 130: Collect the equipment operation data of the subway system in real time and update the equipment operation data to the equipment status variables.
[0033] Here, equipment operation data refers to real-time physical signals or status information generated by subway equipment during operation, such as voltage values of track circuits, position feedback of switches, speed and position information of trains, etc.
[0034] Specifically, data can be collected periodically or event-driven from various field devices through underlying communication interfaces or sensor networks. After receiving this raw data, necessary preprocessing and format conversion are performed, and then, according to a pre-defined mapping relationship, the latest data values are written to the corresponding device status variables in memory. In essence, updating the device status variables with real-time device operating data ensures that subsequent logical judgments are always based on the system's current true state.
[0035] Step 140: Based on the device state variables, recursively evaluate the expression binary tree to obtain the complete operation result of the logical expression.
[0036] The complete result here refers to the Boolean value obtained by the final calculation of the entire logical expression, such as true or false, which represents whether all current device state combinations meet all the conditions for triggering the control command.
[0037] Specifically, the binary tree of the expression constructed in step 120 can be traversed by calling the evaluation engine. The evaluation process typically employs post-order traversal or recursion. More specifically, it can start from the root node and traverse downwards level by level until a leaf node is reached. At the leaf node, the real-time value of the device state variable updated in step 130 is read, for example, whether it is true or false. Then, these values are returned upwards, and the return values of the child nodes are calculated according to the logical operators of the non-leaf nodes, summarizing layer by layer upwards, finally obtaining the complete result of the logical expression at the root node. It should be noted that the recursive evaluation method can adapt to logical nesting of arbitrary complexity, ensuring the accuracy of the calculation.
[0038] Step 150: Based on the complete operation result of the logical expression, trigger the control instruction corresponding to the logical expression.
[0039] Specifically, this can be achieved by checking the complete calculation result obtained in step 140. If the result is true, it indicates that the current equipment status of the subway system fully meets the preset control logic conditions, and the control command in the control rule to which the logic expression belongs is then activated. Understandably, this control command is sent to the subway system's command execution module, ultimately being converted into a drive signal for the physical equipment, such as driving a motor or illuminating a signal light. Conversely, if the calculation result is false, no action is triggered, and the next round of monitoring and calculation continues.
[0040] In one embodiment, taking train washing control as an example, firstly, washing control rules are defined, such as train inspection depot door opening rules, wash depot door opening rules, wash start rules, and wash end rules. These control rules can be… <rule>WASHKKMCF=[TrainNum]ZT[TrainAll].PKSTEADY [Interlock]ZT[CLDTrack].TXCZY [Interlock]DOORZT[CLDDOOR].CLOSED [WashPlan]WASHOPENLJKM[TrainNum].XD< / rule> The command "Open the depot door" indicates that when the train has come to a complete stop, the depot track is occupied, the depot door is closed, and the scheduled time for opening the depot door according to the car wash plan has arrived, the command to open the depot door will be executed. Then, the rule parsing engine can read the configuration file and parse each rule into an expression binary tree. For the above rule, the root node in the constructed expression binary tree is the AND operator, and the four leaf nodes correspond to the four conditions. Next, the equipment status is collected in real time, including train status: whether it has come to a complete stop (PKSTEADY); track status: whether the specified track is occupied (TXCZY); depot door status: whether the specified depot door is closed (CLOSED); and plan status: whether the scheduled time for opening the depot door has arrived (XD). Then, the real-time status values can be substituted into the control rules through the rule evaluation engine. The corresponding binary tree expression is used for calculation. When all conditions are met, i.e., when the expression value is true, the rule evaluation engine triggers the "WASHKKMCF" command, which can then be controlled by the command execution module to open the car wash garage door. It can be understood that the triggering process can achieve a complete automated car wash process through the collaborative work of multiple rules. That is, if the conditions for opening the train inspection garage door are met, the command to open the train inspection garage door is triggered. If the conditions for opening the car wash garage door are met, the command to open the car wash garage door is triggered. If the car wash plan conditions are met, a car wash start prompt is triggered. If the conditions for the train entering the car wash garage are met, a car wash start indicator is triggered. If the conditions for the train leaving the car wash garage are met, a car wash end indicator is triggered. The entire process requires no manual intervention and is completely automatically controlled by the rule engine based on the equipment status.
[0041] The method provided in this invention obtains a set of control rules containing control commands and logical expressions, and parses it into an expression binary tree; it updates the associated equipment status variables by collecting equipment operation data in real time, and recursively evaluates the binary tree to trigger control commands. This transforms traditional hard-coded control logic into dynamic parsing and evaluation based on expression binary trees, enabling flexible, efficient and accurate handling of complex logic nesting, and improving the response efficiency and reliability of the subway signal control system.
[0042] Based on any of the above embodiments, step 140 includes: Starting from the root node of the expression binary tree, if the current node is a leaf node, read the real-time value from the device operation data as the node value based on the device status variable associated with the leaf node. If the current node is a non-leaf node, logical operations are performed on the node return values of the child nodes under the non-leaf node according to the logical operators associated with the non-leaf node to obtain the calculation result of the current node. Based on the calculation result of the root node, the complete calculation result is obtained.
[0043] Specifically, first, the root node pointer of the binary tree corresponding to the rule, stored in memory, can be located. Starting from the root node, a recursive function is initiated, preparing to delve down into each branch of the tree for calculation. It's understandable that this top-down entry method ensures that all conditional branches of the entire logical expression are covered. Here, the root node is the top-level node of the binary tree, representing the final entry point for the entire logical expression.
[0044] Then, when the current node is found to be a leaf node, the real-time value is read from the device operation data based on the device status variable associated with the leaf node and returned as the node value. Specifically, during the recursive process, when the current node is accessed and it is determined that the node has no child nodes, it is confirmed as a leaf node. At this point, the name or ID of the device status variable bound to the leaf node is identified, the latest device operation data corresponding to that variable is read, and the read data is used as the calculation result for the leaf node and returned to the upper-level caller.
[0045] Furthermore, when the current node is a non-leaf node, logical operations are performed on the return values of its child nodes based on the logical operators associated with the non-leaf node to obtain the calculation result for the current node. Here, the return value of a child node refers to the Boolean value reported upwards by the left or right child node of the current node after calculation or reading. In other words, the calculation result for the current node is the value obtained by the current non-leaf node processing the values of its child nodes according to its operator attributes.
[0046] Specifically, when a visited node has child nodes, it is confirmed to be a non-leaf node. In this case, the node represents a logical operation, such as AND, OR, or NOT. Processing of the current node is paused, and its child nodes are recursively evaluated first. After the child nodes return specific Boolean values, the current node performs operations on these return values according to its stored operator type. For example, if the current node is a logical AND node, the return values of its left and right child nodes are ANDed. If it is a logical NOT node, the return values of one child node are negated. The result of the operation is used as the final value of the current node and is then returned to the next higher level.
[0047] Furthermore, as the recursive process returns layer by layer, the computation eventually converges back to the root node of the tree. After processing the return values of its direct child nodes, the root node obtains the final Boolean value, which is the complete result of the entire logical expression. Understandably, this result directly reflects whether the overall state of the current subway system meets the composite conditions for triggering the control command.
[0048] The method provided in this invention, through a recursive traversal mechanism starting from the root node, distinguishes between data reading from leaf nodes and logical operations on non-leaf nodes, achieving bottom-up summarization of logical results. This method can accurately handle logical nesting of arbitrary complexity, such as multiple nested parentheses, ensuring the rigor of control rule judgments. Furthermore, the recursive evaluation method has a clear structure, facilitating standardized processing in the program and greatly improving the versatility and stability of the rule parsing engine.
[0049] To further improve evaluation efficiency, based on any of the above embodiments, the step of performing logical operations on the node return values of the child nodes under the non-leaf nodes according to the logical operators associated with the non-leaf nodes to obtain the calculation result of the current node includes: When the logical operator is logical AND, the value of the left subtree is calculated first. If the value of the left subtree is false, the calculation of the right subtree is stopped, and false is returned directly as the calculation result of the current node. When the logical operator is logical OR, the value of the left subtree is calculated first. If the value of the left subtree is true, the calculation of the right subtree is stopped, and true is returned directly as the calculation result of the current node.
[0050] Here, the left subtree and right subtree refer to the set of all nodes under the left and right branches of the current node, respectively.
[0051] Specifically, when a non-leaf node is encountered and identified by a logical AND operation, the left subtree of that node is recursively evaluated first. If the result returned by the left subtree is false, according to the property of logical AND (if one value is false, then the result is false), regardless of the value of the right subtree, the final result of the current node is destined to be false. Therefore, the traversal and calculation of the right subtree will be terminated immediately, and the associated device state variables in the right subtree will no longer be read. Instead, the false result will be directly returned upwards as the calculation result of the current node.
[0052] Furthermore, when a non-leaf node is encountered and identified by a logical OR operation, the value of the left subtree is calculated first. If the result returned by the left subtree is true, according to the property of logical OR (if one is true, then it is true), the final result of the current node must be true, regardless of the state of the right subtree. In this case, a short-circuit mechanism can be triggered, skipping all calculation steps of the right subtree and directly returning true as the calculation result of the current node upwards.
[0053] The method provided in this invention introduces a short-circuit optimization strategy for logical AND and OR operations during recursive evaluation. Utilizing the mathematical properties of logical operations, it terminates unnecessary right subtree calculations early after the result is determined, significantly reducing the computational load and memory access frequency in each evaluation process. This is particularly useful in subway signaling systems where logical expressions are often very large and evaluation frequencies are extremely high. This short-circuit mechanism can significantly reduce CPU load and improve the system's real-time response speed. Simultaneously, it avoids reading device states under invalid branches, thus improving system operational security.
[0054] Based on any of the above embodiments, step 120 includes: Traverse the string elements in the logical expression and identify the operands and operators in the string elements; Based on the operands, the operand stack is pushed onto the stack to obtain the updated operand stack; Based on the aforementioned operators and operator precedence rules, the top element of the operator stack is compared to determine the pop operator. Based on the pop operator and the corresponding number of operands extracted from the update operand stack, a subtree node is constructed and the subtree node is backfilled into the update operand stack; Repeat the steps of traversal, updating the operand stack, element comparison, and subtree construction and backfilling until the logical expression is traversed and the expression binary tree is constructed.
[0055] Specifically, firstly, characters or substrings in the logical expression string can be read one by one from left to right. For example, a lexical analyzer can be used to distinguish these elements. That is, if the read string matches a preset device status variable format, such as "[Device Type]ZT[Device Identifier].Attribute", it is identified as an operand; if the read characters match preset logical symbols, such as "+", "!", "()", etc., they are identified as operators.
[0056] Then, when an element is identified as an operand, it can be encapsulated as a basic binary tree node, i.e., a leaf node. Next, this node is pushed onto the operand stack. At this point, the state of the operand stack changes, a process called updating the operand stack, awaiting subsequent operator calls.
[0057] When an operator is detected, it is not immediately pushed onto the stack. Instead, the top element of the operator stack is checked. That is, the operator currently being scanned is compared with the operator at the top of the stack according to operator precedence rules. If a specific pop condition is met, such as the top operator having higher precedence (meaning the top operation should be combined first), the top operator is popped and used as the popped operator. If no pop is needed, such as the current operator having higher precedence or the stack being empty, the current operator is directly pushed onto the operator stack.
[0058] Understandably, the operator stack here is a data structure used to temporarily store logical operators that have not yet been executed. The operator precedence rules here are predefined by a dictionary or logical judgment criteria, specifying the order in which different operators are combined. Here, the pop operator refers to the operator that needs to be immediately involved in the computation.
[0059] Furthermore, after determining the pop operator, a subtree node is constructed based on the pop operator and the corresponding number of operands extracted from the update operand stack, and the subtree node is then backfilled into the update operand stack. Here, a subtree node refers to a local tree structure consisting of a root node representing an operator and several child nodes representing operands or smaller subtrees.
[0060] In detail, once the pop operator is determined, a corresponding number of elements can be popped from the operand stack based on the operator's type. For example, for a binary operator such as logical AND, the two top elements are popped as the right and left child nodes, respectively. For a unary operator such as logical NOT, one top element is popped as a child node. The pop operator can be used as the root, and the popped elements as child nodes, linked to form a new binary tree structure, i.e., a subtree node. Subsequently, this newly generated subtree node can be pushed back onto the operand stack as a new operand, completing the structuring of the local logic.
[0061] It should be noted that the process of scanning the remaining part of the logical expression continues, repeating the above steps. When the entire string traversal ends, if there are still residual operators in the operator stack, they are popped one by one, and the subtree construction operation continues until the operator stack is empty. At this point, the only node remaining in the operand stack is the root node of the final complete binary tree of the expression.
[0062] The method provided in this invention utilizes a dual-stack mechanism to convert infix expressions into binary tree structures. By temporarily storing intermediate states through the stack structure and dynamically determining the timing of subtree construction based on priority, it can accurately parse complex logical expressions containing multiple parentheses and operators with different priorities, transforming readable logical rule expressions into efficiently processed tree structures, thus laying the data structure foundation for subsequent recursive evaluation.
[0063] Based on any of the above embodiments, the operator precedence rules include the precedence order of at least one of the following operators: parentheses, logical NOT, logical AND, and logical OR. The step of comparing the top element of the operator stack based on the operators and operator precedence rules to determine the pop operator includes: If the priority of the operator is less than or equal to the priority of the operator at the top of the stack, the operator at the top of the stack is determined as the pop operator.
[0064] Specifically, to ensure that logical operators conform to mathematical logic, the precedence order of at least one operator, including parentheses, logical NOT, logical AND, and logical OR, can be pre-defined. It should be noted that not all logical operators will be listed here. In one embodiment, the precedence from highest to lowest is defined as: parentheses, logical NOT, logical AND, and logical OR. Parentheses are used to force a change in the order of operations and have the highest precedence. Logical NOT is a unary operator, usually represented by !, and its precedence is second only to parentheses. Logical AND is usually represented by... The '&' operator has higher precedence than the logical 'OR' operator. Logical 'OR' (usually represented by '+' or '|') has the lowest precedence.
[0065] Specifically, when comparing the top element of the stack, the principle of combining the highest priority operator first is followed. If the priority of the currently scanned operator is less than or equal to the priority of the operator at the top of the stack, it means that the operation at the top of the stack should take place before the current operation. For example, if the top of the stack is the logical AND operator, and the currently scanned logical OR operator is found, because the logical OR operator has lower priority than the logical AND operator, the operation of the logical AND operator at the top of the stack must be completed first, i.e., the subtree must be built, before the subsequent logical OR operator can be processed.
[0066] Therefore, at this point, we can decide to pop the top operator from the stack and use it as the pop operator for subtree construction. Conversely, if the current operator has higher precedence than the top operator, the current operator is pushed onto the stack, and we wait to find its right operand.
[0067] It's worth noting that the handling of parentheses is slightly different. Left parentheses are pushed directly onto the stack and are not compared. When a right parenthesis is encountered, the top operator is repeatedly popped from the stack until a left parenthesis is encountered, thus processing all the logic within the parentheses.
[0068] The method provided in this invention, through meticulously defined priority rules and stack top comparison strategies, transforms the operation order rules in mathematical logic into computer-executable stack operation instructions, ensuring that the system can correctly understand and process nonlinear logic. This allows the complex combinational logic in the configuration rules to be accurately transformed into a binary tree structure, thereby ensuring the accuracy and safety of the execution of subway signal control logic.
[0069] Based on any of the above embodiments, the device state variable adopts a standardized three-level structure identifier, which includes device type, device identifier, and state attribute; Step 130 includes: Parse the source device information in the device operation data; Based on the three-level structure identifier, regular expression matching or string mapping is performed to locate the corresponding device object in memory and update the status attribute value of the device object. The binary tree of the expression is re-evaluated only when the device state variable contained in the logical expression changes.
[0070] Here, the three-level structure identifier is used to uniquely identify any specific equipment status point in the subway system. This identifier consists of three levels, typically constructed using a format similar to "[Equipment Type]ZT[Equipment Identifier].Status Attribute". The equipment type specifies the type of equipment; for example, "TrainNum" indicates a train, "Interlock" indicates interlocking equipment, and "WashPlan" indicates a car wash plan.
[0071] Equipment identification is used to specifically designate which piece of equipment it is, such as a specific train number, track section number, or depot door number. Track section numbers are like CLDTrack; depot door numbers are like CLDDOOR.
[0072] Additionally, status attributes are used to describe the current physical or logical state of the device. For example, "PKSTEADY" indicates a stopped state, "CLOSED" indicates an off state, and "XD" indicates a countdown has ended. For instance, a complete variable name might be [TrainNum]ZT[TrainAll].PKSTEADY, meaning "stopped state of all trains".
[0073] Specifically, during startup and configuration file loading, the parsing engine can forcibly check whether the variable names used in the rules conform to the three-level structure standard. It should be noted that this standardized naming convention, which includes device type, device identifier, and status attributes, not only facilitates machine parsing but also allows signal engineers to intuitively infer the physical meaning of variables from their names when writing rules, greatly improving the readability and standardization of rule writing.
[0074] Next, the source device information in the device operation data is parsed. Here, source device information refers to the header information or tags carried in the raw data packets collected from the underlying hardware, which indicate the source of the data.
[0075] In detail, when the instant messaging interface receives a status message from a field device, the acquisition module first parses the message header to extract the device type and specific ID that sent the data. For example, if a message is received from the door of car wash garage #2, it contains its current open / closed signal.
[0076] Furthermore, based on the three-level structure identifier, regular expression matching or string mapping is performed to locate the corresponding device object in memory and update the device object's status attribute values. Specifically, the parsed source device information, such as type: KUKA, ID: 2, combined with the specific signal point in the message, such as "closed in place," can be used to construct the corresponding lookup key according to the three-level structure rules. Then, using an efficient hash algorithm or pre-compiled regular expressions, the corresponding variable instance is quickly located in the in-memory device status database. Once the object is found, the latest value from the message is written into the object's attribute field, completing the data synchronization update and ensuring that the memory state is consistent with the actual device state.
[0077] It should be noted that the re-evaluation of the binary tree of the expression is triggered only when the device state variables contained in the logical expression change. Here, re-evaluation refers to the re-execution of the recursive calculation process.
[0078] Specifically, to avoid wasting resources, a loop-based polling approach is not used. When updating a state attribute value, it's checked whether the value has actually changed, i.e., whether the new value is different from the old value. If the value hasn't changed, no further processing is done. If the value changes abruptly, such as from False to True, all expression binary trees referencing that variable are immediately searched. Only these affected binary trees are marked for recalculation or immediately added to the evaluation queue for calculation. For rules that do not depend on this variable, no calculation is performed.
[0079] The method provided in this invention establishes a standardized three-level variable naming system and a change-based event-driven mechanism. It utilizes structured identifiers to achieve rapid mapping from physical devices to logical variables and optimizes the evaluation strategy using incremental computation. This enables efficient and accurate identification and referencing of massive device states in large-scale subway signaling systems, making the retrieval and updating of tens of thousands of signal points orderly. Furthermore, compared to the traditional full-polling mode, the on-demand triggering computation mechanism significantly reduces CPU idle time and substantially improves the system's real-time processing capability and throughput when dealing with high-concurrency signal changes.
[0080] Based on any of the above embodiments Figure 2 This is the second flowchart of the subway signal control method provided by the present invention, as shown below. Figure 2 As shown, the method flow begins with the initiation rule evaluation process.
[0081] First, all existing rules in the rule base are traversed. For each rule encountered, a pre-constructed binary expression tree corresponding to that rule is obtained. It should be noted that by constructing a rule base, modifications, extensions, and maintenance of the control logic can be performed without modifying the program source code, significantly improving the flexibility and maintainability of the control system. Furthermore, the control system dynamically reads and parses these configuration rules through a dedicated parsing engine, achieving visual management and hot-update capabilities for the control strategy.
[0082] Next, the recursive traversal phase of the binary tree begins. For the currently visited node, it is first determined whether it is a leaf node. If it is a leaf node, it means that the node is associated with a specific device state variable. Then, the operation of retrieving the device state value is performed, that is, the latest physical state corresponding to the variable is read from the real-time memory database, such as true or false, and the state value is returned as the node value.
[0083] If the current node is not a leaf node (i.e., a non-leaf node), it indicates that the node represents a logical operation, and the operation calculated based on the operator type is executed. This step typically involves recursively retrieving the return values of the node's child nodes, performing Boolean operations on the child node's return values according to the current node's operator attribute, such as logical AND, logical OR, or logical NOT, and then returning the calculated logical result as the current node's value.
[0084] After the node value is returned, it can be determined whether the binary tree of the current rule has been fully calculated, that is, whether it has recursively returned to the root node and obtained the final result. If not, the process will continue to traverse and calculate the nodes. If the calculation is complete, the final complete result of the logical expression will be obtained, and it will be determined whether the result of the expression is true.
[0085] If the expression evaluates to false, the triggering condition is not met, and the evaluation process for this rule ends immediately. If the expression evaluates to true, the condition is met, and the triggering control instruction is executed, calling the specific control command defined on the left-hand side of the rule, such as opening the garage door. After the instruction is executed, a status update operation can be performed to feed the latest equipment status back into the system memory to maintain data consistency. The evaluation process for this rule then ends. It should be noted that through the cyclical execution of the above steps, the subway signaling system achieves automated processing of complex control logic.
[0086] Based on any of the above embodiments Figure 3 This invention provides a subway signal control device, such as... Figure 3 As shown, the device includes: Acquisition unit 310 acquires the control rule set of the subway system; the control rule set contains at least one control rule consisting of a control instruction and a logical expression. Binary tree construction unit 320 parses the logical expression and constructs an expression binary tree corresponding to the control rule; the leaf nodes of the expression binary tree are used to associate device state variables, and the non-leaf nodes are used to associate logical operators. The status update unit 330 collects the equipment operation data of the subway system in real time and updates the equipment operation data to the equipment status variables; The operation unit 340 recursively evaluates the expression binary tree based on the device state variables to obtain the complete operation result of the logical expression; The control unit 350 triggers the control command corresponding to the logical expression based on the complete calculation result of the logical expression.
[0087] The device provided in this embodiment of the invention acquires a set of control rules containing control instructions and logical expressions, and parses it into an expression binary tree; it updates the associated equipment status variables by collecting equipment operation data in real time, and recursively evaluates the binary tree to trigger control instructions. This realizes the transformation of traditional hard-coded control logic into dynamic parsing and evaluation based on expression binary trees, which can flexibly, efficiently and accurately handle complex logic nesting, and improve the response efficiency and reliability of the subway signal control system.
[0088] Based on any of the above embodiments, the arithmetic unit is specifically used for: Starting from the root node of the expression binary tree, if the current node is a leaf node, read the real-time value from the device operation data as the node value based on the device status variable associated with the leaf node. If the current node is a non-leaf node, logical operations are performed on the node return values of the child nodes under the non-leaf node according to the logical operators associated with the non-leaf node to obtain the calculation result of the current node. Based on the calculation result of the root node, the complete calculation result is obtained.
[0089] Based on any of the above embodiments, the arithmetic unit is further specifically used for: When the logical operator is logical AND, the value of the left subtree is calculated first. If the value of the left subtree is false, the calculation of the right subtree is stopped, and false is returned directly as the calculation result of the current node. When the logical operator is logical OR, the value of the left subtree is calculated first. If the value of the left subtree is true, the calculation of the right subtree is stopped, and true is returned directly as the calculation result of the current node.
[0090] Based on any of the above embodiments, the binary tree construction unit is specifically used for: Traverse the string elements in the logical expression and identify the operands and operators in the string elements; Based on the operands, the operand stack is pushed onto the stack to obtain the updated operand stack; Based on the aforementioned operators and operator precedence rules, the top element of the operator stack is compared to determine the pop operator. Based on the pop operator and the corresponding number of operands extracted from the update operand stack, a subtree node is constructed and the subtree node is backfilled into the update operand stack; Repeat the steps of traversal, updating the operand stack, element comparison, and subtree construction and backfilling until the logical expression is traversed and the expression binary tree is constructed.
[0091] Based on any of the above embodiments, the operator precedence rules include the precedence order of at least one of the following operators: parentheses, logical NOT, logical AND, and logical OR. Binary tree building units are also specifically used for: If the priority of the operator is less than or equal to the priority of the operator at the top of the stack, the operator at the top of the stack is determined as the pop operator.
[0092] Based on any of the above embodiments, the device state variable adopts a standardized three-level structure identifier, which includes device type, device identifier, and state attribute; The state update unit is specifically used for: Parse the source device information in the device operation data; Based on the three-level structure identifier, regular expression matching or string mapping is performed to locate the corresponding device object in memory and update the status attribute value of the device object. The binary tree of the expression is re-evaluated only when the device state variable contained in the logical expression changes.
[0093] Figure 4 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 4 As shown, the electronic device may include a processor 410, a communication interface 420, a memory 430, and a communication bus 440, wherein the processor 410, the communication interface 420, and the memory 430 communicate with each other through the communication bus 440. The processor 410 can call logical instructions in the memory 430 to execute a subway signal control method. This method includes: acquiring a control rule set of the subway system; the control rule set contains at least one control rule composed of a control instruction and a logical expression; parsing the logical expression to construct an expression binary tree corresponding to the control rule; the leaf nodes of the expression binary tree are used to associate with equipment state variables, and the non-leaf nodes are used to associate with logical operators; real-time acquisition of equipment operation data of the subway system and updating the equipment operation data to the equipment state variables; recursively evaluating the expression binary tree based on the equipment state variables to obtain the complete calculation result of the logical expression; and triggering the control instruction corresponding to the logical expression based on the complete calculation result of the logical expression.
[0094] Furthermore, the logical instructions in the aforementioned memory 430 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0095] On the other hand, the present invention also provides a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the metro signal control method provided by the above methods. The method includes: acquiring a control rule set of the metro system; the control rule set includes at least one control rule composed of a control instruction and a logical expression; parsing the logical expression to construct an expression binary tree corresponding to the control rule; the leaf nodes of the expression binary tree are used to associate with equipment state variables, and the non-leaf nodes are used to associate with logical operators; collecting equipment operation data of the metro system in real time and updating the equipment operation data to the equipment state variables; recursively evaluating the expression binary tree based on the equipment state variables to obtain the complete operation result of the logical expression; and triggering the control instruction corresponding to the logical expression based on the complete operation result of the logical expression.
[0096] In another aspect, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon. When executed by a processor, the computer program implements the metro signal control method provided by the above methods. The method includes: acquiring a control rule set of the metro system; the control rule set includes at least one control rule consisting of a control instruction and a logical expression; parsing the logical expression to construct an expression binary tree corresponding to the control rule; the leaf nodes of the expression binary tree are used to associate with equipment state variables, and the non-leaf nodes are used to associate with logical operators; collecting equipment operation data of the metro system in real time and updating the equipment operation data to the equipment state variables; recursively evaluating the expression binary tree based on the equipment state variables to obtain the complete operation result of the logical expression; and triggering the control instruction corresponding to the logical expression based on the complete operation result of the logical expression.
[0097] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0098] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0099] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A subway signal control method, characterized in that, include: Obtain the control rule set of the subway system; the control rule set contains at least one control rule consisting of a control instruction and a logical expression. The logical expression is parsed to construct an expression binary tree corresponding to the control rule; the leaf nodes of the expression binary tree are used to associate device state variables, and the non-leaf nodes are used to associate logical operators. The system collects equipment operation data of the subway system in real time and updates the equipment status variables with the equipment operation data. Based on the device state variables, the expression binary tree is recursively evaluated to obtain the complete operation result of the logical expression; Based on the complete calculation result of the logical expression, the control instruction corresponding to the logical expression is triggered.
2. The subway signal control method according to claim 1, characterized in that, The recursive evaluation of the expression binary tree based on the device state variables to obtain the complete computation result of the logical expression includes: Starting from the root node of the expression binary tree, if the current node is a leaf node, read the real-time value from the device operation data as the node value based on the device status variable associated with the leaf node. If the current node is a non-leaf node, logical operations are performed on the node return values of the child nodes under the non-leaf node according to the logical operators associated with the non-leaf node to obtain the calculation result of the current node. Based on the calculation result of the root node, the complete calculation result is obtained.
3. The subway signal control method according to claim 2, characterized in that, The step of performing logical operations on the return values of the child nodes under the non-leaf nodes according to the logical operators associated with the non-leaf nodes to obtain the calculation result of the current node includes: When the logical operator is logical AND, the value of the left subtree is calculated first. If the value of the left subtree is false, the calculation of the right subtree is stopped, and false is returned directly as the calculation result of the current node. When the logical operator is logical OR, the value of the left subtree is calculated first. If the value of the left subtree is true, the calculation of the right subtree is stopped, and true is returned directly as the calculation result of the current node.
4. The subway signal control method according to any one of claims 1 to 3, characterized in that, The step of parsing the logical expression to construct the binary tree of the expression corresponding to the control rule includes: Traverse the string elements in the logical expression and identify the operands and operators in the string elements; Based on the operands, the operand stack is pushed onto the stack to obtain the updated operand stack; Based on the aforementioned operators and operator precedence rules, the top element of the operator stack is compared to determine the pop operator. Based on the pop operator and the corresponding number of operands extracted from the update operand stack, a subtree node is constructed and the subtree node is backfilled into the update operand stack; Repeat the steps of traversal, updating the operand stack, element comparison, and subtree construction and backfilling until the logical expression is traversed and the expression binary tree is constructed.
5. The subway signal control method according to claim 4, characterized in that, The operator precedence rules include the precedence order of at least one of the following operators: parentheses, logical NOT, logical AND, and logical OR. The step of comparing the top element of the operator stack based on the operators and operator precedence rules to determine the pop operator includes: If the priority of the operator is less than or equal to the priority of the operator at the top of the stack, the operator at the top of the stack is determined as the pop operator.
6. The subway signal control method according to any one of claims 1 to 3, characterized in that, The device status variables adopt a standardized three-level structure identifier, which includes device type, device identifier, and status attribute; The real-time acquisition of equipment operation data of the subway system and the updating of the equipment operation data to the equipment status variables include: Parse the source device information in the device operation data; Based on the three-level structure identifier, regular expression matching or string mapping is performed to locate the corresponding device object in memory and update the status attribute value of the device object. The binary tree of the expression is re-evaluated only when the device state variable contained in the logical expression changes.
7. A subway signal control device, characterized in that, include: The acquisition unit acquires the control rule set of the subway system; the control rule set contains at least one control rule consisting of a control instruction and a logical expression. The binary tree construction unit parses the logical expression and constructs the expression binary tree corresponding to the control rule; the leaf nodes of the expression binary tree are used to associate device state variables, and the non-leaf nodes are used to associate logical operators. The status update unit collects the equipment operation data of the subway system in real time and updates the equipment operation data to the equipment status variables; The arithmetic unit recursively evaluates the expression binary tree based on the device state variables to obtain the complete computation result of the logical expression; The control unit triggers the control command corresponding to the logical expression based on the complete calculation result of the logical expression.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the subway signal control method as described in any one of claims 1 to 6.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the subway signal control method as described in any one of claims 1 to 6.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the subway signal control method as described in any one of claims 1 to 6.