Hydropower station operation state control method, device and product based on large model

By generating standard PLC code through large model optimization and dynamic binding mechanisms, the problems of incompatible knowledge representation and lack of security verification in hydropower station PLC programming are solved, realizing efficient, safe and intelligent operation and maintenance of hydropower stations.

CN121956709APending Publication Date: 2026-05-01CHINA THREE GORGES CORPORATION
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610067748.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-01-19
Publication Date
2026-05-01

AI Technical Summary

Technical Problem

Existing technologies in hydropower station PLC programming suffer from problems such as incompatible knowledge representation, poor domain adaptability, lack of safety verification, and insufficient support for dynamic constraints. These issues result in low control logic accuracy, high error rate, and high operation and maintenance costs, failing to meet the requirements for efficient, safe, and intelligent operation and maintenance.

Method used

By acquiring the PLC target instruction dataset, knowledge graph, and classification rule templates of hydropower stations, we utilize a large model for domain adaptation optimization, a dynamic binding mechanism to convert triples into natural language constraints, and combine static and dynamic verification to generate standard PLC code, ensuring that the code complies with the control logic and safety specifications of hydropower stations.

Benefits of technology

It achieves high-precision, low-error-rate PLC code generation, reduces programming barriers and maintenance costs, improves the stability and intelligent operation and maintenance level of hydropower station equipment, and adapts to complex and ever-changing operation and maintenance scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121956709A_ABST
    Figure CN121956709A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of industrial automation control, and discloses a hydropower station operation state control method, device and product based on a large model, and the method comprises the steps: carrying out the field adaptation optimization of a general large language model based on a hydropower operation and maintenance PLC target instruction data set, enabling the general large language model to accurately master the hydropower field instruction and constraint code mapping logic, and improving the operation efficiency. And the code error rate is reduced. Furthermore, in combination with a classification rule template and a dynamic binding mechanism, the knowledge graph triad is converted into natural language constraint, and the security verification short board is complemented. Furthermore, on the basis of the model and constraint conditions, the natural language requirements are quickly converted into standard PLC codes, the threshold is lowered, the period is shortened, and the maintenance cost is low. Finally, the operation of the hydropower station is controlled through the code, thereby achieving the automatic operation and maintenance of equipment, guaranteeing the stable and reliable operation, and promoting the intelligent upgrading of operation and maintenance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of industrial automation control technology, specifically to a method, device, and product for controlling the operation status of a hydropower station based on a large model. Background Technology

[0002] In the field of hydropower operation and maintenance, PLC (Programmable Logic Controller) programming typically requires specialized engineers to manually write control logic according to the IEC 61131-3 standard. This approach suffers from problems such as long development cycles, high professional barriers, susceptibility to errors, and difficulty in adapting to complex and ever-changing operation and maintenance scenarios. While existing technologies attempt to convert natural language into PLC code, they generally suffer from the following limitations, leading to lower control accuracy in hydropower stations: 1. Incompatibility of knowledge representation: There is a structural contradiction between the standard triple structure (head entity, relation, tail entity) of knowledge graph and the quadruple required by PLC trigger class and time sequence class rules. Forcing the expansion to quadruple will destroy the standardization of knowledge representation and lead to storage redundancy and decreased query efficiency, which in turn affects the accurate implementation of control logic and makes it impossible to quickly respond to the real-time control needs of hydropower station equipment operation. 2. Poor domain adaptability: The general language model lacks understanding of hydropower terminology, control logic and safety specifications, resulting in an error rate of up to 38.7% in the generated code (based on industry research data). If the erroneous code is applied to actual operation, it may cause equipment failure and operation and maintenance accidents, seriously threatening the safe and stable operation of the hydropower station. 3. Lack of security verification mechanism: Existing methods lack a security verification step for control logic before code generation, which makes it difficult to meet the high reliability requirements of hydropower facilities. The continuity and security of hydropower station equipment operation are directly related to the operation and maintenance effectiveness. Unverified code can easily lead to a sharp increase in operation and maintenance risks, increasing maintenance costs and downtime losses. 4. Insufficient support for dynamic constraints: When equipment parameters or control strategies change, the existing system has difficulty in dynamically updating the control logic, requiring model retraining, resulting in high maintenance costs. It cannot adapt to dynamic changes such as equipment aging, operating condition adjustments, and control requirement optimization in hydropower station operation and maintenance scenarios, leading to low operation and maintenance efficiency and making it difficult to achieve intelligent operation and maintenance upgrades.

[0003] As a result, the aforementioned problems overlap, which not only restricts the efficiency and accuracy of PLC code generation, but also directly affects the stability, safety, and intelligent level of hydropower station equipment operation and maintenance, failing to meet the development needs of the new era of hydropower operation and maintenance towards high efficiency, safety, and intelligence. Summary of the Invention

[0004] This invention provides a method, device, and product for controlling the operation status of hydropower stations based on a large model. This addresses the problem that existing technologies not only limit the efficiency and accuracy of PLC code generation but also directly affect the stability, safety, and intelligent level of hydropower station equipment operation, failing to meet the development needs of the new era of hydropower operation and maintenance towards high efficiency, safety, and intelligence.

[0005] In a first aspect, the present invention provides a method for controlling the operating status of a hydropower station based on a large model, for use with a PLC controller; the method includes: This process involves acquiring a dataset of target instructions for hydropower operation and maintenance PLCs, a knowledge graph, and multiple hydropower operation and maintenance classification rule templates for hydropower stations. The target instruction dataset includes the correspondence between text instructions, constraints, and structured code. Based on this dataset, a domain-specific optimization method is used to fine-tune a general language model, resulting in a comprehensive hydropower operation and maintenance PLC instruction understanding model. Using multiple classification rule templates and a dynamic binding mechanism, triples in the knowledge graph are transformed into natural language constraints that conform to hydropower control logic. When a user-input natural language instruction is received, it is processed by the comprehensive hydropower operation and maintenance PLC instruction understanding model and the natural language constraints to generate standard PLC target code. Finally, this standard PLC target code is used to control the operation status of the hydropower station, yielding the station's operational results.

[0006] The hydropower station operation status control method based on a large model provided by this invention avoids control logic deviations caused by fragmented or unprofessional data by acquiring the target instruction dataset, knowledge graph, and multiple hydropower operation and maintenance classification rule templates of the hydropower operation and maintenance PLC. It also maintains the standardization of the knowledge graph triple structure, thus avoiding storage redundancy and query efficiency degradation from the source. Furthermore, based on the hydropower operation and maintenance PLC target instruction dataset, domain adaptation optimization of the general large language model enables the model to accurately learn the mapping logic of hydropower domain instructions, constraints, and codes. This strengthens the understanding of hydropower domain terminology, control logic, and safety specifications, significantly reducing the error rate of code generated by the general model and solving the problem of poor domain adaptability. Furthermore, by utilizing classification rule templates and a dynamic binding mechanism, the knowledge graph triples are transformed into natural language constraints without forcibly expanding the triples to quadruples, perfectly resolving the structural contradiction of incompatible knowledge representations. Simultaneously, the generated constraints provide clear safety boundaries for code generation, compensating for the shortcomings of existing technologies in terms of security verification. Furthermore, by understanding large-scale models and natural language constraints through PLC instructions for hydropower operation and maintenance, professional natural language requirements are transformed into standard PLC code. This lowers the programming barrier, shortens the control logic development cycle, and reduces human error. Simultaneously, constraints dynamically adapt to changes in equipment parameters or control strategies, eliminating the need for model retraining and reducing maintenance costs. Furthermore, by utilizing standard PLC target code to control the hydropower station's operational status and obtain operational results, precise implementation of hydropower station equipment monitoring, control protection, and automated operation and maintenance is achieved. This ensures stable equipment operation according to safety standards and business requirements, improves operational stability and reliability, and adapts to complex and ever-changing operation and maintenance scenarios, driving the upgrade of operation and maintenance models towards intelligence.

[0007] In one optional implementation, the target instruction dataset of the hydropower operation and maintenance PLC for the hydropower station is obtained, including: Acquire the initial business dataset, initial equipment technical dataset, initial PLC standard programming specification document, and initial historical PLC code resources of the hydropower station; perform data cleaning on the initial business dataset, initial equipment technical dataset, initial PLC standard programming specification document, and initial historical PLC code resources to obtain the target business dataset, target equipment technical dataset, target PLC standard programming specification document, and target historical PLC code resources; classify the target business dataset using a preset instruction classification system to obtain multiple instruction data; associate the target equipment technical dataset and multiple instruction data to obtain the first instruction dataset of the hydropower operation and maintenance PLC; construct the target instruction dataset of the hydropower operation and maintenance PLC based on the target PLC standard programming specification document, target historical PLC code resources, and the first instruction dataset of the hydropower operation and maintenance PLC.

[0008] The hydropower station operation status control method based on a large model provided by this invention acquires multi-source data, covering hydropower station business scenarios, equipment characteristics, programming standards, and historical experience, avoiding the problem of incomplete instruction coverage caused by single data sources. Furthermore, data cleaning removes redundant and erroneous data, unifies formats and expressions, ensuring the accuracy and consistency of target data and reducing the impact of data impurities on dataset quality. Furthermore, by organizing instruction logic through a pre-defined classification system, instruction data becomes structured and clearly categorized, facilitating accurate association with equipment parameters and providing a classification training basis for model fine-tuning, improving the model's understanding of different types of instructions. Furthermore, by associating the target equipment technical dataset and multiple instruction datasets to form a first instruction dataset with constraints, the problem of instructions only containing operational requirements and lacking equipment adaptation logic is solved, providing equipment-dimensional constraint support for generating compliant code. Furthermore, by integrating programming specifications, historical code templates, and the first instruction dataset, a triplet of text instructions, constraints, and structured code is formed, ensuring code compliance with standards while inheriting historical operation and maintenance experience, providing direct and efficient training data for model fine-tuning and improving the model's domain adaptability.

[0009] In one optional implementation, based on the target instruction dataset of hydropower operation and maintenance PLCs, a domain-adaptive optimization of the general large language model is performed using a parameter-efficient fine-tuning method to obtain a large-scale model for understanding hydropower operation and maintenance PLC instructions, including: Acquire the hydropower operation and maintenance industrial control question-and-answer pair dataset and composite loss function; construct a fine-tuning training dataset based on the hydropower operation and maintenance PLC target instruction dataset and the hydropower operation and maintenance industrial control question-and-answer pair dataset; use low-rank adaptive technology to inject a low-rank matrix into the attention layer of the general large language model and freeze the basic parameters of the general large language model to obtain the initial large language model; based on the composite loss function, use the fine-tuning training dataset to train the low-rank matrix of the initial large language model until the model converges and the hydropower operation and maintenance PLC instruction understanding large model is obtained.

