PLM system code generation method based on large language model
Through the PLM system code generation method based on large language model, the requirement entries are analyzed, the product requirement model units are constructed and the code is generated, which solves the problem of improving code quality and development efficiency in the existing technology, and realizes automatic generation and review of high-quality codes , significantly improve development efficiency.
Patent Information
- Application Number
- CN202411114834.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-14
- Publication Date
- 2024-12-10
AI Technical Summary
Existing code generation methods have limitations in improving code quality and development efficiency. Formal methods are costly to learn and manage, while programming assistants can only provide limited intelligent prompts and error checks, which cannot effectively improve code quality.
Using the PLM system code generation method based on large language models, analyzing requirements entries, building product demand model units, and using large language models to build a code generation platform to generate high-quality product code to achieve modularization and reuse driven by demand model and integrate to form a virtual team for code generation for auditing and testing.
It significantly improves code quality and development efficiency, changes the work priorities of R&D personnel, from coding implementation to requirements analysis and code review, reduces low-level errors and improves coding efficiency.
Smart Images

Figure CN119105735A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of software development, and in particular to a PLM system code generation method based on a large language model. Background Art
[0002] At present, there are two main methods for code generation in the industry: formal methods and programming assistants. Formal methods are based on strict mathematical foundations. They use mathematical logic proofs to model, regulate, analyze, reason and verify computer hardware and software systems. They can be automatically converted into application codes using professional software and are used in interlocking systems, vehicle systems and other signal systems. However, formal methods have high learning costs, and there are also difficult problems such as complex model libraries and difficult management. Programming assistant software can assist developers in code writing. It reduces the workload of manual code writing through intelligent automatic completion and suggestion functions, helping developers greatly improve coding efficiency. However, the role of programming assistants is limited to intelligent prompts, error checking and automatic code completion, and the improvement of code quality is limited. Summary of the invention
[0003] The purpose of the present invention is to provide a PLM system code generation method based on a large language model, which can improve code quality and development efficiency.
[0004] To achieve the above object, the present invention is implemented through the following technical solutions:
[0005] A method for generating PLM system code based on a large language model, comprising:
[0006] Analyze PLM system requirements, including requirement item embedding, requirement item text splitting, and requirement item vector database construction;
[0007] Building a product demand model unit based on the PLM system requirements;
[0008] Build a code generation platform based on a large language model;
[0009] The product is described by the product requirement model unit, and the product description is input into the code generation platform to generate product code.
[0010] Preferably, the embedding of requirement items includes: converting items in the requirement items that need to be quantified into corresponding numerical values and vectors.
[0011] Preferably, the requirement item text splitting includes: segmenting the requirement conditions and converting them into requirement units.
[0012] Preferably, the requirement item text splitting includes: performing requirement item text splitting by a document splitter.
[0013] Preferably, the product requirement model building unit includes: building a basic data requirement model and building a dynamic function requirement model.
[0014] Preferably, the code generation method further comprises: reviewing and verifying the product code generated by the code generation platform according to coding specifications and requirements.
[0015] Furthermore, the code generation method further includes: constructing a code library corresponding to the product requirement model unit, which is used as a training sample to train the code generation platform.
[0016] Furthermore, the construction of the code library corresponding to the product requirement model unit includes: collecting verified product codes and existing product codes, so as to construct the code library.
[0017] Preferably, the code generation method further comprises: forming a code generation virtual team for correcting the product code generated by the code generation platform.
[0018] Furthermore, the code generation virtual team includes a R&D personnel model, a virtual programmer model and a virtual tester model, which are responsible for PLM system requirement analysis, coding and testing respectively.
[0019] Furthermore, the R&D personnel model's analysis of PLM system requirements includes: splitting the PLM system requirements into several subtasks, and defining the data structure, functional modules, interfaces, and execution process according to each subtask.
[0020] Furthermore, the virtual programmer model encodes the PLM system including: the virtual programmer model encodes according to given requirements, design splits and data structures, and implementation logic, and corresponds each submodule in the code to the split subtask one by one.
[0021] Furthermore, the virtual tester model tests the PLM system including: the virtual tester model writes a test report for the written code to find out errors therein.
[0022] Furthermore, the code generation method further includes: the virtual programmer model modifies the code according to feedback provided in the test report.
[0023] Furthermore, the code generation method further includes: the virtual tester model evaluates the modified code and confirms that the modified code has passed all tests.
[0024] The present invention has the following beneficial effects:
[0025] The PLM system code generation method based on the large language model of the present invention first analyzes the PLM system requirements, including embedding of requirement items, splitting of requirement item texts and construction of a requirement item vector database; then constructs a product requirement model unit based on the PLM system requirements; and then constructs a code generation platform based on the large language model; finally, describes the product through the product requirement model unit, and inputs the product description into the code generation platform to generate product code.
[0026] Based on the itemization and modularization of PLM system requirements, the present invention constructs a product requirement model unit, uses the requirement model to describe the function, structure and behavior of the software system, builds a code generation platform based on the large language model, automatically generates code through the large language model, and drives the modularization, reuse and integration of the system with the requirement model. The main work of R&D personnel is transformed from coding implementation to PLM requirement analysis and decomposition, requirement model construction and automatic code generation review, ultimately achieving improved code quality and development efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] In order to more clearly illustrate the technical solution of the present invention, the following briefly introduces the drawings required for the description. Obviously, the drawings described below are an embodiment of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work:
[0028] Figure 1 A flowchart of a method for generating PLM system code based on a large language model provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0029] The present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. According to the following description, the advantages and features of the present invention will be clearer. It should be noted that the drawings are in a very simplified form and use non-precise proportions, which are only used to conveniently and clearly assist in explaining the purpose of the embodiments of the present invention. In order to make the purposes, features and advantages of the present invention more obvious and easy to understand, please refer to the accompanying drawings. It should be noted that the structures, proportions, sizes, etc. illustrated in the drawings of this specification are only used to match the contents disclosed in the specification for people familiar with this technology to understand and read, and are not used to limit the limiting conditions for the implementation of the present invention, so they have no technical substantive significance. Any structural modification, change in proportional relationship or adjustment of size, without affecting the effects that the present invention can produce and the purposes that can be achieved, should still fall within the scope of the technical content disclosed by the present invention.
[0030] LLM (LARGE LANGUAGE MODEL), also known as large language model, is an artificial intelligence model designed to understand and generate human language. They are trained on large amounts of text data and can perform a wide range of tasks, including code generation. For those who want to learn programming from scratch, the intelligent recognition and interpretation functions of large language models will become their mentors and friends, helping them to quickly master programming skills. At the same time, large language models can also provide a number of practical functions, such as automatic code generation, code completion, code error correction, etc., which greatly improves development efficiency and code quality.
[0031] Aiming at improving the functions of train automatic control systems and developing new product functions, and aiming at improving the quality and efficiency of code implementation, this embodiment provides a PLM (Product Lifecycle Management) system code generation method based on a large language model.
[0032] like Figure 1 As shown, this embodiment provides a PLM system code generation method based on a large language model, including: analyzing PLM system requirements, including embedding of requirement items, splitting of requirement item texts, and construction of a requirement item vector database; constructing a product requirement model unit based on the PLM system requirements; constructing a code generation platform based on a large language model; describing the product through the product requirement model unit, and inputting the product description into the code generation platform to generate product code.
[0033] This embodiment is aimed at improving the functions of the train automatic control system and developing new product functions. In order to improve the quality and efficiency of code implementation, a signal product requirement model unit is constructed on the basis of the itemization and modularization of PLM system requirements. The requirement model is used to describe the functions, structure and behavior of the software system. The code generation platform of the RBC (Radio Block Center) system is constructed based on the LLM large model. The code is automatically generated through the LLM large model. The modularization, reuse and integration of the system are driven by the requirement model. Test case generation, code testing and improvement are achieved in an intelligent collaborative manner. The main work of R&D personnel is transformed from coding implementation to PLM requirement analysis and decomposition, requirement model construction and automatic code generation review, ultimately achieving improved code quality and development efficiency.
[0034] Specifically, embedding the requirement items in this embodiment includes: converting the items in the requirement items that need to be quantified into corresponding numerical values and vectors.
[0035] Specifically, the requirement item text splitting in this embodiment includes: segmenting the requirement conditions and converting them into requirement units.
[0036] Specifically, the requirement item text splitting in this embodiment includes: dividing the longer requirement conditions into small-segment requirement units.
[0037] Specifically, the requirement item text splitting in this embodiment includes: splitting the requirement item text by a document splitter.
[0038] This embodiment deploys a large commercial model privately and interacts with the existing PLM system by designing a dedicated interface. The dedicated interface is developed based on the LangChain framework, which is an open source framework for building applications based on large language models (LLM). The specific process includes the following:
[0039] 1. Recognition of PLM requirements of RBC system
[0040] (1) Embeddings of RBC system PLM requirements: The items that need to be quantified in the RBC requirements are converted into corresponding numerical values and vectors to facilitate the understanding and processing of the large model. For example, the Taf distance is described as the estimated distance of the train to the front section within 300m (according to the configuration); the adjacent RBC communication timeout is converted to 7 seconds (according to the configuration) when no message from the adjacent RBC is received.
[0041] (2) RBC system PLM requirement item text splitting (Text Splitters): Split the longer requirement conditions in PLM and convert them into small segments of requirement units. For example, a requirement "When the front end of the train is estimated to be in the section or track, if RBC determines that the train route information in the station is normal, the turnout status information is correct, the train signal in the station is open, the section disaster area information on the route is not activated, there is no fault protection area on the route, and there is no safety envelope of other communication trains on the route, RBC will treat the route as available." can be split into:
[0042] 1) The front end of the train is estimated to be in the section;
[0043] 2) The front end of the train is estimated to be on the track;
[0044] 3) The train estimates that the front route information is normal;
[0045] 4) The train estimates that the front approach turnout status information is consistent with the offline configuration;
[0046] 5) The train estimates that the front approach signal is in the open state;
[0047] 6) The train estimates that the disaster areas in various sections on the front approach are not activated;
[0048] 7) The train estimates that there is no fault protection zone in each section on the front approach of the front end;
[0049] 8) The train estimates that there is no safety envelope of other communication trains in each section on the front approach;
[0050] 9) It can be considered that the front route ahead of the train is estimated to be available.
[0051] This process can be done with the help of a document splitter.
[0052] (3) RBC system PLM requirement item vector database (Vectorstores): This embodiment uses a vector database to store and index vector embeddings of the PLM requirement item processing model to understand the meaning and context of text strings, items, and requirement scenarios in the requirements, thereby obtaining more accurate and relevant search results.
[0053] This embodiment uses an offline deployment model to ensure data security.
[0054] As a preferred implementation mode, constructing a product requirement model unit includes: constructing a basic data requirement model and constructing a dynamic function requirement model.
[0055] 2. RBC code generation platform model application and continuous optimization
[0056] After the RBC code generation platform was built, the RBC professional vocabulary and requirements have been initially converted and understood. For RBC field requirements, it is difficult for large models to directly generate corresponding codes and decompose them into general requirements. This step is called requirement model unit construction.
[0057] This embodiment builds an RBC demand model unit based on the PLM modular requirements. It includes basic data models such as lines, stations, routes, signals, and switches, as well as dynamic functional models such as train positioning, driving permit generation, and information packet parsing. Each demand model unit is composed of several general model modules. For example, the line data static demand model unit includes general model modules such as line section units and line section linked lists. In the early stage of platform use, you can enter the general model module description in the LLM large model to get the required implementation code.
[0058] As a preferred implementation, the code generation method further includes: reviewing and verifying the product code generated by the code generation platform according to coding specifications and requirements.
[0059] In this embodiment, after the demand model unit is established, the code generation platform can be input to obtain the code implementation that conforms to the latest C language standard. R&D personnel can review the generated product code, use the platform to perform unit testing, and add sufficiently detailed comments. It is also necessary to confirm the accuracy, completeness and execution efficiency of the code, whether it conforms to the coding specifications, etc.
[0060] As a preferred implementation manner, the code generation method further includes: constructing a code library corresponding to the product requirement model unit, which is used as a training sample to train the code generation platform.
[0061] Specifically, the code library corresponding to the product requirement model building unit in this embodiment includes: collecting verified product codes and existing product codes, so as to build the code library.
[0062] During the use of the platform, we can continuously collect the codes modified and improved by R&D personnel and the existing excellent codes to build the code library corresponding to the PLM demand model. The code generation platform is trained with the PLM demand model unit and code library as training samples to cultivate the platform's cognition of the RBC domain model.
[0063] As a preferred implementation manner, the code generation method further includes: forming a code generation virtual team for correcting the product code generated by the code generation platform.
[0064] Specifically, the code generation virtual team in this embodiment includes a R&D personnel model, a virtual programmer model and a virtual tester model, which are responsible for PLM system requirement analysis, coding and testing respectively.
[0065] Specifically, the PLM system requirement analysis by the R&D personnel model in this embodiment includes: dividing the PLM system requirement into a number of subtasks, and defining a data structure, a functional module, an interface, and an execution process according to each subtask.
[0066] More specifically, in this embodiment, the virtual programmer model encodes the PLM system including: the virtual programmer model encodes according to given requirements, design splitting and data structure and implementation logic, and makes each submodule in the code correspond to the split subtask one by one.
[0067] More specifically, the virtual tester model in this embodiment tests the PLM system including: the virtual tester model writes a test report for the written code to find out errors therein.
[0068] More specifically, the code generation method in this embodiment further includes: the virtual programmer model modifies the code according to the feedback provided in the test report.
[0069] More specifically, the code generation method in this embodiment further includes: the virtual tester model evaluates the modified code and confirms that the modified code has passed all tests.
[0070] 3. RBC code quality continuous improvement method
[0071] Code writing is not only related to the coding stage of the software development process, but also needs to consider other stages that are crucial to product quality assurance (such as testing and verification). This embodiment intends to form an RBC code generation virtual team played by multiple models, including RBC R&D personnel model, RBC virtual programmer model and virtual tester model, which are responsible for RBC demand analysis, coding and testing stages of software development, respectively, to further improve the quality of RBC code generation. Specifically:
[0072] 1) The RBC R&D model conducts a comprehensive analysis of PLM requirements, splits them into several easy-to-solve subtasks, and defines the data structure, functional module, interface, and execution process for each subtask.
[0073] 2) The RBC virtual programmer model implements the code according to the given requirements and the designed splitting and data structure, implementation logic, etc. Each submodule in the implementation code is matched one by one with the split subtask.
[0074] 3) The virtual tester model writes a detailed test report for the implemented code and finds out the errors in it. The virtual tester model points out the errors that may occur in the implemented code, which may cause some test cases to fail.
[0075] 4) The virtual programmer model refines the code based on the feedback provided in the test report. The suggestions in the test report are integrated into the revised code provided by the coder.
[0076] 5) The virtual tester model evaluates the modified code and confirms that there are no problems, and the code generation process ends. In the last interaction, the virtual tester confirms that the modified code has passed all tests and meets the requirements.
[0077] This embodiment significantly improves the quality of code generation by adding the settings of RBC R&D personnel model and virtual tester model in the code generation task. Compared with a single role, a multi-role virtual team can more effectively handle various problems and challenges in the code generation process.
[0078] The following uses the RBC system as an example to illustrate the automatic generation of large model code. The RBC system functions implement the train sequencing, driving permit calculation, fault protection zone setting and other modules, which all involve "determining the position relationship between two points". Two requirements for driving permit calculation are extracted from the PLM system:
[0079] Requirement-423424 needs to determine the positional relationship between the end point of the current driving permit and the starting point of the fault protection zone; Requirement-423396 needs to determine the positional relationship between the end point of the current driving permit and the starting point of the phase separation zone.
[0080] First, the demand recognition module is used to abstract the model unit for comparing the position relationship between two points: CellModel_Compare_Positions_of_Two_Points;
[0081] Secondly, the R&D personnel interact with the code automatic generation platform to describe the context of the model unit in detail:
[0082] 1. Define a segment data structure, which consists of segment number, segment length, upstream segment, and downstream segment. The segment lengths are not equal.
[0083] 2. Use a linked list to represent a route consisting of multiple segments.
[0084] 3. Define a point structure, where the location coordinates consist of the segment and offset.
[0085] 4. Suppose there are two points, which may be on the same section of the line or on different sections.
[0086] 5. A function needs to be implemented in C language to start from a point, traverse the segment list in a given direction, and search for another point. If found, it returns TRUE, otherwise it returns FALSE.
[0087] Then input the model unit description into the code automatic generation platform, and you can get the following code:
[0088] #include<stdio.h>
[0089] #include<stdlib.h>
[0090] #include<math.h>
[0091] / / Segment data structure
[0092] typedefstruct{
[0093] int id; / / segment number
[0094] double length; / / segment length
[0095] intup_segment; / / uplink direction segment
[0096] int down_segment; / / Downward direction segment
[0097] }Segment;
[0098] / / Point data structure
[0099] typedefstruct{
[0100] int segment_id; / / segment
[0101] double offset; / / offset
[0102] }Point;
[0103] / / Link list nodes
[0104] typedef structNode {
[0105] Segment*segment; / / segment pointer
[0106] structNode*next; / / next node pointer
[0107] }Node;
[0108] / / Create a new node
[0109] Node*create_node(Segment*segment){
[0110] Node*new_node=(Node*)malloc(sizeof(Node));
[0111] new_node->segment=segment;
[0112] new_node->next = NULL;
[0113] return new_node;
[0114] }
[0115] / / Connect the two nodes into a linked list
[0116] void connect_nodes(Node*head,Node*tail,Segment*segment){
[0117] Node*new_node=create_node(segment);
[0118] tail->next=new_node;
[0119] tail = new_node;
[0120] }
[0121] / / Starting from a point, along a given direction, loop through the segment list to find another point, and return TRUE if found, otherwise return FALSE.
[0122] int search_point(Node*head,Point start,Point target,int direction){
[0123] int current_segment=start.segment_id;
[0124] intnext_segment=current_segment+direction;
[0125] Node*current=head;
[0126] Node*previous=NULL;
[0127] while(current!=NULL&&next_segment>=0&&next_segment <num_segments){
[0128] if(same_segment(start,target)){
[0129] return true;
[0130] }
[0131] previous=current;
[0132] current = current->next;
[0133] next_segment=current->segment->id;
[0134] }
[0135] if (current == NULL) {
[0136] return false;
[0137] }else{
[0138] return same_segment(start,target);
[0139] }
[0140] }
[0141] Finally, virtual testers and virtual programmers will perform quality improvement operations on the code based on the requirement model unit and the generated code, including checking and replacing variable definitions in the code, and checking whether its logic can meet the requirements of the requirement unit model and whether it complies with coding standards.
[0142] After adopting the RBC code automatic generation platform, the coding efficiency increased by 30%, the coding quality was greatly improved, and the occurrence of low-level errors was avoided.
[0143] This embodiment builds a special code generation tool in the RBC field based on the artificial intelligence model to solve the problem of building products with low cost and high efficiency, which is in line with the trend of enabling enterprise development with intelligence and digitalization.
[0144] This embodiment develops a code generation platform adapted to PLM based on the LLM model. Through tools such as demand modeling and code generation, the software system can be quickly built and implemented, reducing development time and cost, and adapting to the needs of the rapid development of the RBC system. It is advanced in research ideas.
[0145] This embodiment combines the characteristics of PLM system requirement itemization and modularization, and reduces the development cost of RBC system software by building requirement unit models, reuse and integration, and has advanced implementation methods.
[0146] The development of the code generation platform in this embodiment is in line with the trend of rapid development, high security and high availability of the train control system. The system development and architecture design are in line with the advanced system design and development concept, and solves the problem of lack of dedicated code generation tool applications in the field of train operation control.
[0147] Although the content of the present invention has been described in detail through the above preferred embodiments, it should be appreciated that the above description should not be considered as a limitation of the present invention. After reading the above content, it will be apparent to those skilled in the art that various modifications and substitutions of the present invention will occur. Therefore, the protection scope of the present invention should be limited by the appended claims.
Claims
1. A method for generating PLM system code based on a large language model, characterized in that: include: Analyze PLM system requirements, including requirement item embedding, requirement item text splitting, and requirement item vector database construction; Building a product demand model unit based on the PLM system requirements; Build a code generation platform based on a large language model; The product is described by the product requirement model unit, and the product description is input into the code generation platform to generate product code.
2. The code generation method according to claim 1, characterized in that: The embedding of requirement items includes: converting items in the requirement items that need to be quantified into corresponding numerical values and vectors.
3. The code generation method according to claim 1, characterized in that: The requirement item text splitting includes: segmenting the requirement conditions and converting them into requirement units.
4. The code generation method according to claim 1, characterized in that: The requirement item text splitting includes: performing requirement item text splitting by a document splitter.
5. The code generation method according to claim 1, characterized in that: The product requirement model building unit includes: building a basic data requirement model and building a dynamic function requirement model.
6. The code generation method according to claim 1, characterized in that: Also includes: The product code generated by the code generation platform is reviewed and verified according to coding standards and requirements.
7. The code generation method according to claim 6, characterized in that: Also includes: A code library corresponding to the product requirement model unit is constructed and used as a training sample to train the code generation platform.
8. The code generation method according to claim 7, characterized in that: The code library corresponding to the product requirement model unit is constructed by collecting verified product codes and existing product codes, thereby constructing the code library.
9. The code generation method according to claim 1, characterized in that: Also includes: A code generation virtual team is formed to correct the product code generated by the code generation platform.
10. The code generation method according to claim 9, characterized in that: The code generation virtual team includes a R&D personnel model, a virtual programmer model and a virtual tester model, which are responsible for PLM system requirement analysis, coding and testing respectively.
Citation Information
Cited By
Heating ventilation and air conditioning system control code automatic generation method based on large language model
CN121277068A
