ConicOptimization[f,cons,vars]
求可最小化受锥约束条件 cons 限制的线性目标函数 f 的变量 vars 的值.
ConicOptimization[…,"prop"]
指定应返回解的属性 "prop".
ConicOptimization
ConicOptimization[f,cons,vars]
求可最小化受锥约束条件 cons 限制的线性目标函数 f 的变量 vars 的值.
ConicOptimization[…,"prop"]
指定应返回解的属性 "prop".
更多信息和选项
- 锥优化亦称为混合整数锥优化、线性锥优化或线性锥规划.
- 锥优化包括许多其他形式的优化,包括线性优化、线性分式优化、二次优化、二阶锥优化,半定优化和几何优化.
- 锥优化是一个凸优化问题,可以使用实数、整数或复数变量全局有效地求解.
- 锥优化求的是能解原问题的
: -
最小化 
受限于约束条件 
其中 
- 集合
应是维度为
的真凸锥. 常见的
的锥规范和与
(VectorGreaterEqual[{x,0},κj]) 相对应的集合为: -
{"NonNegativeCone", m} 
使得
成立的
{"NormCone", m} 
使得
成立的
{"SemidefiniteCone", m} 
对称正半定矩阵 
"ExponentialCone" 
使得
成立的
"DualExponentialCone" 
使得
或
成立的
{"PowerCone",α} 
使得
成立的
{"DualPowerCone",α} 
使得
成立的
- 当目标函数取实数值时,ConicOptimization 在内部将
转换为实变量
(其中
,
),对
的问题进行求解. - 变量指定 vars 应该是一个列表,其中的元素按以下形式给出变量:
-
v 名称为
的变量,维度由推断而得v∈Reals 实标量变量 v∈Integers 整数标量变量 v∈Complexes 复标量变量 v∈ℛ 限制在几何区域
内的向量变量v∈Vectors[n,dom]
或
中的向量变量v∈Matrices[{m,n},dom]
或
中的矩阵变量 - 可用以下形式指定约束条件 cons:
-
LessEqual 
标量不等式 GreaterEqual 
标量不等式 VectorLessEqual 
向量不等式 VectorGreaterEqual 
向量不等式 Equal 
向量或标量等式 Element 
凸域或区域元素 - 对于 ConicOptimization[f,cons,vars],可在约束条件中包括形式为 parval 的参数方程,以定义在 f 或 cons 中使用的参数,其中 par 不在 vars 中,val 是数值或数值数组. »
- 原始最小化问题有相关的最大化问题,即拉格朗日对偶问题. 对偶最大值始终小于或等于原始最小值,因此它给出了下限. 对偶最大值点提供了有关原问题的信息,包括最小值对约束条件变化的敏感性. »
- 锥优化有对偶问题: »
-
最大化 
受限于约束条件 
其中
,
是
的对偶锥 - 可能的解的属性 "prop" 包括: »
-
"PrimalMinimizer" 
一个最小化
的变量值列表"PrimalMinimizerRules" 
最小化
的变量值 vars={v1,…} "PrimalMinimizerVector" 
最小化
的向量"PrimalMinimumValue" 
最小值
"DualMaximizer" 
最大化
的向量"DualMaximumValue" 
对偶最大值 "DualityGap" 
对偶值和原始最优值之间的差 "Slack" 
将不等式约束条件转换为等式约束条件的向量 "ConstraintSensitivity"
对约束条件扰动的敏感性"ObjectiveVector" 
线性目标向量 "ConicConstraints" 
标准形式的锥约束条件列表 "ConicConstraintConeSpecifications" 
锥
的规范列表"ConicConstraintConeDimensions" ![{TemplateBox[{Dimensions, paclet:ref/Dimensions}, RefLink, BaseStyle -> {3ColumnTableMod}][kappa_1],...} {TemplateBox[{Dimensions, paclet:ref/Dimensions}, RefLink, BaseStyle -> {3ColumnTableMod}][kappa_1],...}](Files/ConicOptimization.zh/4.png)
锥约束条件中锥的维度列表 "ConicConstraintAffineLists" 
锥约束条件中仿射变换的矩阵、向量对列表 {"prop1","prop2",…} 几个解的属性 - 可给出以下选项:
-
MaxIterations Automatic 使用的最大迭代次数 Method Automatic 使用的方法 PerformanceGoal $PerformanceGoal 优化的目标 Tolerance Automatic 内部比较采用的容差 - 选项 Method->method 可用来指定使用的方法. 可用的方法包括:
-
Automatic 自动选择方法 "SCS" SCS 劈分圆锥求解器 "CSDP" CSDP 半定优化求解器 "DSDP" DSDP 半定优化求解器 "MOSEK" 商用 MOSEK 凸优化求解器 "Gurobi" 商用 Gurobi 线性和二次优化求解器 "Xpress" 商业 Xpress 线性和二次优化求解器 - 计算受限于 MachinePrecision.
范例
打开所有单元 关闭所有单元基本范例 (3)
res = ConicOptimization[Subscript[x, 1] + 2Subscript[x, 2], {Subscript[x, 1], Subscript[x, 2]}Underscript[, {"NormCone", 2}]0, {Subscript[x, 1], Subscript[x, 2]}]Show[Plot3D[Subscript[x, 1] + 2Subscript[x, 2], {Subscript[x, 1], Subscript[x, 2]}∈ImplicitRegion[Abs[Subscript[x, 1]] ≤ Subscript[x, 2], {Subscript[x, 1], Subscript[x, 2]}], ...], Graphics3D[{Blue, PointSize[0.04], Point[{Subscript[x, 1], Subscript[x, 2], Subscript[x, 1] + 2Subscript[x, 2]} /. res]}]]Subscript[x, min] = ConicOptimization[-(x + y), {x ≥ 0, y ≥ 0, x + 2 y ≤ 2, x^2 + y^2 ≤ 1}, {x, y}]RegionPlot[{x ≥ 0 && y ≥ 0 && x + 2 y ≤ 2, x ^ 2 + y ^ 2 ≤ 1}, ...]ConicOptimization[x + y, Norm[{x, y}] ≤ 1, {x∈Integers, y∈Reals}]范围 (35)
基本用法 (11)
res = ConicOptimization[x + 2y, {x^2 + 2y^2 ≤ 3, x + y == 2, x ≥ 1}, {x, y}]可用 VectorGreaterEqual:表示几个线性不等式约束条件:
ConicOptimization[x + y, VectorGreaterEqual[{{x + 2y, x}, {3, -1}}], {x, y}]用
v>=
或 \[VectorGreaterEqual] 输入向量不等式符号 :
ConicOptimization[x + y, {x + 2y, x}{3, -1}, {x, y}]ConicOptimization[x + y, {x + 2y ≥ 3, x ≥ -1}, {x, y}]ConicOptimization[{1, 1}.v, {{1, 2}, {1, 0}}.v{3, -1}, v]ConicOptimization[{1, 1}.x, {{1, 2}, {1, 0}}.x + {-3, 1}0, x]ConicOptimization[{1, 1}.x, {{1, 2}, {1, 0}}.x{3, -1}, x]为了避免
中无意的 threading,可使用 Inactive[Plus]:
ConicOptimization[{1, 1}.x, {{1, 2}, {1, 0}}.x + {-3, 1}0, x]parEqs = {a == {{1, 2}, {1, 0}}, b == {3, -1}};ConicOptimization[{1, 1}.x, {parEqs, a.x + b0}, x]VectorGreaterEqual 表示相对于的 "NonNegativeCone" 锥不等式:
constraint = VectorGreaterEqual[{{{1, 2}, {1, 0}}.v, {3, -1}}, "NonNegativeCone"]为了明确指定锥的维度,请使用 {"NonNegativeCone",n}:
constraint = VectorGreaterEqual[{{{1, 2}, {1, 0}}.v, {3, -1}}, {"NonNegativeCone", 2}]ConicOptimization[{1, 1}.v, constraint, v]ConicOptimization[x + y, x^2 + y^2 ≤ 9, {x, y}]VectorGreaterEqual[{{x, y, 3}, 0}, {"NormCone", 3}]ConicOptimization[x + y, {x, y, 3}Underscript[, {"NormCone", 3}]0, {x, y}]constraint = VectorGreaterEqual[{{{x, 1}, {1, y}}, 0}, {"SemidefiniteCone", 2}]ConicOptimization[x + 2y, constraint, {x, y}]用向量变量
和 Indexed[x,i] 指定单个分量:
ConicOptimization[{1, 2}.x, (| | |
| --------------- | --------------- |
| Indexed[x, {1}] | 1 |
| 1 | Indexed[x, {2}] |)Underscript[, {"SemidefiniteCone", 2}]0, x]用 Vectors[n] 在未明确给定时指定向量变量的维度:
ConicOptimization[Indexed[x, {1}] + 2Indexed[x, {2}], (| | |
| --------------- | --------------- |
| Indexed[x, {1}] | 1 |
| 1 | Indexed[x, {2}] |)Underscript[, {"SemidefiniteCone", 2}]0, x]ConicOptimization[Indexed[x, {1}] + Indexed[2x, {2}], (| | |
| --------------- | --------------- |
| Indexed[x, {1}] | 1 |
| 1 | Indexed[x, {2}] |)Underscript[, {"SemidefiniteCone", 2}]0, x∈Vectors[2]]用 NonNegativeReals (
) 指定非负约束条件:
ConicOptimization[{1, 1}.x, {Indexed[x, {1}], Indexed[x, {2}], 1}Underscript[, {"NormCone", 3}]0, x∈Vectors[2, NonNegativeReals]]ConicOptimization[{1, 1}.x, {{Indexed[x, {1}], Indexed[x, {2}], 1}Underscript[, {"NormCone", 3}]0, x0}, x]整数变量 (4)
用 Integers 指定整数域约束:
ConicOptimization[x + y, {x + 2y ≥ 3, x ≥ -2}, {x∈Integers, y∈Integers}]用 Vectors[n,Integers] 在向量变量上指定整数域约束:
ConicOptimization[Total[x], {a == {{1, 2}, {1, 0}}, b == {3, -2},
a.xb}, {x∈Vectors[2, Integers]}]用 NonNegativeIntegers (
) 指定非负整数域约束:
ConicOptimization[x + 2y, {x^2 + 2y^2 ≤ 3, x + y == 2, x∈NonNegativeIntegers}, {x, y}]用 NonPositiveIntegers (
) 指定非正整数域约束:
ConicOptimization[-x + y, {x + 2y ≥ 3, x∈NonPositiveIntegers}, {x, y}]复变量 (5)
用 Complexes 指定复变量:
ConicOptimization[Re[z] + Im[z], Abs[z] ≤ 2, z∈ Complexes]constraints = VectorGreaterEqual[{(-1 + 2I) z, -3}] && VectorGreaterEqual[{z, I}]VectorGreaterEqual /@ ComplexExpand[constraints[[All, 1]] /. z -> x + I y]realConstraints = -x - 2y ≥ -3 && 2 x - y ≥ 0 && x ≥ 0 && y ≥ 1;RegionPlot[realConstraints, {x, 0.5, 1}, {y, 1, 1.2}]ConicOptimization[Re[z], constraints, Element[z, Complexes]]ConicOptimization[x, realConstraints, {x, y}]{q, c} = {{{2, 1 + I}, {1 - I, 1}}, {2, 3}};
ConicOptimization[{1, 2}.x, (1 / 2) * x.q.x + c.x1, x∈Vectors[2, Reals]]q = {{3, 1 + I}, {1 - I, 2}};
ConvexOptimization[{1, 2}.Re[x], {(1 / 2) * Inactive[Dot][Conjugate[x], q, x]5}, x∈Vectors[2, Complexes]]q = {{1, 1 + I}, {1 - I, 2}};
ConicOptimization[-{1, 2}.Re[x], {(1 / 2) * Inactive[Dot][Conjugate[x], q, x]0 , {1, I}.x-1 - I}, x∈Vectors[2, Complexes]]将线性矩阵不等式约束条件
与厄米特矩阵或实对称矩阵一起使用:
Subscript[a, 0] = (| | |
| ----- | ----- |
| 0 | 1 + I |
| 1 - I | 0 |);Subscript[a, 1] = (| | |
| - | - |
| 1 | 0 |
| 0 | 0 |);Subscript[a, 2] = (| | |
| - | - |
| 0 | 0 |
| 0 | 1 |);线性矩阵不等式中的变量需为实数,才能使得和依然为厄米特矩阵:
c = {1, 2};
ConicOptimization[c.v, {Subscript[a, 1], Subscript[a, 2]}.vUnderscript[, {"SemidefiniteCone", 2}]-Subscript[a, 0], v∈Vectors[2, Reals]]原始模型属性 (4)
triangle = {x ≥ 0, y ≥ 0, x + 2y ≤ 2};
disk = x ^ 2 + y ^ 2 ≤ 1;sol = ConicOptimization[-(x + y), {triangle, disk}, {x, y}]{xmin, ymin} = ConicOptimization[-(x + y), {triangle, disk}, {x, y}, "PrimalMinimizer"]minval = ConicOptimization[-(x + y), {triangle, disk}, {x, y}, "PrimalMinimumValue"]RegionPlot[{x ≥ 0 && y ≥ 0 && x + 2 y ≤ 2, x ^ 2 + y ^ 2 ≤ 1}, {x, 0, 2}, {y, 0, 1}, AspectRatio -> Automatic, Epilog -> {Red, PointSize[0.025], Point[{x, y} /. sol]}]triangle = {x ≥ 0, y ≥ 0, x + 2y ≤ 2};
disk = x ^ 2 + y ^ 2 ≤ 1;c = ConicOptimization[-(x + y), {triangle, disk}, {x, y}, "ObjectiveVector"]ConicOptimization[-(x + y), {triangle, disk}, {x, y}, "ConicConstraints"]//NormalConicOptimization[-(x + y), {triangle, disk}, {x, y}, "ConicConstraintConeSpecifications"]ConicOptimization[-(x + y), {triangle, disk}, {x, y}, "ConicConstraintConeDimensions"]ConicOptimization[-(x + y), {triangle, disk}, {x, y}, "ConicConstraintAffineLists"]//Normaltriangle = {Subscript[x, 1] ≥ 0, Subscript[x, 2] ≥ 0, Subscript[x, 1] + 2Subscript[x, 2] ≤ 2};
disk = Subscript[x, 1] ^ 2 + Subscript[x, 2] ^ 2 ≤ 1;s = ConicOptimization[-(Subscript[x, 1] + Subscript[x, 2]), {triangle, disk}, {Subscript[x, 1], Subscript[x, 2]}, "Slack"]{x^ * , afflists} = Normal[ConicOptimization[-(Subscript[x, 1] + Subscript[x, 2]), {triangle, disk}, {Subscript[x, 1], Subscript[x, 2]}, {"PrimalMinimizer", "ConicConstraintAffineLists"}]]验证松弛向量满足 aj.x*+bj-sj=0 时 s={s0,…,sk}:
{{Subscript[a, 1], Subscript[b, 1]}, {Subscript[a, 2], Subscript[b, 2]}} = afflists;{Subscript[a, 1].x^ * + Subscript[b, 1], Subscript[a, 2].x^ * + Subscript[b, 2]} - s一些作者将标准形式的圆锥优化问题定义为在满足
和
情况下使
最小化. 要转换为标准格式,请为每个圆锥约束
,添加一个变量
相应的线性相等约束
:
triangle = {Subscript[x, 1] ≥ 0, Subscript[x, 2] ≥ 0, Subscript[x, 1] + 2Subscript[x, 2] ≤ 2};
disk = Subscript[x, 1]^2 + Subscript[x, 2]^2 ≤ 1;{c, {{a[1], b[1]}, {a[2], b[2]}}, {κ[1], κ[2]}} = ConicOptimization[-(Subscript[x, 1] + Subscript[x, 2]), {triangle,
disk}, {Subscript[x, 1], Subscript[x, 2]}, {"ObjectiveVector", "ConicConstraintAffineLists", "ConicConstraintConeSpecifications"}];slackConstraints = Table[VectorGreaterEqual[{Subscript[s, i], 0}, κ[i]], {i, 2}]equalityConstraints = Table[Subscript[s, j] == a[j].{Subscript[x, 1], Subscript[x, 2]} + b[j], {j, 2}];ConicOptimization[c.{Subscript[x, 1], Subscript[x, 2]}, {equalityConstraints,
slackConstraints}, {Subscript[x, 1], Subscript[x, 2], Subscript[s, 1], Subscript[s, 2]}]ConicOptimization[-(Subscript[x, 1] + Subscript[x, 2]), {triangle, disk}, {Subscript[x, 1], Subscript[x, 2]}, {"PrimalMinimizerVector", "Slack"}]对偶模型属性 (3)
c = {1, 1};
Subscript[a, 0] = {{1., -1.}}; Subscript[b, 0] = {0};
Subscript[a, 1] = {{1., 0}, {0, 1}, {0, 0}};Subscript[b, 1] = {0, 0, 1};psol = ConicOptimization[c.x, {Subscript[a, 0].x + Subscript[b, 0] == 0, Subscript[a, 1].x + Subscript[b, 1]Underscript[, {"NormCone", 3}]0}, x]dsol = ConicOptimization[Subscript[b, 0].Subscript[λ, 0] + Subscript[b, 1].Subscript[λ, 1] , {Transpose[Subscript[a, 0]].Subscript[λ, 0] + Transpose[Subscript[a, 1]].Subscript[λ, 1] == c, Subscript[λ, 1]Underscript[, {"NormCone", 3}]0}, {Subscript[λ, 0], Subscript[λ, 1]}]{c.x /. psol, -Subscript[b, 0].Subscript[λ, 0] - Subscript[b, 1].Subscript[λ, 1] /. dsol}ConicOptimization[c.x, {Subscript[a, 0].x + Subscript[b, 0] == 0, Subscript[a, 1].x + Subscript[b, 1]Underscript[, {"NormCone", 3}]0}, x, "DualityGap"]obj = Indexed[x, {1}] + Indexed[x, {2}];
constraints = {Indexed[x, {1}] == Indexed[x, {2}], Indexed[x, {1}]^2 + Indexed[x, {2}]^2 ≤ 1};ConicOptimization[obj, constraints, x∈Vectors[2]]{c, afflists} = ConicOptimization[obj, constraints, x∈Vectors[2], {"ObjectiveVector", "ConicConstraintAffineLists"}];{{Subscript[a, 0], Subscript[b, 0]}, {Subscript[a, 1], Subscript[b, 1]}} = afflists;ConicOptimization[Subscript[b, 0].Subscript[λ, 0] + Subscript[b, 1].Subscript[λ, 1], {Transpose[Subscript[a, 0]].Subscript[λ, 0] + Transpose[Subscript[a, 1]].Subscript[λ, 1] == c, Subscript[λ, 1]Underscript[, {"NormCone", 3}]0}, {Subscript[λ, 0], Subscript[λ, 1]}]ConicOptimization[Indexed[x, {1}] + Indexed[x, {2}], {Indexed[x, {1}] == Indexed[x, {2}], Indexed[x, {1}]^2 + Indexed[x, {2}]^2 ≤ 1}, {Indexed[x, {1}], Indexed[x, {2}]}, "DualMaximumValue"]dualMaximizer = ConicOptimization[Indexed[x, {1}] + Indexed[x, {2}], {Indexed[x, {1}] == Indexed[x, {2}], Indexed[x, {1}]^2 + Indexed[x, {2}]^2 ≤ 1}, {Indexed[x, {1}], Indexed[x, {2}]}, "DualMaximizer"]{Subscript[λ, 0], Subscript[λ, 1]} = dualMaximizer敏感性属性 (3)
a = {{1, 0}, {0, 1}, {-1, -2}};b = {0, 0, 1};
disk = a.{x, y} + bUnderscript[, {"NormCone", 3}]0;minValue = ConicOptimization[-x - y, {disk}, {x, y}, "PrimalMinimumValue"]{s} = ConicOptimization[-x - y, {disk}, {x, y}, "ConstraintSensitivity"]δ = 0.01 * {1, 2, 3};minValue + δ.sConicOptimization[-x - y, {a.{x, y} + (b + δ) Underscript[, {"NormCone", 3}]0}, {x, y}, "PrimalMinimumValue"]a = {{1, 0}, {0, 1}, {-1, -2}};b = {0, 0, 1};
disk = a.{x, y} + bUnderscript[, {"NormCone", 3}]0;{p^ * , sens} = ConicOptimization[-x - y, {disk}, {x, y}, {"PrimalMinimumValue", "ConstraintSensitivity"}]p^ * > ConicOptimization[-x - y, a.{x, y} + (b + {0, 0, 1})Underscript[, {"NormCone", 3}]0, {x, y}, "PrimalMinimumValue"]p^ * < ConicOptimization[-x - y, a.{x, y} + (b + {1, 0, 0})Underscript[, {"NormCone", 3}]0, {x, y}, "PrimalMinimumValue"]-ConicOptimization[-{1, 1}.{x, y}, {{x, y, 1 - x - 2 y}Underscript[, {"NormCone", 3}]0}, {x, y},
"DualMaximizer"]ConicOptimization[-{1, 1}.{x, y}, {{x, y, 1 - x - 2 y}Underscript[, {"NormCone", 3}]0}, {x, y},
"ConstraintSensitivity"]支持的凸锥 (5)
"NonNegativeCone" (1)
{minval, {xmin, ymin}} = ConicOptimization[10x + 11 y, {x, y}∈RegularPolygon[9], {x, y}, {"PrimalMinimumValue", "PrimalMinimizer"}]Show[Plot3D[10x + 11y, {x, y}∈RegularPolygon[9], MeshFunctions -> {#3&}], Graphics3D[{Red, PointSize[0.05], Point[{xmin, ymin, minval}]}]]ConicOptimization[10x + 11 y, {x, y}∈RegularPolygon[9], {x, y}, "ConicConstraintConeSpecifications"]"NormCone" (1)
{minval, {xmin, ymin}} = ConicOptimization[10x + 11 y, {x, y}∈Disk[], {x, y}, {"PrimalMinimumValue", "PrimalMinimizer"}]Show[Plot3D[10x + 11y, {x, y}∈Disk[], MeshFunctions -> {#3&}], Graphics3D[{Red, PointSize[0.05], Point[{xmin, ymin, minval}]}]]ConicOptimization[10.x + 11. y, {x, y}∈Disk[], {x, y}, "ConicConstraintConeSpecifications"]"SemidefiniteCone" (1)
{minval, {xmin, ymin}} = ConicOptimization[10x + 11 y, (| | |
| - | - |
| x | 1 |
| 1 | y |)Underscript[, {"SemidefiniteCone", 2}]0, {x, y}, {"PrimalMinimumValue", "PrimalMinimizer"}]Show[Plot3D[10x + 11y, {x, y}∈ImplicitRegion[ x y ≥ 1, {{x, 0, 5}, {y, 0, 5}}], MeshFunctions -> {#3&}], Graphics3D[{Red, PointSize[0.05], Point[{xmin, ymin, minval}]}]]ConicOptimization[10x + 11y, (| | |
| - | - |
| x | 1 |
| 1 | y |)Underscript[, {"SemidefiniteCone", 2}]0, {x, y}, "ConicConstraintConeSpecifications"]"ExponentialCone" (1)
{minval, {xmin, ymin}} = ConicOptimization[10.x + 11.y, {x ≥ 0, y ≥ 0, -Log[x] - Log[y] ≤ 0}, {x, y}, {"PrimalMinimumValue", "PrimalMinimizer"}, Method -> {"SCS", Tolerance -> 10 ^ -7}]Show[Plot3D[10x + 11y, {x, 0, 10}, {y, 0, 10}, MeshFunctions -> {#3&}, RegionFunction -> Function[{x, y}, x ≥ 0 && y ≥ 0 && -Log[x] - Log[y] ≤ 0]], Graphics3D[{Red, PointSize[0.05], Point[{xmin, ymin, minval}]}]]ConicOptimization[10 x + 11 y, {x ≥ 0, y ≥ 0, -Log[x] - Log[y] ≤ 0}, {x, y}, "ConicConstraintConeSpecifications"]"PowerCone" (1)
{minval, {xmin, ymin}} = ConicOptimization[10.x + 11.y, Inactive[Norm][{x, y}, 4] ≤ 1, {x, y}, {"PrimalMinimumValue", "PrimalMinimizer"}]Show[Plot3D[10x + 11y, {x, y}∈ImplicitRegion[ x ^4 + y^4 ≤ 1, {{x, -1, 1}, {y, -1, 1}}], MeshFunctions -> {#3&}], Graphics3D[{Red, PointSize[0.05], Point[{xmin, ymin, minval}]}]]ConicOptimization[10 x + 11 y, Inactive[Norm][{x, y}, 4] ≤ 1, {x, y}, "ConicConstraintConeSpecifications"]选项 (11)
Method (8)
"SCS" 使用 splitting conic solver 方法:
ConicOptimization[-x - y, {x ≥ 0, y ≥ 0, x + 2y ≤ 2, x^2 + y^2 ≤ 1}, {x, y}, Method -> "SCS"]ConicOptimization[-x - y, {x ≥ 0, y ≥ 0, x + 2y ≤ 2, x^2 + y^2 ≤ 1}, {x, y}, Method -> "CSDP"]ConicOptimization[-x - y, {x ≥ 0, y ≥ 0, x + 2y ≤ 2, x^2 + y^2 ≤ 1}, {x, y}, Method -> "DSDP"]ConicOptimization[-x - y, {x ≥ 0, y ≥ 0, x + 2y ≤ 2, x^2 + y^2 ≤ 1}, {x, y}, Method -> "IPOPT"]{obj, cons, var} = {-x - y, {x ≥ 0, y ≥ 0, x + 2y ≤ 2, x ^ 2 + y ^ 2 ≤ 1}, {x, y}};
props = {"PrimalMinimumValue", "PrimalMinimizer"};{minval, argmin} = Minimize[obj, cons, var];
exact = {minval, var /. argmin};solSCS = ConicOptimization[obj, cons, var, props, Method -> "SCS"];solCSDP = ConicOptimization[obj, cons, var, props, Method -> "CSDP"];solDSDP = ConicOptimization[obj, cons, var, props, Method -> "DSDP"];solIPOPT = ConicOptimization[obj, cons, var, props, Method -> "IPOPT"];solSCS - exact"CSDP"、"DSDP" 和 "IPOPT" 的默认容差为
:
solCSDP - exactsolDSDP - exactsolIPOPT - exact如果指定了方法 "SCS",将使用默认容差为 10-3 的 SCS 库:
ConicOptimization[x + y, {x^2 + y^2 ≤ 1}, {x, y}, Method -> "SCS"]ConicOptimization[x + y, {x^2 + y^2 ≤ 1}, {x, y}]ConicOptimization[x + y, {x^2 + y^2 ≤ 1}, {x, y}, Method -> {"SCS", Tolerance -> 10 ^ -6}]对于半定约束条件使用 "CSDP" 或 "DSDP" 方法:
lin = {{1, 0}, {0, 1}, {-1, -2}}.x + {0, 0, 2}Underscript[, {"NonNegativeCone", 3}]0;norm = {{1, 0}, {0, 1}, {0, 0}}.x + {0, 0, 1}Underscript[, {"NormCone", 3}]0;semi = {{{-4, 0}, {0, 0}}, {{0, 0}, {0, -0.8}}}.x + {{5, 1}, {1, 1}}Underscript[, {"SemidefiniteCone", 2}]0;ConicOptimization[{-1, -1}.x, {lin, norm, semi}, x, Method -> "CSDP"]ConicOptimization[{-1, -1}.x, {lin, norm, semi}, x, Method -> "DSDP"]在 "CSDP" 和 "DSDP" 方法不适用的情况下使用 "IPOPT" 方法获取准确的解:
expConstraint = {{1, 0}, {0, 1}, {-1, -2}}.x + {0, 0, 2}Underscript[, "ExponentialCone"]0;powConstraint = {{1, 0}, {0, 1}, {-1, -2}}.x + {1, 0, 2}Underscript[, {"PowerCone", (1/3)}]0;"IPOPT" 给出的结果比 "SCS" 更准确,但是通常要慢一些:
AbsoluteTiming[xmin = ConicOptimization[{1, 1}.x, {expConstraint, powConstraint}, x, Method -> "IPOPT"]]AbsoluteTiming[xmin = ConicOptimization[{1, 1}.x, {expConstraint, powConstraint}, x, Method -> "SCS"]]PerformanceGoal (1)
PerformanceGoal 选项的默认值为 $PerformanceGoal:
$PerformanceGoal用 PerformanceGoal"Quality" 获取更准确的结果:
ConicOptimization[x + y, {Norm[{x, y}] ≤ Sqrt[2], {x, y}1}, {x, y},
"PrimalMinimumValue", PerformanceGoal -> "Quality"]ConicOptimization[x + y, {Norm[{x, y}] ≤ Sqrt[2], {x, y}1}, {x, y},
"PrimalMinimumValue", PerformanceGoal -> "Speed"]用 PerformanceGoal"Speed" 可更快获得结果,但要以质量为代价:
n = 100000; {obj, const, vars} = {Total[x] / n, {Norm[x] ≤ Sqrt[n], x1}, x∈Vectors[n]};Timing[resSpeed = ConicOptimization[obj, const, vars,
"PrimalMinimumValue", PerformanceGoal -> "Speed"];]Timing[resQuality = ConicOptimization[obj, const, vars,
"PrimalMinimumValue", PerformanceGoal -> "Quality"];]{resSpeed, resQuality}Tolerance (2)
Tolerance 的设置越小给出的结果越精确:
{obj, cons, var} = {-x - y, {x ≥ 0, y ≥ 0, x + 2y ≤ 2, x ^ 2 + y ^ 2 ≤ 1}, {x, y}};用 Minimize 计算精确最小值:
exact = Minimize[obj, cons, var][[1]]计算 Tolerance 设为不同值时最小值的误差:
err = Table[{tol, Abs[ConicOptimization[obj, cons, var, "PrimalMinimumValue", Tolerance -> tol] - exact]}, {tol, 10. ^ -Range[7]}]ListLogLogPlot[err, PlotRange -> All, Joined -> True, PlotMarkers -> Automatic]Tolerance 的设置越小给出的答案越精确,但通常情况下要花费更多的时间进行计算:
n = 100000; {obj, const, vars} = {Total[x] / n, {Norm[x] ≤ Sqrt[n], x1}, x∈Vectors[n]};Timing[ptight = ConicOptimization[obj, const, vars,
"PrimalMinimumValue", Tolerance -> 10^-12];]Timing[ploose = ConicOptimization[obj, const, vars,
"PrimalMinimumValue", Tolerance -> 10^-2];]{ptight, ploose}应用 (29)
基本模型转换 (13)
最大化受约束条件
限制的
. 对目标函数取负求解最大化问题:
ConicOptimization[-(x + y), {x + y == 3, x ≥ 0, y ≤ 2}, {x, y}]-ConicOptimization[-(x + y), {x + y == 3, x ≥ 0, y ≤ 2}, {x, y}, "PrimalMinimumValue"]在圆心位于
、半径为
的圆盘上最小化
. 将目标函数
转换为线性函数
,额外限制条件为
,等价于
:
ConicOptimization[t, {{x, y}∈Disk[{1, 1}, 1], -t ≤ x + y ≤ t}, {x, y, t}]也可用 Norm 表示圆盘约束条件:
ConicOptimization[t, {Norm[{x - 1, y - 1}] ≤ 1, -t ≤ x + y ≤ t}, {x, y, t}]在正五边形上最小化
. 用
将目标函数转换为线性函数,额外限制条件为
:
ConicOptimization[s1 + s2, {{x, y}∈RegularPolygon[5], -s1 ≤ x + 1 ≤ s1, -s2 ≤ x - y ≤ s2}, {x, y, s1, s2}]最小化
. 通过使用辅助变量
,目标函数被转换为最小化受约束条件
限制的
:
{a1, b1} = Block[{n = 10, m = 5}, SeedRandom[123];{RandomReal[{-1, 1}, {n, m}], Range[n]}];ConicOptimization[t, {a == a1, b == b1, Norm[a.x - b] ≤ t}, {t, x}]最小化受约束条件
限制的
. 通过使用两个辅助变量
,将问题转换为最小化受约束条件
限制的
:
ConicOptimization[t1 + t2, {Norm[{x}] ≤ t1, Norm[{y}] ≤ t2, x + y ≤ 0, y ≥ 1}, {x, y, t1, t2}]最小化
. 通过使用辅助变量
,将问题转换为最小化受约束条件
限制的
:
{a1, b1} = IconizedObject[«CompoundExpression»];ConicOptimization[t, {a == a1, b == b1, Norm[a.x - b] ≤ t}, {x, t}]最小化受约束条件
限制的
,其中
为非递减函数,因而可代之以最小化
. 对于两个问题,原始最小值点
将保持不变. 考虑最小化受约束条件
限制的
:
f = Function[{s}, Sqrt[s]];{minval, Subscript[z, min]} = ConicOptimization[x + y, {(| | |
| - | - |
| x | 1 |
| 1 | y |)Underscript[, {"SemidefiniteCone", 2}]0, x + y ≥ 0}, {x, y}, {"PrimalMinimumValue", "PrimalMinimizerRules"}]f[minval]在圆心位于
、半径为
的圆盘上最小化
. 通过使用辅助变量
,目标函数被转换为最小化受额外约束条件
限制的
:
ConicOptimization[-t, {{x, y}∈Disk[{2, 2}], -Log[x + y] ≤ -t}, {x, y, t}]ConicOptimization[-t, {{x, y}∈Disk[{2, 2}], {t, 1, x + y}Underscript[, "ExponentialCone"]0}, {x, y, t}]在圆心位于
、半径为
的圆盘上最小化
. 通过使用辅助变量
,将问题转换为最小化受约束条件
限制的
:
ConicOptimization[t, {{x, y}∈Disk[{1, 1}], x + y^1.5 ≤ t}, {x, y, t}]约束条件
等价于
. 可用 "PowerCone" 通过
来表示:
ConicOptimization[t, {{x, y}∈Disk[{1, 1}], {t, 1, x + y}Underscript[, {"PowerCone", 1 / 1.5}]0}, {x, y, t}]{a, b} = IconizedObject[«BlockRandom»];通过使用辅助变量
,将问题转换为最小化受约束条件
限制的
:
ConicOptimization[t, {ap == a, bp == b, Norm[ap.x - bp, 1.5] ≤ t}, {x, t}]可用 "PowerCone" 约束条件来表示. 因为当且仅当
时
,用
限制
,其中
给出
:
sol = ConicOptimization[t, {{s1, t, a[[1]].x - b[[1]]}Underscript[, {"PowerCone", 1 / 1.5}]0, {s2, t, a[[2]].x - b[[2]]}Underscript[, {"PowerCone", 1 / 1.5}]0, s1 + s2 == t}, {x∈Vectors[2], t, s1, s2}]求最小化对称矩阵的最大特征值的
,该特征值线性依赖于决策变量
,
. 可将该问题表述为线性矩阵不等式,因为
等价于
,其中
是
的第 ![]()
个特征值. 对于线性矩阵函数
:
A[x_, y_] := (| | |
| -- | -- |
| 2 | -3 |
| -3 | 4 |) + (| | |
| - | - |
| 1 | 2 |
| 2 | 3 |) x + (| | |
| - | - |
| 4 | 5 |
| 5 | 6 |) yA[x, y]//MatrixForm可用正交矩阵
将实对称矩阵
对角化,以使得
. 因而当且仅当
时
. 由于任一
,取
,
,因而当且仅当
时
. 进行数值仿真以表明这些式子是等价的:
eigs = Eigenvalues[A[1., 2.]]data = Table[{λ, λ (| | |
| - | - |
| 1 | 0 |
| 0 | 1 |) Underscript[, {"SemidefiniteCone", 2}]A[1., 2.]}, {λ, RandomReal[{0, 35}, 100]}];
{true, false} = {Cases[data, {λ_, True} :> λ], Cases[data, {λ_, False} :> λ]};NumberLinePlot[{eigs, true, false}, IconizedObject[«Rule»]]res = ConicOptimization[λ, λ (| | |
| - | - |
| 1 | 0 |
| 0 | 1 |) Underscript[, {"SemidefiniteCone", 2}]A[x, y], {λ, x, y}]Min[Table[Max[Eigenvalues[A@@RandomReal[{-10000, 10000}, 2]]], 10000]]最小化受约束条件
限制的
,当
时假定
. 通过使用辅助变量
,目标函数变为最小化
以使得
:
{α, β, γ, δ} = {{1, 2}, 1, {-3, 4}, 2};
{a, b} = {{{1, -2}, {-3, 4}}, {-5, -1}};Reduce[Implies[a.{Indexed[x, {1}], Indexed[x, {2}]} + b >= 0, γ.{Indexed[x, {1}], Indexed[x, {2}]} + δ > 0], Reals]舒尔补条件表明如果
,则当且仅当
时分块矩阵
. 因此当且仅当
时
. 用 Inactive Plus 来构建约束条件以避免 threading:
ConicOptimization[t, {(| | |
| ------- | ------- |
| t | α.x + β |
| α.x + β | γ.x + δ |)Underscript[, {"SemidefiniteCone", 2}]0, a.x + b0}, {t, x∈Vectors[2]}]对于二次集合
,其中包括椭球、二次锥体和抛物面,确定
是否成立, 其中
为对称矩阵,
为向量,
为标量:
{a1, b1, c1} = {{{0.7, 0.68}, {0.68, 0.94}}, {0.35, .42}, 0.12};{a2, b2, c2} = {{{0.13, 0.2}, {0.2, 0.62}}, {.2, .4}, .01};With[{x = {x1, x2}}, RegionPlot[{x.a1.x + 2 b1.x + c1 ≤ 0, x.a2.x + 2 b2.x + c2 ≤ 0}, {x1, -2, 2}, {x2, -2, 2}, PlotLegends -> {Subscript[𝒬, 1], Subscript[𝒬, 2]}, ImageSize -> 100]]假定集合 i 为全维 (full dimensional) 集合,S-procedure 表明当且仅当有一些非负数
存在使得
成立时
才成立. 图示有非负数
存在:
m1 = ArrayFlatten[{{a1, {b1}}, {{b1}, {{c1}}}}];
m2 = ArrayFlatten[{{a2, {b2}}, {{b2}, {{c2}}}}];
Plot[Boole[λm1Underscript[, {"SemidefiniteCone", 3}]m2], {λ, 0, 5}, ImageSize -> Small]ConicOptimization[0, λ(| | |
| -- | -- |
| a1 | b1 |
| b1 | c1 |)Underscript[, {"SemidefiniteCone", 3}](| | |
| -- | -- |
| a2 | b2 |
| b2 | c2 |), λ]数据拟合问题 (5)
{a, b} = IconizedObject[«Block»];通过使用辅助变量
,转换后的目标函数为最小化受约束条件
限制的
:
ConicOptimization[t, {Norm[Inactive[Plus][a.x, -b]] ≤ t, x1}, {t, x}]用三次曲线拟合离散数据,以使数据的第一个和最后一个点位于曲线上:
data = IconizedObject[«Block»];用 DesignMatrix 构建矩阵:
a = DesignMatrix[data, {1, x, x^2, x^3}, x];
b = data[[All, 2]];pointConstraints = {a[[1]].λ == b[[1]], a[[-1]].λ == b[[-1]]};通过最小化
求系数
. 通过使用辅助变量
,转换后的目标函数为最小化受约束条件
限制的
:
res = ConicOptimization[t, {Norm[Inactive[Plus][a.λ, -b]] ≤ t, pointConstraints}, {t, λ}]Show[Plot[Evaluate[{1, x, x^2, x^3}.λ /. res], {x, 0, 1}, Epilog -> {Red, PointSize[0.03], Point[data[[{1, -1}]]]}], ListPlot[data]]data = IconizedObject[«Block»];bases = Sqrt[1 + (x - #) ^ 2]& /@ Subdivide[-3, 3, 10];
input = DesignMatrix[data, bases, x, IncludeConstantBasis -> False];
output = data[[All, 2]];由于
,因此使用辅助变量
. 问题被转换为最小化受约束条件
限制的
:
res = ConicOptimization[Total[s], {a == input, b == output, -sa.λ - bs}, {λ, s}];Plot[Evaluate[bases.λ /. res], {x, -3, 3}, Epilog -> {PointSize[0.008], Point[data]}]Plot[{Sin[2x] + Cos[x ^ 2], Evaluate[bases.λ /. res]}, {x, -3, 3}, PlotLegends -> {"Reference", "SubscriptBox[L, 1]fit"}]poly = 2 + 4 x + 6 x^2 + 4 x^3 + x^4;v = {1, x, x^2};n = Length[v];
mat = Array[Indexed[q, {##}] &, {n, n}];
Q = UpperTriangularize[mat] + Transpose[UpperTriangularize[mat, 1]];coeffs = Map[# == 0&, DeleteCases[Flatten[CoefficientList[v.Q.v - poly, {x}]], 0]]res = ConicOptimization[0, {coeffs , qUnderscript[, {"SemidefiniteCone", n}]0}, q]二次项
,其中
是对
进行 Cholesky 分解所得的下三角矩阵:
L = CholeskyDecomposition[(Q /. res)];
g = L.v;
Expand[Sum[g[[i]]^2, {i, Length[g]}]]Chop[Expand[Total[g ^ 2]] - poly, 10^-7]data = Block[{z}, SeedRandom[1234];
Table[{z = RandomComplex[{-2 - 2I, 2 + 2I}], z ^ (3 / 2) + 0.02 RandomComplex[]}, {i, 100}]];用 DesignMatrix 构建矩阵
,对于基
:
basis = {1, z, z ^ 2, z ^ 3};
a = DesignMatrix[data, basis, z];
b = data[[All, 2]];With[{σ = 0.2, m = Length[basis]}, res = ConicOptimization[t, Norm[Inactive[Plus][a.λ, -b]] + σ Norm[λ, 1] < t, {t, Element[λ, Vectors[m, Complexes]]}]]f[x_, y_] := basis.λ /. res /. z -> x + I y;Show[Plot3D[Re[f[x, y]], {x, -2, 2}, {y, -2, 2}], Graphics3D[{PointSize[0.03], Blue, Point[MapThread[Append, {ReIm[data[[All, 1]]], Re[data[[All, 2]]]}]]}]]Show[Plot3D[Im[f[x, y]], {x, -2, 2}, {y, -2, 2}], Graphics3D[{PointSize[0.03], Red, Point[MapThread[Append, {ReIm[data[[All, 1]]], Im[data[[All, 2]]]}]]}]]几何问题 (5)
求圆心位于
和
、半径为 1 的两个圆盘之间的最小距离. 令
为第一个圆盘上的点. 令
为第二个圆盘上的点. 目标是最小化
. 通过使用辅助变量
,转换后的目标函数为最小化受约束条件
限制的
:
res = ConicOptimization[t, {c2 == {2, 1}, Norm[p1] ≤ 1, Norm[p2 - c2] ≤ 1, Norm[p1 - p2] ≤ t}, {t, p1∈Vectors[2], p2∈Vectors[2]}]Graphics[{{Lighter[Blue], Disk[]}, {Lighter[Red], Disk[{2, 1}]}, {Green, PointSize[0.03], Point[{p1, p2} /. res]}}]{t, EuclideanDistance[p1, p2]} /. resregion = [image];constraints = Table[Norm[Inactive[Plus][pi, -c]] ≤ r, {pi, MeshCoordinates[region]}];res = ConicOptimization[r, constraints, {r, c∈Vectors[3]}]Show[Graphics3D[{Opacity[0.2], Red, Ball[c, r] /. res}], region]可用 BoundingRegion 高效求出最小包含球:
BoundingRegion[region, "MinBall"]{Subscript[Ω, 1], Subscript[Ω, 2]} = IconizedObject[«Block»];令
为
上的一个点. 令
为
上的一个点. 目标是最小化
. 通过使用辅助变量
,转换后的目标函数为最小化受约束条件
限制的
:
res = ConicOptimization[t, {p1∈Subscript[Ω, 1], p2∈Subscript[Ω, 2], Norm[p1 - p2] ≤ t}, {p1, p2, t}]根据分隔超平面定理,与约束条件
相关的对偶问题将给出超平面的法线:
{dual, cones} = ConicOptimization[t, {p1∈Subscript[Ω, 1], p2∈Subscript[Ω, 2], Norm[p1 - p2] ≤ t}, {p1, p2, t}, {"DualMaximizer", "ConicConstraintConeSpecifications"}];pos = Position[cones, {"NormCone", _}];
planeNormal = First@Extract[dual, pos]plane = Hyperplane[Most[planeNormal], (p1 + p2) / 2 /. res]Show[Subscript[Ω, 1], Subscript[Ω, 2], Graphics[{{Point[{p1, p2} /. res]}, {Red, plane}}]]cmesh = ConvexHullMesh[IconizedObject[«With»]];凸多边形的每个线段可被表示为半平面
相交的地方. 提取线性不等式:
segs = MeshPrimitives[cmesh, 1][[All, 1]];
a = segs /. {p_, q_} :> {-1, 1} * Reverse[p - q];
b = MapThread[#1.#2&, {a, segs[[All, 1]]}];constraints = Table[Norm[a[[i]].c] + a[[i]].d ≤ b[[i]], {i, Length[a]}];res = ConicOptimization[-Tr[c], constraints, {c∈Matrices[{2, 2}], d}]inscribedEllipse = Ellipsoid[d, Transpose[c].c] /. resShow[cmesh, Graphics[{LightRed, inscribedEllipse}]]求凸多边形的 analytic center. analytic center 是能最大化到限制边界的距离的乘积的点:
cmesh = ConvexHullMesh[IconizedObject[«With»]];凸多边形的每个线段可被表示为半平面
相交的地方. 提取线性不等式:
{a, b} = LinearOptimization[0, x∈cmesh, x, "LinearInequalityConstraints"];目标是最大化
. 对目标函数取
并取负,转换后的目标函数为
:
obj = Total[Table[-Log[a[[i]].x + b[[i]]], {i, Length[a]}]];通过使用辅助变量
,转换后的目标函数为最小化受约束条件
限制的
:
res = ConicOptimization[t, obj ≤ t, {t, x}, Method -> {"SCS", Tolerance -> 10 ^ -7}]Show[cmesh, Graphics[{PointSize[0.02], Point[x /. res]}]]分类问题 (3)
{set1, set2} = IconizedObject[«Block»];对于此分隔问题,第 1 组点必须满足
,第 2 组点必须满足
:
constraints = {set1.a + b1, set2.a + b-1};目标是最小化
,它给出的是
和
之间距离的两倍. 通过使用辅助变量
,目标函数被转换为约束条件
:
res = ConicOptimization[t, {Norm[a] ≤ t, constraints}, {t, a, b}]line = a.{x, y} + b /. resShow[RegionPlot[line ≤ 0, {x, 0, 1}, {y, 0, 1}], ListPlot[{set1, set2}, PlotMarkers -> {Automatic, PointSize[0.025]}]]{set1, set2} = IconizedObject[«Block»];
dataplot = ListPointPlot3D[{set1, set2}, Sequence[...]]用 DesignMatrix 构建两组点的二次多项式数据矩阵:
{data1, data2} = DesignMatrix[#, {x, x^2, y, y^2, x y}, {x, y}]& /@ {set1, set2};对于此分隔问题,第 1 组必须满足
,第 2 组必须满足
:
constraints = {data1.a + b1, data2.a + b-1};通过最小化
找出分隔多项式. 通过使用辅助变量
,转换后的目标函数为最小化受额外约束条件
限制的
:
res = ConicOptimization[t, {Norm[a] ≤ t, constraints}, {t, a, b}]poly = (a.{1, x, x^2, y, y^2, x y} + b) /. resShow[dataplot, ContourPlot3D[poly == 0, {x, -1.5, 1.5}, {y, -1.5, 1.5}, {z, -1, 1}, Sequence[...]]]将给定的点集
分成不同的组. 可通过最小化
找出每组的中心
来完成,其中
是给定的局部核,
是给定的惩罚参数:
x = IconizedObject[«Block»];
{n, dim} = Dimensions[x];
centers = Array[c, n];核
为使得
,否则
成立的
-近邻 (
) 函数. 对于此问题,选择
:
kNN = Nearest[x -> Automatic][x, 10];
κ = SparseArray[Join@@Table[Thread[{i, kNN[[i]]}], {i, n}] -> 1, {n, n}];通过使用辅助变量
,目标函数被转换为最小化受约束条件
限制的
:
c1 = Table[Norm[Inactive[Plus][x[[i]], -c[i]]], {i, n}];
c2 = Flatten[Table[κ[[i, j]]Norm[c[i] - c[j], 1], {i, 1, n}, {j, i + 1, n}]];
constraint = Total[c1 ^ 2] / 2 + 10 Total[c2] ≤ t;vars = Join[{t}, Table[c[i]∈Vectors[dim, Reals], {i, n}]];
res = ConicOptimization[t, constraint, vars, PerformanceGoal -> "Speed"];每个数据点都有一个相应的中心. 属于同一组的数据将具有相同的中心值:
allCenters = centers /. res;
cvals = Map[First, Gather[allCenters, Norm[#1 - #2] ≤ 0.001&]]gpts = Table[Pick[x, Map[Norm[# - ci] ≤ 0.001&, allCenters]], {ci, cvals}];
Show[ListPlot[gpts, PlotStyle -> PointSize[0.02]], ListPlot[allCenters, PlotStyle -> {PointSize[0.03], Magenta}]]最优控制问题 (1)
A = (| | |
| ---- | ---- |
| 2 | -0.5 |
| -0.3 | 2 |);
g[t_] := {Cos[t], Sin[t]};可使用梯形法近似要最小化的函数积分. 离散目标函数变为受额外约束条件
限制的
:
{ti, wts} = 2Pi Most[IconizedObject[«NIntegrate`TrapezoidalRuleData»]];
W = DiagonalMatrix[SparseArray[wts]];
n = Length[ti];dTMat = IconizedObject[«NDSolve`FiniteDifferenceDerivative[1, ti, DifferenceOrder -> 2]»];
ode1 = dTMat.x1 == A[[1]].{x1, x2} + u1;
ode2 = dTMat.x2 == A[[2]].{x1, x2} + u2;可用 Indexed 指定初始约束条件
:
ics = {Indexed[x1, 1] == 0, Indexed[x2, 1] == 0};通过使用辅助变量
,目标函数被转换为最小化受约束条件
限制的
:
{g1, g2} = g[ti];
res = ConicOptimization[t, {ode1, ode2, ics, y.W.y + z.W.zt, y == Inactive[Plus][g1, -x1], z == Inactive[Plus][g2, -x2], -2u12, -2u22}, {u1∈Vectors[n], u2∈Vectors[n], x1, x2, y, z, t}];将离散化结果转换为 InterpolatingFunction:
{u1sol, u2sol, x1sol, x2sol} = Map[ListInterpolation[#, ti]&, {u1, u2, x1, x2} /. res];Plot[{u1sol[t], u2sol[t]}, {t, 0, 2Pi}]{Plot[{x1sol[t], Cos[t]}, {t, 0, 2Pi}, ImageSize -> 200], Plot[{x2sol[t], Sin[t]}, {t, 0, 2Pi}, ImageSize -> 200]}设施选址问题 (1)
clientPos = {{0, 0}, {1, 0}, {3 / 2, 1}, {-1 / 2, 1}, {1 / 2, 3 / 2}, {1 / 2, 1 / 2}, {0, 3 / 2}, {1, 1}, {0, 1}, {3 / 2, 3 / 2}};
nTowers = 3;
nClients = Length[clientPos];每个基站消耗的功率与其范围成正比,由
给出. 目的是最大程度地降低功耗:
objective = Sum[r[i] ^ 1.5, {i, nTowers}];decisionConstraint = 0z1;m = 20;
distConstraint = Table[Norm[Inactive[Plus][p[j], -clientPos[[i]]]] -
m * (1 - Indexed[z, {i, j}]) ≤ r[j], {i, nClients}, {j, nTowers}];coverageConstraint = Total[z, {2}]1;maxCoverageConstraint = Table[0 ≤ r[j] ≤ 1, {j, nTowers}];vars = Flatten[{Table[{p[j]∈Vectors[2], r[j]}, {j, nTowers}], z∈Matrices[{nClients, nTowers}, Integers]}];res = Quiet[ConicOptimization[t, {objective ≤ t, decisionConstraint,
distConstraint, coverageConstraint, maxCoverageConstraint}, Append[vars, t]]]towerPos = Table[p[i], {i, nTowers}] /. res;
towerRange = Table[r[i], {i, nTowers}] /. res;Graphics[{{Orange, PointSize[0.04], Point[towerPos]}, {Magenta, PointSize[0.02], Point[clientPos]}, {...}}, Frame -> True]投资组合优化 (1)
找到资本
的分布以投资六只股票,以在最大程度地降低风险的同时最大化回报:
{μ, Σ} = Block[...];return = μ.w;risk = w.Σ.w;
riskConstraint = risk ≤ s;目的是在使特定风险规避参数的风险最小化的同时,最大化回报率:
objective[α_ ? NumericQ] := -(return - α s);由股票买卖引起的对股票市场价格的影响可以通过
建模,该模型由幂锥建模,使用题词转换:
marketConstraints = Table[Abs[Indexed[w, i]] ^ 1.5 ≤ Indexed[t, i], {i, 6}];权重
必须都大于 0,并且权重加上市场影响成本必须相加为 1:
weightConstraints = {w0, Total[w] + 0.1Total[t] == 1};frontier = Table[res = Quiet@ConicOptimization[objective[α],
{riskConstraint, weightConstraints, marketConstraints}, {w, s, t∈Vectors[6]}];
{risk, return} /. res, {α, Subdivide[0, 10, 200]}];randomRiskReturns = Table[{risk, return}, {w, Table[...]}];
Show[ListPlot[frontier, ...], ListPlot[randomRiskReturns, Rule[...]]]riskAversionParameter = N@{1 / 1000, 1 / 100, 1 / 2, 1, 5, 10, 15, 20};
res = Table[{α, return, Quiet@Append[w, 1 - Total[w]]} /.
Quiet@ConicOptimization[objective[α],
{riskConstraint, weightConstraints, marketConstraints}, {w, s, t∈Vectors[6]}], {α, riskAversionParameter}];通过考虑市场成本,可以获得低风险规避的分散投资组合,但是当风险规避较高时,由于购买分散程度较低的股票,市场影响成本占主导地位:
Legended[BarChart[res[[All, -1]], ...], SwatchLegend[...]]属性和关系 (8)
ConicOptimization 给出目标函数的全局最小值:
res = ConicOptimization[2Subscript[x, 1] + 3Subscript[x, 2], (| | |
| -- | -- |
| x1 | 1 |
| 1 | x2 |)Underscript[, {"SemidefiniteCone", 2}]0, {Subscript[x, 1], Subscript[x, 2]}]Show[Plot3D[2Subscript[x, 1] + 3Subscript[x, 2], {Subscript[x, 1], Subscript[x, 2]}∈ImplicitRegion[...]], Graphics3D[...]]Minimize 给出锥优化问题的全局精确结果:
Minimize[{2Subscript[x, 1] + 3Subscript[x, 2], (| | |
| -- | -- |
| x1 | 1 |
| 1 | x2 |)Underscript[, {"SemidefiniteCone", 2}]0}, {Subscript[x, 1], Subscript[x, 2]}]%//NNMinimize 可用全局方法获得近似结果:
NMinimize[{2Subscript[x, 1] + 3Subscript[x, 2], (| | |
| -- | -- |
| x1 | 1 |
| 1 | x2 |)Underscript[, {"SemidefiniteCone", 2}]0}, {Subscript[x, 1], Subscript[x, 2]}]FindMinimum 可用局部方法获得近似结果:
FindMinimum[{2Subscript[x, 1] + 3Subscript[x, 2], (| | |
| -- | -- |
| x1 | 1 |
| 1 | x2 |)Underscript[, {"SemidefiniteCone", 2}]0}, {Subscript[x, 1], Subscript[x, 2]}]SemidefiniteOptimization 是 ConicOptimization 的特例:
SemidefiniteOptimization[10x + 11y, {x + y ≥ 2, (| | |
| - | - |
| x | 1 |
| 1 | y |)Underscript[, {"SemidefiniteCone", 2}]0}, {x, y}]ConicOptimization[10x + 11y, {x + y ≥ 2, (| | |
| - | - |
| x | 1 |
| 1 | y |)Underscript[, {"SemidefiniteCone", 2}]0}, {x, y}]SecondOrderConeOptimization 是 ConicOptimization 的特例:
SecondOrderConeOptimization[10x + 11 y, {x + y ≥ 1, {x, y}∈Disk[]}, {x, y}]ConicOptimization[10x + 11 y, {x + y ≥ 1, {x, y}∈Disk[]}, {x, y}]QuadraticOptimization 是 ConicOptimization 的特例:
obj = 2x^2 + 20y^2 + 6x y + 5x;
cons = {-x + y ≥ 2, y ≥ 0};QuadraticOptimization[obj, cons, {x, y}]ConicOptimization[t, {obj ≤ t, cons}, {x, y, t}]LinearOptimization 是 ConicOptimization 的特例:
LinearOptimization[10.x + 11.y, {x, y}∈RegularPolygon[4], {x, y}]ConicOptimization[10.x + 11.y, {x, y}∈RegularPolygon[4], {x, y}]可能存在的问题 (6)
res = ConicOptimization[x + y, {x^2 + y^2 ≤ 1}, {x, y}]x^2 + y^2 ≤ 1 /. resx^2 + y^2 - 1 /. res通常可以用 Tolerance 选项控制对约束条件的违反:
res = ConicOptimization[x + y, {x^2 + y^2 ≤ 1}, {x, y}, Tolerance -> 10 ^ -8]x^2 + y^2 - 1 /. resConicOptimization[x, {x ≤ 0, x ≥ 1}, x, "PrimalMinimumValue"]最小值点为 Indeterminate:
ConicOptimization[x, {x ≤ 0, x ≥ 1}, x]ConicOptimization[-(x + y), x + y ≥ 1, {x, y}, "PrimalMinimumValue"]最小值点为 Indeterminate:
ConicOptimization[-(x + y), x + y ≥ 1, {x, y}]ConicOptimization[x + y + z, {x ^ 2 + y ^ 2 + z ^ 2 ≤ 10 ^ 20, x > 5, y > 5}, {x, y, z}]Minimize[{x + y + z, {x ^ 2 + y ^ 2 + z ^ 2 ≤ 10 ^ 20, x ≥ 5, y ≥ 5}}, {x, y, z}][[2]]//NConicOptimization[x + y + z, {x ^ 2 + y ^ 2 + z ^ 2 ≤ 1, x > 5*^-10, y > 5*^-10}, {x, y, z}]
、
的位于 5*10-10 ±10-6 上下的结果将符合容差 10-6,当去掉缩放后可产生的最大错误为:
10 ^ 10 * 10 ^ -6ConicOptimization[x + y + z, {x ^ 2 + y ^ 2 + z ^ 2 ≤ 10 ^ 20, x > 5, y > 5}, {x, y, z}, Tolerance -> 10 ^ -13]ConicOptimization[t, {2x^2 + 20y^2 + 6x y + 5x ≤ t, -x + y ≥ 2}, {x∈Integers, y, t}, {"DualMaximumValue", "DualMaximizer", "DualityGap"}]{q, c} = {{{2, 1 + I}, {1 - I, 1}}, {2, 3}};
ConicOptimization[{1, 2}.x, (1 / 2) * x.q.x + c.x1, x∈Vectors[2, Reals]]即便理论上两边都是实数,只使用 Less 也是不可行的:
{q, c} = {{{2, 1 + I}, {1 - I, 1}}, {2, 3}};
ConicOptimization[{1, 2}.x, (1 / 2) * x.q.x + c.x < 1, x∈Vectors[2, Reals]]相关指南
-
▪
- 凸优化 ▪
- 基于矩阵的最小化 ▪
- 最优化 ▪
- 符号向量、矩阵和数组
文本
Wolfram Research (2019),ConicOptimization,Wolfram 语言函数,https://reference.wolfram.com/language/ref/ConicOptimization.html (更新于 2020 年).
CMS
Wolfram 语言. 2019. "ConicOptimization." Wolfram 语言与系统参考资料中心. Wolfram Research. 最新版本 2020. https://reference.wolfram.com/language/ref/ConicOptimization.html.
APA
Wolfram 语言. (2019). ConicOptimization. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/ConicOptimization.html 年
BibTeX
@misc{reference.wolfram_2026_conicoptimization, author="Wolfram Research", title="{ConicOptimization}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/ConicOptimization.html}", note=[Accessed: 09-September-2026]}
BibLaTeX
@online{reference.wolfram_2026_conicoptimization, organization={Wolfram Research}, title={ConicOptimization}, year={2020}, url={https://reference.wolfram.com/language/ref/ConicOptimization.html}, note=[Accessed: 09-September-2026]}