[0010] This invention provides a large-model-based hydropower station operation status control method. By acquiring a question-and-answer pair dataset of hydropower operation and maintenance industrial control, it supplements the logical knowledge of the hydropower operation and maintenance domain, solving the problem of models understanding syntax but not business logic. Simultaneously, by using a composite loss function that balances task accuracy, safety constraints, and generation consistency, it provides multi-dimensional optimization objectives for model training, avoiding the neglect of safety rules or chaotic generation logic caused by a single loss. Furthermore, by fusing the target instruction dataset and question-and-answer pairs, it enriches the scenario coverage and knowledge dimension of the training data, enabling the model to learn both the mapping between instructions and code and understand domain-specific logic, thus improving the model's deep understanding of hydropower PLC instructions. Furthermore, by utilizing low-rank adaptive technology to inject a low-rank matrix and freeze basic parameters, it can achieve domain adaptation of a general model with only a few parameter updates, significantly reducing computational costs and training cycles, while avoiding the model forgetting its general capabilities due to full training, thus balancing domain specialization and model generalization. Furthermore, by training a low-rank matrix until the model converges, the model focuses on learning the instruction understanding and code generation logic in the hydropower field, enhancing its sensitivity to safety constraints. This results in a higher accuracy rate in understanding domain terminology in the final model, and the generated code conforms to hydropower operation and maintenance logic and PLC programming standards, thus solving the problem of poor domain adaptability of general models.

[0011] In one optional implementation, multiple hydropower operation and maintenance classification rule templates are used, and a dynamic binding mechanism is employed to transform triples in the knowledge graph into natural language constraints that conform to hydropower control logic, including: The triples in the knowledge graph are parsed to obtain equipment entities, control logic relationships, and associated parameter features. Based on the entities, control logic relationships, and associated parameter features, the corresponding target hydropower operation and maintenance classification rule template is matched among multiple hydropower operation and maintenance classification rule templates. Through relationship chain queries, the control operations associated with the triples are dynamically obtained from the knowledge graph. The entities, control logic relationships, associated parameter features, and control operations are input into the target hydropower operation and maintenance classification rule template, and natural language constraints that conform to hydropower control logic are generated.

[0012] The hydropower station operation status control method based on a large model provided by this invention avoids constraint generation errors caused by ambiguous entity recognition or misunderstanding of relationships by extracting information on hydropower-specific equipment, control logic, and parameters from a knowledge graph. Furthermore, it accurately matches trigger-type, sequence-type, or mutually exclusive templates based on triplet features, ensuring that the constraint generation logic is compatible with the instruction type and avoiding the problem of constraint representations not fitting the hydropower control scenario caused by general templates. Furthermore, it derives the control actions corresponding to triples in real time through graph queries, resolving the structural contradiction between knowledge graph triples and PLC quadruples, eliminating the need for redundant storage of operation information, ensuring both the standardization of knowledge representation and the completeness of constraint conditions. Finally, it integrates entities, relationships, parameters, and operations into constraints that conform to hydropower logic, providing clear safety rules and operational boundaries for code generation from the large model, effectively suppressing model illusions and ensuring that the generated code complies with hydropower operation and maintenance safety specifications.

[0013] In one optional implementation, upon receiving a natural language instruction from the user, based on the natural language instruction, and after processing the large model and natural language constraints by the hydropower operation and maintenance PLC instruction understanding, standard PLC target code is generated, including: Upon receiving natural language commands from the user, the PLC interpreter processes the large-scale model and natural language constraints based on these commands to generate standard PLC initial code. A constrained-bind search algorithm is then used to perform static knowledge verification on the standard PLC initial code. Once the standard PLC initial code passes the static knowledge verification, a digital twin model is used to perform dynamic security verification. Finally, once the standard PLC initial code passes the dynamic security verification, it is determined to be the standard PLC target code.

[0014] The hydropower station operation status control method based on a large model provided by this invention ensures that the initial code conforms to standards by combining the model's instruction understanding capabilities with natural language constraints. Furthermore, static knowledge verification using a constrained search algorithm can eliminate static logic errors in advance during the code generation stage, reducing the risk and cost of subsequent dynamic verification and improving the initial code pass rate. Furthermore, dynamic safety verification of the standard PLC initial code using a digital twin model can accurately capture timing errors and dynamic conflicts, ensuring the safety and effectiveness of the code in actual operation and meeting the high reliability requirements of hydropower facilities. Finally, after both static and dynamic verification, the final output code possesses syntactic correctness, logical compliance, and operational adaptability, and can be directly deployed to the field PLC, significantly reducing on-site debugging risks and operation and maintenance costs.

[0015] In one alternative implementation, a constrained bundle search algorithm is used to perform static knowledge verification on the standard PLC initial code, including: The content of the standard PLC initial code is checked using a constrained bundle search algorithm. If the content check passes, the syntax of the standard PLC initial code is checked. If the syntax check passes, the standard PLC initial code is confirmed to have passed static knowledge verification.

[0016] The hydropower station operation status control method based on a large model provided by this invention verifies whether the initial code of a standard PLC violates knowledge graph constraints by checking its content. This allows for the filtering of non-compliant code at the business logic level, ensuring that the code complies with hydropower operation and maintenance safety rules and preventing equipment damage or maintenance accidents caused by logical errors. Furthermore, by checking the syntax of the initial code of the standard PLC, syntax errors are eliminated, ensuring that the code is compilable and executable, preventing PLC malfunctions or execution anomalies caused by syntax issues. Moreover, through dual content and syntax checks, the code possesses both business compliance and syntactic correctness at the static level, providing high-quality input for subsequent dynamic verification, reducing invalid simulations in the dynamic verification stage, and improving overall code generation efficiency.

[0017] In an optional implementation, the method further includes: correcting the standard PLC initial code when it fails static knowledge verification or dynamic security verification.

[0018] The hydropower station operation status control method based on a large model provided by this invention avoids the scrapping of the solution due to a one-time generation error by making targeted adjustments to the problems exposed by static verification or dynamic verification, ensuring that the final output code meets the safety and functional requirements of hydropower operation and maintenance, and improving the fault tolerance and reliability of the solution.

[0019] Secondly, the present invention provides a hydropower station operation status control device based on a large model, the device comprising: The system comprises four modules: an acquisition module, an optimization module, and a control module. The acquisition module acquires a dataset of PLC target instructions for hydropower operation and maintenance, a knowledge graph, and multiple classification rule templates for hydropower operation and maintenance. The dataset includes the correspondence between text instructions, constraints, and structured code. An optimization module optimizes the general language model based on the PLC target instruction dataset using a parameter-efficient fine-tuning method to obtain a comprehensive PLC instruction understanding model. A transformation module uses multiple classification rule templates and a dynamic binding mechanism to transform triples in the knowledge graph into natural language constraints that conform to hydropower control logic. A processing module, upon receiving natural language instructions from the user, processes them using the comprehensive PLC instruction understanding model and natural language constraints to generate standard PLC target code. A control module uses the standard PLC target code to control the operation of the hydropower station and obtain the station's operational results.

[0020] Thirdly, the present invention provides an electronic device, comprising: a memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the computer instructions to perform the above-described first aspect or any corresponding embodiment of the large-model-based hydropower station operation state control method.

[0021] Fourthly, the present invention provides a computer-readable storage medium storing computer instructions for causing a computer to execute the large-model-based hydropower station operation state control method described in the first aspect or any corresponding embodiment thereof.

[0022] Fifthly, the present invention provides a computer program product, including computer instructions, which are used to cause a computer to execute the large-model-based hydropower station operation status control method described in the first aspect or any corresponding embodiment thereof. Attached Figure Description

[0023] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0024] Figure 1 This is a flowchart illustrating the hydropower station operation status control method based on a large model according to an embodiment of the present invention. Figure 2 This is a schematic diagram of the code generation and verification process according to an embodiment of the present invention; Figure 3 This is a structural block diagram of a hydropower station operation status control device based on a large model according to an embodiment of the present invention; Figure 4 This is a schematic diagram of the hardware structure of an electronic device according to an embodiment of the present invention. Detailed Implementation

[0025] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0026] It is understood that before using the technical solutions disclosed in the various embodiments of the present invention, users should be informed of the types, scope of use, and usage scenarios of the personal information involved in the present invention and their authorization should be obtained in accordance with relevant laws and regulations through appropriate means.

[0027] The terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of this invention, "a plurality of" means two or more, unless otherwise explicitly specified.

[0028] As an optional application scenario of this invention, a PLC (Programmable Logic Controller) is a digital computing and operating electronic system specifically designed for industrial automation control. Its core function is to realize automation functions such as equipment logic control, timing control, and process control, and it is widely adaptable to the operation and maintenance needs of industrial scenarios such as hydropower stations. 1. Hardware architecture adapted to industrial environment: Adopting an industrial-grade hardware design that is anti-interference, resistant to high and low temperatures, and vibration-proof, it can operate stably in complex working conditions such as hydropower station machine rooms and outdoor control boxes, ensuring the continuous and reliable execution of control commands; 2. Unified programming standards: Supports multiple programming methods defined by the IEC 61131-3 standard, such as ladder diagrams (LD) and structured text (ST), and is fully compatible with the code format generated in this embodiment, allowing for direct deployment without additional format conversion; 3. Flexible and programmable control logic: Through the program stored in the internal memory, it can realize the switching control, parameter adjustment, interlock protection and other operations of hydropower station equipment (such as gates, water pumps and generator sets), and can accurately respond to the diverse control needs of operation and maintenance scenarios; 4. Rich interfaces and easy integration: It has multiple interfaces such as digital input / output, analog input / output, and communication interface, which can be seamlessly connected to the sensors (water level, temperature, pressure), actuators (valve, motor) and monitoring system (SCADA) of hydropower stations to realize bidirectional transmission of data acquisition and control commands; 5. Safety Redundancy Guarantee: Supports safety mechanisms such as dual-machine hot standby and fault self-diagnosis, meeting the high reliability requirements of hydropower facilities and effectively avoiding operation and maintenance accidents caused by controller failure.

[0029] According to an embodiment of the present invention, a method for controlling the operation status of a hydropower station based on a large model is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.

[0030] This embodiment provides a hydropower station operation status control method based on a large model, which can be used with the aforementioned PLC controller. Figure 1 This is a flowchart of a hydropower station operation state control method based on a large model according to an embodiment of the present invention, such as... Figure 1 As shown, the process includes the following steps: Step S101: Obtain the hydropower operation and maintenance PLC target instruction dataset, knowledge graph, and multiple hydropower operation and maintenance classification rule templates for the hydropower station.

[0031] In one optional embodiment, the hydropower operation and maintenance PLC target instruction dataset represents a high-quality structured dataset built for hydropower station operation and maintenance scenarios, which may include the correspondence between text instructions, constraints, and structured codes.

[0032] In one optional embodiment, the knowledge graph represents a graph model that stores structured knowledge in the field of hydropower operation and maintenance. It integrates core information such as equipment parameters, control logic, and safety rules in the form of triples of head entity, relation, and tail entity. It covers equipment entities such as sensors, gates, and generator sets, as well as control relations such as exceedance, delay, and mutual exclusion, providing knowledge support for the generation of constraints.

[0033] For example, firstly, relevant rules and information on hydropower operation and maintenance PLCs can be collected from multiple professional sources, which may include: 1. Industry standards and programming specifications: IEC 61131-3 standard documents, hydropower station PLC programming manual, extracted code syntax rules, function block usage specifications, etc.; 2. Equipment and Operation and Maintenance Data: Hydropower station equipment manuals, maintenance logs, collection of equipment parameters (such as sensor thresholds, equipment models), operation logic (such as start-up and shutdown procedures), and fault handling rules; 3. Historical control data: Existing PLC control rule library and equipment operation records, extracting the implemented trigger-type, timing-type, and mutual exclusion-type control logic.

[0034] Secondly, the collected unstructured / semi-structured data is transformed into a triple structure of head entity-relationship-tail entity: 1. Entity Extraction: Identify hydropower-specific entities, including equipment entities, parameter entities, and status entities. Equipment entities may include water level sensors, gates, main pumps, etc.; parameter entities may include 10m, 5 minutes, 80℃, etc.; status entities may include running, energized, etc.

[0035] 2. Relationship Extraction: Mining control logic relationships between entities, such as exceedance, delay, mutual exclusion, trigger, and after shutdown; 3. Triple combination: Combine the extracted results according to the format of head entity-relationship-tail entity to form basic triples, such as (water level sensor, exceeding, 10m) and (main pump, cooling requirement after shutdown).

[0036] Then, based on the control logic type, the triples are categorized into trigger-type, time-series-type, and mutual-exclusion-type, corresponding to causal relationships, temporal order relationships, and logical mutual exclusion relationships, respectively. Furthermore, for trigger-type and time-series triples, the derivation paths of associated operations are analyzed to reserve query links for subsequent dynamic binding.

[0037] For example, the derivation path of the associated operation is as follows: (water level sensor, more than 10m) can close the gate operation by triggering and associating with it.

[0038] Furthermore, duplicate triples are removed and logical contradictions (such as incorrect mutual exclusion relationships) are corrected to ensure the accuracy and standardization of the graph knowledge.

[0039] Finally, the optimized triplet data is stored in a graph database, and the knowledge graph is constructed. 1. Node and Edge Creation: Create nodes for each entity and edges for relationships in the database to establish the association structure between entities and relationships; 2. Query Rule Configuration: Preset basic query statements support quick retrieval of triples and related operations during subsequent dynamic binding. These basic query statements can include entity retrieval, relationship traversal, and relationship chain queries.

[0040] 3. Graph initialization verification: Verify the accuracy of entity and relationship associations through sampling queries to ensure that the graph can normally support the generation of constraints.

[0041] In one optional embodiment, multiple hydropower operation and maintenance classification rule templates represent a standardized template system designed for hydropower control scenarios. These templates can include three types of extensible templates: trigger-based, time-series, and mutual exclusion-based. Each type of template has a preset variable mapping relationship and logical expression structure, which can transform knowledge graph triples into natural language constraints that large models can understand, thus adapting to complex hydropower control scenarios.

[0042] Among them, trigger-based classes focus on the causal relationship between sensor values ​​and operational actions; timing-based classes focus on the temporal sequence or delayed execution requirements of device operations; and mutual exclusion-based classes focus on the logical dependencies or mutual exclusion conditions between device outputs. 1) Triggering rules: a) Template structure: "If the value of {head entity} is {relation} {tail entity}, then execute {association operation}".

[0043] b) Variable mapping relationship: {Head Entity}: Sensor or monitoring device entity (such as water level sensor, temperature probe); {Relation}: Logical comparison operators (such as "exceeds", "below", "equal to"); {Tail Entity}: Threshold parameters (including units, such as 10m, 50℃); {Associated Operations}: Triggered control actions (such as "close the gate" or "start the standby pump").

[0044] c) Example: Triplet: (water level sensor, exceeds, 10m, close gate) Generate constraint: "If the water level sensor value exceeds 10m, then close the gate".

[0045] d) Dynamically binding query statements: MATCH (s:Sensor {name:"Water Level Sensor"})-[r:EXCEEDS]->(t:Threshold{value:10, unit:"m"}) / / Match the "EXCEEDS" relationship between the "water level sensor" entity (labeled Sensor) and the "10m threshold" entity (labeled Threshold) in the knowledge graph; OPTIONAL MATCH (s)-[:TRIGGERS]->(a:Action) / / Optional Matching: Action entities (labeled Action) associated with the "Level Sensor" entity through the "TRIGGERS" relationship; RETURN s.name AS head, r.type AS relation, t.value+t.unit AS tail, a.name AS operation / / Return query results: / / s.name: Header entity name (i.e., "water level sensor") / / r.type: Relation type (i.e., "EXCEEDS") / / t.value+t.unit: Tail unit (i.e., "10m", concatenating the value and unit) / / a.name: The name of the associated operation (i.e., the name of the action entity, such as "close the gate").

[0046] e) Technical extension notes: Support for multi-level response mechanisms to adapt to complex control scenarios, as shown in Table 1 below.

[0047] Table 1

[0048] 2) Sequential rules: a) Template structure: "After {head entity} executes {relationship}, {tail entity} needs to be delayed before {association operation} is executed."

[0049] b) Variable mapping relationship: {Head Entity}: The device or signal that triggers the delayed operation (such as a motor or timer); {Relationship}: Triggering conditions (such as "start", "stop", "reach threshold"); {Tail Entity}: Time parameters (including units, such as 5 seconds, 10 minutes); {Associated Operations}: Actions triggered after the delay ends (such as "start cooling fan" or "close valve").

[0050] c) Example: The triplet (water pump, cooling delay after shutdown, 5 minutes) generates a constraint through dynamic binding: "After the water pump performs a shutdown operation, the cooling fan must be turned off after a delay of 5 minutes".

[0051] d) Composite time parameter processing algorithm: def resolve_timing_parameter(param): / / Define a composite time parameter processing function to convert different types of time parameters into natural language descriptions; if param.type == "FIXED_DELAY": / / Check if the parameter type is "fixed delay"; return f"delay{param.value}{param.unit}" / / Returns a natural language description in the format of "delay[numerical value][unit]" (e.g., "delay 5 minutes"); elif param.type == "CONDITIONAL_DELAY": / / Check if the parameter type is "conditional delay"; return f"until {param.condition} is met, within {param.value}{param.unit}" / / Returns a description in the format "until [condition] is met [value] [unit]" (e.g., "until the water level stabilizes within 30 seconds"). elif param.type == "PERIODIC": / / Determine if the parameter type is "periodic interval"; The return value f" is executed repeatedly every {param.period}{param.unit}. / / Returns a description in the format of “repeated every [period][unit]” (e.g., “repeated every 2 hours”).

[0052] e) Technical extension notes: The time parameter needs to support composite types to adapt to complex scenarios, as shown in Table 2 below.

[0053] Table 2

[0054] 3) Mutual exclusion rules: a) Template structure: "When {head entity} is in {state}, then {tail entity} is prohibited from being activated."

[0055] b) Variable mapping relationship: {Head Entity}: Main control device or signal (such as motor forward rotation command); {Status}: Active status (e.g., "Running" or "Powered on"); {Tail Entity}: Mutual exclusive devices or signals (such as motor reverse commands).

[0056] c) Example: The constraint generated by the ternary set (water pump, cooling delay after shutdown, 5 minutes) is "After the water pump performs a shutdown operation, the cooling fan must be turned off after a 5-minute delay". d) Mutual exclusion type differentiation mechanism: / / Define an enumeration class for mutex types, covering common mutex types in hydropower operation and maintenance scenarios. public enum ExclusionType { PHYSICAL_INTERLOCK, / / Physical interlock ELECTRICAL_CONFLICT, / / Electrical conflict LOGICAL_DEPENDENCY / / Logical dependency / / Generate natural language constraints for the corresponding mutual exclusion types / / Parameter description: head = Head entity (master device / signal), state = Head entity status, tail = Tail entity (mutually exclusive device / signal) public String generateConstraint(HeadEntity head, State state,TailEntity tail) { / / Generate constraint descriptions for the corresponding scenario based on the current mutual exclusion type. switch(this) { / / Physical interlock scenario: Generating constraints related to mechanical interlocks case PHYSICAL_INTERLOCK: return String.format("Mechanical interlock prohibits %s from operating synchronously with %s", head.getName(), tail.getName()); / / Electrical conflict scenario: Generating constraints related to power supply circuit conflicts case ELECTRICAL_CONFLICT: return String.format("Power supply circuit detected a conflict between %s and %s, automatically disconnecting secondary devices", head.getName(), tail.getName()); / / Default (Logical Dependency) Scenario: Generate constraints related to state latching default: return String.format("State latch variable prevents %s from activating %s in state %s", tail.getName(), state.getName(), head.getName()); } } }

[0057] e) Technical extension notes: Mutual exclusion types need to be distinguished between hardware interlocking and software interlocking mechanisms, as shown in Table 3 below.

[0058] Table 3

[0059] Step S102: Based on the target instruction dataset of hydropower operation and maintenance PLC, the general large language model is optimized for domain adaptation using the parameter efficient fine-tuning method to obtain the large model for understanding hydropower operation and maintenance PLC instructions.

[0060] In one optional embodiment, the parameter-efficient fine-tuning method represents a lightweight adaptation technique for large language models. It achieves domain adaptation by updating only a small number of key parameters of the model (rather than all parameters), thereby reducing computational costs, shortening the training cycle, and avoiding the model forgetting general capabilities, thus adapting to the rapid iteration needs of hydropower operation and maintenance scenarios.

[0061] In one optional embodiment, the general large language model represents a basic model with general natural language understanding and generation capabilities, which can handle various general text scenarios.

[0062] In one optional embodiment, a parameter fine-tuning method is used to allow the general large language model to absorb domain knowledge from the target instruction dataset of hydropower operation and maintenance PLC, thereby enhancing the understanding and generation capabilities of hydropower PLC instructions, and ultimately obtaining a special instruction understanding model adapted to hydropower scenarios, namely the large instruction understanding model of hydropower operation and maintenance PLC.

[0063] Step S103: Using multiple hydropower operation and maintenance classification rule templates, the triples in the knowledge graph are transformed into natural language constraints that conform to hydropower control logic through a dynamic binding mechanism.

[0064] In one optional embodiment, the dynamic binding mechanism represents a knowledge graph triple mapping technology adapted to hydropower operation and maintenance scenarios. It can deduce the associated operations corresponding to the triples from the knowledge graph in real time through a preset query path, and complete the control logic without modifying the standard triple structure. This enables the unification of knowledge representation standardization and business logic integrity.

[0065] In one optional embodiment, the hydropower control logic represents a professional logic system that conforms to the operation and maintenance needs of hydropower station equipment. It may include core rules such as equipment trigger response, timing execution, mutual exclusion avoidance, and safety protection, which comply with the operating characteristics and safety specifications of hydropower station equipment (such as gates, generator sets, and water pumps), thereby ensuring that the control actions are scientific and compliant.

[0066] In one optional embodiment, the natural language constraint represents normative text generated based on the hydropower control logic that can be directly understood by the large model. It clarifies the boundaries and requirements of code generation in natural language form and may include core constraints such as safety thresholds, operation timing, and mutual exclusion relationships. It is used to guide the model to generate PLC code that meets the needs of the hydropower scenario.

[0067] In one optional embodiment, the standardized expression framework provided by the hydropower operation and maintenance classification rule template can be used to resolve the structural contradiction between the knowledge graph triplet and the PLC control rule quadruplet through a dynamic binding mechanism, and the association operation can be completed without destroying the graph standardization.

[0068] At the same time, by combining the variable mapping relationship preset in the template, the structured knowledge such as entities, relations and parameters in the triple can be transformed into natural language descriptions that conform to the hydropower control logic, forming constraints that the model can understand, namely natural language constraints, which helps to inject domain-specific security rules and control logic into code generation.

[0069] Step S104: When a natural language instruction is received from the user, standard PLC target code is generated based on the natural language instruction, after the PLC instruction understanding of the water and electricity operation and maintenance system and the natural language constraint processing.

[0070] In one optional embodiment, natural language instructions represent the hydropower operation and maintenance control requirements input by the user in everyday language. They do not need to follow professional programming syntax and can directly reflect the operation and maintenance needs of hydropower station equipment control, status monitoring, and fault handling. They may include information such as triggering conditions, operation objects, and control objectives.

