当前位置:网站首页>Mathematical modeling column | Part 5: MATLAB optimization model solving method (Part I): Standard Model

Mathematical modeling column | Part 5: MATLAB optimization model solving method (Part I): Standard Model

2022-04-23 20:20:00 Install a sound 77

Optimization problem is one of the most common problems in mathematical modeling competition . As a general rule , Those who seek the greatest 、 Minimum 、 furthest 、 lately 、 Most economical 、 Richest 、 Most efficient 、 The most time-consuming goal , Can be classified into the category of optimization problems .MATLAB Optimization toolbox and global optimization toolbox provide complete solutions to multiple optimization problems , The former covers linear programming 、 Mixed integer linear programming 、 Second planning 、 Nonlinear optimization 、 Solver for nonlinear least squares , The latter includes global search 、 Multiple initial points 、 Pattern search 、 Genetic algorithm and other solving algorithms .

This lecture mainly introduces how to use the optimization toolbox to solve the standard optimization model in mathematical modeling . More content , Welcome to MathWorks Website and MATLAB Software documentation .

1. Talk about optimization

Optimization means that under certain conditions , Seek to minimize your goals ( Big ) Design parameters or decisions . There are two key objects in the optimization problem : Objective functions and constraints ( Optional ). General optimization problems , Its mathematical expression can be described as :

 

among x For the length n Decision variable vector ,f(x) Is the target function ,G(x) Is a constraint function .

Solve the minimum of the objective function ( Big ) value , An efficient and accurate solution depends not only on constraints and the number of variables , It depends more on the characteristics of objective function and constraint function . Clarifying the optimization type is the premise of confirming the optimization scheme , Let's see how these features are divided :

 

Common objective functions are :

Linear programming : It is widely used in financial information that can be expressed linearly between variables 、 energy 、 In modern management fields such as operation research .

Mixed integer linear programming : The linear programming problem is extended , The constraint that some or all variables in the optimal solution must be integers is added . for example , If a variable represents the number of shares to be subscribed , Then only the integer value should be rounded . Again , If a variable represents the on of the generator / Off state , Then only binary values should be taken (0 or 1).

Second planning : The objective function or constraint function is a multivariate quadratic function . This optimization is applied to portfolio optimization in finance 、 Power plant generation optimization 、 Design optimization and other fields in engineering .

least square : It is divided into linear and nonlinear , Find the optimal function matching of variables by minimizing the sum of squares of errors . Nonlinear least squares optimization can also be used for curve fitting .

2.  There are too many optimization solvers , How to choose ?

Yes MATLAB Provide algorithms for various optimization problems , We call it a solver (Solver). According to it, solve the goal , Divided into four groups :

  • Minimum optimization group : Find the starting point of the objective function x0 Local minima in the vicinity

  • Multi objective optimization group : Find or minimize the maximum value of a set of functions or the specified value

  • Equation solving system : Find the nonlinear equation f(x) = 0 starting point x0 Near solution

  • Least square method ( Curve fitting ) Group : Minimize the sum of squares

The optimization toolbox alone provides nearly 20 A solver , Faced with such a wide range of options , Users are often confused . fortunately ,MATLAB Provides a simple and clear reference tool ——  Optimize the decision table . It can be said that a watch is in hand , Optimization does not worry :

The above table * The representation algorithm is provided by the global toolbox . Besides , Multiobjective optimization and equation solvers are not listed in this table , More solver options , You can click to read the original .

3. Write beautiful 、 Efficient code

After confirming the optimization strategy , You can start writing code . Let's take an example , Understand the steps and precautions for writing efficient optimization algorithm code .

[ subject ]

-  Objective function

-   Constraint function ( All variables are positive )

[ answer ]

a.  First , According to the title, it is confirmed that this is a linear programming problem . The general mathematical expression of linear programming and MATLAB The standard form is :

  Create a file that conforms to the standard format A、b、Aeq、beq、lb、ub Parameters , Only then can the optimization algorithm run smoothly .

b.  For the optimization steps of linear programming ( It is also applicable to other optimization schemes ), Recommendations are as follows :

    1 )  Select the optimization solver

    2 )  Merge all variables into one vector

    3 )  Create boundary constraints (lb,ub)

    4 )  Create linear inequality constraints (A,b)

    5 )  Create a linear equality constraint (Aeq,beq)

    6 )  Create objective functions

    7 )  Optimization problem solving

    8 )  Results test

c. MATLAB Code and comments :

 

d.  Optimization results :

e.  If the result is not satisfactory , You can adjust the optimization options , Iterative calculation .

4.  Integer programming artifact

In optimization , We often encounter integer programming problems , In especial 0-1 Programming problem , MATLAB For integer programming problems , There is a special solver intlinprog. This function can not only solve the general integer programming problem , We can also solve mixed integer programming problems , That is, the decision variable can be either an integer or a decimal , Just specify the number of the decision variable that is an integer . Through a concrete example , Let's take a look at the use of this function .

The problem is :

The solution code is :

Run code , The optimal solution can be obtained quickly x = [1 0 1].

5. Popular graphical applications

MATLAB So popular in the field of data analysis , In addition to providing a rich set of built-in algorithms , There are all kinds of friendly application interfaces . In the optimization toolbox , There is also such a powerful tool —— Optimization App, Can be in MATLAB Apps Window or run optmitool Command to open . It is an interactive graphical application tool , No need to write code , Directly set various solvers in the graphical interface 、 Configure the objective function 、 constraint condition , You can run the optimization algorithm and visualize the intermediate and final results .

stay Optimization App in , Just click... In the menu bar File > Generate Code, Can be App The settings in are automatically generated MATLAB Code , The user can realize the reuse and secondary development of the algorithm .

Besides , Facing more and more complex optimization problems , How to speed up the operation of the algorithm is also a problem we often hear . For this demand , Can combine MATLAB Parallel computing toolbox , Use the multi-core hardware resources of the computer , Realize algorithm acceleration , Interested users can click to read the original text, watch the video and learn more .

版权声明
本文为[Install a sound 77]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210551491858.html

随机推荐