主要内容

optimproblem

Create optimization problem

描述

采用optimproblem创建优化问题。

Tip

对于完整的工作流程,请参阅Problem-Based Optimization Workflow

example

概率= optimproblemcreates an optimization problem with default properties.

example

概率= optimproblem(Name,Value)使用一个或多个指定的其他选项Name,Valuepair arguments. For example, to specify a maximization problem instead of a minimization problem, useprob = optimproblem('ObjectiveSense','maximize')

Note

All names in an optimization problem must be unique. Specifically, all variable names, objective function names, and constraint function names must be different.

例子

全部收缩

Create an optimization problem with default properties.

概率= optimproblem
prob =具有属性的优化问题:description:''objectivesense:'最小化变量:[0x0 struct]包含0 Optimization Variables目标:[0x0 Optimization Expertexpression]约束:[0x0 struct]包含0 Optimization optimization contrization contraints nosization contraints没有任何问题。

创建一个线性编程问题以进行最大化。该问题具有两个正变量和三个线性不等式约束。

prob = optimproblem('ObjectiveSense','最大限度');

创建正变量。在问题中包括目标函数。

x = optimvar('x',2,1,'LowerBound',0);prob.Objective = x(1) + 2*x(2);

Create linear inequality constraints in the problem.

cons1 = x(1) + 5*x(2)<= 100;CONS2 = x(1) + x(2)<= 40;cons3 = 2*x(1) + x(2)/2 <= 60;prob.constraints.cons1 = cons1;prob.constraints.cons2 = cons2;prob.constraints.cons3 = cons3;

查看问题。

show(prob)
OptimizationProblem : Solve for: x maximize : x(1) + 2*x(2) subject to cons1: x(1) + 5*x(2) <= 100 subject to cons2: x(1) + x(2) <= 40 subject to cons3: 2*x(1) + 0.5*x(2) <= 60 variable bounds: 0 <= x(1) 0 <= x(2)

解决这个问题。

sol = solve(prob);
Solving problem using linprog. Optimal solution found.
sol.x
ans =2×125.0000 15.0000

Create a problem with two objective functions of a 2-D variablex。创建目标函数作为表达式x, and place them in the objective as structures.

x = optimvar("x",2,LowerBound=-2,UpperBound=2); prob = optimproblem; prob.Objective.first = norm(x)^2; prob.Objective.second = norm(x - [1;0])^2;

解决这个问题。

RNGdefault%可再现性sol = solve(prob);
使用gamultiobj解决问题。优化终止:帕累托解决方案的平均变化小于选项。功能耐受性。金宝搏官方网站

Plot the solution.

paretoplot(sol)

图包含一个轴对象。带有标题Pareto正面的轴对象包含4个类型文本的对象,分散。

Examine one point on the Pareto front. To do so, click the figure and click the Data Tips tool:

这n click a point on the Pareto front.

这index of the pictured point is 9. You can find thexvalue associated with this point as the solution with index 9.

sol(9).x
ans =2×10.5544 -0.0306

Input Arguments

全部收缩

Name-Value Arguments

将可选的参数对Name1=Value1,...,NameN=ValueN, whereNameis the argument name and价值是相应的值。名称值参数必须在其他参数之后出现,但是对的顺序并不重要。

Before R2021a, use commas to separate each name and value, and encloseNamein quotes.

例子:要指定最大化问题,请使用prob = optimproblem('ObjectiveSense','maximize')

问题约束,指定为OptimizationConstraint阵列或结构OptimizationConstraint数组作为字段。

例子:prob = optimproblem('Constraints',sum(x,2) == 1)

问题标签,指定为字符串或字符向量。该软件不使用描述for computation.描述是您可以出于任何原因使用的任意标签。例如,您可以共享,存档或提出模型或问题,并存储有关模型或问题的描述性信息描述

例子:"An iterative approach to the Traveling Salesman problem"

Data Types:char|string

目标功能, specified as a scalarOptimizationExpressionobject, an array ofOptimizationExpression对象或标量的结构OptimizationExpression作为字段。

  • 对于标量(单目标)问题,将目标函数指定为标量优化表达式或标量优化表达式作为值的结构。

  • 对于多目标问题,将目标函数指定为矢量值的优化表达式,作为一系列优化表达式或优化表达式的结构。例如,该目标是标量优化变量中优化表达式的结构x:

    prob = optimproblem;prob.Objective.first = x^2;prob.Objective.second =(x + 1)^2;

例子:prob = optimproblem('Objective',sum(sum(x)))for a 2-D variablex

例子:prob = optimproblem('Objective',(x-a).^2)wherexahave size 2-by-1, andxis an optimization variable.

优化感, specified as'minimize'或者'最大化'。您也可以指定'min'to obtain'minimize'或者'最大限度'to obtain'最大化'。这solvefunction minimizes an objective when目标是is'minimize'和maximizes an objective when目标是is'最大化'

目标是可以是具有值的结构'minimize','min','最大化', or'最大限度'。You can use this form when the problem objective is a structure. The客观的目标是结构应具有相同的字段名称,因此目标是applies to the corresponding客观的。For example,

x = optimvar('x',2,"UpperBound",2,“下部”,-2); prob = optimproblem; prob.Objective.first = norm(x)^2; prob.Objective.second = -norm(x - [1;0])^2; prob.ObjectiveSense.first ="min";prob.Objectivesense.second ="max";

如果客观的is a structure, you can specify目标是as a name such as'最大限度'。In this case, all objectives have the same目标是

例子:prob = optimproblem('objectivesense','max')

Data Types:char|string

Output Arguments

全部收缩

Optimization problem, returned as anOptimizationProblemobject. Typically, to complete the problem description, you specify an objective function and constraints. However, you can have a feasibility problem, which has no objective function, or you can have a problem with no constraints. Solve a complete problem by callingsolve

警告

基于问题的方法不支持目标函数,非线性平等或非线性不等式中的复杂值。金宝app如果函数计算具有复杂的值,即使是中间值,则最终结果可能是不正确的。

版本嗨story

Introduced in R2017b