[0071] In one optional embodiment, upon receiving a natural language instruction input by the user, the system first performs in-depth analysis of the natural language instruction through the large model of PLC instruction understanding for water and electricity operation and maintenance, accurately identifying core elements such as equipment entities, control logic, and operation targets, and grasping the user's actual operation and maintenance needs.

[0072] Furthermore, using natural language constraints as safety boundaries and logical criteria, the code generation process of the model is constrained to ensure that the generated code not only meets user needs but also complies with hydropower control logic, IEC 61131-3 standards, and safety specifications. At the same time, the built-in verification mechanism can avoid logical conflicts and safety risks, and finally output standard target code, i.e., standard PLC target code, which can be directly used in hydropower station PLC controllers.

[0073] Step S105: Using standard PLC target code, control the operation status of the hydropower station to obtain the operation results of the hydropower station.

[0074] In one optional embodiment, the control instructions after code parsing are transmitted to various actuators through the hardware interface and communication protocol of the PLC controller, triggering the equipment to act according to preset logic, thereby achieving precise control of the hydropower station's operating status.

[0075] Meanwhile, the sensors and monitoring equipment of the hydropower station collect operational data in real time (such as equipment start-up and shutdown status, parameter values, environmental conditions, etc.) and feed it back to the control system to form a complete record of operational results. This can not only verify the execution effect of control commands, but also provide data support for subsequent operation and maintenance adjustments and logic optimization.

[0076] For example, standard PLC target code is imported into the PLC controller in a format supported by the PLC controller (such as structured text ST or ladder diagram LD files) to complete the compilation and loading of the code.

[0077] During deployment, it is necessary to ensure that the code is compatible with the PLC controller hardware model and interface configuration, and that the communication links with the hydropower station's SCADA monitoring system and equipment actuators are unobstructed to ensure that control commands can be transmitted normally.

[0078] Furthermore, after receiving control commands, the actuator can perform corresponding operations as required to regulate the operating status of the hydropower station. 1. If it is a trigger-based control (such as closing the gate when the water level exceeds the threshold), the gate drive device will start the mechanical structure after receiving the instruction to complete the gate closing action and regulate the reservoir water level; 2. If it is a time-series control (such as a delay after the main pump stops and the cooling pump is turned off), the cooling pump will continue to run according to the preset delay logic until the stop condition is met and then it will automatically stop to ensure the cooling effect of the equipment; 3. If it is a mutually exclusive control (such as gate lifting / lowering interlock), the control circuit prevents the execution of conflicting commands through contact interlocking logic to avoid mechanical or electrical conflicts of the equipment; 4. If it is a safety protection control (such as over-temperature load reduction), the generator set control system receives the load reduction command and adjusts the load output step by step to ensure that the equipment operates within the safe parameter range.

[0079] Furthermore, during equipment operation, various sensors (water level, temperature, pressure, current sensors, etc.) and status monitoring modules of the hydropower station collect equipment operation data and environmental parameters in real time and transmit them to the PLC controller and SCADA monitoring system.

[0080] The equipment operation data and environmental parameters may include information such as equipment start / stop status, operating parameter values, control command execution progress, and whether there are any abnormal alarms.

[0081] Furthermore, the collected real-time operational data is processed and analyzed to generate hydropower station operation results, which may include: 1. Equipment operating status results, such as whether the gates have opened and closed as instructed, whether the generator load has reached the target value, and whether the cooling system has started and stopped normally; 2. Safety and compliance results, such as whether the equipment operating parameters are within the safety threshold range defined by the knowledge graph, and whether there are no mutual exclusion conflicts or timing errors; 3. Operation and maintenance results, such as whether the preset control objectives have been achieved, whether abnormal alarms have been triggered and the reasons for the alarms, etc.

[0082] Furthermore, the operational results can be output in the form of data reports, status indicator lights, and monitoring interface displays, providing decision-making basis for operation and maintenance personnel.

[0083] The hydropower station operation status control method based on a large model provided in this embodiment avoids control logic deviations caused by fragmented or unprofessional data by acquiring the target instruction dataset, knowledge graph, and multiple hydropower operation and maintenance classification rule templates of the hydropower operation and maintenance PLC. It also maintains the standardization of the knowledge graph triple structure, thus avoiding storage redundancy and query efficiency degradation from the source. Furthermore, based on the hydropower operation and maintenance PLC target instruction dataset, domain adaptation optimization of the general large language model enables the model to accurately learn the mapping logic of hydropower domain instructions, constraints, and codes. This strengthens the understanding of hydropower professional terminology, control logic, and safety specifications, significantly reducing the error rate of code generated by the general model and solving the problem of poor domain adaptability. Furthermore, by utilizing classification rule templates and a dynamic binding mechanism, knowledge graph triples are transformed into natural language constraints without forcibly expanding triples to quadruples, perfectly resolving the structural contradiction of incompatible knowledge representations. Simultaneously, the generated constraints provide clear safety boundaries for code generation, compensating for the shortcomings of existing technologies in terms of security verification. Furthermore, by understanding large-scale models and natural language constraints through PLC instructions for hydropower operation and maintenance, professional natural language requirements are transformed into standard PLC code. This lowers the programming barrier, shortens the control logic development cycle, and reduces human error. Simultaneously, constraints dynamically adapt to changes in equipment parameters or control strategies, eliminating the need for model retraining and reducing maintenance costs. Furthermore, by utilizing standard PLC target code to control the hydropower station's operational status and obtain operational results, precise implementation of hydropower station equipment monitoring, control protection, and automated operation and maintenance is achieved. This ensures stable equipment operation according to safety standards and business requirements, improves operational stability and reliability, and adapts to complex and ever-changing operation and maintenance scenarios, driving the upgrade of operation and maintenance models towards intelligence.

[0084] In some optional implementations, obtaining the hydropower operation and maintenance PLC target instruction dataset for the hydropower station in step S101 above includes: Step a1: Obtain the initial business dataset, initial equipment technical dataset, initial PLC standard programming specification document, and initial historical PLC code resources for the hydropower station.

[0085] In one optional embodiment, the initial business dataset represents a set of raw data collected from the hydropower station business system that reflects the operation and maintenance business scenarios and operational requirements, and may include historical operation and maintenance logs, equipment operation records, fault handling work orders, etc.

[0086] In one optional embodiment, the initial equipment technical dataset represents the raw data set extracted from hydropower station equipment manuals and technical specifications, which may include equipment model parameters, control thresholds (such as sensor warning values), safe operating boundaries, start-stop logic requirements, etc.

[0087] In one optional embodiment, the initial PLC standard programming specification document refers to a collection of original documents covering industry standards and programming rules, which may include IEC 61131-3 standard documents, hydropower station-specific PLC programming manuals, etc., used to determine the syntax format of PLC code, function block usage specifications, comment requirements, etc.

[0088] In one optional embodiment, the initial historical PLC code resource represents the set of original code collected from the existing PLC code library of the hydropower station. It may include code files such as ladder diagrams (LD) and structured text (ST) that have been implemented and are in operation, and can cover mature control logic for various operation and maintenance scenarios.

[0089] Step a2 involves cleaning the initial business dataset, initial equipment technology dataset, initial PLC standard programming specification document, and initial historical PLC code resources to obtain the target business dataset, target equipment technology dataset, target PLC standard programming specification document, and target historical PLC code resources.

[0090] In one optional embodiment, the original data contains issues such as duplicate records, inconsistent formats, and logical contradictions. Direct use of this data would degrade the quality of the instruction dataset, affecting model fine-tuning and code generation accuracy. Targeted data cleaning can unify data formats, correct errors, and remove invalid data, ensuring data usability and reliability.

[0091] For example, for the initial business dataset, duplicate operation records and invalid fault work orders (such as false alarm work orders) can be removed, the device name descriptions can be standardized, and the dataset can be standardized and organized according to the format of operation time-device object-operation content-execution result to form the corresponding target business dataset.

[0092] Furthermore, for the initial equipment technical dataset, parameter entry errors can be corrected, technical data of outdated equipment (retired) can be removed, parameter units can be standardized, and the dataset can be structured according to equipment type, parameter name, parameter value, and safety boundary to form the corresponding target equipment technical dataset.

[0093] Furthermore, for the initial PLC standard programming specification document, duplicate specification clauses can be removed, conflicting rules from different documents can be integrated, and the document can be categorized and sorted according to syntax rules, function block usage, comment requirements, and safety specifications to form a standardized specification document, namely the target PLC standard programming specification document.

[0094] Furthermore, for the initial historical PLC code resources, redundant comments and invalid code segments can be removed, syntax errors can be corrected, code format can be standardized, and the code can be classified and stored according to control logic type, application device, and code content, thereby forming the target historical PLC code resources.

[0095] Step a3: Use a preset instruction classification system to classify the target business dataset to obtain multiple instruction data.

[0096] In one optional embodiment, the preset instruction classification system represents standardized instruction classification rules designed for hydropower operation and maintenance PLC control scenarios. It may include four categories: trigger type, timing type, mutual exclusion type, and safety protection type. Each category corresponds to clear control logic characteristics and application scenarios, and is used to structurally classify business instructions.

[0097] In an optional embodiment, the operational requirements in the target business data are scattered and have no clear category division. In this embodiment, the cleaned target business dataset can be classified into trigger-type, time-series-type, mutual exclusion-type, and security protection-type instruction data according to the control logic characteristics based on a preset instruction classification system, so that the instruction logic is clear and the categories are clear.

[0098] For example, classification rules can be formulated based on a preset instruction classification system: 1. Trigger type: Contains logical comparison words such as "exceeds", "below", and "equals", and triggers operations based on sensor values; 2. Time-series type: Includes time-related expressions such as delay, after, every XX time, etc., emphasizing the order or periodicity of operations, such as turning off the cooling fan 5 minutes after the water pump stops; 3. Mutually exclusive categories: These include expressions such as "prohibited" and "cannot be performed simultaneously," and involve avoiding conflicts in equipment operation. 4. Safety Protection Category: Includes safety-related descriptions such as over-temperature, overload, and emergency shutdown, used for emergency protection in case of equipment failure.

[0099] Furthermore, a combination of manual review and machine classification can be used to classify and label each operation requirement in the target business dataset, generating four types of instruction data: trigger type, time sequence type, mutual exclusion type, and security protection type, ensuring a classification accuracy of ≥98%.

[0100] Step a4: Associate the target equipment technical dataset and multiple instruction data to obtain the first instruction dataset of the hydropower operation and maintenance PLC.

[0101] In one optional embodiment, the instruction data only specifies what to do, while the equipment technical data specifies what the equipment can do and what the safety boundaries are. Therefore, by binding the equipment parameters, safety thresholds, and other constraint information in the target equipment technical dataset to the categorized instruction data one by one, each instruction can be accompanied by equipment adaptation parameters and safety constraints, thereby forming a first instruction dataset for hydropower operation and maintenance PLC containing equipment constraints. Furthermore, through association and binding, it helps ensure that the subsequently generated code not only meets operational requirements but also adapts to equipment characteristics, thereby avoiding code execution anomalies caused by parameter mismatches.

[0102] For example, a mapping relationship between instruction data and device technical data can be established using the device object as the associated keyword.

[0103] Specifically, for trigger-type instructions, the threshold parameters of the corresponding sensor are associated; for timing-type instructions, the delay allowable range of the device is associated; for mutual exclusion-type instructions, the operating parameter constraints of the mutually exclusive device are associated; and for safety protection-type instructions, the safety operating boundary of the device is associated.

