CN113918133B - Optimal control problem solver construction method and system - Google Patents

Optimal control problem solver construction method and system Download PDF

Info

Publication number
CN113918133B
CN113918133B CN202111524158.5A CN202111524158A CN113918133B CN 113918133 B CN113918133 B CN 113918133B CN 202111524158 A CN202111524158 A CN 202111524158A CN 113918133 B CN113918133 B CN 113918133B
Authority
CN
China
Prior art keywords
function
model
optimal control
code
control problem
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202111524158.5A
Other languages
Chinese (zh)
Other versions
CN113918133A (en
Inventor
周冲
史世杰
芦子豪
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuhan Dingyuan Tongli Technology Co ltd
Original Assignee
Wuhan Dingyuan Tongli Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wuhan Dingyuan Tongli Technology Co ltd filed Critical Wuhan Dingyuan Tongli Technology Co ltd
Priority to CN202111524158.5A priority Critical patent/CN113918133B/en
Publication of CN113918133A publication Critical patent/CN113918133A/en
Application granted granted Critical
Publication of CN113918133B publication Critical patent/CN113918133B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/20Software design
    • G06F8/24Object-oriented
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/34Graphical or visual programming
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/35Creation or generation of source code model driven
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation

Abstract

The invention relates to the technical field of electromechanical coupling system simulation, and discloses a construction method and a system of an optimal control problem solver. The optimal control problem solver construction method comprises the following steps: obtaining a model intermediate code of a controlled object; acquiring a template code of an optimal control problem, and performing instantiation processing on the template code to obtain a model code of the current optimal control problem; performing code combination on the model intermediate code and the model code to obtain a solving code for calculating the optimal solution of the current optimal control problem; and compiling the solving code to obtain an optimal control problem solver. The invention realizes the integration of modeling and solving of the optimal control problem in the simulation process of the electromechanical coupling system, improves the automation degree of the simulation of the electromechanical coupling system, and simultaneously improves the simulation efficiency and the simulation flexibility of the electromechanical coupling system.

Description

Optimal control problem solver construction method and system
Technical Field
The invention relates to the technical field of electromechanical coupling system simulation, in particular to a construction method and a system of an optimal control problem solver.
Background
The electromechanical coupling system is a modern mechanical system which fully utilizes the information processing and control functions of an electronic computer and the characteristics of controllable driving elements, and realizes the automation and the intellectualization of the mechanical system. The electromechanical coupling system needs to be designed, simulated and debugged using an automatic control technology. The automatic control means that a certain working state or parameter (controlled quantity) of a machine, equipment or a production process (controlled system) automatically operates according to a predetermined rule by using an additional device or device (controller) without direct participation of a person. The modern control theory is a control theory established on the basis of a state space method, is based on a state variable concept, utilizes a modern mathematical method and a computer analysis and comprehensive complex control system, and is a main component of an automatic control theory. One of the centers of modern control theory is optimal control theory. The optimal control means that under a given constraint condition, a control is sought, so that the performance index of a given dynamic system reaches the optimal value within a certain period of time, and the optimal control is widely applied to the fields of space technology, system engineering, economic management, population control and the like.
The optimal control of the electromechanical coupling system means that the electromechanical coupling system (such as an automobile and an industrial robot) seeks a control state under given constraint conditions, so that the performance index of the system reaches the optimal value within a certain period of time. In order to solve the optimal control problem of the electromechanical coupling system, a motion equation describing a controlled motion process of the electromechanical coupling system needs to be established, a value range of a control variable is given, an initial state and a target state of the motion process are specified, and a performance index for evaluating the quality of the motion process of the electromechanical coupling system is specified. In the existing simulation technology, the solution of the optimal control problem of the electromechanical coupling system is generally divided into two steps: firstly, mathematical equation description is carried out on an electromechanical coupling system to be simulated to construct physical modeling, and a mathematical model of a corresponding optimal control problem is generated based on the constructed physical model; and secondly, solving the generated mathematical model of the optimal control problem by applying a mathematical method, thereby realizing the optimal control simulation of the electromechanical coupling system. The physical modeling and the problem solving of the electromechanical coupling system are generally carried out separately and independently, so that the constructed physical model cannot be directly applied to the construction and the solving of the optimal control problem, the reason for the problem is that the physical models constructed by using different physical modeling tools are incompatible with each other, and the mathematical theories adopted by different physical modeling tools are greatly different, so that the generated mathematical analytic expressions are different and cannot be reused, and therefore, the solving codes for realizing the optimal control problem need to be independently written for different physical models, the automation degree of the simulation of the electromechanical coupling system is greatly hindered, and the simulation efficiency and the simulation flexibility of the electromechanical coupling system are also reduced.
Disclosure of Invention
The invention mainly aims to provide a construction method and a system of an optimal control problem solver, and aims to solve the technical problem that in the existing electromechanical coupling system simulation technology, a constructed physical model cannot be directly applied to construction and solution of an optimal control problem, so that the automation degree of the electromechanical coupling system simulation is reduced.
The invention provides a method for constructing an optimal control problem solver, which comprises the following steps:
building a physical model of the electromechanical coupling system by using an object-oriented modeling tool, wherein the physical model is composed of a plurality of equations for describing the dynamic characteristics of the electromechanical coupling system;
partitioning each equation in the physical model to obtain a plurality of equation regions, and writing the content of each equation region into a corresponding preset function respectively to obtain a model intermediate code of the electromechanical coupling system, wherein the model intermediate code comprises a plurality of function functions;
acquiring a template code of an optimal control problem, and instantiating the template code by using an interactive panel to obtain a mathematical model code of the optimal control problem of the electromechanical coupling system;
carrying out solving code configuration by utilizing an interactive panel, and filling a function in the model intermediate code into the mathematical model code to obtain a solving code for calculating the optimal solution of the optimal control problem;
and compiling the solving code to obtain an optimal control problem solver of the electromechanical coupling system.
Optionally, in a first implementation manner of the first aspect of the invention,
the equation area includes: a constant area, a parameter area, a variable area, a dynamic calculation area and a function area; the constant area, the parameter area and the variable area are used for representing the definition and initialization of constants, parameters and variables in the physical model; the dynamic calculation region is used for representing a state variable derivation function and a local variable calculation function in the physical model; the function area is used for representing built-in functions or self-defined functions in the physical model.
Optionally, in a second implementation manner of the first aspect of the present invention, the partitioning each equation in the physical model to obtain a plurality of equation regions includes:
based on the constant declaration characteristics in the physical model, dividing the definition and the initialization content of the constant from each course respectively and writing the constant into the constant area;
based on the parameter declaration characteristics in the physical model, dividing parameter definition and initialization content from each equation in the physical model respectively and writing the parameter definition and initialization content into the parameter area;
based on variable declaration characteristics in the physical model, dividing definition and initialization content of variables from each equation in the physical model respectively and writing the definition and initialization content into the variable area;
based on the variable dependency relationship in the physical model, dividing a state variable derivation function and a local variable calculation function from each equation in the physical model respectively and writing the state variable derivation function and the local variable calculation function into the dynamic calculation area;
and based on the mathematical function identification in the physical model, respectively dividing built-in functions or self-defined functions from all equations in the physical model and writing the functions into the function area.
Optionally, in a third implementation manner of the first aspect of the present invention, the model intermediate code includes the following functional functions:
the variable definition block is used for storing the contents of the constant region, the parameter region and the variable region;
the variable setting function provides a function calling interface and is used for setting the variable in the physical model;
the variable obtaining function provides a function calling interface and is used for obtaining the variable in the physical model;
a model instantiation function for instantiating a model object of the physical model and providing a control handle;
a model initialization function for setting initial values of variables in the physical model;
a model state derivative function for calculating a derivative of a state variable in the dynamic calculation region;
an event processing function for processing a target event occurring in the dynamic calculation region;
and the calculation function is used for calculating the local variables in the dynamic calculation area and the built-in function or the self-defined function of the function area.
Optionally, in a fourth implementation manner of the first aspect of the present invention, the writing the content of each equation region into a corresponding preset function respectively to obtain a model intermediate code of the electromechanical coupling system includes:
respectively writing the definition and initialization content of the constant area, the definition and initialization content of the parameter area, and the definition and initialization content of the variable area into the variable definition block;
writing the state variable derivative function of the dynamic calculation region into the model state derivative function; and writing the local variable calculation function of the dynamic calculation region, the built-in function of the function region or the self-defined function into the calculation function to obtain a model intermediate code of the electromechanical coupling system.
Optionally, in a fifth implementation manner of the first aspect of the present invention, the mathematical model code includes: the system comprises a main function and a configuration function, wherein the main function is used for calling the configuration function when solving an optimal control problem; the configuration function is used for realizing the optimal control problem solving of the electromechanical coupling system based on the calling of the main function;
wherein the configuration function comprises: the performance index function is used for evaluating the performance index of the optimal control problem solution; the state constraint function is used for constraining the state of the optimal control problem solution; the path constraint function is used for constraining the path for solving the optimal control problem; the event function is used for constraining the events of the optimal control problem solution; and the connection function is used for constraining the multi-stage connection of the optimal control problem solution.
Optionally, in a sixth implementation manner of the first aspect of the present invention, the instantiating the template code by using an interactive panel to obtain a mathematical model code of an optimal control problem of the electromechanical coupling system includes:
utilizing an interactive panel to configure and evaluate a performance index of an optimal control problem and a cost function corresponding to the performance index, and writing the cost function into a performance index function of the configuration function;
configuring a path constraint function by using an interactive panel, and writing the path constraint function into a path constraint function of the configuration function;
configuring an event constraint function by using an interactive panel, and writing the event constraint function into an event function of the configuration function;
and configuring a stage continuous constraint function by using an interactive panel, and writing the stage continuous constraint function into a connection function of the configuration function to obtain a mathematical model code of the optimal control problem of the electromechanical coupling system.
Optionally, in a seventh implementation manner of the first aspect of the present invention, the configuring, with an interactive panel, of the solving code includes:
configuring a numerical solving algorithm for solving an optimal control problem by using an interactive panel, and configuring the numerical solving algorithm to a solving information configuration part of the main function;
and configuring a nonlinear programming solving algorithm by using an interactive panel, and configuring the nonlinear programming solving algorithm to a solving part of the main function.
Optionally, in an eighth implementation manner of the first aspect of the present invention, the filling the functional function in the model intermediate code into the mathematical model code includes:
filling a model instantiation function in the model intermediate code into a physical model instantiation part in the main function;
filling a model initialization function in the model intermediate code into a problem initialization part in the main function;
and filling a model state derivative function in the model intermediate code into a state constraint function in the configuration function.
A second aspect of the present invention provides an optimal control problem solver construction system, including:
the model building module is used for building a physical model of the electromechanical coupling system by utilizing an object-oriented modeling tool, wherein the physical model is composed of a plurality of equations used for describing the dynamic characteristics of the electromechanical coupling system;
the partition mapping module is used for partitioning each equation in the physical model to obtain a plurality of equation regions, and writing the content of each equation region into a corresponding preset function respectively to obtain a model intermediate code of the electromechanical coupling system, wherein the model intermediate code comprises a plurality of function functions;
the template instantiation module is used for acquiring a template code of the optimal control problem, instantiating the template code by using an interactive panel and acquiring a mathematical model code of the optimal control problem of the electromechanical coupling system;
the model filling module is used for configuring solving codes by utilizing an interactive panel and filling a function in the model intermediate code into the mathematical model code to obtain a solving code for calculating the optimal solution of the optimal control problem;
and the solver generation module is used for compiling the solving code to obtain an optimal control problem solver of the electromechanical coupling system.
Optionally, in a first implementation manner of the second aspect of the present invention, the equation region includes: a constant area, a parameter area, a variable area, a dynamic calculation area and a function area;
the constant area, the parameter area and the variable area are used for representing the definition and initialization of constants, parameters and variables in the physical model; the dynamic calculation region is used for representing a state variable derivation function and a local variable calculation function in the physical model; the function area is used for representing built-in functions or self-defined functions in the physical model.
Optionally, in a second implementation manner of the second aspect of the present invention, the partition mapping module includes:
the partitioning unit is used for partitioning each equation in the physical model to obtain a plurality of equation areas;
the mapping unit is used for writing the content of each equation area into a corresponding preset function respectively to obtain a model intermediate code of the electromechanical coupling system, wherein the model intermediate code comprises a plurality of function functions;
wherein the partition unit is specifically configured to:
based on the constant declaration characteristics in the physical model, dividing the definition and the initialization content of the constant from each course respectively and writing the constant into the constant area; based on the parameter declaration characteristics in the physical model, dividing parameter definition and initialization content from each equation in the physical model respectively and writing the parameter definition and initialization content into the parameter area; based on variable declaration characteristics in the physical model, dividing definition and initialization content of variables from each equation in the physical model respectively and writing the definition and initialization content into the variable area; based on the variable dependency relationship in the physical model, dividing a state variable derivation function and a local variable calculation function from each equation in the physical model respectively and writing the state variable derivation function and the local variable calculation function into the dynamic calculation area; and based on the mathematical function identification in the physical model, respectively dividing built-in functions or self-defined functions from all equations in the physical model and writing the functions into the function area.
Optionally, in a third implementation manner of the second aspect of the present invention, the model intermediate code includes the following functional functions:
the variable definition block is used for storing the contents of the constant region, the parameter region and the variable region;
the variable setting function provides a function calling interface and is used for setting the variable in the physical model;
the variable obtaining function provides a function calling interface and is used for obtaining the variable in the physical model;
a model instantiation function for instantiating a model object of the physical model and providing a control handle;
a model initialization function for setting initial values of variables in the physical model;
a model state derivative function for calculating a derivative of a state variable in the dynamic calculation region;
an event processing function for processing a target event occurring in the dynamic calculation region;
and the calculation function is used for calculating the local variables in the dynamic calculation area and the built-in function or the self-defined function of the function area.
Optionally, in a fourth implementation manner of the second aspect of the present invention, the mapping unit is specifically configured to:
respectively writing the definition and initialization content of the constant area, the definition and initialization content of the parameter area, and the definition and initialization content of the variable area into the variable definition block;
writing the state variable derivative function of the dynamic calculation region into the model state derivative function; and writing the local variable calculation function of the dynamic calculation region, the built-in function of the function region or the self-defined function into the calculation function to obtain a model intermediate code of the electromechanical coupling system.
Optionally, in a fifth implementation manner of the second aspect of the present invention, the mathematical model code includes: the system comprises a main function and a configuration function, wherein the main function is used for calling the configuration function when solving an optimal control problem; the configuration function is used for realizing the optimal control problem solving of the electromechanical coupling system based on the calling of the main function;
wherein the configuration function comprises: the performance index function is used for evaluating the performance index of the optimal control problem solution; the state constraint function is used for constraining the state of the optimal control problem solution; the path constraint function is used for constraining the path for solving the optimal control problem; the event function is used for constraining the events of the optimal control problem solution; and the connection function is used for constraining the multi-stage connection of the optimal control problem solution.
Optionally, in a sixth implementation manner of the second aspect of the present invention, the template instantiation module includes:
the acquisition unit is used for acquiring a template code of the optimal control problem;
the instantiation unit is used for instantiating the template codes by utilizing an interactive panel to obtain mathematical model codes of the optimal control problem of the electromechanical coupling system;
wherein the instantiation unit is specifically configured to:
utilizing an interactive panel to configure and evaluate a performance index of an optimal control problem and a cost function corresponding to the performance index, and writing the cost function into a performance index function of the configuration function; configuring a path constraint function by using an interactive panel, and writing the path constraint function into a path constraint function of the configuration function; configuring an event constraint function by using an interactive panel, and writing the event constraint function into an event function of the configuration function; and configuring a stage continuous constraint function by using an interactive panel, and writing the stage continuous constraint function into a connection function of the configuration function to obtain a mathematical model code of the optimal control problem of the electromechanical coupling system.
Optionally, in a seventh implementation manner of the second aspect of the present invention, the model filling module includes:
the configuration unit is used for carrying out solving code configuration by utilizing the interactive panel;
the filling unit is used for filling a function in the model intermediate code into the mathematical model code to obtain a solving code for calculating the optimal solution of the optimal control problem;
wherein the configuration unit is specifically configured to:
configuring a numerical solving algorithm for solving an optimal control problem by using an interactive panel, and configuring the numerical solving algorithm to a solving information configuration part of the main function; and configuring a nonlinear programming solving algorithm by using an interactive panel, and configuring the nonlinear programming solving algorithm to a solving part of the main function.
Optionally, in an eighth implementation manner of the second aspect of the present invention, the filling unit is specifically configured to:
filling a model instantiation function in the model intermediate code into a physical model instantiation part in the main function; filling a model initialization function in the model intermediate code into a problem initialization part in the main function; and filling a model state derivative function in the model intermediate code into a state constraint function in the configuration function.
According to the technical scheme provided by the invention, a physical model of the electromechanical coupling system is constructed by utilizing a physical modeling tool, then the constructed physical model is partitioned and written into a corresponding function according to partitions, so that a corresponding model intermediate code is obtained, the difference of physical modeling of different modeling tools is shielded by the model intermediate code through the partitions, and the obtained model intermediate code can be reused; then instantiating an optimal control problem template code to obtain a mathematical model code of an optimal control problem, filling a functional function of a model intermediate code into the mathematical model code and configuring solving information by using an interactive panel to obtain a solving code, thereby automatically realizing the integration of physical modeling and optimal control problem solving; and finally compiling the solving code to obtain an optimal control problem solver. The method uses the model intermediate code to represent the physical model of the electromechanical coupling system, one physical model can be compatible with different physical modeling tools, meanwhile, the model intermediate code is connected with the physical modeling step and the optimal control problem solver constructing step, and automatically generates the solving code, so that the integration of optimal control problem modeling and solving in the electromechanical coupling system simulation process is realized, the automation degree of the electromechanical coupling system simulation is improved, and the simulation efficiency and the simulation flexibility of the electromechanical coupling system are also improved.
Drawings
FIG. 1 is a schematic diagram of a first embodiment of a method for constructing an optimal control problem solver according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of a second embodiment of a method for constructing an optimal control problem solver according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of a third embodiment of a method for constructing an optimal control problem solver according to an embodiment of the present invention;
FIG. 4 is a schematic view of a cart pendulum ball system according to an embodiment of the present disclosure;
FIG. 5 is a schematic diagram of an embodiment of an optimal control problem solver construction system according to the embodiments of the present invention.
Detailed Description
The embodiment of the invention provides a method and a system for constructing an optimal control problem solver, which realize the integration of optimal control problem modeling and solving in the simulation process of an electromechanical coupling system, improve the automation degree of the simulation of the electromechanical coupling system, and simultaneously improve the simulation efficiency and the simulation flexibility of the electromechanical coupling system.
The terms "first," "second," "third," "fourth," and the like in the description and in the claims, as well as in the drawings, if any, are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It will be appreciated that the data so used may be interchanged under appropriate circumstances such that the embodiments described herein may be practiced otherwise than as specifically illustrated or described herein. Furthermore, the terms "comprises," "comprising," or "having," and any variations thereof, are intended to cover non-exclusive inclusions, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
For convenience of understanding, a specific flow of the embodiment of the present invention is described below, and referring to fig. 1, a first embodiment of a method for constructing an optimal control problem solver according to the embodiment of the present invention includes:
101. building a physical model of the electromechanical coupling system by using an object-oriented modeling tool, wherein the physical model is composed of a plurality of equations for describing the dynamic characteristics of the electromechanical coupling system;
in this embodiment, the object-oriented modeling tool refers to a tool for constructing a physical model of a physical object (electromechanical coupling system) in an object-oriented manner, and includes, but is not limited to, Simulink, MWorks, Dymola, and Adams. The physical model constructed by the present embodiment is an equation set for describing the behavior characteristics of the electromechanical coupling system. Such as acceleration control, braking distance control, etc., of the electro-mechanical coupling system.
In this embodiment, the dynamic characteristics refer to various state variables of the system and the interrelation between the variables of the system in the dynamic process.
In this embodiment, the equations include differential equations and algebraic equations, where the high index differential algebraic equations are converted into ordinary differential equations by means of index reduction.
102. Partitioning each equation in the physical model to obtain a plurality of equation regions, and writing the content of each equation region into a corresponding preset function respectively to obtain a model intermediate code of the electromechanical coupling system, wherein the model intermediate code comprises a plurality of function functions;
optionally, in an embodiment, the equation region includes: a constant area, a parameter area, a variable area, a dynamic calculation area and a function area;
the constant area, the parameter area and the variable area are used for representing the definition and initialization of constants, parameters and variables in the physical model; the dynamic calculation region is used for representing a state variable derivation function and a local variable calculation function in the physical model; the function area is used for representing built-in functions or self-defined functions in the physical model.
In this embodiment, the constant refers to a constant quantity, such as a circumferential rate pi, a gravitational acceleration g; the parameter refers to a parameter in the electromechanical coupling system; variables are alphabetic characters representing numbers, both arbitrary and unknown; the state variables are variable groups with the minimum number of contained variables capable of completely describing the time domain behavior of the dynamic system, the state equations are first-order differential equation groups formed by the state variables of the system, and the state variable derivation functions are used for solving the state equations; the local variable is a variable defined in the function, and the local variable calculation function is used for solving the local variable; the built-in function refers to a mathematical function provided by a modeling tool, and generally refers to an elementary mathematical function, such as a sin function, a cos function and a log function; the custom function refers to a function customized by a user, and is an algorithm step for realizing a certain specific function, such as calculating a relative error.
Optionally, in an embodiment, the partitioning each equation in the physical model to obtain a plurality of equation regions includes:
based on the constant declaration characteristics in the physical model, dividing the definition and the initialization content of the constant from each course respectively and writing the constant into the constant area;
based on the parameter declaration characteristics in the physical model, dividing parameter definition and initialization content from each equation in the physical model respectively and writing the parameter definition and initialization content into the parameter area;
based on variable declaration characteristics in the physical model, dividing definition and initialization content of variables from each equation in the physical model respectively and writing the definition and initialization content into the variable area;
based on the variable dependency relationship in the physical model, dividing a state variable derivation function and a local variable calculation function from each equation in the physical model respectively and writing the state variable derivation function and the local variable calculation function into the dynamic calculation area;
and based on the mathematical function identification in the physical model, respectively dividing built-in functions or self-defined functions from all equations in the physical model and writing the functions into the function area.
In this embodiment, if the statement of the physical quantity has a constant keyword const during modeling, the physical quantity is a constant, and the assignment equation is written into the constant region; if the name of the physical quantity has a parameter prefix, the physical quantity is a parameter, and an assignment equation of the physical quantity is written into a parameter area; if the statement of the physical quantity does not have the two prefixes, the physical quantity is a variable and needs to be calculated by a constant, a parameter or other variables, and an assignment equation of the physical quantity is written into a variable area.
In this embodiment, the physical modeling tool may analyze which variables of the variables are state variables, or a user may indicate which state variables exist during modeling, and write an equation including the state variables and an equation including other variables required for calculating the state variables into the dynamic calculation area; and writing the rest variable calculation functions into the dynamic calculation area.
In this embodiment, the mathematical function identifier refers to a mathematical function such as sin or cos, and the custom function has a function prefix identifier, and identifies a built-in function or a custom function according to the mathematical function identifier and writes the function in the function area.
Optionally, in an embodiment, the model intermediate code includes the following function:
the variable definition block is used for storing the contents of the constant region, the parameter region and the variable region;
the variable setting function provides a function calling interface and is used for setting the variable in the physical model;
the variable obtaining function provides a function calling interface and is used for obtaining the variable in the physical model;
a model instantiation function for instantiating a model object of the physical model and providing a control handle;
a model initialization function for setting initial values of variables in the physical model;
a model state derivative function for calculating a derivative of a state variable in the dynamic calculation region;
an event processing function for processing a target event occurring in the dynamic calculation region;
and the calculation function is used for calculating the local variables in the dynamic calculation area and the built-in function or the self-defined function of the function area.
In this embodiment, the variable definition block is a code block, and stores the contents of the constant region, the parameter region, and the variable region.
In this embodiment, the value of the variable may be modified by the variable setting function, and the value of the variable may be obtained by the variable obtaining function.
In this embodiment, the model object is generated after the physical model object is instantiated, the object instantiation allocates a memory space to the physical model object, and the control handle points to the memory space to establish a unique relationship with the model object.
In this embodiment, the model initialization function is used to set initial values of variables in the physical model, variable values describing the initial state of the system are set according to actual conditions, and other variables are calculated according to the variable values describing the initial state of the system to obtain initial values.
In this embodiment, the derivative of the state variable is calculated, i.e. the state equation is solved.
In this embodiment, the event processing function is used to determine a target event, and when the target event occurs, corresponding operations are executed.
In this embodiment, the model intermediate code refers to a physical model described in a programming language, and the application of the model intermediate code enables a physical model constructed by a physical modeling tool to be directly used for constructing an optimal control problem.
In this embodiment, the model intermediate code may be directly saved in the form of a source code, or may be packaged into a library file and provide an interface for external use, so that the model intermediate code acquired in this embodiment may be generated by another program or manually written.
Optionally, in an embodiment, the writing the content of each equation region into a corresponding preset function respectively to obtain a model intermediate code of the electromechanical coupling system includes:
respectively writing the definition and initialization content of the constant area, the definition and initialization content of the parameter area, and the definition and initialization content of the variable area into the variable definition block;
writing the state variable derivative function of the dynamic calculation region into the model state derivative function; and writing the local variable calculation function of the dynamic calculation region, the built-in function of the function region or the self-defined function into the calculation function to obtain a model intermediate code of the electromechanical coupling system.
103. Acquiring a template code of an optimal control problem, and instantiating the template code by using an interactive panel to obtain a mathematical model code of the optimal control problem of the electromechanical coupling system;
in this embodiment, the template code of the optimal control problem is preset and used to describe the code of the general mathematical model of the optimal control problem.
In this embodiment, the interactive panel is a man-machine interface, and the user may select from preset options through the interactive panel as needed, or fill in a designated area.
The mathematical model code in the embodiment refers to instantiated code describing an optimal control problem of the electromechanical coupling system.
Optionally, in an embodiment, the mathematical model code includes: the system comprises a main function and a configuration function, wherein the main function is used for calling the configuration function when solving an optimal control problem; the configuration function is used for realizing the optimal control problem solving of the electromechanical coupling system based on the calling of the main function; wherein the configuration function comprises: the performance index function is used for evaluating the performance index of the optimal control problem solution; the state constraint function is used for constraining the state of the optimal control problem solution; the path constraint function is used for constraining the path for solving the optimal control problem; the event function is used for constraining the events of the optimal control problem solution; and the connection function is used for constraining the multi-stage connection of the optimal control problem solution.
In this embodiment, the master function includes a physical model instantiation portion, a problem initialization portion, a solution information configuration portion, and a solution portion; the problem initialization part is used for setting initial values of variables in the physical model, the solving information configuration part is used for configuring a numerical solving algorithm for solving an optimal control problem, and the solving part is used for configuring a nonlinear programming solving algorithm.
In this embodiment, the performance indicator function is a standard for measuring system performance; the state constraint function is a constraint condition which must be met by the state of the current electromechanical coupling system, namely a physical model of the electromechanical coupling system; the path constraint function is the constraint of the system path, i.e. the state constraint that the system needs to reach at a certain time or period; the event function is used for executing corresponding operation when the system meets certain event constraint; the linkage function is used to control the system phase transition when the system transitions from the first phase to the second phase.
In this embodiment, each parameter and constraint condition are acquired through an interactive panel, and a template code is instantiated into a mathematical model code describing an optimal control problem of the electromechanical coupling system according to the acquired parameters and constraint conditions.
104. Carrying out solving code configuration by utilizing an interactive panel, and filling a function in the model intermediate code into the mathematical model code to obtain a solving code for calculating the optimal solution of the optimal control problem;
in this embodiment, the solving code is a code describing a complete mathematical model of an optimal control problem of the electromechanical coupling system.
In this embodiment, a solving algorithm is obtained by using an interactive panel and corresponding configuration is performed according to the obtained solving algorithm.
In this embodiment, if the model intermediate code is stored in the form of a source code, the function of the model intermediate code is correspondingly filled into the mathematical model code; and if the model intermediate code is packaged into a library file and provides an interface for external use, adding a corresponding function call in the mathematical model code.
105. And compiling the solving code to obtain an optimal control problem solver of the electromechanical coupling system.
In this embodiment, the solution code is compiled to generate an executable file, that is, an optimal control problem solver.
In the embodiment of the invention, a physical model of the electromechanical coupling system is constructed by utilizing a physical modeling tool, then the constructed physical model is partitioned and written into a corresponding function according to partitions, so as to obtain a corresponding model intermediate code, the difference of the physical modeling of different modeling tools is shielded by the model intermediate code through the partitions, and the obtained model intermediate code can be reused; then instantiating an optimal control problem template code to obtain a mathematical model code of an optimal control problem, filling a functional function of a model intermediate code into the mathematical model code and configuring solving information by using an interactive panel to obtain a solving code, thereby automatically realizing the integration of physical modeling and optimal control problem solving; and finally compiling the solving code to obtain an optimal control problem solver. The method uses the model intermediate code to represent the physical model of the electromechanical coupling system, one physical model can be compatible with different physical modeling tools, meanwhile, the model intermediate code is connected with the physical modeling step and the optimal control problem solver constructing step, and automatically generates the solving code, so that the integration of optimal control problem modeling and solving in the electromechanical coupling system simulation process is realized, the automation degree of the electromechanical coupling system simulation is improved, and the simulation efficiency and the simulation flexibility of the electromechanical coupling system are also improved.
Referring to fig. 2, a second embodiment of the method for constructing an optimal control problem solver according to the embodiment of the present invention includes:
201. building a physical model of the electromechanical coupling system by using an object-oriented modeling tool, wherein the physical model is composed of a plurality of equations for describing the dynamic characteristics of the electromechanical coupling system;
202. partitioning each equation in the physical model to obtain a plurality of equation regions, and writing the content of each equation region into a corresponding preset function respectively to obtain a model intermediate code of the electromechanical coupling system, wherein the model intermediate code comprises a plurality of function functions;
optionally, in an embodiment, the generated model intermediate code is saved in a preset model code library. The model code base stores the model intermediate codes of the historical physical models, and can be added, deleted, changed and checked, the stored model intermediate codes can be exported from the historical model intermediate codes to the model code base, and codes constructed by other tools or manually written can also be imported into the model code base.
Optionally, in an embodiment, a preset model code library is retrieved, and it is determined whether a model intermediate code of the current electromechanical coupling system exists in the model code library, and if so, the model intermediate code may be directly derived from the model code library.
203. Acquiring a template code of an optimal control problem, utilizing an interactive panel to configure and evaluate a performance index of the optimal control problem and a cost function corresponding to the performance index, and writing the cost function into a performance index function of the configuration function;
in this embodiment, the interactive panel is used to obtain the type of the performance index, including any one of mayer, bourbon and lagrange, and the mayer problem emphasizes the requirement on the end-state performance index of the system; lagrangian problems reflect the requirements for the entire control process of the system; the Boerza problem has both requirements on the whole control process of the system and emphasizes the requirements on the end state of the system.
In this embodiment, a corresponding cost function is configured according to the obtained performance index type, and if the obtained performance index type is a meyer type, a corresponding terminal cost function is obtained by using an interactive panel; if the obtained performance index type is a Lagrange type, obtaining a corresponding process cost function by using an interactive panel; and if the obtained performance index type is the Bolza type, obtaining a corresponding terminal cost function and a corresponding process cost function by using the interactive panel.
In this embodiment, the interactive panel is used to obtain the time interval related to the optimal control problem, that is, the initial time and the terminal time.
In this embodiment, the interactive panel is used to obtain the weight parameters of each part in the performance index function, and weight parameter configuration is performed on the cost function.
In this embodiment, the cost function generated by configuration is written into the performance index function of the configuration function.
Optionally, in an embodiment, the template code for describing the current optimal control problem is obtained from an optimal control template code library. The template codes are stored in a template code library, and the user can select the desired template code using an interactive panel. The template code library is constructed in a folder or database mode and supports the increase, deletion, modification and check of the template codes.
Optionally, in an embodiment, the model intermediate code is kept consistent with the programming language used by the template code library, and the used programming language is not limited.
204. Configuring a path constraint function by using an interactive panel, and writing the path constraint function into a path constraint function of the configuration function;
in this embodiment, if necessary, the interactive panel is used to obtain the path constraint function, and obtain the upper and lower bounds of the constraint, and write the obtained constraint condition into the path constraint function of the configuration function.
205. Configuring an event constraint function by using an interactive panel, and writing the event constraint function into an event function of the configuration function;
in this embodiment, if necessary, the interactive panel is used to obtain the event constraint function, and obtain the upper and lower bounds of the constraint, and write the obtained constraint condition into the event constraint function of the configuration function.
206. Configuring a stage continuous constraint function by using an interactive panel, and writing the stage continuous constraint function into a connection function of the configuration function to obtain a mathematical model code of an optimal control problem of the electromechanical coupling system;
in this embodiment, if necessary, the interactive panel is used to obtain the continuous constraint function at the stage, obtain the upper and lower bounds of the constraint, and write the obtained constraint condition into the connection function of the configuration function.
207. Carrying out solving code configuration by utilizing an interactive panel, and filling a function in the model intermediate code into the mathematical model code to obtain a solving code for calculating the optimal solution of the optimal control problem;
208. and compiling the solving code to obtain an optimal control problem solver of the electromechanical coupling system.
In the embodiment of the invention, a physical model of an electromechanical coupling system is constructed by using a physical modeling tool, the physical model is partitioned and written into corresponding function functions according to the partition to obtain corresponding model intermediate codes, a performance index function, a path constraint function, a time function and a connection function of an interactive surface variation configuration function are used to obtain mathematical model codes, the function functions of the model intermediate codes are filled into the mathematical model codes, solution information is configured by using an interactive panel to obtain solution codes, and the solution codes are compiled to obtain an optimal control problem solver. The embodiment of the invention supports the configuration of corresponding performance index functions and various constraint conditions aiming at different optimal control problem requirements, meets the requirements under various conditions, reduces the modeling difficulty, improves the accuracy, reduces the labor cost and improves the efficiency of optimal control problem construction.
Referring to fig. 3, a third embodiment of the method for constructing an optimal control problem solver according to the embodiment of the present invention includes:
301. building a physical model of the electromechanical coupling system by using an object-oriented modeling tool, wherein the physical model is composed of a plurality of equations for describing the dynamic characteristics of the electromechanical coupling system;
302. partitioning each equation in the physical model to obtain a plurality of equation regions, and writing the content of each equation region into a corresponding preset function respectively to obtain a model intermediate code of the electromechanical coupling system, wherein the model intermediate code comprises a plurality of function functions;
303. acquiring a template code of an optimal control problem, and instantiating the template code by using an interactive panel to obtain a mathematical model code of the optimal control problem of the electromechanical coupling system;
304. configuring a numerical solving algorithm for solving an optimal control problem by using an interactive panel, and configuring the numerical solving algorithm to a solving information configuration part of the main function;
in this embodiment, the interactive panel is used to obtain a numerical solution algorithm for solving the optimal control problem, which includes but is not limited to a target practice method, a local coordination method, and a global coordination method.
In this embodiment, if the obtained numerical solving algorithm is a target practice method, the interactive panel is used to further obtain the type of the target practice method, that is, the target practice method or the multiple target practice method; if the obtained numerical solving algorithm is a local matching method, the integral formula types including but not limited to trapezoidal integral and Simpson integral are further obtained by utilizing an interactive panel; if the obtained numerical solution algorithm is a global fitting point method, namely a pseudo-spectrum method, the pseudo-spectrum method type is further obtained by utilizing an interactive panel, wherein the pseudo-spectrum method type comprises but is not limited to Legendre type, Gaussian type and Chebyshev type.
In this embodiment, the number of discrete nodes in the numerical algorithm is obtained by using an interactive panel. The variables of the optimal control problem are continuous variables related to time, and if a certain state variable is represented in a coordinate system, the abscissa is a time axis, and the ordinate is the value of the variable, a continuous curve can be obtained; however, when the optimal control problem is solved by using a numerical method, such as a global coordination method, a continuous curve needs to be discretized, the state of a variable is represented by values at a plurality of time points, which is equivalent to sampling the curve, and at this time, the state of the curve solving of the original problem is converted into the state of solving a plurality of discrete points, and the discrete points are discrete nodes.
305. Configuring a nonlinear programming solving algorithm by using an interactive panel, and configuring the nonlinear programming solving algorithm to a solving part of the main function;
in this embodiment, an interactive panel is used to obtain a nonlinear programming solver or a solving method, and if the nonlinear programming solver is used, a corresponding nonlinear programming solver is called through a preset interface; if a specific nonlinear programming solving method is used, a corresponding solving algorithm in a preset algorithm library is used.
In this embodiment, the optimized iteration number and the threshold are obtained by using an interactive panel. When a nonlinear planner is used for solving the optimization problem, an iterative method is mainly adopted, namely, the optimization variables are continuously adjusted based on the optimization method from given initial values of the optimization variables; the threshold is a standard for judging whether the optimized variable obtained by the current iteration is proper or whether the iteration converges, if the results of the previous iteration and the next iteration are differed, when the remaining item is smaller than the preset threshold, the current iteration process can be determined to be converged, the iteration calculation does not need to be continued, and if the iteration times reach the preset value and still does not reach the threshold of convergence, the iteration calculation is stopped.
In this embodiment, an interactive panel is used to obtain a linear algebra/nonlinear algebra library or a linear algebra/nonlinear algebra solution method. When the optimal control problem is solved, a linear equation set and a nonlinear equation set need to be calculated, a plurality of numerical methods and a plurality of mathematical libraries are available for calculating the linear equation set and the nonlinear equation set, and if a linear algebra/nonlinear algebra library is used, the corresponding linear algebra/nonlinear algebra library is called through a preset interface link; if a specific linear algebra/nonlinear algebra library solving method is used, a corresponding algorithm function is called.
In this embodiment, the solving algorithm includes, but is not limited to, LU decomposition, singular value decomposition, and QR decomposition.
306. Filling a functional function in the model intermediate code into the mathematical model code to obtain a solving code for calculating the optimal solution of the optimal control problem;
optionally, in an embodiment, the step 306 includes:
filling a model instantiation function in the model intermediate code into a physical model instantiation part in the main function;
filling a model initialization function in the model intermediate code into a problem initialization part in the main function;
and filling a model state derivative function in the model intermediate code into a state constraint function in the configuration function.
In this embodiment, the model intermediate code further includes a model destruction function, which is used for releasing the memory after the simulation is finished.
In this embodiment, if the model intermediate code is directly stored in the form of a source code, the corresponding function may be directly written into the main function and the configuration function; and if the model intermediate code is packaged into a library file and provides an interface for external use, calling a corresponding preset interface in the main function and the configuration function.
In this embodiment, other function functions in the model intermediate code, except for the model instantiation function, the model initialization function, and the model state derivation function, are called by the model instantiation function, the model initialization function, and the model state derivation function.
307. And compiling the solving code to obtain an optimal control problem solver of the electromechanical coupling system.
In the embodiment of the invention, a physical model of an electromechanical coupling system is constructed by using a physical modeling tool, the constructed physical model is partitioned and written into corresponding function functions according to partitions to obtain corresponding model intermediate codes, optimal control problem template codes are instantiated to obtain mathematical model codes, the function functions of the model intermediate codes are filled into the mathematical model codes, a solution code is obtained by using an interactive panel configuration numerical solution algorithm and a nonlinear programming solution algorithm, and the solution code is compiled to obtain an optimal control problem solver. The embodiment of the invention utilizes the interactive panel to obtain and configure the numerical solving algorithm and the nonlinear programming solving algorithm, meets different algorithm requirements under different optimal control problems, is convenient to use, reduces the construction difficulty of the optimal control problem solver, improves the accuracy, reduces the labor cost and improves the construction efficiency of the optimal control problem.
To facilitate a better understanding of the present invention, an electromechanical coupling system is exemplified below as a cart pitching system. Referring to the cart pendulum ball system shown in fig. 4, a method for constructing an optimal control problem solver of the cart pendulum ball system is specifically described in this embodiment.
A physical model of the cart pendulum ball system is first constructed in an object-oriented manner through a physical modeling tool. The cart pendulum ball system comprises a trolley and a pendulum ball, the trolley is connected with the pendulum ball through a rod, when a force is applied to the trolley, the pendulum ball can swing along with the trolley, and the pendulum ball can be kept in an upright state by pushing the trolley left and right. When the thrust is larger, more energy is consumed, and when the thrust is smaller, less energy is consumed, so that an optimal control problem is generated, namely how to consume the least energy to reach a target, and the corresponding performance index function is used for judging the energy consumed by various schemes; the time taken to reach the goal varies, thus creating another optimal control problem, namely how to reach the goal in the shortest time, and the corresponding performance index function is used to judge how much time is taken by each scheme.
In this embodiment, the dynamic characteristics of the system include the acceleration of the cart, the calculation of the acceleration of the cart, the force to push the cart, and the like. The constants used by the system include the circumferential rate pi, the gravitational acceleration g, and the like. The parameters comprise the mass of the pendulum ball, the length of the connecting trolley and the pendulum ball, and the like. The variables include the displacement of the trolley, the speed of the trolley, the acceleration of the trolley, the angular speed of the pendulum ball, the angular acceleration of the pendulum ball, and the like.
When the initial state of the cart ball swinging system is a static state, the initial value of the speed of the cart is zero. And when the angular displacement of the pendulum ball is larger than a preset value, determining that the regulation and control of the cart pendulum ball system are failed, and stopping control. And if the angular displacement of the pendulum ball is larger than a preset value, a target event is obtained. The requirement for the cart teeming system to move from point a to point B, an obstacle above point C at a position intermediate A, B, the requirement for the teeming ball to be unable to stand at point C is a path constraint, and the requirement for the cart teeming system to run to the tenth second doubles the maximum thrust allowed by the system is an event constraint. The state constraints are a physical model of the cart pendulum system, as the cart pendulum system needs to satisfy the equation constraints of the dynamics of the physical model, no matter what control scheme is used.
With reference to fig. 5, the method for constructing an optimal control problem solver according to the embodiment of the present invention is described above, and a system for constructing an optimal control problem solver according to the embodiment of the present invention is described below, where an embodiment of the system for constructing an optimal control problem solver according to the embodiment of the present invention includes:
a model building module 501, configured to build a physical model of the electromechanical coupling system by using an object-oriented modeling tool, where the physical model is formed by a plurality of equations for describing physical characteristics of the electromechanical coupling system;
a partition mapping module 502, configured to partition each equation in the physical model to obtain a plurality of equation regions, and write the content of each equation region into a corresponding preset function respectively to obtain a model intermediate code of the electromechanical coupling system, where the model intermediate code includes a plurality of function functions;
the template instantiation module 503 is configured to obtain a template code of the optimal control problem, instantiate the template code by using an interactive panel, and obtain a mathematical model code of the optimal control problem of the electromechanical coupling system;
a model filling module 504, configured to perform solving code configuration by using an interactive panel, and fill a function in the model intermediate code into the mathematical model code to obtain a solving code for calculating an optimal solution of the optimal control problem;
and a solver generating module 505, configured to compile the solution code to obtain an optimal control problem solver of the electromechanical coupling system.
Optionally, in an embodiment, the equation region includes: a constant area, a parameter area, a variable area, a dynamic calculation area and a function area;
the constant area, the parameter area and the variable area are used for representing the definition and initialization of constants, parameters and variables in the physical model; the dynamic calculation region is used for representing a state variable derivation function and a local variable calculation function in the physical model; the function area is used for representing built-in functions or self-defined functions in the physical model.
Optionally, in an embodiment, the partition mapping module 502 includes:
a partitioning unit 5021, configured to partition each equation in the physical model to obtain multiple equation regions;
a mapping unit 5022, configured to write the content of each equation region into a corresponding preset function, respectively, to obtain a model intermediate code of the electromechanical coupling system, where the model intermediate code includes a plurality of function functions;
the partition unit 5021 is specifically configured to:
based on the constant declaration characteristics in the physical model, dividing the definition and the initialization content of the constant from each course respectively and writing the constant into the constant area; based on the parameter declaration characteristics in the physical model, dividing parameter definition and initialization content from each equation in the physical model respectively and writing the parameter definition and initialization content into the parameter area; based on variable declaration characteristics in the physical model, dividing definition and initialization content of variables from each equation in the physical model respectively and writing the definition and initialization content into the variable area; based on the variable dependency relationship in the physical model, dividing a state variable derivation function and a local variable calculation function from each equation in the physical model respectively and writing the state variable derivation function and the local variable calculation function into the dynamic calculation area; and based on the mathematical function identification in the physical model, respectively dividing built-in functions or self-defined functions from all equations in the physical model and writing the functions into the function area.
Optionally, in an embodiment, the model intermediate code includes the following function:
the variable definition block is used for storing the contents of the constant region, the parameter region and the variable region;
the variable setting function provides a function calling interface and is used for setting the variable in the physical model;
the variable obtaining function provides a function calling interface and is used for obtaining the variable in the physical model;
a model instantiation function for instantiating a model object of the physical model and providing a control handle;
a model initialization function for setting initial values of variables in the physical model;
a model state derivative function for calculating a derivative of a state variable in the dynamic calculation region;
an event processing function for processing a target event occurring in the dynamic calculation region;
and the calculation function is used for calculating the local variables in the dynamic calculation area and the built-in function or the self-defined function of the function area.
Optionally, in an embodiment, the mapping unit 5022 is specifically configured to:
respectively writing the definition and initialization content of the constant area, the definition and initialization content of the parameter area, and the definition and initialization content of the variable area into the variable definition block;
writing the state variable derivative function of the dynamic calculation region into the model state derivative function; and writing the local variable calculation function of the dynamic calculation region, the built-in function of the function region or the self-defined function into the calculation function to obtain a model intermediate code of the electromechanical coupling system.
Optionally, in an embodiment, the mathematical model code includes: the system comprises a main function and a configuration function, wherein the main function is used for calling the configuration function when solving an optimal control problem; the configuration function is used for realizing the optimal control problem solving of the electromechanical coupling system based on the calling of the main function;
wherein the configuration function comprises: the performance index function is used for evaluating the performance index of the optimal control problem solution; the state constraint function is used for constraining the state of the optimal control problem solution; the path constraint function is used for constraining the path for solving the optimal control problem; the event function is used for constraining the events of the optimal control problem solution; and the connection function is used for constraining the multi-stage connection of the optimal control problem solution.
Optionally, in an embodiment, the template instantiation module 503 includes:
an obtaining unit 5031, configured to obtain a template code of the optimal control problem;
an instantiation unit 5032, configured to instantiate the template code by using an interactive panel to obtain a mathematical model code of the optimal control problem of the electromechanical coupling system;
wherein, the instantiation unit 5031 is specifically configured to:
utilizing an interactive panel to configure and evaluate a performance index of an optimal control problem and a cost function corresponding to the performance index, and writing the cost function into a performance index function of the configuration function; configuring a path constraint function by using an interactive panel, and writing the path constraint function into a path constraint function of the configuration function; configuring an event constraint function by using an interactive panel, and writing the event constraint function into an event function of the configuration function; and configuring a stage continuous constraint function by using an interactive panel, and writing the stage continuous constraint function into a connection function of the configuration function to obtain a mathematical model code of the optimal control problem of the electromechanical coupling system.
Optionally, in an embodiment, the model filling module 504 includes:
a configuration unit 5041, configured to perform solving code configuration by using an interactive panel;
a filling unit 5042, configured to fill a function in the model intermediate code into the mathematical model code, so as to obtain a solution code for calculating an optimal solution of the optimal control problem;
wherein the configuration unit 5041 is specifically configured to:
configuring a numerical solving algorithm for solving an optimal control problem by using an interactive panel, and configuring the numerical solving algorithm to a solving information configuration part of the main function; and configuring a nonlinear programming solving algorithm by using an interactive panel, and configuring the nonlinear programming solving algorithm to a solving part of the main function.
Optionally, in an embodiment, the filling unit 5042 is specifically configured to:
filling a model instantiation function in the model intermediate code into a physical model instantiation part in the main function; filling a model initialization function in the model intermediate code into a problem initialization part in the main function; and filling a model state derivative function in the model intermediate code into a state constraint function in the configuration function.
In the embodiment of the invention, a physical model of the electromechanical coupling system is constructed by utilizing a physical modeling tool, then the constructed physical model is partitioned and written into a corresponding function according to partitions, so as to obtain a corresponding model intermediate code, the difference of the physical modeling of different modeling tools is shielded by the model intermediate code through the partitions, and the obtained model intermediate code can be reused; then instantiating an optimal control problem template code to obtain a mathematical model code of an optimal control problem, filling a functional function of a model intermediate code into the mathematical model code and configuring solving information by using an interactive panel to obtain a solving code, thereby automatically realizing the integration of physical modeling and optimal control problem solving; and finally compiling the solving code to obtain an optimal control problem solver. The method uses the model intermediate code to represent the physical model of the electromechanical coupling system, one physical model can be compatible with different physical modeling tools, meanwhile, the model intermediate code is connected with the physical modeling step and the optimal control problem solver constructing step, and automatically generates the solving code, so that the integration of optimal control problem modeling and solving in the electromechanical coupling system simulation process is realized, the automation degree of the electromechanical coupling system simulation is improved, and the simulation efficiency and the simulation flexibility of the electromechanical coupling system are also improved.
It can be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working processes of the system, the module and the unit described above may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a read-only memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
The above-mentioned embodiments are only used for illustrating the technical solutions of the present invention, and not for limiting the same; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.

Claims (8)

1. A method for constructing an optimal control problem solver of an electromechanical coupling system is characterized by comprising the following steps:
building a physical model of the electromechanical coupling system by using an object-oriented modeling tool, wherein the physical model is composed of a plurality of equations for describing the dynamic characteristics of the electromechanical coupling system;
partitioning each equation in the physical model to obtain a plurality of equation regions, and writing the content of each equation region into a corresponding preset function respectively to obtain a model intermediate code of the electromechanical coupling system, wherein the model intermediate code comprises a plurality of function functions;
acquiring a template code of an optimal control problem, and instantiating the template code by using an interactive panel to obtain a mathematical model code of the optimal control problem of the electromechanical coupling system;
carrying out solving code configuration by utilizing an interactive panel, and filling a function in the model intermediate code into the mathematical model code to obtain a solving code for calculating the optimal solution of the optimal control problem;
compiling the solving code to obtain an optimal control problem solver of the electromechanical coupling system;
wherein the equation region includes: a constant area, a parameter area, a variable area, a dynamic calculation area and a function area; the constant area, the parameter area and the variable area are used for representing the definition and initialization of the constant, the parameter and the variable in the physical model; the dynamic calculation region is used for representing a state variable derivation function and a local variable calculation function in the physical model; the function area is used for representing built-in functions or self-defined functions in the physical model;
wherein the partitioning each equation in the physical model to obtain a plurality of equation regions comprises:
based on the constant declaration characteristics in the physical model, dividing the definition and the initialization content of the constant from each course respectively and writing the constant into the constant area;
based on the parameter declaration characteristics in the physical model, dividing parameter definition and initialization content from each equation in the physical model respectively and writing the parameter definition and initialization content into the parameter area;
based on variable declaration characteristics in the physical model, dividing definition and initialization content of variables from each equation in the physical model respectively and writing the definition and initialization content into the variable area;
based on the variable dependency relationship in the physical model, dividing a state variable derivation function and a local variable calculation function from each equation in the physical model respectively and writing the state variable derivation function and the local variable calculation function into the dynamic calculation area;
and based on the mathematical function identification in the physical model, respectively dividing built-in functions or self-defined functions from all equations in the physical model and writing the functions into the function area.
2. The method of constructing an optimal control problem solver for an electromechanical coupling system according to claim 1, wherein said model intermediate code comprises the following function functions:
the variable definition block is used for storing the contents of the constant region, the parameter region and the variable region;
the variable setting function provides a function calling interface and is used for setting the variable in the physical model;
the variable obtaining function provides a function calling interface and is used for obtaining the variable in the physical model;
a model instantiation function for instantiating a model object of the physical model and providing a control handle;
a model initialization function for setting initial values of variables in the physical model;
a model state derivative function for calculating a derivative of a state variable in the dynamic calculation region;
an event processing function for processing a target event occurring in the dynamic calculation region;
and the calculation function is used for calculating the local variables in the dynamic calculation area and the built-in function or the self-defined function of the function area.
3. The method for constructing the optimal control problem solver of the electromechanical coupling system according to claim 2, wherein the step of writing the contents of the equation regions into the corresponding preset function functions respectively to obtain the model intermediate code of the electromechanical coupling system comprises:
respectively writing the definition and initialization content of the constant area, the definition and initialization content of the parameter area, and the definition and initialization content of the variable area into the variable definition block;
writing the state variable derivative function of the dynamic calculation region into the model state derivative function; and writing the local variable calculation function of the dynamic calculation region, the built-in function of the function region or the self-defined function into the calculation function to obtain a model intermediate code of the electromechanical coupling system.
4. The method of constructing an optimal control problem solver for an electro-mechanical coupling system of claim 3, wherein the mathematical model code comprises: the system comprises a main function and a configuration function, wherein the main function is used for calling the configuration function when solving an optimal control problem; the configuration function is used for realizing the optimal control problem solving of the electromechanical coupling system based on the calling of the main function;
wherein the configuration function comprises: the performance index function is used for evaluating the performance index of the optimal control problem solution; the state constraint function is used for constraining the state of the optimal control problem solution; the path constraint function is used for constraining the path for solving the optimal control problem; the event function is used for constraining the events of the optimal control problem solution; and the connection function is used for constraining the multi-stage connection of the optimal control problem solution.
5. The method as claimed in claim 4, wherein the instantiating the template code with an interactive panel to obtain the mathematical model code of the optimal control problem of the electromechanical coupling system comprises:
utilizing an interactive panel to configure and evaluate a performance index of an optimal control problem and a cost function corresponding to the performance index, and writing the cost function into a performance index function of the configuration function;
configuring a path constraint function by using an interactive panel, and writing the path constraint function into a path constraint function of the configuration function;
configuring an event constraint function by using an interactive panel, and writing the event constraint function into an event function of the configuration function;
and configuring a stage continuous constraint function by using an interactive panel, and writing the stage continuous constraint function into a connection function of the configuration function to obtain a mathematical model code of the optimal control problem of the electromechanical coupling system.
6. The method for building an optimal control problem solver for an electro-mechanical coupling system as claimed in claim 4 wherein said using an interactive panel to solve code configuration comprises:
configuring a numerical solving algorithm for solving an optimal control problem by using an interactive panel, and configuring the numerical solving algorithm to a solving information configuration part of the main function;
and configuring a nonlinear programming solving algorithm by using an interactive panel, and configuring the nonlinear programming solving algorithm to a solving part of the main function.
7. The method for building an optimal control problem solver of an electromechanical coupling system according to claim 4 or 6, wherein the filling the function in the model intermediate code into the mathematical model code comprises:
filling a model instantiation function in the model intermediate code into a physical model instantiation part in the main function;
filling a model initialization function in the model intermediate code into a problem initialization part in the main function;
and filling a model state derivative function in the model intermediate code into a state constraint function in the configuration function.
8. An optimal control problem solver construction system for an electromechanical coupling system, the optimal control problem solver construction system comprising:
the model building module is used for building a physical model of the electromechanical coupling system by utilizing an object-oriented modeling tool, wherein the physical model is composed of a plurality of equations used for describing the dynamic characteristics of the electromechanical coupling system;
the partition mapping module is used for partitioning each equation in the physical model to obtain a plurality of equation regions, and writing the content of each equation region into a corresponding preset function respectively to obtain a model intermediate code of the electromechanical coupling system, wherein the model intermediate code comprises a plurality of function functions;
the template instantiation module is used for acquiring a template code of the optimal control problem, instantiating the template code by using an interactive panel and acquiring a mathematical model code of the optimal control problem of the electromechanical coupling system;
the model filling module is used for configuring solving codes by utilizing an interactive panel and filling a function in the model intermediate code into the mathematical model code to obtain a solving code for calculating the optimal solution of the optimal control problem;
the solver generation module is used for compiling the solving code to obtain an optimal control problem solver of the electromechanical coupling system;
wherein the equation region includes: a constant area, a parameter area, a variable area, a dynamic calculation area and a function area; the constant area, the parameter area and the variable area are used for representing the definition and initialization of the constant, the parameter and the variable in the physical model; the dynamic calculation region is used for representing a state variable derivation function and a local variable calculation function in the physical model; the function area is used for representing built-in functions or self-defined functions in the physical model;
wherein the partition mapping module comprises:
the partitioning unit is used for partitioning each equation in the physical model to obtain a plurality of equation areas;
the mapping unit is used for respectively writing the contents of the equation areas into corresponding preset function functions to obtain model intermediate codes of the electromechanical coupling system;
the partition unit is specifically configured to: based on the constant declaration characteristics in the physical model, dividing the definition and the initialization content of the constant from each course respectively and writing the constant into the constant area; based on the parameter declaration characteristics in the physical model, dividing parameter definition and initialization content from each equation in the physical model respectively and writing the parameter definition and initialization content into the parameter area; based on variable declaration characteristics in the physical model, dividing definition and initialization content of variables from each equation in the physical model respectively and writing the definition and initialization content into the variable area; based on the variable dependency relationship in the physical model, dividing a state variable derivation function and a local variable calculation function from each equation in the physical model respectively and writing the state variable derivation function and the local variable calculation function into the dynamic calculation area; and based on the mathematical function identification in the physical model, respectively dividing built-in functions or self-defined functions from all equations in the physical model and writing the functions into the function area.
CN202111524158.5A 2021-12-14 2021-12-14 Optimal control problem solver construction method and system Active CN113918133B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111524158.5A CN113918133B (en) 2021-12-14 2021-12-14 Optimal control problem solver construction method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111524158.5A CN113918133B (en) 2021-12-14 2021-12-14 Optimal control problem solver construction method and system

Publications (2)

Publication Number Publication Date
CN113918133A CN113918133A (en) 2022-01-11
CN113918133B true CN113918133B (en) 2022-02-25

Family

ID=79249168

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111524158.5A Active CN113918133B (en) 2021-12-14 2021-12-14 Optimal control problem solver construction method and system

Country Status (1)

Country Link
CN (1) CN113918133B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115756416B (en) * 2022-10-18 2023-06-02 元计算(天津)科技发展有限公司 Program generation method and device of physical mechanism solver calculation unit

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107423516A (en) * 2017-08-01 2017-12-01 元计算(天津)科技发展有限公司 A kind of coding method based on finite element language, compiler and method for solving
CN111159946A (en) * 2019-12-30 2020-05-15 河海大学 Discontinuous problem partition solving method based on minimum potential energy principle

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7107568B2 (en) * 2002-10-07 2006-09-12 Hewlett-Packard Development Company, Lp. System and method for reducing wire delay or congestion during synthesis of hardware solvers
US9354846B2 (en) * 2011-11-08 2016-05-31 The Mathworks, Inc. Bidomain simulator
CN105335213A (en) * 2015-10-28 2016-02-17 苏州同元软控信息技术有限公司 Method for realizing simulation report automatic generation through embedding Modelica model in Word file
CN107403037B (en) * 2017-07-04 2021-05-07 清华大学 Open source finite element solving and optimizing analysis method
CN107748716A (en) * 2017-09-15 2018-03-02 深圳英飞拓科技股份有限公司 The lookup method and terminal device of a kind of bug
CN111523242A (en) * 2020-04-29 2020-08-11 江苏华路信息科技有限公司 CAE solver result sliced output method
CN112434448B (en) * 2021-01-27 2021-04-09 中国人民解放军国防科技大学 Proxy model constraint optimization method and device based on multipoint adding

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107423516A (en) * 2017-08-01 2017-12-01 元计算(天津)科技发展有限公司 A kind of coding method based on finite element language, compiler and method for solving
CN111159946A (en) * 2019-12-30 2020-05-15 河海大学 Discontinuous problem partition solving method based on minimum potential energy principle

Also Published As

Publication number Publication date
CN113918133A (en) 2022-01-11

Similar Documents

Publication Publication Date Title
US11638994B2 (en) Robotic digital twin control with industrial context simulation
Rodič Industry 4.0 and the new simulation modelling paradigm
Cingolani et al. jFuzzyLogic: a java library to design fuzzy logic controllers according to the standard for fuzzy control programming
Arnold et al. Bridging the gap between product design and product manufacturing by means of graph-based design languages
JP6784003B2 (en) Methods, devices, computer-readable storage media, and programs for configuring collaborative simulations for integrated systems
CN105807628B (en) Robot flexibility controller and its implementation for complicated CPS
CN113918133B (en) Optimal control problem solver construction method and system
CN107553496A (en) The determination of mechanical arm inverse kinematics method error and bearing calibration and device
Ivan et al. Exotica: An extensible optimization toolset for prototyping and benchmarking motion planning and control
Thibeault et al. Psy-taliro: A python toolbox for search-based test generation for cyber-physical systems
Breckle et al. The evolving digital factory–new chances for a consistent information flow
CN114818286A (en) Engineering machinery complete machine simulation model construction system and method
CN112966433A (en) Instant compiling-based neurodynamics simulation method and device
Sinnemann et al. Architecture for simulation and optimization of energy consumption of automated production systems
Corbera Caraballo et al. A performance-based design framework for enhancing decision-making at the conceptual phase of a motorcycle rear suspension development
Santamaría et al. Framework in PYOMO for the assessment and implementation of (as) NMPC controllers
KR101672763B1 (en) The method for generating interface of simulation and the realtime simulation apparatus
Zhou et al. A sustainability toolkit for simulaiton: Recent developments and future capabilities
CN114818414A (en) Simulation method, device, equipment and medium of transverse stabilizer bar
Bévan et al. Generation of multiplatform control for transitic systems using a component-based approach
Valasek Modeling, simulation and control of mechatronical systems
Morency Automatic generation of real-time simulation code for vehicle dynamics using linear graph theory and symbolic computing
Hensel et al. Generator for modular virtual sensors
Dai et al. A model-based design approach for simulation and virtual prototyping of automotive control systems using port-Hamiltonian systems
Pascual et al. Optimizing Ergonomics and Productivity by Connecting Digital Human Modeling and Production Flow Simulation Software

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant