A double-agent driven modelica simulation optimization method
By combining a dual-agent collaborative simulation optimization system with a large language model, automated modeling and control strategy optimization of complex physical systems are achieved, solving the problem of low automation in existing technologies, improving the efficiency and accuracy of simulation optimization, and possessing high versatility and interpretability.
Patent Information
- Application Number
- CN202610970541.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-01
- Publication Date
- 2026-11-24
Smart Images

Figure CN123159053A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of physical system modeling and simulation optimization technology, specifically to a dual-agent collaborative simulation optimization system, method, and medium based on a large language model. It is particularly suitable for modeling, control strategy optimization, and automatic hyperparameter tuning of complex physical systems, and belongs to the interdisciplinary technical field of computer simulation, artificial intelligence, automatic control, and optimization algorithms. Background Technology
[0002] With the development of artificial intelligence, intelligent modeling, simulation, and optimization of complex physical systems have become an important direction in modern engineering. Object-oriented multi-domain modeling languages, such as Modelica, are widely used in power, mechanical, and aerospace systems. However, as system scale and coupling complexity increase, traditional simulation optimization is gradually revealing its shortcomings in terms of automation, iterative efficiency, and intelligence.
[0003] Common optimization methods currently include: 1. Gradient-based methods: These methods update parameters through the gradient of the objective function and converge quickly, but they rely on differentiable objective functions, making it difficult to achieve automated modeling and control optimization of complex multiphysics systems.
[0004] 2. Heuristic and intelligent search-based algorithms, such as genetic algorithms, particle swarm optimization, and simulated annealing, have global search capabilities, but parameter selection relies on human experience, resulting in limited intelligence.
[0005] 3. Simulation-based global optimization methods, such as surrogate models, response surfaces, and multifidelity methods, can reduce simulation overhead, but model building and sample design require manual intervention and lack intelligence.
[0006] 4. Machine learning-based methods, such as neural networks and reinforcement learning, can automatically learn system patterns and optimize strategies. However, training is highly sensitive to hyperparameters and network structure, lacks adaptive closed-loop optimization, and is difficult to achieve complete autonomy.
[0007] Overall, existing technologies rely on engineers' experience, with model building, control strategies, and hyperparameter optimization being fragmented. They lack multi-task collaboration mechanisms, making it difficult to simulate multi-expert collaborative design and limiting the efficiency and accuracy of simulation optimization for complex systems. Summary of the Invention
[0008] To overcome the shortcomings of existing technologies, this invention provides a dual-agent collaborative simulation optimization system, method, and medium. By introducing a Large Language Model (LLM) and a dual-agent architecture, it achieves unified optimization of model structure, control strategy, and hyperparameters, thereby improving the autonomy of simulation optimization and the efficiency of engineering applications.
[0009] To achieve the above objectives, this invention provides a dual-agent driven Modelica simulation optimization method, applied to a system comprising a first agent, a second agent, a physical simulation environment, and a large language model. The method includes: S1: The first intelligent agent reads the current state vector from the physical simulation environment, uses a reinforcement learning algorithm to output a control quantity based on the state vector, and inputs the control quantity into the physical simulation model; S2: Call the physical simulation environment to perform single-step integral calculation, obtain the state and output at the next moment, calculate the reward signal, update the reinforcement learning policy network parameters based on the state-action-reward sequence, and form an inner layer control optimization closed loop; S3: Calculate the current control performance index. When the control effect does not meet the preset conditions, construct the control effect, system index and engineering requirements as structured input, add natural language description and input them into the large language model. S4: The large language model automatically generates or modifies the physical simulation model structure based on the input information, outputs the simulation model code framework, updates the physical simulation model in the physical simulation environment, resets the reinforcement learning policy network, and retrains the reinforcement learning to form a model optimization closed loop. S5: The second agent monitors the training process of the first agent in real time, collects training data including learning curves, convergence performance and control performance, and inputs it into the large language model; S6: The large language model directly generates hyperparameter configurations based on the training data, and the second agent directly uses the hyperparameter configurations to control the first agent to retrain using the new hyperparameters, forming an outer hyperparameter optimization closed loop.
[0010] Furthermore, in step S2, let the control quantity at the current moment be at, the output of the physical simulation environment be yt, and the reward signal be rt. The formula for calculating the reward signal rt is: ;
[0011] Where yref is the reference output, α1, α2 and α3 are the weight coefficients, and Iconstraint is the constraint violation indicator function.
[0012] Further, in step S2, let the current state vector be st, and the reinforcement learning algorithm be the PPO algorithm. The first agent stores the state-action-reward sequence containing the state vector st, the control variable at, and the reward signal rt into an experience replay buffer. When the buffer data reaches a preset batch size, the PPO algorithm is used to update the policy network parameters θ. The objective function of the PPO algorithm is: ;
[0013] in, Importance sampling ratio, This is the estimated value of the dominance function. The pruning factor is used; the update formula for the policy network parameter θ is: ;
[0014] in, Set the learning rate to [value]. .
[0015] Furthermore, in step S3, the control performance indicators include steady-state error ess, overshoot Mp, and settling time ts; let the actual output of the physical simulation environment be y(t), the maximum output be ymax, and the reference output be yref; the formula for calculating the steady-state error ess is: ; The formula for calculating the overshoot Mp is: ;
[0016] The settling time ts is defined as the time required for the system response to first enter and remain within the error band ±2%; the control effect not meeting the preset conditions means that when the steady-state error ess≥0.05, the overshoot Mp≥0.1, or the settling time ts≥2 seconds, the large language model is triggered to perform model optimization.
[0017] Furthermore, in step S4, the automatic generation or modification of the physical simulation model structure by the large language model specifically includes: adding or removing components, adjusting the topology, and modifying the parameter range and constraints of the physical simulation model.
[0018] Furthermore, in step S5, the learning curve in the training data collected by the second agent includes the cumulative reward Repisode, policy loss, and value loss; assuming the reward signal at time t is rt, the formula for calculating the cumulative reward Repisode is: ;
[0019] Where T is the number of rounds and γ is the discount factor.
[0020] Furthermore, in step S6, the hyperparameter configuration generated by the large language model includes: learning rate, discount factor, PPO pruning factor, number of policy network layers, number of neurons per layer, and training batch size; The process of generating hyperparameter configurations by the large language model includes: when training anomalies occur, the large language model performs diagnostic analysis on the training dynamics; if the analysis shows that the learning rate is too high, resulting in excessive policy updates, the learning rate is automatically reduced and other relevant hyperparameters are adjusted, and the generated hyperparameter configurations are directly fed back to the second agent.
[0021] Furthermore, the method also includes a system termination condition determination step, wherein the system stops running and outputs the final optimization result when any of the following conditions are met: The control performance meets the requirements of steady-state error ess < 0.01, overshoot Mp < 0.05, and settling time ts < 1 second; Hyperparameter configuration convergence was observed, with performance improvement less than 1% after 10 consecutive hyperparameter configuration updates. It can reach the maximum running time of 72 hours.
[0022] To achieve the above objectives, the present invention also provides a dual-agent collaborative simulation optimization system, applied to a system comprising a first agent, a second agent, a physical simulation environment, and a large language model. The simulation optimization system includes: The first intelligent agent module is adapted to read the current state vector from the physical simulation environment, use a reinforcement learning algorithm to output a control quantity based on the state vector, and input the control quantity into the physical simulation model; The simulation calculation module is suitable for calling the physical simulation environment to perform single-step integral calculations, obtain the state and output at the next moment, calculate the reward signal, update the reinforcement learning policy network parameters based on the state-action-reward sequence, and form an inner-layer control optimization closed loop. The large language model module is suitable for calculating the current control performance index. When the control effect does not meet the preset conditions, the control effect, system index and engineering requirements are constructed as structured input and natural language description is added before being input into the large language model. The closed-loop control module is suitable for the large language model to automatically generate or modify the physical simulation model structure based on the input information, output the simulation model code framework, update the physical simulation model in the physical simulation environment and reset the reinforcement learning policy network, retrain the reinforcement learning, and form a model optimization closed loop. The second intelligent agent module is suitable for the second intelligent agent to monitor the training process of the first intelligent agent in real time, collect training data including learning curves, convergence performance and control performance, and input them into the large language model; The hyperparameter configuration module is suitable for the large language model to directly generate hyperparameter configurations based on the training data. The second agent directly uses the hyperparameter configurations to control the first agent to retrain using the new hyperparameters, forming an outer hyperparameter optimization closed loop.
[0023] To achieve the above objectives, the present invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the above method.
[0024] Compared with the prior art, the present invention has the following beneficial effects: 1. Achieve end-to-end automation, significantly reducing professional barriers and labor costs. This invention leverages the powerful code generation and logical reasoning capabilities of large language models to replace the tedious process of manual modification of physical models by domain experts and manual parameter tuning by algorithm engineers in traditional workflows. The system only needs to input initial engineering requirements to automatically complete the end-to-end closed loop of "model building - strategy training - parameter tuning," greatly reducing the barrier to entry for optimizing complex systems.
[0025] 2. Constructing a "structure-control" collaborative optimization mechanism to overcome the performance bottleneck of single optimization. Traditional methods often separate physical model design from control strategy design, leading to the control strategy often getting stuck in local optima under a given physical structure. This invention can trigger the large language model to directly modify the underlying physical simulation model (such as adjusting component topology or modifying constraints) when the control effect is poor, realizing joint optimization of physical structure and control algorithm, making it easier to reach the global optimum.
[0026] 3. Dynamic diagnosis and adaptive hyperparameter adjustment significantly improve training stability and convergence efficiency. Reinforcement learning is highly sensitive to hyperparameters and is prone to training crashes. This invention introduces a second intelligent agent as a "supervisor," which, combined with a large language model, performs real-time diagnosis of training curves and abnormal features. When slow convergence or drastic fluctuations are detected, the system can analyze the root cause (such as an excessively high learning rate) like a human expert and dynamically issue new hyperparameter configurations, effectively avoiding unnecessary computational waste and significantly shortening the optimization cycle.
[0027] 4. High versatility and cross-domain applicability. This invention adopts a standardized state-action interface and natural language prompt mechanism, without relying on prior mathematical models specific to any particular domain. Whether it's a power grid, robotic arm control, or a thermal system, as long as it can be connected to a physical simulation environment, this dual-agent collaborative optimization framework can be reused, making it extremely valuable for engineering application.
[0028] 5. Enhanced interpretability of the black-box optimization process. Traditional reinforcement learning or heuristic algorithms are often "black-box" processes, making it difficult to trace the reasons for parameter adjustments. In this invention, while the large language model outputs hyperparameters or model code, its internal reasoning process can be transformed into a natural language diagnostic report, providing engineers with clear optimization logic and decision-making basis, thus improving the credibility of engineering applications. Attached Figure Description
[0029] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.
[0030] Figure 1 This is a system architecture diagram of an embodiment of the present invention; Figure 2 This is a schematic diagram of the two-layer closed-loop collaborative optimization mechanism in an embodiment of the present invention; Figure 3 This is a flowchart illustrating the control optimization process of the first intelligent agent according to an embodiment of the present invention. Figure 4 This is a flowchart of the model optimization process for the large language model in the first intelligent agent according to an embodiment of the present invention. Figure 5 This is a flowchart illustrating the hyperparameter optimization process of the second intelligent agent in an embodiment of the present invention. Figure 6 This is a flowchart illustrating the hyperparameter optimization auxiliary process for a large language model according to an embodiment of the present invention. Figure 7 This is a schematic diagram of the simulation optimization system according to an embodiment of the present invention; Figure 8 This is a schematic diagram of the structure of a computer device according to an embodiment of the present invention. Detailed Implementation
[0031] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without inventive effort are within the scope of protection of this invention.
[0032] Example 1 Please see Figure 1 and Figure 2 The optimization method for dual-agent collaborative simulation provided by this invention mainly includes a first agent (simulation and control agent), a second agent (parameter optimization agent), a physical simulation environment, and a large language model service. In this embodiment, the physical simulation environment is specifically the Modelica simulation environment. Modelica, as an object-oriented physical modeling language, supports unified modeling across multiple domains, automatic equation solving, and model reuse. This embodiment uses OpenModelica or Dymola as the underlying simulation engine, configures the simulation step size to 0.01 seconds, and sets a status output interface to output system physical quantities in real time.
[0033] In this architecture, the first agent, acting as the "executor" that directly interacts with the physical simulation environment, has the core task of training the underlying control policy through reinforcement learning. The first agent can be built using Python and internally encapsulates deep reinforcement learning algorithm libraries such as Stable-Baselines3, supporting algorithms like PPO, DDPG, and SAC. In terms of network structure, the first agent comprises a policy network (Actor) and a value network (Critic). The number of nodes in the input layer of the policy network matches the dimension of the state vector output by the physical simulation environment, and the number of nodes in the output layer matches the dimension of the control quantity. The hidden layer uses a multilayer perceptron (MLP) structure by default. In terms of execution logic, the first agent establishes a connection with the simulation environment through a Python-Modelica interface (such as PyFMI or OMPython). In each control cycle, the first agent calls the `step()` function to send the control quantity calculated by the policy network to the simulation environment and then blocks, waiting for the simulation environment to return the state vector, reward signal, and end-of-cycle flag for the next time step. The first agent maintains an experience replay buffer to temporarily store the data sequence generated by the interaction. When the buffer is full, the first agent pauses its interaction with the environment, calls the internal Adam optimizer to perform backpropagation, and updates the neural network parameters.
[0034] To provide high-dimensional supervision and scheduling of the training process of the first agent, this invention incorporates a second agent within the system. The second agent acts as the "supervisor" of the entire training process, operating independently of the first agent's control loop, typically existing as an asynchronous thread or callback function. Internally, the second agent includes a state evaluation module and a parameter scheduling module: the state evaluation module extracts training logs after each training episode or at a preset time step; the parameter scheduling module parses the new hyperparameter configurations returned by the large language model and securely injects them into the first agent. Those skilled in the art will understand that hyperparameters are parameters pre-set manually or algorithmically before the machine learning or reinforcement learning model begins training. They control the learning process itself, rather than the internal weights (such as connection weights in a neural network) automatically learned during training. Common hyperparameters in reinforcement learning include learning rate, discount factor, batch size, and pruning factor. Organizing and storing multiple hyperparameters and their corresponding values together in the form of "key-value pairs" constitutes a hyperparameter dictionary. For example, when the learning rate needs to be updated, the second agent will modify the lr attribute in the first agent's optimizer; when the network structure needs to be changed, the second agent will control the first agent to save the current experience, destroy the old network instance, and reinitialize the policy network according to the new parameters.
[0035] During system operation, a tight data interaction loop of "bottom-up reporting" and "top-down control" is formed between the first and second agents. Bottom-up reporting involves the first agent periodically sending structured state data packets to the second agent. These packets contain not only scalar metrics at the bottom level of reinforcement learning (such as policy loss, value loss, and average round reward) but also engineering metrics at the physical control level. Top-down control is manifested in the second agent issuing control commands and parameter data packets to the first agent after receiving the decisions from the large language model. This interaction process employs a thread-safe locking mechanism: the second agent first sends a "pause training" command, suspending the first agent after completing the current gradient update; subsequently, the second agent overwrites the new hyperparameter dictionary (e.g., {"learning_rate": 1e-4, "batch_size": 128, "clip_range": 0.2}) into the first agent's memory space; finally, the second agent sends a "resume training" command, allowing the first agent to continue executing subsequent reinforcement learning loops based on the new parameters.
[0036] The two agents mentioned above heavily rely on large language models when performing complex decisions and optimizations. A large language model (LLM) is an artificial intelligence model built using deep learning techniques, specifically designed to understand, generate, and process human language. Currently, most mainstream large language models (such as the GPT series, Claude, and Qianwen) are based on the Transformer architecture. The core of this architecture is the "attention mechanism," which allows the model to pay attention to other relevant words in the context when processing a single word, thus greatly improving its ability to understand long texts and complex contexts.
[0037] In this invention, the system accesses a large language model deployed in the cloud or locally via an HTTP / RESTful API. To balance the creativity of the generated code with the rigor of engineering code, the temperature parameter is set to 0.7 during the call. To improve the inference accuracy of the large language model in specific physical domains, the system introduces a retrieval-enhanced generation (RAG) mechanism when accessing the large language model. Specifically, the system locally mounts a vector database containing Modelica standard library documentation, control theory expert experience, and historical successful optimization cases. Before sending a request to the large language model, the system first converts the current performance bottleneck (such as "excessive steady-state error") into a vector, retrieves the three most relevant expert experiences or code templates from the database, and injects them as background context into the prompt words, thereby effectively suppressing the "illusion" of the large language model and ensuring that the generated physical model structure and hyperparameters conform to engineering common sense.
[0038] In terms of prompt word construction, the system adopts a three-part combination mechanism of "system prompt words + contextual memory + task prompt words". System prompt words are used to set strict role boundaries and output format specifications. The contextual memory module uses a sliding window mechanism to manage historical training logs. To avoid exceeding the token limit of the large language model, the system only retains the key indicator sequences of the most recent 50 training rounds, and compresses earlier data into mean and variance features through statistical algorithms. Task prompt words are dynamically concatenated by the program, forcing the large language model to adopt a chain-of-thought (CoT) reasoning mode. For example, in the hyperparameter optimization scenario, the task prompt words require the large language model to first output the "root cause analysis" of the current learning curve fluctuations, then output the "adjustment strategy", and finally output the specific hyperparameter dictionary wrapped in JSON. This forced reasoning process not only improves the rationality of parameter generation, but also provides engineers with readable diagnostic reports.
[0039] To address potential syntax errors or logical inconsistencies in the automatically generated Modelica code or hyperparameters from the large language model, the system employs a robust safety verification and fallback mechanism at the execution layer. After the regular expression parser extracts the Modelica code block generated by the large language model, the system does not immediately overwrite the original model. Instead, it first calls the Modelica compiler's syntax checking interface in a sandbox environment. If compilation fails, the system automatically captures compilation logs containing specific error line numbers and reasons, feeding these back to the large language model as new warning messages, requiring it to self-correct. This automatic repair process allows a maximum of three retries. If compilation still fails after three consecutive repairs, or if applying new hyperparameters causes gradient explosion (e.g., NaN loss) within five rounds in the first agent's training, the system triggers a fallback mechanism. It automatically discards the current generated results, reverts to the previous validated and usable physical model version and hyperparameter snapshot, and sends a penalty signal to the large language model to adjust subsequent generation strategies. This closed-loop verification mechanism ensures the absolute stability of the dual-agent collaborative optimization process in an unattended state.
[0040] For details on the control optimization process, please refer to [link / reference]. Figure 3 The inner-layer control optimization closed loop of the first agent relies on the coordinated operation of the reward function and the policy update formula. At the end of each simulation step, the first agent needs to quantify the merits of the current action, at which point the reward function formula is applied: ;
[0041] In the above formula, yref is the reference output, α1, α2, and α3 are weight coefficients, and Iconstraint is the constraint violation indicator function. This formula is applied in the environmental feedback phase. Specifically, the system obtains the squared deviation between the current actual output yt and the reference target yref as the tracking error penalty (weight α1), obtains the squared value of the current control quantity at as the energy consumption penalty (weight α2), and checks whether the safety constraint Iconstraint is triggered (1 if triggered, 0 otherwise, weight α3). The calculated scalar... It is stored in the experience replay buffer to guide the agent in subsequent training to find the optimal control strategy that can accurately track the target, save energy, and not violate physical constraints.
[0042] When the amount of data in the experience replay buffer reaches the preset batch_size, the first agent enters the neural network parameter update phase, at which point the objective function formula of the PPO algorithm is applied: ;
[0043] This formula is used to prevent training from crashing due to drastic changes in the policy during a single update. Specifically, the system first calculates the ratio of the output probabilities of the old and new policies. and the advantage function estimate of the current action (That is, how much better the action is than the average level). The ratio is limited to the range [1-ε, 1+ε] by the clip function (ε is usually 0.2), and the minimum value before and after clipping is taken as the final expected loss.
[0044] Subsequently, the optimizer uses the gradient of the objective function to update the policy network parameters, applying the update formula: ;
[0045] In practical use, the system will calculate the gradient Multiply by the current learning rate (Initially set to 3×10-4), and accumulated onto the current network weight θt, thus obtaining the new weight θt+1 for the next iteration.
[0046] For model optimization, please refer to Figure 4 In the first intelligent agent, the optimization process of the large language model depends on the calculation of macroscopic control performance indicators. When a complete simulation episode ends, the system needs to evaluate the overall control quality to determine whether to trigger the reconstruction of the underlying physical model. At this time, the formulas for calculating steady-state error, overshoot, and settling time are applied.
[0047] Steady-state error formula The application scenario is to evaluate the final tracking accuracy of the system. The specific method is to extract the actual output y(t) at the end of the round and calculate the absolute difference between it and the target value yref.
[0048] Overshoot The calculation formula is: ;
[0049] Its application scenario is to evaluate the safety and stability of the system response process. The specific method is to traverse the output trajectory of the entire round to find the peak value ymax and calculate the percentage that it exceeds the target value.
[0050] The settling time ts is defined as the point in time when the output first enters and remains within the ±2% error band of the target value by traversing the trajectory. If the calculated steady-state error ess ≥ 0.05, overshoot Mp ≥ 0.1, or settling time ts ≥ 2 seconds, the system constructs these specific index values along with engineering requirements into a structured input, triggering the large language model to automatically modify the Modelica model structure (including adding or removing components, adjusting topology, and modifying parameter ranges and constraints), thereby forming a closed loop for model optimization.
[0051] For hyperparameter optimization, please refer to [link / reference]. Figure 5 and Figure 6 The outer closed-loop process of the second agent relies on the calculation of cumulative rewards. At the end of each round, the second agent needs to evaluate the overall performance of the first agent in that round, at which point the cumulative reward formula is applied: ;
[0052] in, The length of the episode. As a discount factor, this formula is used to generate learning curves for large language model diagnostics. Specifically, the second agent extracts the immediate rewards for all T steps within that round. A discount factor γ (usually close to 1, such as 0.99) is introduced to decay and sum the future rewards.
[0053] The second agent plots the repisodes from multiple consecutive rounds into learning curves, and feeds these curves, along with feature data such as policy loss and value loss, into a structured input to the large language model. Based on these macroscopic training performance metrics, the large language model directly generates hyperparameter configurations, including learning rate, discount factor, PPO pruning factor, number of policy network layers and neurons, and training batch size. For example, if the large language model detects through the learning curves that the initial convergence is extremely rapid but the later stages exhibit significant oscillations, it diagnoses this as an excessively high learning rate leading to excessive policy updates, and automatically generates a new configuration with a lower learning rate. The second agent analyzes this configuration and directly controls the first agent to train using the new parameters, forming a feedback loop.
[0054] The system terminates under any of the following conditions: First, the control performance satisfies steady-state error ess < 0.01, overshoot Mp < 0.05, and settling time ts < 1 second; second, hyperparameter configuration converges, meaning the performance improvement is less than 1% after 10 consecutive hyperparameter configuration updates; third, the maximum running time of 72 hours is reached. When the termination conditions are met, the system stops running and outputs the optimal model structure, control strategy, hyperparameter configuration, and final control performance indicators.
[0055] In general, after the second agent of this invention parses the hyperparameter configuration output by the large language model, it writes each parameter in the configuration (such as learning rate, discount factor, batch size, number of network layers, etc.) into the corresponding parameter setting interface of the first agent. After completing the hyperparameter injection, it sends a retraining instruction to the first agent, driving the first agent to re-execute the inner layer control optimization closed loop with the new hyperparameters. This forms a complete outer layer hyperparameter optimization closed loop of data acquisition → large language model generates hyperparameter configuration → writes new hyperparameters and retrains.
[0056] The following is a specific control training process according to the present invention: First round of training: The first agent is trained with default hyperparameters (lr=0.0003, gamma=0.99, layers=[64,64]). The second agent collects data (average reward -91.12, standard deviation 116.73, overall score 0.732) and inputs it into the large model. The large model diagnoses drastic training fluctuations and adopts a minimal intervention strategy, only reducing gamma from 0.99 to 0.95, leaving other parameters unchanged. The second agent writes the new gamma into the first agent and triggers retraining.
[0057] Second round of training: The first agent was retrained with gamma=0.95. The data improved to an average return of -45.3, a standard deviation of 52.1, and an overall score of 0.851. The large model determined that fluctuations had been suppressed and performance continued to improve, requiring only minor adjustments to the entropy coefficient. After the second agent was written, the next round continued.
[0058] This process of data collection → generating hyperparameter configurations for the large language model → writing new hyperparameters and retraining continues until the overall score exceeds the set threshold or the number of iterations is exhausted.
[0059] The following is a specific example of the hyperparameter optimization process according to the present invention: For example, after collecting training data, the second agent discovered three problems: a stable but slow learning curve (std=6.3, trend=8.7), a large steady-state error (0.118, far exceeding the 0.05 threshold), and underlearning of the controller. Based on this, the large language model made three diagnoses and provided corresponding adjustments: Slow improvement → Learning rate increased from 0.0003 to 0.00045, entropy coefficient decreased from 0.01 to 0.003 (reducing exploration and accelerating utilization), n_steps decreased from 2048 to 1024 (doubled update frequency); Large steady-state error → The first layer of the policy network was expanded from 64 to 128 neurons to enhance fitting ability; Adjustments were made to double the batch_size from 64 to 128 (to ensure gradient quality) and restore gamma to 0.99.
[0060] Specifically, after the second agent parses the JSON output by the large model, it writes each parameter into the first agent: the learning rate of 0.00045 is written into the learning rate parameter and the optimizer is rebuilt; the discount factor of 0.99 is written into the discount factor parameter; n_steps of 1024 is written into the interaction step parameter; batch_size of 128 is written into the batch size parameter; the entropy coefficient of 0.003 is written into the entropy regularization parameter; after writing the network structure [128, 64], the first agent rebuilds the policy network according to the new structure. and value network and reinitialize and After all data is written, a retraining command is sent to drive the first agent to execute the inner closed loop of reading the state vector, outputting the policy action, simulating the step, and calculating the reward with the new parameters. This forms the outer closed loop of data acquisition → generating hyperparameter configuration for the large language model → writing the new hyperparameters and retraining.
[0061] This embodiment also provides a dual-agent collaborative simulation optimization system, applicable to a system comprising a first agent, a second agent, a physical simulation environment, and a large language model. For example... Figure 7 As shown, the simulation optimization system 70 includes: The first intelligent agent module 71 is adapted to read the current state vector from the physical simulation environment, use a reinforcement learning algorithm to output a control quantity based on the state vector, and input the control quantity into the physical simulation model; The simulation calculation module 72 is suitable for calling the physical simulation environment to perform single-step integral calculation, obtain the state and output at the next moment, calculate the reward signal, update the reinforcement learning policy network parameters based on the state-action-reward sequence, and form an inner layer control optimization closed loop. The large language model module 73 is suitable for calculating the current control performance index. When the control effect does not meet the preset conditions, the control effect, system index and engineering requirements are constructed as structured input and natural language description is added before being input into the large language model. The closed-loop control module 74 is suitable for the large language model to automatically generate or modify the physical simulation model structure according to the input information, output the simulation model code framework, update the physical simulation model in the physical simulation environment and reset the reinforcement learning policy network, retrain the reinforcement learning, and form a model optimization closed loop. The second intelligent agent module 75 is adapted to monitor the training process of the first intelligent agent in real time, collect training data including learning curves, convergence performance and control performance, and input them into the large language model; The hyperparameter configuration module 76 is suitable for the large language model to directly generate hyperparameter configurations based on the training data. The second agent directly uses the hyperparameter configurations to control the first agent to retrain using the new hyperparameters, forming an outer hyperparameter optimization closed loop.
[0062] This embodiment also provides a computer device, such as a smartphone, tablet computer, laptop computer, desktop computer, rack server, blade server, tower server, or cabinet server (including a standalone server or a server cluster composed of multiple servers), etc., capable of executing programs. The computer device 80 in this embodiment includes, but is not limited to, a memory 81 and a processor 82 that can be interconnected via a system bus. Figure 8 As shown. It should be noted that, Figure 8 Only a computer device 80 with components 81-82 is shown; however, it should be understood that it is not required to implement all of the components shown, and more or fewer components may be implemented instead.
[0063] In this embodiment, the memory 81 (i.e., the readable storage medium) includes flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 81 may be an internal storage unit of the computer device 80, such as the hard disk or memory of the computer device 80. In other embodiments, the memory 81 may also be an external storage device of the computer device 80, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the computer device 80. Of course, the memory 81 may include both the internal storage unit and the external storage device of the computer device 80. In this embodiment, the memory 81 is typically used to store the operating system and various application software installed on the computer device 80, such as the program code of the simulation optimization system 70 in Embodiment 1. In addition, the memory 81 can also be used to temporarily store various types of data that have been output or will be output.
[0064] In some embodiments, processor 82 may be a central processing unit (CPU), controller, microcontroller, microprocessor, or other data processing chip. This processor 82 is typically used to control the overall operation of the computer device 80. In this embodiment, processor 82 is used to run program code stored in memory 81 or process data, for example, to run a permission management system 80 to implement the simulation optimization method of Embodiment 1.
[0065] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0066] Any process or method described in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or more executable instructions for implementing a particular logical function or process, and the scope of the preferred embodiments of the invention includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the functions involved, as will be understood by those skilled in the art to which embodiments of the invention pertain.
[0067] Those skilled in the art will understand that all or part of the steps of the methods described in the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable medium, and when executed, it includes one or a combination of the steps of the method embodiments.
[0068] In the description of this specification, references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0069] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method.
[0070] The above are merely preferred embodiments of the present invention and do not limit the scope of the patent. Any equivalent structural or procedural transformations made based on the description and drawings of the present invention, or direct or indirect applications in other related technical fields, are similarly included within the scope of patent protection of the present invention.
Claims
1. A dual-agent driven Modelica simulation optimization method, characterized in that, Applied to a system comprising a first intelligent agent, a second intelligent agent, a physical simulation environment, and a large language model, the method includes: S1: The first intelligent agent reads the current state vector from the physical simulation environment, uses a reinforcement learning algorithm to output a control quantity based on the state vector, and inputs the control quantity into the physical simulation model; S2: Call the physical simulation environment to perform single-step integral calculation, obtain the state and output at the next moment, calculate the reward signal, update the reinforcement learning policy network parameters based on the state-action-reward sequence, and form an inner layer control optimization closed loop; S3: Calculate the current control performance index. When the control effect does not meet the preset conditions, construct the control effect, system index and engineering requirements as structured input, add natural language description and input them into the large language model. S4: The large language model automatically generates or modifies the physical simulation model structure based on the input information, outputs the simulation model code framework, updates the physical simulation model in the physical simulation environment, resets the reinforcement learning policy network, and retrains the reinforcement learning to form a model optimization closed loop. S5: The second agent monitors the training process of the first agent in real time, collects training data including learning curves, convergence performance and control performance, and inputs it into the large language model; S6: The large language model directly generates hyperparameter configurations based on the training data, and the second agent directly uses the hyperparameter configurations to control the first agent to retrain using the new hyperparameters, forming an outer hyperparameter optimization closed loop.
2. The Modelica simulation optimization method driven by dual agents according to claim 1, characterized in that, In step S2, let the control quantity at the current moment be at, the output of the physical simulation environment be yt, and the reward signal be rt. The formula for calculating the reward signal rt is: ; Where yref is the reference output, α1, α2 and α3 are the weight coefficients, and Iconstraint is the constraint violation indicator function.
3. The Modelica simulation optimization method driven by dual agents as described in claim 2, characterized in that, In step S2, let the current state vector be st, and the reinforcement learning algorithm be the PPO algorithm. The first agent stores the state-action-reward sequence containing the state vector st, the control variable at, and the reward signal rt into an experience replay buffer. When the buffer data reaches a preset batch size, the PPO algorithm is used to update the policy network parameters θ. The objective function of the PPO algorithm is: ; in, Importance sampling ratio, This is the estimated value of the dominance function. The pruning factor is used; the update formula for the policy network parameter θ is: ; in, Set the learning rate to [value]. .
4. The Modelica simulation optimization method driven by dual agents as described in claim 1, characterized in that, In step S3, the control performance indicators include steady-state error ess, overshoot Mp, and settling time ts; let the actual output of the physical simulation environment be y(t), the maximum output be ymax, and the reference output be yref; the formula for calculating the steady-state error ess is: ; The formula for calculating the overshoot Mp is: ; The settling time ts is defined as the time required for the system response to first enter and remain within the error band ±2%; the control effect not meeting the preset conditions means that when the steady-state error ess≥0.05, the overshoot Mp≥0.1, or the settling time ts≥2 seconds, the large language model is triggered to perform model optimization.
5. The Modelica simulation optimization method driven by dual agents as described in claim 1, characterized in that, In step S4, the automatic generation or modification of the physical simulation model structure by the large language model specifically includes: adding or removing components, adjusting the topology, and modifying the parameter range and constraints of the physical simulation model.
6. The Modelica simulation optimization method driven by dual agents as described in claim 1, characterized in that, In step S5, the learning curve in the training data collected by the second agent includes the cumulative reward Repisode, policy loss, and value loss; let the reward signal at time t be rt, and the formula for calculating the cumulative reward Repisode is: ; Where T is the number of rounds and γ is the discount factor.
7. The Modelica simulation optimization method driven by dual agents as described in claim 1, characterized in that, In step S6, the hyperparameter configuration generated by the large language model includes: learning rate, discount factor, PPO pruning factor, number of policy network layers, number of neurons per layer, and training batch size; The process of generating hyperparameter configurations by the large language model includes: when training anomalies occur, the large language model performs diagnostic analysis on the training dynamics; if the analysis shows that the learning rate is too high, resulting in excessive policy updates, the learning rate is automatically reduced and other relevant hyperparameters are adjusted, and the generated hyperparameter configurations are directly fed back to the second agent.
8. The Modelica simulation optimization method driven by dual agents as described in claim 4, characterized in that, The method further includes a system termination condition determination step, wherein the system stops running and outputs the final optimization result when any of the following conditions are met: The control performance meets the requirements of steady-state error ess < 0.01, overshoot Mp < 0.05, and settling time ts < 1 second; Hyperparameter configuration convergence was observed, with performance improvement less than 1% after 10 consecutive hyperparameter configuration updates. It can reach the maximum running time of 72 hours.