[0104] Furthermore, the correlation results are integrated to form a first instruction dataset for hydropower operation and maintenance PLC, which includes instruction content, equipment parameters, and safety constraints for each instruction.

[0105] Step a5: Based on the target PLC standard programming specification document, the target historical PLC code resources, and the first instruction dataset of the hydropower operation and maintenance PLC, construct the target instruction dataset of the hydropower operation and maintenance PLC.

[0106] In one optional embodiment, the first instruction dataset provides the association between instructions and constraints, the target PLC standard programming specification ensures code standardization, and the target historical PLC code resources provide mature code templates. Therefore, by integrating the three, a triplet target dataset of text instructions, constraints, and structured code can be formed, namely the hydropower operation and maintenance PLC target instruction dataset, which not only ensures that the code conforms to programming standards, but also inherits historical operation and maintenance experience.

[0107] For example, for each instruction in the first instruction dataset, the corresponding code syntax requirements and function block selection are determined according to the target PLC standard programming specification document. For instance, trigger-type instructions use the COMPARE comparator, and timing-type instructions use the TON timer, etc.

[0108] Furthermore, mature code corresponding to similar instructions is retrieved from the target historical PLC code resources, the core code logic is extracted as a template, and combined with the constraints and programming specifications of the current instruction, structured code corresponding to each instruction is generated.

[0109] Furthermore, following the triplet format of text instruction-constraints-structured code, all data is integrated to form a target instruction dataset for hydropower operation and maintenance PLC.

[0110] Furthermore, the dataset can be sampled and validated to confirm the logical consistency, code standardization, and device compatibility of each triple, ultimately forming a high-quality target dataset that can be directly used for model fine-tuning.

[0111] In some optional implementations, step S102 above includes: Step S1021: Obtain the hydropower operation and maintenance industrial control question-and-answer pair dataset and composite loss function.

[0112] In one optional embodiment, the hydropower operation and maintenance industrial control question-and-answer dataset represents a professional question-and-answer dataset built for hydropower PLC operation and maintenance scenarios, consisting of question and answer pairs. The questions can include core requirements in areas such as hydropower equipment control logic, PLC programming specifications, and fault handling, while the answers can include explanations of professional terminology, control logic principles, and compliant operating procedures, used to supplement the model's domain knowledge reserves and enhance its understanding of hydropower professional scenarios.

[0113] In an optional embodiment, the composite loss function represents a multi-objective optimization function for the customized hydropower PLC instruction understanding scenario. By weighted fusion of task loss, safety loss, and consistency loss, it takes into account the accuracy of instruction and code conversion, compliance with safety constraints, and consistency of generation logic in the model. This can solve the problem of neglecting safety rules or generating logic confusion caused by a single loss function, ensuring that the generated code of the model is both accurate and safe, as shown in the following relationship (1): (1) In the formula: Represents the total composite loss function; , , Indicates the weighting coefficient. Used to adjust the proportion of task loss in the total loss. Optimization priorities are used to strengthen safety constraints, ensuring that the generated model code complies with hydropower operation and maintenance safety standards. Used to maintain the consistency of the logic for generating similar instructions and avoid contradictions in model output; This represents task loss and is used to measure the degree of matching between the PLC code generated by the model and the real label code (such as historical compliant code), ensuring that the code can accurately respond to the requirements of natural language instructions; This represents a safety loss and is used to penalize code generated by the model that violates the safety rules of hydropower operation and maintenance (such as triggering mutual exclusion operations or exceeding equipment safety thresholds), thereby ensuring the operational safety of the generated code. This represents consistency loss, used to measure the logical consistency of the model's generated code for similar hydropower operation and maintenance instructions, thereby improving the maintainability and stability of the code.

[0114] For example, , , .

[0115] In one alternative embodiment, the general-purpose large language model lacks expertise in the hydropower field, and training solely through instruction-code triples makes it difficult to deeply understand the principles behind the control logic. Question-answering pairs can fill this gap. Furthermore, a single loss function cannot simultaneously address the accuracy, security, and consistency of code generation. In this embodiment, a composite loss function, through multi-dimensional weighted optimization, guides the model to prioritize learning security constraints and domain logic, thereby meeting the high reliability requirements of hydropower operation and maintenance.

[0116] Step S1022: Based on the hydropower operation and maintenance PLC target instruction dataset and the hydropower operation and maintenance industrial control question and answer pair dataset, construct a fine-tuning training dataset.

[0117] In one alternative embodiment, the target instruction dataset enables the model to learn the direct mapping between input requirements and output codes, while the question-and-answer pair dataset enables the model to understand the underlying logic of why the code is generated in this way. Therefore, by integrating the hydropower operation and maintenance PLC target instruction dataset and the hydropower operation and maintenance industrial control question-and-answer pair dataset, a fine-tuning training dataset with both mapping relationship learning and knowledge understanding capabilities can be formed. This helps to prevent the model from mechanically imitating the code format while ignoring the core logic and safety constraints, and improves the model's adaptability to complex scenarios.

[0118] Step S1023: Using low-rank adaptive technology, a low-rank matrix is ​​injected into the attention layer of the general large language model, and the basic parameters of the general large language model are frozen to obtain the initial large language model.

[0119] In one alternative embodiment, Low-Rank Adaptation (LoRA) represents a technique for efficiently fine-tuning large machine learning models by introducing a low-rank matrix to approximate weight updates, thereby reducing computational resource consumption.

[0120] In one alternative embodiment, the parameters of a general-purpose large language model are enormous (typically in the billions to hundreds of billions). Full training is not only computationally expensive but may also cause the model to forget its general language comprehension capabilities. In this embodiment, a low-rank adaptive technique is used. By injecting a low-rank matrix into the attention layer of the general-purpose large language model and updating only a small number of parameters related to this matrix (accounting for 1%-5% of the total parameters), the model can quickly learn domain knowledge while freezing the basic parameters to ensure the model's original general capabilities. This achieves low-cost, high-efficiency, and highly adaptable domain optimization.

[0121] For example, a specialized terminology list for the hydropower field can be constructed, which can include core equipment terms such as hydro turbine generator sets, gates, and sensors, as well as professional operation terms such as load reduction, mutual exclusion locks, and timing delays. The terminology list can be integrated into the model's word embedding layer to improve the model's recognition accuracy of domain terms.

[0122] Furthermore, LoRA technology is used to inject low-rank matrices into all attention layers of the model, with the low-rank dimension r=8, where r=8 is the optimal value for adapting to hydropower scenarios as verified by experiments.

[0123] Furthermore, all basic parameters (weights, biases, etc.) of the general large language model are frozen, and only the trainable permissions of the low-rank matrix and word embedding layer are retained, resulting in an initial large language model that can achieve domain adaptation with only a few parameters needing to be updated.

[0124] Step S1024: Based on the composite loss function, the low-rank matrix of the initial large language model is trained using the fine-tuned training dataset until the model converges and the large model for understanding hydropower operation and maintenance PLC instructions is obtained.

[0125] In one optional embodiment, the low-rank matrix of the initial large language model is iteratively trained using a fine-tuned training dataset as input and a composite loss function as the optimization objective until the model converges, ultimately obtaining a specialized model capable of understanding instructions and generating code in the field of hydropower.

[0126] During the training process, Guide the model to learn the precise mapping of instructions and code. Penalize generated results that violate safety constraints (such as unblocked mutual exclusion operations). To ensure consistency in the generation logic of similar instructions, multi-objective collaborative optimization is used to enable the model to gradually master professional knowledge and control logic in the field of hydropower, thereby realizing the transformation from a general model to a special model.

[0127] For example, first, set the batch size to 16, the learning rate to 2e-4 (the optimal learning rate to fit LoRA parameters), and the training epochs to 10, and use the AdamW optimizer to update the parameters.

[0128] Secondly, the initial large language model is iteratively trained using the fine-tuning training dataset. Furthermore, after each training round, the composite loss function value is calculated using the validation set. If the loss value on the validation set does not decrease for three consecutive rounds, an early stopping mechanism is triggered to prevent model overfitting.

[0129] Furthermore, model performance metrics can be monitored in real time during training, including instruction comprehension accuracy, code generation syntax correctness, and safety constraint compliance, to ensure continuous optimization of these metrics.

[0130] Finally, when the model converges (i.e., the validation set loss value stabilizes), and the safety constraint compliance rate is ≥98% and the code syntax accuracy is ≥99%, training is stopped, and the trainable parameters (low-rank matrix, word embedding layer update parameters) and model structure are saved, ultimately yielding a large-scale model for understanding PLC instructions in hydropower operation and maintenance. This model may include the low-rank matrix, word embedding layer update parameters, etc.

[0131] In some optional implementations, step S103 above includes: Step S1031: Parse the triples in the knowledge graph to obtain device entities, control logic relationships, and associated parameter features.

[0132] In one optional embodiment, the triples of the knowledge graph are a structured storage form of domain knowledge. However, the original triples do not clearly distinguish the element types and cannot be directly adapted to rule templates. In this embodiment, by performing structured parsing on the head entity-relationship-tail entity triples stored in the knowledge graph, three types of core information in the hydropower operation and maintenance scenario are separated: equipment entities, control logic relationships, and associated parameter features. This clarifies the core components of the control logic and avoids subsequent constraint generation errors caused by element confusion.

[0133] For example, traverse all triples related to PLC control for hydropower operation and maintenance in the knowledge graph, and extract core elements according to preset parsing rules: 1. Equipment Entities: Identify the hydropower station equipment or monitoring objects involved in the triplet, which may include sensors, actuators, control signals, etc. 2. Control logic relationships: Extract the relationship logic between entities, which may include trigger-type relationships, sequence-type relationships, mutual exclusion-type relationships, etc. 3. Associated parameter features: Extract the quantization parameters from the triples, which may include threshold parameters, time parameters, state parameters, etc., and simultaneously extract the parameter units and constraint boundaries.

[0134] Furthermore, the analysis results are standardized and organized to form a structured combination of elements, including equipment entities, control logic relationships, and associated parameter features. This helps ensure that each triple corresponds to a set of clear and reusable core elements.

[0135] Step S1032: Based on the characteristics of entities, control logic relationships, and associated parameters, match the corresponding target hydropower operation and maintenance classification rule template among multiple hydropower operation and maintenance classification rule templates.

[0136] In one optional embodiment, different types of control logic (triggering, timing, mutual exclusion) need to correspond to different expression templates. By parsing the device entities, control logic relationships and associated parameter features, a target template that completely matches the current control logic type is selected from multiple preset hydropower operation and maintenance classification rule templates. This ensures that the expression of constraints conforms to the logical habits of hydropower control scenarios.

[0137] For example, logic with elements of exceeding or thresholding corresponds to trigger class templates, and logic with elements of delay or lag corresponds to sequence class templates. This helps to avoid the problem of constraint expressions that do not fit actual needs caused by general templates.

[0138] For example, a template matching rule base is established, and the correspondence between different element combinations and template types is determined.

[0139] Specifically, if the control logic relationship is greater than, less than, or equal to, and the associated parameter feature is a threshold parameter (including the unit), then the trigger-type rule template is matched; if the control logic relationship is after shutdown, after startup, or after delay, and the associated parameter feature is a time parameter (including the unit), then the timing-type rule template is matched; if the control logic relationship is mutually exclusive or synchronization is prohibited, and the device entities are pairs of devices / signals with logical conflicts, then the mutual exclusion-type rule template is matched.

