Annotating simulation model self-generation method and device
By using the annotation information automatic matching and classification module, XML is generated and encapsulated into a JSON format simulation model, which solves the problems of repetitive building and non-standard naming in model simulation software, and realizes efficient and standardized model building and simplification of the simulation system.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHEJIANG DIJIE SOFTWARE TECH CO LTD
- Filing Date
- 2023-02-02
- Publication Date
- 2026-04-28
AI Technical Summary
Existing model simulation software suffers from problems such as repetitive model building, redundant model data settings, and non-standard module variable naming, resulting in low model building efficiency, chaotic layout, and poor readability.
By using an annotation-based simulation model self-generation method, module queues are automatically generated by matching module names and attributes with annotation information, classifying module types, and parsing and simulating through XML model files. Finally, the model is encapsulated in JSON format to improve the standardization and readability of the model construction.
It achieves efficient and standardized model building process, reduces duplication rate, improves the clarity of model layout and consistency of variable naming, reduces manpower, material resources and time costs, and enhances the versatility and ease of secondary development of simulation system.
Smart Images

Figure CN116341191B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to computer technology, and more particularly to a method and apparatus for automatic model generation based on model simulation software. Background Technology
[0002] Model simulation is a tool used to build and simulate mathematical models of linear, nonlinear, discrete, and continuous systems. Currently, model simulation software such as ANSYS SCADE and MathWorks Simulink Code support modeling and simulating complex systems. By using the basic modules provided by the software itself, such as addition, multiplication, differentiation, and state machine modules, the system equation model can be built manually.
[0003] Currently, when using simulation software for modeling, designers typically build models manually using the software's basic modules based on their understanding of the system's physical characteristics and related equations. This manual modeling process has the following problems: Building simple models requires repeatedly selecting and connecting modules, which is inefficient. The number and relationships of modules in a model often increase with the complexity of the mathematical equations, leading to a chaotic layout and poor readability. Building complex models usually involves dividing the model into multiple parts completed by different people; such collaborative work, without standardization, often results in inconsistent model and variable naming and style.
[0004] Therefore, there is an urgent need for a method and apparatus for self-generating simulation models to overcome the shortcomings of existing technologies. Summary of the Invention
[0005] The purpose of this invention is to provide an annotation-based self-generation method for simulation models, which can solve the problems of repeated building of simple models, repeated setting of model data, and non-standard naming of modules and variables in existing model simulation software, making the model building process more efficient and standardized.
[0006] To achieve the above objectives, this invention provides a method for self-generating simulation models based on annotations. The method includes: matching keywords of model names in annotation information with module names in a model library; adding modules with the same matching keywords to the same module queue, generating multiple module queues; dividing the annotation information into multiple corresponding information segments based on the modules stored in the module queues; obtaining keywords of module attributes from each information segment; matching the keywords of module attributes with module attributes in the module library; storing the attribute names of successfully matched module attributes in a data list; analyzing the module queues through annotation information to classify modules by type and generate port connection relationships for the corresponding modules; writing the corresponding module names, module attributes, and port connection relationships into an XML model file; and parsing and simulating the XML model file.
[0007] As a preferred approach, modules can be categorized by type, including dividing them into data providing modules, logic calculation modules, and data receiving modules based on their input / output port information.
[0008] As a preferred approach, the port connection relationships of the corresponding modules include: traversing the module queue, using either the logic calculation module or the data receiving module as a separator, dividing the user requirement model into n sub-models consisting of a data providing module and one logic calculation module, where n ≥ 1. Analyzing the modules in the module queue, the ports connecting each sub-model to the logic calculation module, and the ports connecting the sub-models to each other.
[0009] As a preferred method, before matching the keywords of the annotation information with the module name, the user inputs the annotation information of the requirement model through a graphical interface. The graphical interface sends the data to the storage device for storage through the communication interface. The annotation information includes the model name and its corresponding model attributes and model coordinates.
[0010] As a preferred method, when the simulation of the XML model file fails, the port connection relationships are reset: the connection relationships between the ports of the data providing module and the logic calculation module are traversed, and the connection order between the corresponding ports of the data providing module and the logic calculation module in the XML model file is adjusted. After traversing the connection relationships between the ports of the data providing module and the logic calculation module, the logic calculation module is traversed, and the connection relationships between the ports of the logic calculation module are adjusted.
[0011] As a preferred method, after successfully simulating the XML model file, the XML format model is encapsulated into a JSON format simulation model.
[0012] As a preferred method, encapsulating the XML format model into a JSON format simulation model includes: converting the XML model to a JSON model; determining the positional relationships of each module in the empty canvas through the connection relationships in the XML file; and adding the coordinate data of each module to the JSON file. The corresponding subsystem modules of the model are then located using the positional data recorded in the annotation information.
[0013] As a preferred method, after encapsulating the XML format model into a JSON format simulation model, the model-related data stored in the JSON model file is updated, and the corresponding model in the graphical interface is refreshed and displayed.
[0014] As a preferred method, extract the model-related simulation data from the annotation information in the XML model file, and create a new XML file to store the corresponding simulation data. Store the attribute names of the data list as global variables in the XML file. If there are identical attribute names, categorize and store them according to their corresponding module names.
[0015] On the other hand, the present invention also provides an annotation-based simulation model self-generation device, including an annotation information input module, an annotation information analysis module, a model data storage module, and a model data simulation display module. The annotation information input module receives annotation information of the required model input by the user through a graphical interface and sends the data to a storage device for storage through a communication interface. The annotation information includes the model name, its corresponding model attributes, and model coordinates. The annotation information analysis module matches the keywords of the model name in the annotation information with the module names in the model library, and adds the corresponding modules with the same keyword matching to the same module queue, generating multiple module queues. Furthermore, based on the corresponding modules stored in the module queues, the annotation information is divided into multiple corresponding information segments. Through the annotation information analysis module queues, the modules are classified by type, and the port connection relationships of the corresponding modules are generated. The model data storage module obtains the keywords of the module attributes in each information segment and matches the keywords of the module attributes with the module attributes in the module library, storing the attribute names of the successfully matched corresponding module attributes in a data list. The corresponding module names, module attributes, and port connection relationships are written into an XML model file. The model data simulation display module parses the XML model file and displays the simulation.
[0016] Compared with existing technologies, this invention provides an annotation-based automatic model generation method and apparatus suitable for model simulation systems. It solves the problems of repetitive model building, redundant model data settings, and inconsistent module and variable naming in existing model simulation software, thereby making the model building process more efficient and standardized, with a clear layout, significantly improved readability, and unified and standardized model and variable naming and style. This invention overcomes the shortcomings of existing model simulation software in terms of repetitive model building, redundant model data settings, and inconsistent module and variable naming, achieving standardized naming, simplified model building, and reduced model duplication rate in model simulation systems. This invention primarily replaces the current manual module selection for model building by generating corresponding model data based on user-defined annotation inputs based on model requirements. By assigning values to specific attributes in modules as variables, it allows for better viewing and modification of model data compared to manual assignment within modules. This invention significantly improves the versatility of simulation annotation systems, effectively reduces the manpower, material resources, and time costs required for maintaining simulation annotation systems, and makes simulation annotation systems easier for secondary development.
[0017] In short, this invention solves the problems of repetitive model building, repetitive model data setting, and non-standard module and variable naming in existing model simulation software, making the model building process more efficient and standardized, thereby overcoming the above-mentioned defects of the prior art. Thus, it realizes the standardization of model simulation system naming, simplifies model building, and reduces model duplication rate. Attached Figure Description
[0018] Figure 1 This is a flowchart illustrating the annotation-based simulation model self-generation method of the present invention.
[0019] Figure 2 This is a schematic diagram illustrating the replacement module attribute values of the present invention.
[0020] Figure 3 This is a schematic diagram illustrating the replacement of variable names in this invention.
[0021] Figure 4 This is a schematic diagram illustrating the connection order and relationships stored in the XML of this invention.
[0022] Figure 5 This is a schematic diagram of the submodule division of the present invention. Detailed Implementation
[0023] In the following description, embodiments of the annotation-based simulation model self-generation method and apparatus of the present invention will be described with reference to the accompanying drawings.
[0024] The embodiments described herein are specific implementations of the present invention, used to illustrate the concept of the invention, and are illustrative and exemplary, and should not be construed as limiting the embodiments or scope of the present invention. In addition to the embodiments described herein, those skilled in the art can employ other obvious technical solutions based on the content disclosed in the claims and specification of this application. These technical solutions include those that make any obvious substitutions and modifications to the embodiments described herein.
[0025] The accompanying drawings in this specification are schematic diagrams used to help illustrate the concept of the invention, and schematically show the shape of each part and their interrelationship.
[0026] In current modeling technologies, designers typically build models manually using basic modules within the software, based on their understanding of the system's physical characteristics and related equations. This manual modeling process suffers from several problems: Building simple models requires repeatedly selecting and connecting modules, leading to inefficiency. The number and relationships of modules within a model often increase with the complexity of the mathematical equations, resulting in a chaotic layout and poor readability. Building complex models often involves dividing the model into multiple parts completed by different people; without standardization, this collaborative approach frequently leads to inconsistent model and variable naming and style.
[0027] like Figure 1 As shown, this invention illustrates a flowchart of a method for self-generating simulation models based on annotations. By acquiring module data, segmenting the model, and setting corresponding connection relationships, this invention can automatically analyze and uniformly modify and update parameters such as the name and attributes of loaded modules. This invention primarily replaces the current method of manually selecting modules for model building by generating corresponding model data based on user-defined annotation inputs regarding model requirements. This invention assigns values to specific attributes within modules in the form of variables, which allows for better viewing and modification of model data compared to manually assigning values within modules. This annotation-based self-generating simulation model method may include the following steps:
[0028] Step 101: The user inputs annotation information of the requirement model through the graphical interface. The graphical interface sends the data to the storage device for storage through the communication interface. The annotation information includes the model name and its corresponding model attributes and model coordinates.
[0029] Specifically, recording the coordinates is for replacing the annotations with the coordinates after the model is generated and encapsulated into a subsystem. An example of annotation information is as follows: "Model of adding a const with a value of 1 and a const with a value of 2", where "1" and "2" are the values of the value attribute in const, and const and "add" represent the constant and add modules in the module library, respectively.
[0030] Step 102: Match the keywords of the model name in the annotation information with the module names in the model library, and add the corresponding modules with the same keyword matching module names to the same module queue, generating multiple module queues.
[0031] Step 103: Extract the model-related simulation data from the annotation information in the XML model file, and create a new XML file to store the corresponding simulation data.
[0032] Step 104: Store the attribute names of the data list as global variables in an XML file. If there are multiple attribute names with the same name, store them according to their corresponding module names.
[0033] Specifically, such as Figure 2 As shown, module attributes are stored in XML by adding them using templates and replacing attribute values with defined variables. For example... Figure 3 As shown, the value of the `constant.value` property will then be replaced with the name of the defined variable. The property name includes the module name and the property name within the module, connected by ".". It is stored as a string array. For example, the `constant.value` in `constant` will be stored in a string array with the name `constant.constantValue`.
[0034] Step 105: Based on the corresponding modules stored in the module queue, divide the annotation information into multiple corresponding information segments.
[0035] Specifically, the segmentation is based on the module names in the module queue and the corresponding words in the input information. For example, the input information "a model that adds a value of 1 to a value of const and a value of 2 to const" is segmented into three parts: "a value of 1 to const", "a value of 2 to const" and "add" by using the constant and add modules in the module queue.
[0036] Step 106: Obtain the keywords of module attributes in each information segment. Match the keywords of the module attributes with the module attributes in the module library, and store the attribute names of the corresponding module attributes that match successfully in a data list. Analyze the module queue through annotation information, classify the modules by type, and generate the corresponding port connection relationships for each module. Write the corresponding module name, module attribute, and port connection relationship into an XML model file.
[0037] Step 107: Parse and simulate the XML model file.
[0038] Specifically, the necessary attributes for model simulation include: solver selection, simulation time, and simulation step size. This invention automatically extracts these attributes from the current simulation model for simulation.
[0039] Step 108: After successfully simulating the XML model file, encapsulate the XML format model into a JSON format simulation model.
[0040] Step 109: When the XML model file simulation fails, reset the port connection relationships: traverse the port connection relationships between the data providing module and the logic calculation module, and adjust the connection order between the corresponding ports of the data providing module and the logic calculation module in the XML model file. After traversing the port connection relationships between the data providing module and the logic calculation module, traverse the logic calculation module and adjust the connection relationships between the ports of the logic calculation module.
[0041] Specifically, such as Figure 4 As shown, the two `const` values of 1 represent `constant0` and `constant1` in the model. When analyzing input information, `constant0` has an index of 0 in the list, and `constant1` has an index of 1. Therefore, when implementing the connection relationship in XML, `constant0` is connected to the first port of `add`, and `constant1` is connected to the second port of `add`.
[0042] Adjusting connections involves swapping the target value within a connection. This adjustment applies only to each sub-model, and only one sub-model's connections can be swapped at a time. For example, suppose sub-model 1 has 3 input ports ('add') and 3 constants. There are 6 possible ordering relationships for the constants. When the simulation fails, these ordering relationships are traversed, and the constants in each order are connected to the 'add' ports in sequence. Once the traversal is complete, the connection adjustment ends regardless of whether the simulation failed.
[0043] Step 110: After encapsulating the XML format model into a JSON format simulation model, update the model-related data stored in the JSON model file, refresh and display the corresponding model in the graphical interface.
[0044] In a further preferred embodiment, the modules are classified by type as follows: the modules are divided into data providing modules, logic calculation modules, and data receiving modules based on input and output port information.
[0045] Specifically, the data providing module, logic calculation module, and data receiving module are divided by input / output ports. For example: Figure 5 As shown, the `const` module has only an input port and is defined as a data provider module, used to provide the data needed for calculation; it is the data source for the model. The `add` module has both input and output ports and is defined as a logic calculation module to perform logical calculations. The `scope` module has only an input port and is defined as a data receiving module used for the final data display.
[0046] In a further preferred embodiment, the port connection relationships of the corresponding modules include: by traversing the module queue, using the logic calculation module or data receiving module as a separator, the user requirement model is divided into n sub-models consisting of a data providing module and one logic calculation module, where n ≥ 1. The modules in the module queue are analyzed, and the ports connecting each sub-model to the logic calculation module, as well as the ports connecting each sub-model to each other, are identified.
[0047] Specifically, such as Figure 5 As shown, a model that splits into sub-models, such as "the model that adds two const values of 1 to each other and then multiplies them by another const value of 1", will be split into sub-model 1 and sub-model 2. Sub-model 1 is the addition of two const values of 1 to each other. Sub-model 2 is the multiplication of the calculated value by a constant value of 1.
[0048] In a further preferred embodiment, encapsulating the XML format model into a JSON format simulation model includes: converting the XML model into a JSON model; determining the positional relationships of each module in the empty canvas through the connection relationships in the XML file; and adding the coordinate data of each module to the JSON file. The corresponding subsystem modules of the model are then located using the positional data recorded in the annotation information.
[0049] Specifically, the steps to determine positional relationships include:
[0050] Calculate the number of sub-models, n, and obtain the width and height of the current modeling canvas. Divide the canvas width into n parts, placing one sub-module in each part. Divide the width into 1 / 2 or 1 / 1 portions based on the module type within each sub-model. Then, divide the height of the 1 / n portion of the canvas into m parts according to the number of input ports of the logic calculation modules in each sub-model. Determine the module coordinates based on the center coordinates of each divided canvas.
[0051] The present invention has the following advantages over the prior art:
[0052] Instead of manually adding modules repeatedly, the model is generated by reading user input, which reduces the repetitive addition of simple models and improves the efficiency of model building.
[0053] The user requirement model is displayed as a subsystem, which reduces errors that may occur during the construction of complex models due to the large number of modules and complex connections.
[0054] Models generated using the same standard can solve the naming and layout issues that arise from different builders of complex models.
[0055] This invention provides an annotation-based simulation model self-generation device, comprising an annotation information input module, an annotation information analysis module, a model data storage module, and a model data simulation display module.
[0056] The annotation information input module receives the annotation information of the requirement model input by the user through a graphical interface, and sends the data to the storage device for storage through a communication interface. The annotation information includes the model name and its corresponding model attributes and model coordinates.
[0057] The annotation information analysis module matches the keywords of the model name in the annotation information with the module names in the model library, and adds the corresponding modules with the same keyword matching to the same module queue, generating multiple module queues. Based on the corresponding modules stored in the module queues, the annotation information is divided into multiple corresponding information segments.
[0058] The module queue is analyzed using annotation information. Modules are categorized by type, and corresponding port connection relationships are generated. The model data storage module retrieves the keywords of module attributes from each information segment. These keywords are then matched against module attributes in the module library, and the attribute names of successfully matched module attributes are stored in a data list. Finally, the corresponding module name, module attribute, and port connection relationship are written into the XML model file.
[0059] The model data simulation display module parses and displays the XML model file.
[0060] The present invention has the following advantages over the prior art:
[0061] Instead of manually adding modules repeatedly, the model is generated by reading user input, which reduces the repetitive addition of simple models and improves the efficiency of model building.
[0062] The user requirement model is displayed as a subsystem, which reduces errors that may occur during the construction of complex models due to the large number of modules and complex connections.
[0063] Models generated using the same standard can solve the naming and layout issues that arise from different builders of complex models.
[0064] Compared with existing technologies, this invention provides an annotation-based automatic model generation method suitable for model simulation systems. It solves the problems of repetitive model building, redundant model data settings, and inconsistent module and variable naming in existing model simulation software. This makes the model building process more efficient and standardized, with a clear layout, significantly improved readability, and unified and standardized model and variable naming and style. This invention overcomes the shortcomings of existing model simulation software, such as repetitive model building, redundant model data settings, and inconsistent module and variable naming, achieving standardized naming, simplified model building, and reduced model duplication rate in model simulation systems. This invention primarily replaces the current manual module selection for model building by generating corresponding model data based on user-defined annotation inputs based on model requirements. Assigning values to specific attributes in modules as variables allows for better viewing and modification of model data compared to manual assignment within modules. This invention significantly improves the versatility of simulation annotation systems, effectively reduces the manpower, material resources, and time costs required for system maintenance, and facilitates secondary development of the simulation annotation system.
[0065] The embodiments of the annotation-based simulation model self-generation method and apparatus of the present invention have been described above, with the aim of explaining the spirit of the present invention. Please note that those skilled in the art can modify and combine the features of the above embodiments without departing from the spirit of the present invention; therefore, the present invention is not limited to the above embodiments. Specific features of the annotation-based simulation model self-generation apparatus of the present invention, such as shape, size, and position, can be specifically designed based on the functions of the features disclosed above, and these designs are all achievable by those skilled in the art. Furthermore, the disclosed technical features are not limited to the disclosed combinations with other features; those skilled in the art can also make other combinations between the technical features according to the purpose of the invention to achieve the purpose of the present invention.
Claims
1. A self-generation method for simulation models based on annotations, characterized in that, The method includes: Match the keywords of the model name in the annotation information with the module names in the model library, and add the corresponding modules with the same keyword matching module names to the same module queue, generating multiple module queues. Based on the corresponding modules stored in the module queue, the annotation information is divided into multiple corresponding information segments; Retrieve keywords for module attributes in each information segment; Match the keywords of the module attributes with the module attributes in the module library, and store the attribute names of the corresponding module attributes that match successfully into a data list. By analyzing the module queue through annotation information, the modules are categorized by type, and the corresponding port connection relationships of the modules are generated; among them, Modules can be categorized by type as follows: based on input / output port information, modules can be divided into data providing modules, logic calculation modules, and data receiving modules. The port connection relationships for generating the corresponding modules include: By traversing the module queue, the user requirement model is divided into n data providing modules and 1 logic calculation module as the separator, where n≥1; Analyze the modules in the module queue, identify the ports connecting each sub-model to the logic calculation module, and the ports connecting each sub-model; write the corresponding module name, module attributes, and port connection relationships into the XML model file; The XML model file is parsed and simulated.
2. The annotation-based simulation model self-generation method according to claim 1, characterized in that, Also includes: Before matching the keywords of the annotation information with the module name, the user inputs the annotation information of the requirement model through the graphical interface. The graphical interface sends the data to the storage device for storage through the communication interface. The annotation information includes the model name and its corresponding model attributes and model coordinates.
3. The annotation-based simulation model self-generation method according to claim 1, characterized in that, Also includes: When XML model file simulation fails, reset the port connection relationship: Iterate through the connection relationships between the ports of the data providing module and the logic calculation module, and adjust the connection order between the corresponding ports of the data providing module and the logic calculation module in the XML model file; After traversing the connection relationships between the ports of the data providing module and the logic calculation module, the logic calculation module is then traversed and the connection relationships between the ports of the logic calculation module are adjusted.
4. The annotation-based simulation model self-generation method according to claim 1, characterized in that, Also includes: After successfully simulating the XML model file, the XML format model is encapsulated into a JSON format simulation model.
5. The annotation-based simulation model self-generation method according to claim 1, characterized in that, Encapsulating an XML-formatted model into a JSON-formatted simulation model includes: Convert the XML model to a JSON model; The positional relationship of each module in the empty canvas is determined by the connection relationship in the XML file, and the coordinate data of each module is added to the JSON file; The corresponding subsystem modules of the model are located using the position data recorded in the annotation information.
6. The annotation-based simulation model self-generation method according to claim 5, characterized in that, Also includes: After encapsulating the XML format model into a JSON format simulation model, update the model-related data stored in the JSON model file, and refresh and display the corresponding model in the graphical interface.
7. The annotation-based simulation model self-generation method according to claim 1, characterized in that, Also includes: Extract the model-related simulation data from the annotation information in the XML model file, and create a new XML file to store the corresponding simulation data; The attribute names of the data list are stored as global variables in the XML file; If there are attributes with the same name, they are stored according to their corresponding module names.
8. A simulation model self-generation device based on annotation, characterized in that, It includes an annotation information input module, an annotation information analysis module, a model data storage module, and a model data simulation display module; among which, The annotation information input module receives the annotation information of the requirement model input by the user through a graphical interface, and sends the data to the storage device for storage through a communication interface. The annotation information includes the model name and its corresponding model attributes and model coordinates. The annotation information analysis module matches the keywords of the model names in the annotation information with the module names in the model library, and adds the corresponding modules with the same keyword matching to the same module queue, generating multiple module queues. Furthermore, based on the corresponding modules stored in the module queues, the annotation information is divided into multiple corresponding information segments. Through the annotation information analysis module queues, modules are classified by type, and the port connection relationships of the corresponding modules are generated. Modules can be categorized by type as follows: based on input / output port information, modules can be divided into data providing modules, logic calculation modules, and data receiving modules. The process of generating port connection relationships for the corresponding modules includes: traversing the module queue and dividing the user requirement model into n sub-models consisting of a data provision module and a logic calculation module, with the logic calculation module or data receiving module as the separator, where n≥1; analyzing the modules in the module queue, connecting the ports between each sub-model and the logic calculation module, and connecting the ports between each sub-model. The model data storage module obtains the keywords of module attributes in each information segment; matches the keywords of module attributes with the module attributes in the module library, stores the attribute names of the corresponding module attributes that match successfully into the data list; and writes the corresponding module name, module attribute, and port connection relationship into the XML model file. The model data simulation and display module parses and simulates the XML model file.
Citation Information
Patent Citations
Synchronous simulation code generating method based on annotation
CN104199664A