Engineering optimization scene automatic modeling and programming method and device
Through a two-way interactive mechanism between a large language model and mathematical description, the system automatically parses, corrects, and generates engineering optimization models, solving the problems of low efficiency and reliance on professional personnel in traditional methods, and achieving efficient optimization modeling and programming.
Patent Information
- Application Number
- CN202511552483.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-28
- Publication Date
- 2026-02-03
AI Technical Summary
Traditional engineering optimization modeling methods are inefficient, rely on professional personnel, and are disconnected from the programming implementation. Large language models fail to form a complete solution, mathematical descriptions are out of touch with business needs, and model corrections rely on manual intervention.
A two-way interaction mechanism between a large language model and mathematical description is constructed. The optimization requirements are analyzed through a pre-trained model, the mathematical description is displayed and users are allowed to modify it, a standardized optimization model is generated, and the built-in solution tool code template automatically generates solution code and verifies it.
It enables intelligent modeling and programming of engineering optimization scenarios, shortens the modeling cycle, improves the matching degree between the model and the requirements and the code executability, and reduces the dependence on professional personnel.
Smart Images

Figure CN121455475A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of engineering optimization modeling, and in particular to an engineering optimization scenario automatic modeling and programming method and device. BACKGROUND
[0002] In the fields of industrial manufacturing, logistics management, etc., the solution of optimization problems such as workshop scheduling, supply chain inventory optimization, etc. usually relies on the process of “problem analysis, mathematical modeling, programming solution”. However, the traditional method has the following shortcomings, mainly embodied in the following aspects.
[0003] High modeling threshold and low efficiency: traditional engineering optimization modeling requires professional personnel to deeply understand business requirements, manually construct objective functions and constraint conditions, and the entire process is time-consuming and prone to model failure due to demand understanding deviation, making it difficult to adapt to the characteristics of rapid iteration of engineering scenarios.
[0004] Mathematical description and business requirements are disconnected: business personnel in engineering scenarios can usually only describe optimization requirements in natural language, such as “minimize the total time of workshop production, and the daily working time of each machine is not more than 8 hours”, while professional modeling personnel need to convert natural language into rigorous mathematical expressions, such as “min T = Σti, s.t. Σtij ≤ 480 minutes”, this conversion process lacks effective interaction mechanism, and is prone to the problem of mismatch between mathematical description and actual business requirements, which needs to be repeatedly communicated and corrected, further prolonging the modeling cycle.
[0005] Model and programming implementation are disconnected: even if the mathematical model is constructed, the developer needs to choose the appropriate solving tool according to the model type, such as linear programming, integer programming, heuristic algorithm, etc., and manually write the solving code. In this process, model parameter adjustment and constraint condition modification need to be modified simultaneously, there is “model change, code reconstruction” repeated labor, and the quality of code writing depends on the experience of the developer, which is prone to syntax errors or logical loopholes, resulting in the model cannot be normally solved.
[0006] Limitations of large language model application: in the prior art, although the large language model can be used for preliminary analysis of natural language requirements, it can only output textual mathematical description or simple code fragments, and cannot realize the closed loop of “requirement analysis - mathematical correction - model generation - code verification”. For example, some tools can convert “minimize cost” to “min C”, but cannot automatically modify the constraint condition according to the user's subsequent supplement “raw material cost does not exceed 1000 yuan”, and cannot generate complete code that can directly call the solver, still need manual intervention to complete the subsequent work, and cannot fully play the intelligent advantage of large language model.
[0007] In summary, the traditional engineering optimization modeling and programming implementation method has the problems of low efficiency, dependence on professional personnel and fragmented process. The existing application of large language models fails to form a full-process solution, and there is an urgent need for a method that can integrate large language models and mathematical description interaction to realize automatic modeling and programming landing. SUMMARY
[0008] Therefore, it is necessary to provide an engineering optimization scenario automatic modeling and programming method and device to effectively solve the technical problem that engineering optimization modeling based on a large language model cannot form a full-process solution.
[0009] The present application provides an engineering optimization scenario automatic modeling and programming method, comprising the following steps: step S1, obtaining an engineering optimization requirement in natural language form input by a user, inputting the engineering optimization requirement into a pre-trained large language model to obtain a requirement classification, engineering entities and a preliminary mathematical description; Step S2, displaying the preliminary mathematical description in the form of natural language combined with mathematical formulas for the user to correct, and automatically checking the logical consistency of the corrected mathematical description using the large language model; Step S3, completing the standardization of the objective function, constraint condition and basic data based on the mathematical description to obtain a standardized optimization model; Step S4, matching an internal code template according to the standardized model used by the optimization model, and filling in parameters to obtain a solving code, and calling a solver to check and test the solving code.
[0010] Preferably, the step S1 is specifically: The large language model is pre-trained using engineering optimization field expectations, the engineering optimization requirement is input into the pre-trained large language model to obtain a requirement classification, engineering entities and a preliminary mathematical description; the requirement classification specifically includes identifying optimization scenario types, optimization target types and constraint condition types, the engineering entities specifically include key business entities and corresponding mathematical model parameters, and the preliminary mathematical description is specifically a semi-structured mathematical expression containing optimization targets, constraint conditions and basic data.
[0011] Preferably, the step S2 is specifically: Based on the requirement classification and engineering entities, an explanation text in natural language form is output to explain the preliminary mathematical description, and the explanation text and the preliminary mathematical description in standard mathematical format are output synchronously; The user corrects the preliminary mathematical description in natural language or mathematical format; The large language model is used to detect conflicts between the revised mathematical description and historical requirements, consistency of the optimization direction of the objective function and the constraint condition, and prompt the user to confirm, to obtain the final mathematical description.
[0012] Preferably, the standardization of the objective function in step S3 is specifically: The target type is labeled before the mathematical expression of the objective function, the types, definitions, and data sources of the variables and parameters in the objective function are defined, and the expression of the objective function is standardized in a unified format.
[0013] Preferably, the standardization of the constraint condition in step S3 is specifically: The constraint condition is divided into different types of constraints, including time constraints, resource constraints, and logical constraints; the constraint usage range is specified for each type of constraint; the expressions of various types of constraints are standardized in a unified format; finally, the large language model is used to check the logical conflicts between all types of constraint conditions, and guide the user to modify.
[0014] Preferably, the standardization of the basic data in step S3 specifically includes: The large language model is used to divide the basic data into different types of data, including set data, numerical data, table data, and time series data; The original data input by the user is mapped to the model parameters, and the user is prompted to supplement the missing data; Each type of data is converted into a code-callable format to complete the standardization of the data format.
[0015] Preferably, in step S4, the standardized model matching the built-in code template is matched according to the optimization model, and the parameters are filled to obtain the solving code, specifically: According to the optimization type and the parameters of the optimization model, the solving tool template corresponding to the optimization model is matched from the built-in code template library, the objective function, the constraint condition, and the basic data parameters are automatically filled into the solving tool template, and the complete solving code is generated.
[0016] Preferably, in step S4, the verification module is used to call the solver to check and test the solving code, specifically: The interpreter is called to detect syntax errors in the solving code; the solving code is run with example data to verify whether the solver returns an optimal solution; the large language model is used to check whether the running result meets all the constraint conditions.
[0017] Preferably, the engineering optimization scenario corresponding to the engineering optimization requirement specifically includes industrial production scheduling, logistics path planning, and resource allocation optimization, and also includes a dynamic engineering optimization scenario in which the optimization target or constraint condition needs to be adjusted.
[0018] The application further provides an engineering optimization scenario automatic modeling and programming device, comprising a memory and a processor, wherein the memory stores a computer program, and the computer program is executed by the processor to implement the engineering optimization scenario automatic modeling and programming method.
[0019] Compared with the prior art, the application has the beneficial effects that: the application constructs a bidirectional interaction mechanism of a large language model and mathematical description, and realizes intelligent modeling and programming automatic generation of an engineering optimization scenario through multiple rounds of iteration. First, a large language model with mathematical logic understanding ability is selected to understand and analyze optimization requirements, and the analysis accuracy is improved through pre-training; the analysis results are displayed in the form of mathematical formulas supplemented by natural language explanations, and the user is allowed to directly modify the generated mathematical expressions; an optimization model is generated based on the modified mathematical expressions to complete modeling; a code template library of mainstream solving tools is built in, and the generated standardized model is automatically matched with a template and filled with parameters to realize code automatic generation; finally, the verification module performs syntax checking and small-scale data testing on the generated code by calling a solver to ensure the code executability. The whole forms a closed-loop process of "input, analysis, correction, generation, and verification". BRIEF DESCRIPTION OF DRAWINGS
[0020] The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiments of the application and serve to explain the principles of the application. In the drawings: Fig. 1 is a flowchart of an embodiment of the engineering optimization scenario automatic modeling and programming method provided by the application; Figure 2 Fig. 2 is a functional module diagram of the embodiment of the engineering optimization scenario automatic modeling and programming method provided by the application; Figure 3 Fig. 3 is a work flow diagram of the embodiment of the engineering optimization scenario automatic modeling and programming method provided by the application. DETAILED DESCRIPTION
[0021] The preferred embodiments of the application are specifically described below with reference to the accompanying drawings, wherein the drawings constitute a part of this application, and together with the embodiments of the application serve to explain the principles of the application, but are not used to limit the scope of the application.
[0022] Embodiment 1 Referring to Figure 1 The engineering optimization scenario automatic modeling and programming method in the embodiment specifically comprises the following steps: Step S1, obtaining an engineering optimization requirement in natural language form input by a user, inputting the engineering optimization requirement into a pre-trained large language model to obtain a requirement classification, engineering entities, and a preliminary mathematical description; Step S2, displaying the preliminary mathematical description in a form combining natural language and mathematical formulae for the user to modify, and automatically checking the logical consistency of the modified mathematical description by using the large language model; Step S3, completing standardization of a target function, constraint conditions, and basic data based on the mathematical description to obtain a standardized optimization model; Step S4, matching a built-in code template according to a standardized model adopted by the optimization model, and filling in parameters to obtain a solving code, and calling a solver to perform inspection and testing on the solving code.
[0023] The method aims to solve the technical problems of low modeling efficiency, high dependence on professional personnel, and disconnection between models and programming implementation in a traditional engineering optimization scenario. The method builds a whole-process system of “natural language requirement analysis, interactive mathematical description modification, optimization model automatic generation, code mapping and verification”, utilizes the complementary advantages of semantic understanding ability of a large language model and precision of mathematical description, realizes intelligent modeling of a target function, constraint conditions, and basic data in an engineering optimization scenario, and automatically generates an optimization solving code that can be directly run.
[0024] As shown in Figure 2 The whole process is divided into five modules: a natural language requirement input module, an LLM requirement analysis and preliminary modeling module, an interactive mathematical description modification module, an optimization model standardization generation module, and a solving code automatic mapping and verification module, which form a closed-loop process of “input, analysis, modification, generation, and verification” in cooperation. The LLM module selects a large language model with mathematical logic understanding ability, and through pre-training of engineering optimization field corpus such as a mathematical model library related to workshop scheduling and logistics optimization and business requirement documents, the requirement analysis accuracy is improved. The interactive mathematical description modification module supports standard mathematical format input such as LaTeX and MathML, and allows the user to directly modify the mathematical expression generated by the LLM. The code mapping module has built-in code template libraries of mainstream solving tools such as Gurobi, CPLEX, Python pulp, and Matlab Optimization Toolbox, can automatically match templates and fill in parameters according to the generated standardized model, and realizes code generation. The verification module performs syntax checking and small-scale data testing on the generated code by calling a solver to ensure the code executability.
[0025] The method can effectively shorten the modeling cycle of engineering optimization scenarios, reduce the dependence on professional optimization personnel, and improve the matching degree of the model and actual demand and the executability of the code, providing an efficient solution for the rapid landing of engineering optimization problems.
[0026] Reference Figure 3 The following will be specifically described.
[0027] Step S1: natural language requirement input and LLM preliminary analysis Step S11, requirement input: the user inputs the engineering optimization requirement in the form of natural language through the interactive interface. Structured input is supported, such as inputting "optimization goal: minimize total production time in workshop; constraint condition: 1. Each machine single-day working time ≤ 8 hours; 2. Product A needs to be produced before product B; basic data: machine quantity 3, product variety 5, single product production time table see appendix". Unstructured input is also supported, such as inputting "we have 3 machines in the workshop, want to produce 5 products, want to make the total production time shortest, and each machine can't work more than 8 hours a day, in addition, product A must be done before product B, and the production time of each product on different machines is different, the data has been uploaded".
[0028] Step S12, LLM preliminary analysis: after receiving the requirement, the LLM completes three tasks through the pre-training knowledge in the field, which are requirement classification, entity extraction and preliminary mathematical description generation.
[0029] Requirement classification includes: identifying optimization scenario types such as workshop scheduling, resource allocation; optimization goal types such as minimizing cost, maximizing efficiency; constraint condition types such as time constraint, resource constraint.
[0030] Entity extraction includes: extracting key business entities such as "3 machines", "5 products", "8 hours", and mapping them to parameters in the mathematical model, such as setting machine set , product set P , machine maximum working time minutes.
[0031] Preliminary mathematical description generation: convert natural language requirements into semi-structured mathematical expressions, for example, for workshop scheduling requirements, the LLM generates the following preliminary mathematical description: Optimization goal: , is the total production time, is the time spent by machine to produce product , is a 0-1 variable representing whether machine produces product ; Constraint 1: , Total time spent on each machine does not exceed 8 hours; Constraint 2: , , and the end time of product is ≤ the start time of product , product is produced before product ; Base data: , P , The data is derived from user-uploaded attachments, and the user needs to confirm the data mapping relationship.
[0032] Step S2: Interactive correction of mathematical description In traditional methods, the mathematical description generated by LLM cannot be directly corrected. This step solves this problem through a two-way interactive mechanism. The specific process is as follows: Mathematical description visualization: The preliminary mathematical description generated by LLM is displayed to the user in the form of "natural language explanation + standard mathematical format, such as LaTeX or MathML", for example: Natural language explanation: "The objective function is 'total production time = the sum of the time spent on each product by each machine and the identification of whether it is produced or not', i.e., minimize the total production time", plus mathematical format: After generating the preliminary mathematical description, the user can correct the mathematical description in two ways: natural language or mathematical format.
[0033] Natural language correction: If the user thinks the objective function is wrong, such as "not total production time, but total waiting time", directly input the natural language. After LLM receives the correction requirement, it automatically updates the mathematical description to , is the total waiting time, is the waiting time of machine producing product , and the natural language explanation is updated synchronously; Mathematical format direct modification: If the user has a certain mathematical foundation, they can directly modify the expression in the LaTeX editor, such as changing the constraint condition "≤480" to "≤540". The system detects the modified content in real time and generates the modified natural language explanation through LLM, such as "adjusting the daily working hours of each machine to 9 hours", to ensure that the user confirms that the modification intention is correct.
[0034] Logical consistency check: After each revision, LLM automatically checks the logical consistency of the mathematical description, for example: if the user deletes the constraint "Product A is produced before Product B" and adds "Product B is produced before Product A", LLM will prompt "The current constraint condition conflicts with the historical requirement 'Product A is produced before Product B', please confirm whether to keep the new constraint"; if the user modifies the objective function to "maximize production", but the constraint condition is still "minimize time", LLM will prompt "The objective function and the constraint condition optimization direction are inconsistent, please check the requirement description".
[0035] Step S3: After interactive revision, the mathematical description is converted into a standardized form to obtain a standardized optimization model. The standardization of mathematical description mainly includes three parts: objective function standardization, constraint condition standardization, and basic data standardization.
[0036] Step S31, objective function standardization description After interactive revision, LLM converts the objective function into a standardized mathematical form, clearly defines the target type, variable definition, and parameter source. Specifically, the target type of the mathematical expression is marked in front of the mathematical expression, such as "[minimize]" "[maximize]"; the variable and parameter source definition is listed in a table form, including decision variables and intermediate variables, as shown in Table 1: Table 1, variable and parameter source definition Finally, based on the above expression of the objective function, the standardization is performed: the form of "target variable = mathematical operation" is adopted, for example: [minimize] , to ensure that the subsequent code mapping module can automatically recognize the structure of the objective function.
[0037] Step S32, constraint condition standardization description The standardization of constraint conditions needs to clearly define the constraint type, including equality constraints and inequality constraints, clearly define the applicable scope, including global constraints and local constraints, and clearly define the logical relationship.
[0038] LLM constraint classification: According to the revised mathematical description, LLM classifies the constraint conditions into time constraints, resource constraints, and logical constraints, for example, "each machine single-day working time ≤ 8 hours" is classified as "time constraint, machine working time constraint"; Constraint range annotation: the applicable scope of the constraint is clearly defined by subscript or set symbol, for example, " indicates that the constraint applies to all machines, and " indicates that the constraint only applies to product ; Finally, based on constraint classification and constraint range labeling, the expressions for constraint conditions are standardized: a unified format of "left-hand expression, constraint symbol, right-hand value" is adopted, for example: Time constraints: ; Logical constraints: ; For products Production end time, For products Production start time; Secondary conflict detection verification: LLM re-verifies the logical conflicts between all constraints. For example, if there is a conflict such as "Machine 1 produces products", it will check for conflicts in the logic between all constraints. The system will alert the user to the conflict between the constraints “Machine 1 does not produce any products” and “Machine 1 does not produce any products”.
[0039] Step S33, Standardized Description of Relevant Basic Data Basic data is the core input for model solving. This step uses LLM to interact with users to standardize and organize the data, specifically including two parts: data type identification and data mapping and completion.
[0040] Data type identification: Based on the requirements analysis results, LLM identifies basic data types, such as set data, numerical data, tabular data, and time-series data. For example, "number of machines: 3" is classified as "set data". The "Time Consumption Table" is categorized under "Table Data"; Data Mapping and Completion: LLM automatically maps user-inputted or uploaded raw data to model parameters. For example, it maps the time "20 minutes" for "Machine 1 - Product 1" in a user-uploaded Excel sheet to "...". If data is missing, LLM will prompt the user to supplement it, such as prompting the user that "Production time for Product 3 is not filled in," or providing suggestions for completion based on historical data, such as suggesting that "Product 3 has a similar process to Product 2, and it is recommended to refer to..." "Value"; Data format standardization: Transforming basic data into a code-callable format, such as converting tabular data into data fields, like... Convert collection data into a list, such as This ensures that the code can be directly called during subsequent code generation.
[0041] Step S4: Automatic mapping and verification of the solution code Code automatic mapping: the code mapping module matches the template of the corresponding solving tool from the built-in code template library according to the optimization type of the standardized model, such as integer programming, and the parameters, including the objective function, constraint conditions, and basic data, fills in the parameters in the template automatically to generate complete solving code, including problem instance creation, variable definition, objective function addition, constraint condition addition, solver calling, and result output module; After the code is automatically generated, code verification is performed. First, syntax checking is performed: the corresponding programming language interpreter, such as Python, is called to detect whether there are syntax errors in the code, such as undefined variables, unmatched parentheses, and if there are errors, step S2 is returned, and the user is prompted to correct the mathematical description. After the syntax check is correct, small-scale data testing is performed: the code is run with example data, such as the number of machine products, time-consuming data, etc. input in step S1, to verify whether the solver returns the optimal solution "Optimal", and the LLM automatically checks whether the result meets all the constraint conditions, such as machine time limit, production order requirement, etc., to ensure that the code is executable and the model meets the requirements.
[0042] The specific steps of the embodiment are described in detail above, and the application details of the embodiment are specifically described in the following specific scenarios.
[0043] Taking the workshop scheduling scenario as an example, a certain mechanical processing plant has 3 machines , needs to produce 5 products , and the optimization goal is to minimize the total production time, and the constraint conditions include: 1. Each machine works no more than 8 hours a day, i.e. 480 minutes; 2. Product must be produced before ; 3. Machine can only produce , , and cannot produce . The implementation process of the present application is described in detail in the following scenario: Step S1: natural language requirement input, LLM preliminary analysis The user inputs the unstructured requirement through the system interaction interface: "We have 3 machines in our factory, which are , , , and we want to produce to five products. We want to make the total production time as short as possible, and each machine can work no more than 8 hours a day, must be produced before , and in addition can only produce and , cannot produce other products. I have uploaded a table of the time consumption of each machine for each product in Excel, with the machine number in the first column, the product number in the first row, and the time consumption in minutes in the middle. At the same time, the user uploads the basic data Excel table, part of the data as follows: The system calls the pre-trained workshop scheduling LLM to complete entity extraction and preliminary mathematical description generation.
[0044] Entity extraction: LLM extracts key entities from the requirements and maps them to mathematical parameters. The results are as follows: Machine set: , with identifier corresponding to the actual machine; Product set: ; Maximum machine working time: H = 480 minutes, corresponding to 8 hours; Machine production limit: production product subset , , production product subset ; Time consumption parameters: , taken from the user-uploaded Excel table, such as , , etc.
[0045] Preliminary mathematical description generation: LLM generates a semi-structured mathematical description by combining the characteristics of the workshop scheduling scenario. The semi-structured mathematical description is as follows: Optimization goal: , is the total production time, taking the maximum value of all machine working times, consistent with the characteristics of the flow shop scheduling "bottleneck machine determines the total time"; is a 0-1 decision variable, indicates that machine produces product , otherwise; Constraint 1, machine production limit: , does not produce ; Constraint 2, machine time limit: ; Constraint 3, product production uniqueness: Each product is produced by only one machine; Constraint 4, production order restriction: Start time of production of product , End time of production of product , End time is not later than start time; Base data: Refer to Excel mapping table for values, Parameters are defined as above.
[0046] Step S2: Mathematical description of interactive correction Visualization and user feedback: The system displays the preliminary mathematical description in "natural language + LaTeX". The user finds that the objective function has a bias and feedbacks: "The total production time is not the maximum value of machine time, but the maximum value of the production end time of all products, because products may be produced in sequence on different machines."
[0047] LLM correction and verification: After receiving the feedback, the LLM adjusts the logic of the objective function.
[0048] New variables: , 0-1 variable represents that product is produced on machine and is located before product ; Correct the objective function: , is the final production end time of product ; Add constraints, production sequence within machine: On the same machine, product can only be produced after the previous product ends; Logical verification: The LLM automatically verifies the modified model and prompts "New variable needs to add the constraint 'product production sequence within each machine is unique'", and automatically adds: , to avoid product conflict between previous and subsequent sequences, and the user confirms that the correction is correct.
[0049] Step S3: Standardized model generation Objective function standardization Constraint condition standardization Base data standardization Convert Excel data to Python callable format: #Machines and Products Collection machines = ["M1", "M2", "M3"] products = ["P1", "P2", "P3", "P4", "P5"] #Production time parameters ( ) processing_time = { "M1": {"P1": 20, "P2": 25, "P3": 0, "P4": 0, "P5": 0}, # 0 indicates no production. "M2": {"P1": 18, "P2": 22, "P3": 30, "P4": 28, "P5": 26}, "M3": {"P1": 22, "P2": 24, "P3": 29, "P4": 31, "P5": 27} } max_work_time = 480 # Maximum machine working time (minutes) Step S4: Automatic mapping and verification of the solution code Based on the standardized model, the code mapping module selects the "Python + PuLP + Gurobi Solver" template and automatically generates the following code: import pulp as pl # 1. Create a problem instance prob = pl.LpProblem("Workshop_Scheduling_Optimization",pl.LpMinimize) # 2. Define variables x = pl.LpVariable.dicts("x", (machines, products), cat=pl.LpBinary) #x_ij y = pl.LpVariable.dicts("y", (machines, products, products), cat=pl.LpBinary) # y_ijk S = pl.LpVariable.dicts("S", products, lowBound=0) # Start time E = pl.LpVariable.dicts("E", products, lowBound=0) # End time T = pl.LpVariable("Total_Time", lowBound=0) # Total production time # 3. Add the objective function prob += T, "Minimize_Total_Production_Time" prob += T >= pl.lpSum(E[j] for j in products) # T is the maximum end time of all products # 4. Add constraints # 4.1 Production restriction (M1 does not produce P3-P5) for j in ["P3", "P4", "P5"]: prob += x["M1"][j] == 0, f"M1_No_Produce_{j}" # 4.2 Machine time limit for i in machines: prob += pl.lpSum(processing_time[i][j] * x[i][j] for j in products) <= max_work_time, f"Machine_{i}_Time_Limit" # 4.3 Product production uniqueness for j in products: prob += pl.lpSum(x[i][j] for i in machines) == 1, f"Product_{j}_Unique_Producer" # 4.4 Define product end time (E_j = S_j + production time) for j in products: prob += E[j] == S[j] + pl.lpSum(processing_time[i][j] * x[i][j] for i in machines), f"Product_{j}_End_Time" # 4.5 P2 precedes P4 production prob += E["P2"] <= S["P4"], "P2_Before_P4" # 4.6 Machine In-Process Sequence Constraints for i in machines: for j in products: for k in products: if j!= k: # If j is produced before k on the same machine, k should not start until j is finished prob += E[j] + processing_time[i][k] * x[i][k] * y[i][j][k] <= S[k], f"Machine_{i}_Order_{j}_{k}" # Avoid product k from having both pre and post sequence conflicts prob += pl.lpSum(y[i][j][k] for j in products if j!=k) + pl.lpSum(y[i][k][l] for l in products if l!= k) <= 1, f"Machine_{i}_No_Conflict_{k}" # 5. Solve and Output Results prob.solve(pl.GUROBI(msg=0)) # Call Gurobi solver with log output off print("Solving Status:", pl.LpStatus[prob.status]) print("Optimal Total Production Time:", pl.value(T), "minutes") # Output product-machine assignment results for j in products: for i in machines: if pl.value(x[i][j]) == 1: print(f"Product {j} produced by machine {i}, start time: {pl.value(S[j]):.0f}, end time: {pl.value(E[j]):.0f}") Code verification includes syntax checking and small-scale data testing.
[0050] Syntax check: System calls Python interpreter to detect code without syntax errors. Small-scale data test: Run the code with sample data on 3 machines, 5 products, the solver returns the "Optimal" solution, the optimal total production time is 105 minutes, and the product allocation results are as follows: Product P1: M2 production (start 0, end 18); Product P2: M1 production (start 0, end 25); Product P3: M3 production (start 0, end 29); Product P4: M2 production (start 18, end 46); Product P5: M3 production (start 29, end 56); Constraint satisfaction check: LLM automatically checks whether the result satisfies all constraints, such as M1 not producing P3-P5, M2 total time 18+28=46≤480, P2 end time 25≤P4 start time 18, etc., and confirms that there is no constraint violation.
[0051] Example two The embodiment provides an engineering optimization scenario automatic modeling and programming device, comprising a memory and a processor, the memory is stored with a computer program, and the computer program is executed by the processor to realize the engineering optimization scenario automatic modeling and programming method in the embodiment one.
[0052] The engineering optimization scenario automatic modeling and programming device provided in the embodiment is used for realizing the engineering optimization scenario automatic modeling and programming method, therefore, the engineering optimization scenario automatic modeling and programming device also has the technical effects of the engineering optimization scenario automatic modeling and programming method, and details are not repeated here.
[0053] The above is only the preferred embodiment of the present application, but the protection scope of the present application is not limited to this, any person skilled in the art can easily think of changes or replacements within the technical range disclosed in the present application, which should be covered in the present application.
Claims
1. An engineering optimization scenario auto-modeling and programming method, characterized in that, The method comprises the following steps: Step S1, obtaining an engineering optimization requirement in natural language input by a user, inputting the engineering optimization requirement into a pre-trained large language model to obtain a requirement classification, engineering entities and a preliminary mathematical description; Step S2, displaying the preliminary mathematical description in the form of natural language combined with mathematical formulae for the user to correct, and automatically checking the logical consistency of the corrected mathematical description by using the large language model; Step S3, completing the standardization of a target function, constraint conditions and basic data based on the mathematical description to obtain a standardized optimization model; Step S4, matching an internal code template according to the standardized model adopted by the optimization model, filling in parameters to obtain a solving code, and calling a solver to test the solving code.
2. The method of claim 1, wherein, The step S1 specifically comprises: The large language model is pre-trained by using engineering optimization field expectations, the engineering optimization requirement is input into the pre-trained large language model to obtain a requirement classification, engineering entities and a preliminary mathematical description; the requirement classification specifically comprises identifying optimization scene types, optimization target types and constraint condition types, the engineering entities specifically comprise key business entities and corresponding mathematical model parameters, and the preliminary mathematical description specifically comprises a semi-structured mathematical expression containing optimization targets, constraint conditions and basic data.
3. The method of claim 1, wherein, The step S2 specifically comprises: Based on the requirement classification and engineering entities, an explanation text in natural language form is output to explain the preliminary mathematical description, and the explanation text and the preliminary mathematical description in standard mathematical format are synchronously output; The user corrects the preliminary mathematical description in the form of natural language or mathematical format; The large language model is used to detect the conflict of the corrected mathematical description with historical requirements, the consistency of the optimization direction of the target function and the constraint conditions, and the user is prompted to confirm, to obtain a final mathematical description.
4. The method of claim 1, wherein, The standardization of the target function in the step S3 specifically comprises: The target type is labeled in front of the mathematical expression of the target function, the types, definitions and data sources of variables and parameters in the target function are defined, and the expression of the target function is standardized in a unified format.
5. The method of claim 1, wherein, The standardization of the constraint conditions in the step S3 specifically comprises: The constraint conditions are decomposed into different types of constraints, including time constraints, resource constraints and logical constraints; the constraint usage range is specified for each type of constraint; the expressions of various types of constraints are standardized in a unified format; finally, the large language model is used to check the logical conflicts among all types of constraint conditions and guide the user to correct.
6. The method of claim 1, wherein, The standardization of the basic data in the step S3 specifically comprises: The large language model is used to divide the basic data into different types of data, including set data, numerical data, table data and time series data; The original data input by the user is mapped to model parameters, and the user is prompted to supplement missing data; Each type of data is converted into a code-callable format to complete the standardization of the data format.
7. The method of claim 1, wherein, The standardization model adopted in the step S4 according to the optimization model matches the built-in code template and fills in the parameters to obtain the solving code, specifically: According to the optimization type and the parameters of the optimization model, a solving tool template corresponding to the optimization model is matched from a built-in code template library, the objective function, the constraint condition and the basic data parameters are automatically filled into the solving tool template, and a complete solving code is generated.
8. The method of claim 1, wherein, In the step S4, a verification module is used to call a solver to check and test the solving code, specifically: The interpreter is called to detect the syntax error of the solving code; the solving code is run with example data to verify whether the solver returns the optimal solution; and the large language model is used to check whether the running result meets all the constraint conditions.
9. The method of claim 1, wherein, The engineering optimization scenarios corresponding to the engineering optimization requirements specifically include industrial production scheduling, logistics path planning and resource allocation optimization, and also include dynamic engineering optimization scenarios in which the optimization target or the constraint condition needs to be adjusted.
10. An engineering optimization scenario auto-modeling and programming apparatus, characterized by, The computer program is stored on the memory and is executed by the processor to implement the engineering optimization scenario automatic modeling and programming method according to any one of claims 1-9.