[0140] Furthermore, the entity, control logic relationship, and associated parameter features are input into the matching rule base, and the target template, namely the target hydropower operation and maintenance classification rule template, is automatically filtered through element type comparison.

[0141] Furthermore, the matching results can be validated to ensure that the variable mapping relationship of the target template is fully adapted to the parsed elements.

[0142] Step S1033: Dynamically obtain the control operations associated with the triples in the knowledge graph through relation chain query.

[0143] In one optional embodiment, the knowledge graph triples only store devices, relationships, and parameters, without directly containing control operations, while PLC control rules need to determine the complete logic of triggering conditions and operation actions. Therefore, in this embodiment, through relationship chain queries, control operations associated with the current triple can be retrieved in real time in the knowledge graph based on the device entities and control logic relationships in the triples. This allows for the completion of the logic chain without compromising the standardization of the graph triples, achieving a balance between storage simplicity and logical completeness.

[0144] For example, a relationship chain query statement can be constructed based on the device entity and control logic relationship parsed in step S1031.

[0145] Specifically, for trigger-type triples, the query statement focuses on the device entity-trigger relationship-associated operation link; for time-series triples, the query statement focuses on the device entity-time-series relationship-associated operation link; and for mutual exclusion triples, the query statement focuses on the device entity-mutual exclusion relationship-associated prohibited operation link.

[0146] Furthermore, the query statement is executed to dynamically retrieve associated control operations from the knowledge graph, and single or multiple operations can be extracted.

[0147] Furthermore, the validity of the acquired control operations can be verified to ensure that the operations match the current control logic and to eliminate invalid or conflicting operations.

[0148] Step S1034: Input the entity, control logic relationship, associated parameter features and control operation into the target hydropower operation and maintenance classification rule template, and generate natural language constraints that conform to hydropower control logic.

[0149] In one optional embodiment, the target hydropower operation and maintenance classification rule template provides a standardized natural language expression framework. Therefore, by filling and integrating the parsed equipment entities, control logic relationships, associated parameter features and dynamically acquired control operations according to the preset format of the target template, scattered knowledge elements can be transformed into coherent and standardized constraint descriptions, thereby generating natural language constraint conditions that conform to hydropower control logic and can be directly understood by the large model.

[0150] Meanwhile, the preset logic of the target hydropower operation and maintenance classification rule template ensures that the constraints conform to the expression habits of hydropower operation and maintenance scenarios, enabling the large model to accurately identify the constraint boundaries and avoid code generation deviations caused by ambiguous expressions.

[0151] In some optional implementations, step S104 above includes: Step S1041: When a natural language instruction is received from the user, based on the natural language instruction, the large model is understood by the water and electricity operation and maintenance PLC instruction and the natural language constraint conditions are processed to generate standard PLC initial code.

[0152] In one optional embodiment, upon receiving a natural language instruction input by the user, the system first utilizes the domain semantic parsing capability of the large model to understand the hydropower operation and maintenance PLC instructions. This allows for in-depth analysis of core elements such as equipment entities and control targets within the natural language instructions. Then, guided by safety rules based on natural language constraints, the non-standard requirements are transformed into PLC initial code conforming to the IEC61131-3 standard. This ensures that the initial code not only meets user needs but also complies with hydropower control logic and programming standards, avoiding invalid or non-compliant code generated without constraints.

[0153] For example, upon receiving a natural language instruction from the user, the natural language constraints are invoked and injected into a preset Prompt template along with the natural language instruction.

[0154] Furthermore, the large-scale model for understanding PLC instructions in hydropower operation and maintenance is initiated. This model can then generate initial code in structured text (ST) or ladder diagram (LD) conforming to the IEC 61131-3 standard, based on the role definitions, scenario descriptions, and constraints in the Prompt. This code further includes complete control logic, variable definitions, and basic comments.

[0155] Furthermore, the initial code can be formatted to ensure that the code file can be recognized by the PLC controller, has no obvious formatting errors, and outputs standard PLC initial code.

[0156] Step S1042: Static knowledge verification is performed on the initial code of the standard PLC using the constrained bundle search algorithm.

[0157] Specifically, step S1042 includes: Step b1: Use the constrained bundle search algorithm to check the contents of the standard PLC initial code.

[0158] Step b2: Once the content check passes, the syntax of the standard PLC initial code is checked.

[0159] Step b3: Once the syntax check passes, it is confirmed that the standard PLC initial code has passed the static knowledge verification.

[0160] In one optional embodiment, the Constrained Beam Search algorithm represents a large model decoding optimization algorithm that integrates knowledge constraints. Based on the traditional beam search that retains the top-k candidate sequences, it adds a knowledge graph constraint verification mechanism. By performing real-time logical compliance judgment on the generated code candidate sequences, it filters out invalid sequences that violate water and electricity control rules (such as mutual exclusion relationships and safety thresholds), thereby ensuring the static logical correctness of the generated code and solving the logical conflict problem caused by the illusion of large models.

[0161] In one optional embodiment, the standard PLC initial code is double-checked using a constrained search algorithm, namely, content checking and syntax checking, and static logic conflicts and syntax errors in the code are filtered out, thereby ensuring that the code has both logical compliance and syntax correctness at the static level.

[0162] For example, start the restricted beam search algorithm, set the beam width to 5, and then the algorithm automatically parses the core elements of entity association and control logic in the standard PLC initial code.

[0163] Furthermore, the real-time knowledge graph validator is invoked to match and verify the elements in the code against the rules in the knowledge graph: 1. Check mutual exclusion logic: For example, does the code contain logic that simultaneously activates gate raising and gate lowering commands? If so, trigger a conflict alarm. 2. Check safety thresholds: such as whether the temperature trigger threshold in the code exceeds the device safety boundary defined by the knowledge graph; 3. Check the operation logic: such as whether the triggering instruction contains a complete condition-action chain to avoid logical breaks.

[0164] Furthermore, if the code has no logical conflicts, it passes the content check; if conflicts exist, the algorithm automatically filters out the non-compliant logical segments, retains the compliant parts, marks the conflict points, and returns correction suggestions.

[0165] Furthermore, for the initial code that passes the content check, a syntax checker is activated to perform item-by-item verification according to the IEC 61131-3 standard and the hydropower station PLC programming specifications: 1. Variable validation: Check whether the variable naming conforms to the rules, whether there are any undefined variables, and whether the variable types match, such as mixing digital and analog quantities; 2. Function block validation: Check whether the parameter configuration of the standard function block is correct and whether the calling format is standardized; 3. Syntax structure verification: Check whether the code statements are complete, whether the logical operators are used correctly, and whether the comment format is consistent.

[0166] Furthermore, a syntax check report is generated. If a syntax error is found, the error location is automatically located and the direction of correction is suggested; if no error is found, the syntax check is passed.

[0167] Furthermore, considering both the content check results and the syntax check results, if there are no uncorrected errors in either, and all conflict points have been rectified, then the standard PLC initial code is deemed to have passed the static knowledge verification.

[0168] Furthermore, if there are unrectified errors or major logical conflicts (such as mutually exclusive logical errors that cannot be avoided by simple correction), return to step S1041 and regenerate the initial code based on the verification feedback.

[0169] Step S1043: After the standard PLC initial code passes the static knowledge verification, the standard PLC initial code is dynamically verified for security using a digital twin model.

[0170] In one alternative embodiment, the digital twin model represents a high-fidelity dynamic simulation model built for key equipment of a hydropower station (such as turbines, gates, and generator sets).

[0171] Furthermore, by mapping the physical characteristics, operating parameters, and environmental interaction logic of real equipment, the response behavior of the equipment under real working conditions can be simulated. In addition, this digital twin model supports dynamic operation simulation of PLC code, which can accurately capture problems that cannot be detected by static verification, such as timing errors and load conflicts, and helps to provide a virtual test environment for code security verification.

[0172] In one alternative embodiment, static verification can only verify the correctness of the code's written logic and cannot simulate the physical interactions and timing dependencies during device operation (such as insufficient cooling due to improper delay parameters). In contrast, a digital twin model, by recreating the dynamic characteristics of a real device, can transform code into the operating instructions of a virtual device, monitor device operating parameters (such as temperature, speed, and load) in real time, and thus accurately identify dynamic risks such as timing errors and parameter mismatches, ensuring the code runs safely in real-world scenarios.

[0173] For example, the initial PLC code that has passed static verification is compiled into simulation instructions that the digital twin model can recognize, loaded into the hydropower station's digital twin system, and the corresponding simulation scenario is selected. Then, simulation parameters are configured, and real operating conditions are simulated.

[0174] Furthermore, the simulation is initiated, and the digital twin model drives the virtual device to perform operations according to the code logic, while collecting device operation data in real time. Next, the simulation data is analyzed, and key indicators are verified, which may include timing accuracy, security stability, and response effectiveness.

[0175] Furthermore, if there are no abnormal alarms during the simulation process and the core indicators meet the requirements, the dynamic security verification is passed; if there are timing conflicts, excessive load, or other issues, return to step S1041 for code optimization.

[0176] Step S1044: When the standard PLC initial code passes the dynamic security verification, the standard PLC initial code is determined to be the standard PLC target code.

[0177] In one optional embodiment, based on the dual qualified results of static knowledge verification and dynamic security verification, it can be determined that the code has avoided static logic conflicts, syntax errors and dynamic operation risks, meets the safety requirements of hydropower operation and maintenance and the execution standards of PLC controllers, and has the conditions to be directly deployed to field equipment. That is, the standard PLC initial code is formally determined as the standard PLC target code that can be directly deployed, ensuring that the code has both logical correctness, syntactic standardization and operational security.

[0178] In some optional implementations, step S104 above further includes: Step c1: If the standard PLC initial code fails the static knowledge verification or the dynamic security verification, the standard PLC initial code is corrected.

[0179] In an optional embodiment, when the standard PLC initial code fails static knowledge verification (logical conflicts, syntax errors) or dynamic safety verification (timing errors, operational risks), the initial code can be specifically modified based on the problem type and specific reasons of the verification / verification feedback, thereby ensuring that the code complies with the requirements of water and electricity control logic, programming standards and safe operation.

[0180] In one example, a hydropower operation and maintenance PLC code generation system based on knowledge graph dynamic binding and natural language understanding is provided, including: 1. Hydropower Operation and Maintenance PLC Instruction Knowledge Base Construction Module: Constructs a set of control and protection instructions for equipment such as hydro-generator units, transformers, and gates; 2. Domain-Adaptive Large Language Model Fine-Tuning Module: Improves the general large model's ability to understand and generate hydropower PLC instructions through efficient parameter fine-tuning; 3. Knowledge Graph Dynamic Binding Module: Enables dynamic mapping from triples to natural language constraints, resolving structural contradictions; 4. PLC Code Generation and Verification Module: Converts natural language into PLC code that conforms to the IEC 61131-3 standard, and ensures security through multi-layer verification.

[0181] Furthermore, the method for generating PLC code for hydropower operation and maintenance based on knowledge graph dynamic binding and natural language understanding includes: 1. Construct a dedicated instruction dataset for hydropower operation and maintenance PLCs.

[0182] Construct high-quality text instruction-structured code pairs, collect historical operation and maintenance logs and equipment operation records of power plants from business systems, extract control parameters and safety thresholds of hydropower special equipment from equipment manuals, extract programming specifications from IEC 61131-3 standard documents and PLC programming manuals, and collect and clean ladder diagrams and structured text pairs from existing PLC code libraries; The instruction classification system is as follows: class PLCDirectiveType(Enum): TRIGGER = 1# Trigger Class: Close the gate when the water level exceeds the threshold. TIMING = 2# Timing-based: After the water pump stops, the cooling system will shut down 5 minutes later. MUTUAL_EXCLUSIVE = 3# Mutual exclusion class: Unit B is prohibited from starting while Unit A is running. SAFETY_PROTECTION = 4 # Protection class: Automatic load reduction when temperature > 80°C.

[0183] 2. Construct a large-scale model for understanding PLC instructions in hydropower operation and maintenance using efficient parameter fine-tuning methods.

[0184] A specialized glossary of terms for the hydropower field was constructed. Using LoRA (Low-Rank Adaptation) technology, a low-rank matrix was injected into the key attention layer. A domain-specific loss function was designed as shown in equation (1) above, enhancing sensitivity to safety constraints. Furthermore, the data format includes (instruction, constraint, code) triples. The basic large model is fine-tuned by using question-and-answer pairs related to hydropower operation and maintenance industrial control, enhancing the accuracy of the general-purpose large language model's understanding of specialized PLC instructions.

[0185] 3. A method for dynamic binding of knowledge graph constraints and natural language generation for PLC control systems in hydropower operation and maintenance.

[0186] This example proposes a dynamic binding method that uses template-based structured definitions and a dynamic binding mechanism to map triples to natural language constraints.

[0187] (1) Structured definition of PLC template for hydropower operation and maintenance.

[0188] PLC operation rules were extracted from IEC 61131-3 standard documents, PLC programming manuals, and equipment maintenance logs. The PLC operation rules (such as equipment parameters and control logic) in the field of hydropower operation and maintenance were constructed into triples (head entity, relation, tail entity) of a knowledge graph KG. Based on the daily work of hydropower operation and maintenance, the rules were specifically divided into three categories: trigger type, timing type, and mutual exclusion type.

[0189] Trigger-based algorithms focus on the causal relationship between sensor values ​​and operational actions; timing-based algorithms focus on the temporal sequence of device operations or delayed execution requirements; and mutual exclusion-based algorithms focus on the logical dependencies or mutual exclusion conditions between device outputs. Refer to the relevant descriptions in step S101 above for details.

[0190] (2) Dynamic binding implementation mechanism.

[0191] Template matching is used to transform triples into LLM-understandable natural language constraints, realizing the mapping from triples to natural language templates. For trigger-type and time-series rules with a quadruple structure, since the triple representation of knowledge graphs usually adopts a standard triple structure, this patent proposes a dynamic binding method. This method obtains the {association operation} in real time from the subgraph query of the knowledge graph, and then uses "If {head entity}{relation}{tail entity}, then execute {association operation}" as a template to dynamically populate the {association operation} at the application layer, achieving dynamic operation binding.

[0192] The specific steps are as follows: Step 1: Parse the user's natural language commands and extract entities and relations. Step 2: Perform a subgraph query in the knowledge graph to obtain the basic triples. Step 3: Dynamically retrieve related operations through relationship chain queries Step 4: Combine the triples with the association operation to generate natural language constraints. Step 5: Inject constraints into the Prompt template to guide LLM in generating code. Furthermore, the key algorithm: def dynamic_binding(natural_language_input): # Step 1: Parse the input entities, relations = extract_entities_and_relations(natural_language_input) # Step 2: Obtain the basic triples base_triples = kg_query(entities, relations) # Step 3: Dynamically obtain operations through relationship chains associated_operations = [] for triple in base_triples: operations = kg_query_related_operations(triple) # Relationship chain query associated_operations.extend(operations) # Step 4: Generate constraints constraints = [] for triple, operation in zip(base_triples, associated_operations): template = select_template_by_type(triple.type) constraint = template.format( head = triple.head, relation = triple.relation, tail = triple.tail, operation=operation ) constraints.append(constraint) # Step 5: Build the complete Prompt prompt = build_prompt_with_constraints(natural_language_input,constraints) return prompt.

[0193] (3) Construct a Prompt template library for knowledge graph constraints.

[0194] The control requirements are transformed into structured prompts, using a multi-layered structure: roles, scenarios, tasks, instructions, and constraints, ensuring that the generated code conforms to the constraints. [Role Definition] You are a PLC control engineer with 20 years of experience in hydropower stations, proficient in the IEC 61131-3 standard and familiar with the characteristics of hydropower station equipment.

[0195] [Scene Description] {Scenario description, such as: Upgrading the temperature protection system of a hydro-generator set} [Task Requirements] Generate structured text (ST) or ladder diagram (LD) code conforming to the IEC 61131-3 standard to implement the specified control logic.

[0196] [Operation Instructions] {Natural language instructions entered by the user, such as: when the stator temperature exceeds 120℃, alarm and reduce load by 30%}.

[0197] [Dynamic Constraints] {Security constraints dynamically retrieved from the knowledge graph, such as:} 1. If the stator temperature exceeds 100℃, a log entry must be made and the frequency of inspections increased. 2. If the stator temperature exceeds 120℃, the load must be reduced before starting the cooling system. 3. The unloading operation must be performed in 5 steps, with an interval of no less than 10 seconds between each step.

[0198] [Output Specifications] 1. Strictly adhere to IEC 61131-3 syntax. 2. Includes complete comments explaining the function of each line of code. 3. Use standard function blocks (such as TON timer, COMPARE comparator). 4. Prioritize safety interlocking logic.

[0199] (4) Code generation and verification, such as Figure 2 As shown.

[0200] Code generator: During the natural language → PLC code conversion process, the following steps are executed sequentially: Semantic parsing (identifying device objects and operation types in instructions) → Logical compliance check (verifying whether parameters are within the allowed range defined by the knowledge graph) → Security simulation (pre-simulating the execution effect of instructions through digital twins).

[0201] Content Inspector (Beg-Restricted Search): During LLM decoding, candidate sequences from the beam search are compared with a real-time knowledge verifier. This verifier quickly matches the entities and relationships parsed from the code against the Knowledge Base (KG). For example, if generated code attempts to simultaneously set both "motor forward" and "motor reverse" coils, and the KG contains a mutually exclusive relationship (motor forward, isMutexWith, motor reverse), the verifier will set the score of this candidate sequence to negative infinity, thus filtering it out. A beam width of 5 is recommended.

[0202] Digital twin safety simulation: A high-fidelity dynamic model of key equipment (such as turbines and gates) is established. The generated PLC code is compiled and loaded into the simulation PLC for co-simulation with the digital twin model. The simulation step size is set to 1ms to accurately capture timing errors and logic conflicts.

[0203] Furthermore, the constrained search algorithm employs a tree-based search combined with constraint rule filtering during the large language model decoding stage. function constrained_decoding(input, constraints): beam = [(start_token, 0.0)]# (token_sequence, score) while not all_end(beam): new_beam = [] For seq, score in beam: next_tokens = model.predict_next_tokens(seq) for token in next_tokens: new_seq = seq + [token] # Applying Knowledge Graph Constraints if validate_against_constraints(new_seq, constraints): new_score = score + log_prob(token|seq) new_beam.append((new_seq, new_score)) # Retain top-k candidates beam = select_top_k(new_beam, k=beam_width) return best_sequence(beam).

[0204] This example provides a hydropower operation and maintenance PLC code generation system and method based on knowledge graph dynamic binding and natural language understanding, which has the following effects: 1. Addressing the structural contradiction between standard triples in knowledge graphs and quadruples in PLC control rules, this example does not employ a data redundancy storage scheme that disrupts the graph's standardization. Instead, it innovatively proposes a dynamic binding method that derives association operations in real-time from pre-registered graph query paths. This mechanism achieves a balance between data storage simplicity and the completeness of business logic expression.

[0205] 2. This example goes beyond simply using LLM to generate code, constructing an intelligent system with a knowledge graph as its control core. KG, through dynamically generated constraints and mandatory verification during the decoding phase, deeply embeds itself into the reasoning and generation chain of LLM, forming a closed loop of "knowledge-guided generation." This fundamentally improves the domain accuracy, security, and reliability of the generated code, effectively suppressing the "illusion" problem of LLM.

[0206] 3. This example systematically summarizes the control logic of hydropower operation and maintenance, and designs three major categories of extensible natural language and graph query templates: trigger-based, sequence-based, and mutual exclusion-based. These templates support complex industrial scenarios such as multi-level response, compound delay, and multiple mutual exclusions, providing LLM with a structured and understandable domain knowledge representation method, significantly improving the efficiency and accuracy of human-computer interaction.

[0207] 4. This example integrates semantic parsing, static knowledge verification, and dynamic digital twin simulation into a coherent automated process. This combined static and dynamic verification system ensures that the generated PLC code is not only syntactically and logically correct, but also runs safely and effectively in the simulated real physical environment, greatly reducing the risks and costs of on-site debugging and improving the level of intelligence in hydropower operation and maintenance.

[0208] Furthermore, based on the above examples, the hydropower operation and maintenance PLC code generation system and method based on knowledge graph dynamic binding and natural language understanding are provided in the following embodiments.

[0209] Example 1: Multi-level early warning control of trigger-based rules.

[0210] Scenario: Intelligent monitoring of reservoir water levels.

[0211] Enter the command: "Automatically control the floodgates based on the water level."

[0212] KG Query and Dynamic Binding: The system identifies the "water level" entity. It executes predefined multi-level queries: 1) Query (water level sensor, exceeds, 107.0m), associated operation is (send, warning information); 2) Query (water level sensor, exceeds, 108.5m), associated operations are (open, floodgate A) and (start, alarm).

[0213] Constraint generation: Two constraints are dynamically generated: "If the water level sensor reading exceeds 107.0 meters, send an early warning message"; "If the water level sensor reading exceeds 108.5 meters, open the floodgate A and activate the alarm".

[0214] LLM Generation and Verification: The LLM generation process generates a ladder diagram containing two Compare Instructions (CMPs). A content detector ensures that the code includes independent output points for both warning and alarm signals. Digital twin simulation verifies that only the warning is triggered at a water level of 107.5 meters, and the gate is correctly opened and the alarm sounds correctly at 109 meters.

[0215] Example 2: Conditional delay control for time-series rules.

[0216] Scenario: Cooling process after a water turbine is shut down.

[0217] Enter the command: "After the main pump stops, the cooling water pump will continue to run until the bearing temperature is below 50°C."

[0218] KG Query and Dynamic Binding: Identify the "Main Pump" entity. Query the timing rules (Main Pump, after shutdown, requires cooling), and further obtain the conditions for the associated operation (Stop, Cooling Water Pump) through the relationship chain (Bearing temperature, below, 50℃).

[0219] Constraint generated: "After the main pump performs a shutdown operation, the cooling water pump must not be stopped until the bearing temperature is below 50°C."

[0220] LLM Generation and Verification: The LLM generation uses a normally closed contact (representing main pump stop) and a comparison command (monitoring bearing temperature <50℃) connected in series to control the cooling water pump coil. Simulation verified that the cooling water pump continued to run after the main pump stopped, and automatically stopped after the bearing temperature dropped to 49℃.

[0221] Example 3: Software interlock control of mutual exclusion rules.

[0222] Scenario: To prevent conflicts between gate lifting and lowering commands.

[0223] Input command: "Control the gate by pressing buttons to raise and lower it."

[0224] KG Query and Dynamic Binding: Identify "gate lifting command" and "gate lowering command". Query mutual exclusion rules (gate lifting command, isMutexWith, gate lowering command) with type "logical mutual exclusion".

[0225] Constraints are generated as follows: "When the gate lifting command is active, the gate lowering command is prohibited from being activated," and vice versa.

[0226] LLM Generation and Verification: The LLM generates a standard electrical interlock ladder diagram, connecting the normally closed contact of the lifting button in series with the control circuit of the lowering button, and vice versa. A content detector verifies the existence of the interlock logic. In the simulation, pressing both buttons simultaneously results in no gate movement, effectively preventing mechanical conflict.

[0227] This embodiment also provides a hydropower station operation status control device based on a large model. This device is used to implement the above embodiments and preferred embodiments, and details already described will not be repeated. As used below, the term "module" can refer to a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.

[0228] This embodiment provides a hydropower station operation status control device based on a large model, such as... Figure 3 As shown, the device includes: The acquisition module 301 is used to acquire the hydropower operation and maintenance PLC target instruction dataset, knowledge graph and multiple hydropower operation and maintenance classification rule templates of the hydropower station. The hydropower operation and maintenance PLC target instruction dataset includes the correspondence between text instructions, constraints and structured codes.

[0229] The optimization module 302 is used to perform domain adaptation optimization on a general large language model based on the target instruction dataset of hydropower operation and maintenance PLC, using an efficient parameter fine-tuning method, to obtain a large model for understanding hydropower operation and maintenance PLC instructions.

[0230] The transformation module 303 is used to transform triples in the knowledge graph into natural language constraints that conform to the hydropower control logic by using multiple hydropower operation and maintenance classification rule templates and through a dynamic binding mechanism.

[0231] The processing module 304 is used to generate standard PLC target code based on the natural language instructions received from the user, the large model of water and electricity operation and maintenance PLC instructions, and the natural language constraints.

[0232] The control module 305 is used to control the operating status of the hydropower station using standard PLC target code and obtain the operating results of the hydropower station.

[0233] The hydropower station operation status control device based on a large model provided in this invention can execute the hydropower station operation status control method based on a large model provided in any embodiment of this invention, and has the corresponding functional modules and beneficial effects of the method. Further functional descriptions of the above modules are the same as in the corresponding embodiments described above, and will not be repeated here.

[0234] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention.

[0235] The following is a detailed reference. Figure 4 This diagram illustrates a structural schematic suitable for implementing an electronic device according to embodiments of the present invention. The electronic device may include a processor (e.g., a central processing unit, graphics processor, etc.) 401, which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 402 or a program loaded from memory 408 into random access memory (RAM) 403. The RAM 403 also stores various programs and data required for the operation of the electronic device. The processor 401, ROM 402, and RAM 403 are interconnected via a bus 404. An input / output (I / O) interface 405 is also connected to the bus 404.

[0236] Typically, the following devices can be connected to I / O interface 405: input devices 406 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 407 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; memory devices 408 including, for example, magnetic tapes, hard disks, etc.; and communication devices 409. Communication device 409 allows electronic devices to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 4Electronic devices with various devices are shown, but it should be understood that it is not required to implement or have all of the devices shown, and more or fewer devices may be implemented or have instead.

[0237] In particular, according to embodiments of the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of the present invention include a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device 409, or installed from a memory 408, or installed from a ROM 402. When the computer program is executed by the processor 401, it performs the functions defined in the large-model-based hydropower station operation state control method of the embodiments of the present invention.

[0238] Figure 4 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments of the present invention.

[0239] This invention also provides a computer-readable storage medium. The methods described above according to embodiments of the invention can be implemented in hardware or firmware, or implemented as computer code that can be recorded on a storage medium, or implemented as computer code downloaded via a network and originally stored on a remote storage medium or a non-transitory machine-readable storage medium and then stored on a local storage medium. Thus, the methods described herein can be processed by software stored on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. The storage medium can be a magnetic disk, optical disk, read-only memory, random access memory, flash memory, hard disk, or solid-state drive, etc.; further, the storage medium can also include combinations of the above types of memory. It is understood that computers, processors, microprocessor controllers, or programmable hardware include storage components capable of storing or receiving software or computer code. When the software or computer code is accessed and executed by the computer, processor, or hardware, the large-model-based hydropower station operation state control method shown in the above embodiments is implemented.

[0240] A portion of this invention can be applied as a computer program product, such as computer program instructions, which, when executed by a computer, can invoke or provide the methods and / or technical solutions according to the invention through the operation of the computer. Those skilled in the art will understand that the forms in which computer program instructions exist in a computer-readable medium include, but are not limited to, source files, executable files, installation package files, etc. Correspondingly, the ways in which computer program instructions are executed by a computer include, but are not limited to: the computer directly executing the instructions, or the computer compiling the instructions and then executing the corresponding compiled program, or the computer reading and executing the instructions, or the computer reading and installing the instructions and then executing the corresponding installed program. Here, the computer-readable medium can be any available computer-readable storage medium or communication medium accessible to a computer.

[0241] Although embodiments of the invention have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the invention, and such modifications and variations all fall within the scope defined by the appended claims.

Claims

1. A method for controlling the operating state of a hydropower station based on a large model, characterized in that, For use with a PLC controller; the method includes: Obtain the hydropower operation and maintenance PLC target instruction dataset, knowledge graph, and multiple hydropower operation and maintenance classification rule templates for hydropower stations. The hydropower operation and maintenance PLC target instruction dataset includes the correspondence between text instructions, constraints, and structured codes. Based on the target instruction dataset of hydropower operation and maintenance PLC, the general large language model is optimized for domain adaptation using the parameter efficient fine-tuning method to obtain a large model for understanding hydropower operation and maintenance PLC instructions. Using the multiple hydropower operation and maintenance classification rule templates, the triples in the knowledge graph are transformed into natural language constraints that conform to hydropower control logic through a dynamic binding mechanism; When a natural language instruction is received from the user, based on the natural language instruction, the large model of hydropower operation and maintenance PLC instruction understanding and the natural language constraint conditions are processed to generate standard PLC target code. The standard PLC target code is used to control the operation status of the hydropower station and obtain the operation results of the hydropower station.

2. The method according to claim 1, characterized in that, Obtain the target instruction dataset of the hydropower operation and maintenance PLC for the hydropower station, including: Obtain the initial business dataset, initial equipment technical dataset, initial PLC standard programming specification document, and initial historical PLC code resources of the hydropower station; Data cleaning is performed on the initial business dataset, the initial equipment technology dataset, the initial PLC standard programming specification document, and the initial historical PLC code resources respectively to obtain the target business dataset, the target equipment technology dataset, the target PLC standard programming specification document, and the target historical PLC code resources. The target business dataset is classified using a preset instruction classification system to obtain multiple instruction data. The target equipment technical dataset and the multiple instruction data are associated to obtain the first instruction dataset of the hydropower operation and maintenance PLC; Based on the target PLC standard programming specification document, the target historical PLC code resources, and the first instruction dataset of the hydropower operation and maintenance PLC, construct the target instruction dataset of the hydropower operation and maintenance PLC.

3. The method according to claim 1, characterized in that, Based on the aforementioned target instruction dataset of hydropower operation and maintenance PLCs, a domain-specific optimization method is used to adapt the general large language model to the parameter, resulting in a large model for understanding hydropower operation and maintenance PLC instructions, including: Obtain the question-and-answer pair dataset and composite loss function for hydropower operation and maintenance industrial control; Based on the hydropower operation and maintenance PLC target instruction dataset and the hydropower operation and maintenance industrial control question and answer pair dataset, a fine-tuning training dataset is constructed. Using low-rank adaptive techniques, a low-rank matrix is ​​injected into the attention layer of the general large language model, and the basic parameters of the general large language model are frozen to obtain an initial large language model. Based on the composite loss function, the low-rank matrix of the initial large language model is trained using the fine-tuned training dataset until the model converges and the large model for understanding hydropower operation and maintenance PLC instructions is obtained.

4. The method according to claim 1, characterized in that, Using the aforementioned multiple hydropower operation and maintenance classification rule templates, and through a dynamic binding mechanism, the triples in the knowledge graph are transformed into natural language constraints that conform to hydropower control logic, including: The triples in the knowledge graph are parsed to obtain device entities, control logic relationships, and associated parameter features; Based on the entity, the control logic relationship, and the associated parameter features, match the corresponding target hydropower operation and maintenance classification rule template among the multiple hydropower operation and maintenance classification rule templates; By querying the relationship chain, the control operations associated with the triple are dynamically obtained in the knowledge graph; The entity, the control logic relationship, the associated parameter features, and the control operation are input into the target hydropower operation and maintenance classification rule template, and the natural language constraints that conform to the hydropower control logic are generated.

5. The method according to claim 1, characterized in that, Upon receiving a natural language instruction from the user, based on the natural language instruction, and after processing the large-scale model of the hydropower operation and maintenance PLC instruction understanding and the natural language constraints, standard PLC target code is generated, including: When a natural language instruction is received from the user, based on the natural language instruction, the PLC instruction for hydropower operation and maintenance understands the large model and processes the natural language constraints to generate standard PLC initial code. Static knowledge verification was performed on the initial code of the standard PLC using a constrained bundle search algorithm. Once the standard PLC initial code passes static knowledge verification, a digital twin model is used to perform dynamic security verification on the standard PLC initial code. When the standard PLC initial code passes the dynamic security verification, the standard PLC initial code is determined to be the standard PLC target code.

6. The method according to claim 5, characterized in that, Static knowledge verification of the standard PLC initial code is performed using a constrained bundle search algorithm, including: The content of the standard PLC initial code is checked using the constrained bundle search algorithm. Once the content check passes, the syntax of the standard PLC initial code is checked. Once the syntax check passes, it is determined that the standard PLC initial code has passed the static knowledge verification.

7. The method according to claim 5, characterized in that, The method further includes: If the standard PLC initial code fails the static knowledge verification or the dynamic security verification, the standard PLC initial code shall be corrected.

8. A hydropower station operation status control device based on a large model, characterized in that, For a PLC controller; the device includes: The acquisition module is used to acquire the hydropower operation and maintenance PLC target instruction dataset, knowledge graph and multiple hydropower operation and maintenance classification rule templates of the hydropower station. The hydropower operation and maintenance PLC target instruction dataset includes the correspondence between text instructions, constraints and structured code. The optimization module is used to optimize the general large language model based on the target instruction dataset of the hydropower operation and maintenance PLC using an efficient parameter fine-tuning method, so as to obtain a large model for understanding hydropower operation and maintenance PLC instructions. The conversion module is used to convert the triples in the knowledge graph into natural language constraints that conform to the hydropower control logic by using the multiple hydropower operation and maintenance classification rule templates and through a dynamic binding mechanism. The processing module is used to generate standard PLC target code based on the natural language instructions received from the user, the large model of hydropower operation and maintenance PLC instructions, and the natural language constraints, after processing the natural language instructions. The control module is used to control the operating status of the hydropower station using the standard PLC target code, and to obtain the operating results of the hydropower station.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for causing the computer to execute the hydropower station operation status control method based on a large model as described in any one of claims 1 to 7.

10. A computer program product, characterized in that, It includes computer instructions for causing a computer to execute the hydropower station operation status control method based on a large model, as described in any one of claims 1 to 7.