({{, (RefLink[ConicOptimization, paclet:ref/ConicOptimization])[f,cons,vars] 
finds values of variables vars that minimize the linear objective f subject to conic constraints cons.}, {, (RefLink[ConicOptimization, paclet:ref/ConicOptimization])[…,"prop"]
specifies what solution property "prop" should be returned.}})

OpenersNotesSection(Spacer1)Details and Options

Conic optimization is also known as linear conic optimization or linear conic programming.

Conic optimization includes many other forms of optimization, including linear optimization, linear fractional optimization, quadratic optimization, second-order cone optimization, semidefinite optimization and geometric optimization.

Conic optimization is a convex optimization problem that can be solved globally and efficiently.

Conic optimization finds x that solves the primal problem:

The set (Subscript[κ, j]) should be a proper convex cone of dimension (Subscript[m, i]). Common cone specifications for (Subscript[κ, j]) and the sets corresponding to x(Subscript[\[VectorGreaterEqual], (Subscript[κ, j])])0 are:

The constraints cons can be specified by:

With (RefLink[ConicOptimization, paclet:ref/ConicOptimization])[f,cons,vars], parameter equations of the form par==val, where par is not in vars and val is numerical or an array with numerical values, may be included in the constraints to define parameters used in f or cons. »

The primal minimization problem has a related maximization problem that is the Lagrangian dual problem. The dual maximum value is always less than or equal to the primal minimum value, so it provides a lower bound. The dual maximizer provides information about the primal problem, including sensitivity of the minimum value to changes in the constraints. »

The conic optimization has a dual problem: »

The possible solution properties "prop" include:

The following options may be given:

The option (RefLink[Method, paclet:ref/Method])->method may be used to specify the method to use. Available methods include:

Computations are limited to (RefLink[MachinePrecision, paclet:ref/MachinePrecision]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (76)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Minimize (Subscript[x, 1])+2(Subscript[x, 2]) over a two-dimensional "NormCone":

res=ConicOptimization[(Subscript[x, 1])+2(Subscript[x, 2]),{(Subscript[x, 1]),(Subscript[x, 2])}(Underscript[\[VectorGreaterEqual], (NormConeList[2])])0, {(Subscript[x, 1]),(Subscript[x, 2])}]

The optimal point is where (Subscript[x, 1])+2(Subscript[x, 2]) is smallest within the region defined by the constraints:

Show[Plot3D[(Subscript[x, 1])+2(Subscript[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])+2(Subscript[x, 2])}/.res]}]]

Minimize -(x+y) over the intersection of a triangle x≥0,y≥0,x+2y≤2 and a disk (x^2)+(y^2)≤1:

(Subscript[x, min])=ConicOptimization[-(x+y),{x≥0,y≥0,x+2 y≤2,(x^2)+(y^2)≤1},{x,y}]

Visualize the location of the minimizing point:

RegionPlot[{x≥0&&y≥0&&x+2 y≤2,x^2+y^2≤1},]

OpenersExampleSection1(Spacer1)Scope  (25)

OpenersExampleSubsection0(Spacer1)Basic Uses  (11)

Minimize x+2y subject to constraints (x^2)+2(y^2)≤3,x+y==2,x≥1:

res=ConicOptimization[x+2y,{(x^2)+2(y^2)≤ 3,x+y==2,x≥ 1},{x,y}]

Several linear inequality constraints can be expressed with (RefLink[VectorGreaterEqual, paclet:ref/VectorGreaterEqual]):

ConicOptimization[x+y,VectorGreaterEqual[{{x+2y,x},{3,-1}}],{x,y}]

Use (Key0[esc]) v>= (Key0[esc]) or (RefLink[\[VectorGreaterEqual], paclet:ref/character/VectorGreaterEqual]) to enter the vector inequality sign \[VectorGreaterEqual]:

ConicOptimization[x+y,{x+2y,x}\[VectorGreaterEqual]{3,-1},{x,y}]

An equivalent form using scalar inequalities:

ConicOptimization[x+y,{x+2y≥3,x≥-1},{x,y}]

Use a vector variable v={x,y}:

ConicOptimization[{1,1}.v, {{1,2},{1,0}}.v\[VectorGreaterEqual]{3,-1},v]

The inequality a.x+b\[VectorGreaterEqual]0 may not be the same as a.x\[VectorGreaterEqual]-b due to possible threading in a.x+b:

ConicOptimization[{1,1}.x, {{1,2},{1,0}}.x+{-3,1}\[VectorGreaterEqual]0,x]

ConicOptimization[{1,1}.x, {{1,2},{1,0}}.x\[VectorGreaterEqual]{3,-1},x]

To avoid unintended threading in a.x+b, use (RefLink[Inactive, paclet:ref/Inactive])[(RefLink[Plus, paclet:ref/Plus])]:

ConicOptimization[{1,1}.x,{{1,2},{1,0}}.x+{-3,1}\[VectorGreaterEqual]0,x]

Use parameter equations to avoid unintended threading in a.x+b:

parEqs={a=={{1,2},{1,0}},b=={3,-1}};

ConicOptimization[{1,1}.x,{parEqs,a.x+b\[VectorGreaterEqual]0},x]

(RefLink[VectorGreaterEqual, paclet:ref/VectorGreaterEqual]) represents a conic inequality with respect to the "NonNegativeCone":

constraint= VectorGreaterEqual[{{{1,2},{1,0}}.v,{3,-1}},"NonNegativeCone"]

To explicitly specify the dimension of the cone, use {"NonNegativeCone",n}:

constraint= VectorGreaterEqual[{{{1,2},{1,0}}.v,{3,-1}},{"NonNegativeCone",2}]

Find the solution:

ConicOptimization[{1,1}.v, constraint,v]

Minimize x+2y subject to the constraint (x^2)+(y^2)≤9:

ConicOptimization[x+y,(x^2)+(y^2)≤9,{x,y}]

Specify the constraint (x^2)+(y^2)≤9 using a conic inequality with "NormCone":

VectorGreaterEqual[{{x,y,3},0},{"NormCone",3}]

Find the solution:

ConicOptimization[x+y,{x,y,3}(Underscript[\[VectorGreaterEqual], (NormConeList[3])])0,{x,y}]

Minimize x+2y subject to the positive semidefinite matrix constraint (({{x, 1}, {1, y}}))(Underscript[\[VectorGreaterEqual], (SemidefiniteConeList[2])])0:

constraint=  VectorGreaterEqual[{{{x,1},{1,y}},0}, {"SemidefiniteCone",2}]

Find the solution:

ConicOptimization[x+2y,constraint,{x,y}]

Use a vector variable x and (RefLink[Indexed, paclet:ref/Indexed])[x,i] to specify individual components:

ConicOptimization[{1,2}.x,(({{(IndexedDefault[x, 1]), 1}, {1, (IndexedDefault[x, 2])}}))(Underscript[\[VectorGreaterEqual], (SemidefiniteConeList[2])])0,x]

Use (RefLink[Vectors, paclet:ref/Vectors])[n] to specify the dimension of a vector variable when it is ambiguous:

ConicOptimization[(IndexedDefault[x, 1])+2(IndexedDefault[x, 2]),(({{(IndexedDefault[x, 1]), 1}, {1, (IndexedDefault[x, 2])}}))(Underscript[\[VectorGreaterEqual], (SemidefiniteConeList[2])])0,x]

ConicOptimization[(IndexedDefault[x, 1])+(IndexedDefault[2x, 2]),(({{(IndexedDefault[x, 1]), 1}, {1, (IndexedDefault[x, 2])}}))(Underscript[\[VectorGreaterEqual], (SemidefiniteConeList[2])])0,x∈Vectors[2]]

Specify non-negative constraints using (RefLink[NonNegativeReals, paclet:ref/NonNegativeReals]) ((NonNegativeReals)):

ConicOptimization[{1,1}.x, {(IndexedDefault[x, 1]),(IndexedDefault[x, 2]),1}(Underscript[\[VectorGreaterEqual], (NormConeList[3])])0,x∈Vectors[2, NonNegativeReals]]

An equivalent form using vector inequality x\[VectorGreaterEqual]0:

ConicOptimization[{1,1}.x, {{(IndexedDefault[x, 1]),(IndexedDefault[x, 2]),1}(Underscript[\[VectorGreaterEqual], (NormConeList[3])])0,x\[VectorGreaterEqual]0},x]

OpenersExampleSubsection1(Spacer1)Primal Model Properties  (3)

Minimize -(x+y) over the intersection of a triangle x≥0,y≥0,x+2y≤2 and a disk (x^2)+(y^2)≤1:

triangle = {x≥0,y≥0,x+2y≤2};
disk = x^2+y^2≤1;

sol=ConicOptimization[-(x+y),{triangle,disk},{x,y}]

Get the primal minimizer as a vector:

{xmin,ymin}=ConicOptimization[-(x+y),{triangle,disk},{x,y},"PrimalMinimizer"]

Get the minimal value:

minval =ConicOptimization[-(x+y),{triangle,disk},{x,y},"PrimalMinimumValue"]

Plot the solution:

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]}]

Extract the objective vector:

triangle = {x≥0,y≥0,x+2y≤2};
disk = x^2+y^2≤1;

c=ConicOptimization[-(x+y),{triangle,disk},{x,y},"ObjectiveVector"]

Extract the conic constraints:

ConicOptimization[-(x+y),{triangle,disk},{x,y},"ConicConstraints"]//Normal

Extract the cone specification {(Subscript[κ, 1]),…} in the conic constraints:

ConicOptimization[-(x+y),{triangle,disk},{x,y},"ConicConstraintConeSpecifications"]

Extract the cone dimensions {dims((Subscript[κ, 1])),…} in the conic constraints:

ConicOptimization[-(x+y),{triangle,disk},{x,y},"ConicConstraintConeDimensions"]

Extract the affine lists {{(Subscript[a, 0]),(Subscript[b, 0])},…} in the conic constraints:

ConicOptimization[-(x+y),{triangle,disk},{x,y},"ConicConstraintAffineLists"]//Normal

The slack for an inequality (Subscript[a, j]).x+(Subscript[b, j])(Underscript[\[VectorGreaterEqual], (Subscript[κ, j])])0 at the minimizer (SuperStar[x]) is given by  (Subscript[a, j]).(SuperStar[x])+(Subscript[b, j])-(Subscript[s, j])=0:

triangle = {(Subscript[x, 1])≥0,(Subscript[x, 2])≥0,(Subscript[x, 1])+2(Subscript[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"]

Extract the minimizer and conic constraint affine lists:

{(SuperStar[x]), afflists}=Normal[ConicOptimization[-((Subscript[x, 1])+(Subscript[x, 2])),{triangle,disk},{(Subscript[x, 1]),(Subscript[x, 2])},{"PrimalMinimizer", "ConicConstraintAffineLists"}]]

Verify that the slack satisfies s={(Subscript[s, 0]),…,(Subscript[s, k])} with (Subscript[a, j]).(SuperStar[x])+(Subscript[b, j])-(Subscript[s, j])=0.

{{(Subscript[a, 1]),(Subscript[b, 1])},{(Subscript[a, 2]),(Subscript[b, 2])}}  = afflists;

{(Subscript[a, 1]).(SuperStar[x]) +(Subscript[b, 1]),(Subscript[a, 2]).(SuperStar[x]) +(Subscript[b, 2])}-s

OpenersExampleSubsection2(Spacer1)Dual Model Properties  (3)

Minimize c.x subject to (Subscript[a, 0]).x+(Subscript[b, 0])==0 and (Subscript[a, j]).x+(Subscript[b, j])(Subscript[\[VectorGreaterEqual], (Subscript[κ, j])])0.

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[\[VectorGreaterEqual], (NormConeList[3])])0},x]

The dual problem is to maximize -(Subscript[b, 0])(Subscript[λ, 0])-(∑_(i=1)^k)(Subscript[b, i]).(Subscript[λ, i]) subject to (Subscript[a, 0]^ᵀ).(Subscript[λ, 0])+(∑_(i=1)^k)(Subscript[a, i]^ᵀ).(Subscript[λ, i])=c, (Subscript[λ, i])(Subscript[\[VectorGreaterEqual], (Subscript[κ, i]^( * ))])0:

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[\[VectorGreaterEqual], (NormConeList[3])])0},{(Subscript[λ, 0]),(Subscript[λ, 1])}]

The primal minimum value and the dual maximum value coincide because of strong duality:

{c.x/.psol,- (Subscript[b, 0]).(Subscript[λ, 0])-(Subscript[b, 1]).(Subscript[λ, 1]) /.dsol}

That is the same as having a duality gap of zero. In general, c.(SuperStar[x])≤-(Subscript[b, 0])(SuperStar[(Subscript[λ, 0])])-(∑_(i=1)^k)(Subscript[b, i]).(SuperStar[(Subscript[λ, i])]) at optimal points:

ConicOptimization[c.x,{(Subscript[a, 0]).x+(Subscript[b, 0])==0,(Subscript[a, 1]).x+(Subscript[b, 1])(Underscript[\[VectorGreaterEqual], (NormConeList[3])])0},x,"DualityGap"]

Construct the dual problem using coefficients extracted from the primal problem:

obj=(IndexedDefault[x, 1])+(IndexedDefault[x, 2]);
 constraints={(IndexedDefault[x, 1])==(IndexedDefault[x, 2]),((IndexedDefault[x, 1])^2)+((IndexedDefault[x, 2])^2)≤1};

ConicOptimization[obj,constraints,x∈Vectors[2]]

Extract the objective vector and constraint affine lists:

{c,afflists}=ConicOptimization[obj,constraints,x∈Vectors[2],{"ObjectiveVector","ConicConstraintAffineLists"}];

Get the (Subscript[a, i]) and (Subscript[b, i]):

{{(Subscript[a, 0]),(Subscript[b, 0])}, {(Subscript[a, 1]),(Subscript[b, 1])}}  = afflists;

The dual problem is to maximize -(Subscript[b, 0])(Subscript[λ, 0])-(∑_(i=1)^k)(Subscript[b, i]).(Subscript[λ, i]) subject to (Subscript[a, 0]^ᵀ).ν+(∑_(i=1)^k)(Subscript[a, i]^ᵀ).(Subscript[λ, i])=c, (Subscript[λ, i])(Subscript[\[VectorGreaterEqual], (Subscript[κ, i]^( * ))])0:

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[\[VectorGreaterEqual], (NormConeList[3])])0},{(Subscript[λ, 0]),(Subscript[λ, 1])}]

Get the dual maximum value and dual maximizer directly using solution properties:

ConicOptimization[(IndexedDefault[x, 1])+(IndexedDefault[x, 2]),{(IndexedDefault[x, 1])==(IndexedDefault[x, 2]),((IndexedDefault[x, 1])^2)+((IndexedDefault[x, 2])^2)≤1},{(IndexedDefault[x, 1]),(IndexedDefault[x, 2])}, "DualMaximumValue"]

The "DualMaximizer" can be obtained with:

dualMaximizer=ConicOptimization[(IndexedDefault[x, 1])+(IndexedDefault[x, 2]),{(IndexedDefault[x, 1])==(IndexedDefault[x, 2]),((IndexedDefault[x, 1])^2)+((IndexedDefault[x, 2])^2)≤1},{(IndexedDefault[x, 1]),(IndexedDefault[x, 2])},"DualMaximizer"]

The dual maximizer vector partitions match the number and dimensions of the dual cones:

{(Subscript[λ, 0]),(Subscript[λ, 1])}= dualMaximizer

OpenersExampleSubsection3(Spacer1)Sensitivity Properties  (3)

Find the change in optimal value due to constraint perturbations:

a={{1,0},{0,1},{-1,-2}};b={0,0,1};
disk=a.{x,y}+b(Underscript[\[VectorGreaterEqual], (NormConeList[3])])0;

minValue=ConicOptimization[-x-y,{disk},{x,y}, "PrimalMinimumValue"]

Compute the "ConstraintSensitivity":

{s}=ConicOptimization[-x-y,{disk},{x,y}, "ConstraintSensitivity"]

Consider new constraint a.{x,y}+b+δ(Underscript[\[VectorGreaterEqual], (NormConeList[3])])0 where δ is the perturbation:

δ=0.01*{1,2,3};

The new optimal value can be estimated to be:

minValue+δ.s

Compare to directly solving the perturbed problem:

ConicOptimization[-x-y,{a.{x,y}+(b+δ) (Underscript[\[VectorGreaterEqual], (NormConeList[3])])0},{x,y}, "PrimalMinimumValue"]

The optimal value changes according to the signs of the sensitivity elements:

a={{1,0},{0,1},{-1,-2}};b={0,0,1};
disk=a.{x,y}+b(Underscript[\[VectorGreaterEqual], (NormConeList[3])])0;

{(SuperStar[p]),sens}=ConicOptimization[-x-y,{disk},{x,y},{"PrimalMinimumValue","ConstraintSensitivity"}]

At negative sensitivity element position, a positive perturbation will decrease the optimal value:

(SuperStar[p])>ConicOptimization[-x-y,a.{x,y}+(b+{0,0,1})(Underscript[\[VectorGreaterEqual], (NormConeList[3])])0,{x,y},"PrimalMinimumValue"]

At positive sensitivity element position, a positive perturbation will increase the optimal value:

(SuperStar[p])<ConicOptimization[-x-y,a.{x,y}+(b+{1,0,0})(Underscript[\[VectorGreaterEqual], (NormConeList[3])])0,{x,y},"PrimalMinimumValue"]

The constraint sensitivity can also be obtained as the negative of the dual maximizer:

-ConicOptimization[-{1,1}.{x,y},{{x,y,1-x-2 y}(Underscript[\[VectorGreaterEqual], (NormConeList[3])])0},{x,y},
 "DualMaximizer"]

ConicOptimization[-{1,1}.{x,y},{{x,y,1-x-2 y}(Underscript[\[VectorGreaterEqual], (NormConeList[3])])0},{x,y},
"ConstraintSensitivity"]

OpenersExampleSubsection4(Spacer1)Supported Convex Cones  (5)

OpenersExampleSubsubsection0(Spacer1)"NonNegativeCone"  (1)

Minimize 10 x+11y over a regular nonagon:

{minval, {xmin,ymin}} = ConicOptimization[10x+11 y,{x,y}∈RegularPolygon[9],{x,y},{"PrimalMinimumValue", "PrimalMinimizer"}]

Show the minimizer on a plot of the objective function:

Show[Plot3D[10x+11y,{x,y}∈RegularPolygon[9],MeshFunctions->{#3&}], Graphics3D[{Red,PointSize[0.05],Point[{xmin,ymin,minval}]}]]

Show the cones used in the conic constraints:

ConicOptimization[10x+11 y,{x,y}∈RegularPolygon[9],{x,y},"ConicConstraintConeSpecifications"]

OpenersExampleSubsubsection1(Spacer1)"NormCone"  (1)

Minimize 10 x+11y over a disk:

{minval,{xmin,ymin}} = ConicOptimization[10x+11 y,{x,y}∈Disk[],{x,y},{"PrimalMinimumValue","PrimalMinimizer"}]

Show the minimizer on a plot of the objective function:

Show[Plot3D[10x+11y,{x,y}∈Disk[],MeshFunctions->{#3&}], Graphics3D[{Red,PointSize[0.05],Point[{xmin,ymin,minval}]}]]

Show the cones used in the conic constraints:

ConicOptimization[10.x+11.  y,{x,y}∈Disk[],{x,y},"ConicConstraintConeSpecifications"]

OpenersExampleSubsubsection2(Spacer1)"SemidefiniteCone"  (1)

Minimize 10 x+11y such that (({{x, 1}, {1, y}})) is positive semidefinite:

{minval, {xmin,ymin}} = ConicOptimization[10x+11 y,(({{x, 1}, {1, y}}))(Underscript[\[VectorGreaterEqual], (SemidefiniteConeList[2])])0,{x,y},{"PrimalMinimumValue","PrimalMinimizer"}]

Show the minimizer on a plot of the objective function:

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}]}]]

Show the cones used in the conic constraints:

ConicOptimization[10x+11y,(({{x, 1}, {1, y}}))(Underscript[\[VectorGreaterEqual], (SemidefiniteConeList[2])])0,{x,y},"ConicConstraintConeSpecifications"]

OpenersExampleSubsubsection3(Spacer1)"ExponentialCone"  (1)

Minimize 10 x+11y subject to the constraints x≥0,y≥0,-log(x)-log(y)≤ 0:

{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 the minimizer on a plot of the objective function:

Show[Plot3D[10x+11y, {x,y}∈ImplicitRegion[{x≥ 0,y≥ 0,-Log[x] - Log[y]≤ 0},{{x,-10,10},{y,-10,10}}],MeshFunctions->{#3&}], Graphics3D[{Red,PointSize[0.05],Point[{xmin,ymin,minval}]}]]

Show the cones used in the conic constraints:

ConicOptimization[10 x+ 11 y,{x≥ 0,y≥ 0,-Log[x] - Log[y]≤ 0},{x,y},"ConicConstraintConeSpecifications"]

OpenersExampleSubsubsection4(Spacer1)"PowerCone"  (1)

Minimize 10 x+11y over the 4-norm unit disk:

{minval,{xmin,ymin}} = ConicOptimization[10.x+11.y,Inactive[Norm][{x,y},4]≤1,{x,y},{"PrimalMinimumValue","PrimalMinimizer"}]

Show the minimizer on a plot of the objective function:

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}]}]]

Show the cones used in the conic constraints:

ConicOptimization[10 x+11 y,Inactive[Norm][{x,y},4]≤1,{x,y},"ConicConstraintConeSpecifications"]

OpenersExampleSection2(Spacer1)Options  (11)

OpenersExampleSubsection5(Spacer1)Method  (8)

"SCS" uses a splitting conic solver method:

ConicOptimization[-x-y,{x≥0,y≥0,x+2y≤2,(x^2)+(y^2)≤1},{x,y},Method->"SCS"]

"CSDP" is an interior point method for semidefinite problems:

ConicOptimization[-x-y,{x≥0,y≥0,x+2y≤2,(x^2)+(y^2)≤1},{x,y},Method->"CSDP"]

"DSDP" is an alternative interior point method for semidefinite problems:

ConicOptimization[-x-y,{x≥0,y≥0,x+2y≤2,(x^2)+(y^2)≤1},{x,y},Method->"DSDP"]

"IPOPT" is an interior point method for nonlinear problems:

ConicOptimization[-x-y,{x≥0,y≥0,x+2y≤2,(x^2)+(y^2)≤1},{x,y},Method->"IPOPT"]

Different methods have different default tolerances, which affects the accuracy and precision:

{obj,cons,var}={-x-y,{x≥0,y≥0,x+2y≤2,x^2+y^2≤1}, {x,y}};
props={"PrimalMinimumValue", "PrimalMinimizer"};

Compute exact and approximate solutions:

{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"];

"SCS" has a default tolerance of (10^(-3)):

solSCS-exact

"CSDP", "DSDP" and "IPOPT" have default tolerances of (10^(-8)):

solCSDP-exact

solDSDP-exact

solIPOPT-exact

When method "SCS" is specified, it is called with the SCS library default tolerance of (10^(-3)):

ConicOptimization[x+y,{(x^2) +(y^2)≤ 1},{x,y}, Method->"SCS"]

With default options, this problem is solved by method "SCS" with tolerance (10^(-6)):

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}]

Use methods "CSDP" or "DSDP" for up to semidefinite constraints:

lin = {{1,0},{0,1},{-1,-2}}.x+{0,0,2}(Underscript[\[VectorGreaterEqual], (NonNegativeConeList[3])])0;

norm = {{1,0},{0,1},{0,0}}.x+{0,0,1}(Underscript[\[VectorGreaterEqual], (NormConeList[3])])0;

semi = {{{-4,0},{0,0}},{{0,0},{0,-0.8}}}.x+{{5,1},{1,1}}(Underscript[\[VectorGreaterEqual], (SemidefiniteConeList[2])])0;

Solve the problem using method "CSDP":

ConicOptimization[{-1,-1}.x,{lin, norm, semi},x,Method->"CSDP"]

Solve the problem using method "DSDP":

ConicOptimization[{-1,-1}.x,{lin, norm, semi},x,Method->"DSDP"]

Use method "IPOPT" to obtain accurate solutions when "CSDP" and "DSDP" are not applicable:

expConstraint={{1,0},{0,1},{-1,-2}}.x+{0,0,2}(Underscript[\[VectorGreaterEqual], (ExponentialConeString)])0;

powConstraint={{1,0},{0,1},{-1,-2}}.x+{1,0,2}(Underscript[\[VectorGreaterEqual], (PowerConeList[(1/3)])])0;

"IPOPT" produces more accurate results than "SCS" but is typically slower:

AbsoluteTiming[xmin=ConicOptimization[{1,1}.x,{expConstraint,powConstraint},x,Method->"IPOPT"]]

Compare timing with method "SCS":

AbsoluteTiming[xmin=ConicOptimization[{1,1}.x,{expConstraint,powConstraint},x,Method->"SCS"]]

OpenersExampleSubsection6(Spacer1)Tolerance  (2)

A smaller (RefLink[Tolerance, paclet:ref/Tolerance]) setting gives a more precise result:

{obj,cons,var}={-x-y,{x≥0,y≥0,x+2y≤2,x^2+y^2≤1}, {x,y}};

Compute the exact minimum value with (RefLink[Minimize, paclet:ref/Minimize]):

exact = Minimize[obj,cons,var][[1]]

Compute the error in the minimum value with different (RefLink[Tolerance, paclet:ref/Tolerance]) settings:

err=Table[{tol,Abs[ConicOptimization[obj,cons,var,"PrimalMinimumValue",Tolerance->tol]-exact]},{tol,10.^-Range[7]}]

Visualize the change in minimum value error with respect to tolerance:

ListLogLogPlot[err, PlotRange->All,Joined->True,PlotMarkers->Automatic]

A smaller (RefLink[Tolerance, paclet:ref/Tolerance]) setting gives a more precise answer, but may take longer to compute:

n=100000; {obj,const,vars}={Total[x]/n,{Norm[x]≤Sqrt[n],x\[VectorGreaterEqual]1},x∈Vectors[n]};

A smaller tolerance takes longer:

Timing[ptight=ConicOptimization[obj,const,vars,
"PrimalMinimumValue",Tolerance->(10^(-12))];]

Timing[ploose=ConicOptimization[obj,const,vars,
"PrimalMinimumValue",Tolerance->(10^(-2))];]

The tighter tolerance gives a more precise answer:

{ptight,ploose}

OpenersExampleSubsection7(Spacer1)PerformanceGoal  (1)

The default value of the option (RefLink[PerformanceGoal, paclet:ref/PerformanceGoal]) is (RefLink[$PerformanceGoal, paclet:ref/$PerformanceGoal]):

$PerformanceGoal

Use (RefLink[PerformanceGoal, paclet:ref/PerformanceGoal])->"Quality" to get a more accurate result:

ConicOptimization[x+y,{Norm[{x,y}]≤Sqrt[2], {x,y}\[VectorGreaterEqual]1},{x,y},
"PrimalMinimumValue",PerformanceGoal->"Quality"]

ConicOptimization[x+y,{Norm[{x,y}]≤Sqrt[2], {x,y}\[VectorGreaterEqual]1},{x,y},
"PrimalMinimumValue",PerformanceGoal->"Speed"]

Use (RefLink[PerformanceGoal, paclet:ref/PerformanceGoal])->"Speed" to get a result faster, but at the cost of quality:

n=100000; {obj,const,vars}={Total[x]/n,{Norm[x]≤Sqrt[n],x\[VectorGreaterEqual]1},x∈Vectors[n]};

Compare the timings:

Timing[resSpeed=ConicOptimization[obj,const,vars,
"PrimalMinimumValue",PerformanceGoal->"Speed"];]

Timing[resQuality=ConicOptimization[obj,const,vars,
"PrimalMinimumValue",PerformanceGoal->"Quality"];]

The "Speed" goal gives a less accurate result:

{resSpeed, resQuality}

OpenersExampleSection3(Spacer1)Applications  (26)

OpenersExampleSubsection8(Spacer1)Basic Modeling Transformations  (13)

Maximize x+y subject to x+y=3,x≥0,y≤2. Solve a maximization problem by negating the objective function:

ConicOptimization[-(x+y),{x+y==3,x≥0,y≤2},{x,y}]

Negate the primal minimum value to get the corresponding maximal value:

-ConicOptimization[-(x+y),{x+y==3,x≥0,y≤2},{x,y},"PrimalMinimumValue"]

Minimize |x+y| over a disk centered at {1,1} with radius 1. Convert the objective |x+y| into a linear function t with the additional constraint |x+y|≤t, which is equivalent to  -t≤x+y≤t:

ConicOptimization[t,{{x,y}∈Disk[{1,1},1], -t≤x+y≤t},{x,y,t}]

The disk constraint can also be represented using (RefLink[Norm, paclet:ref/Norm]):

ConicOptimization[t,{Norm[{x-1,y-1}]≤1,-t≤x+y≤t},{x,y,t}]

Minimize ||{x+1,x-y}(Subscript[||, 1]) over a regular pentagon. Convert the objective into a linear function using ||{x+y,x-y}(Subscript[||, 1])≤(Subscript[s, 1])+(Subscript[s, 2]) and the additional constraints -(Subscript[s, 1])≤x+1≤(Subscript[s, 1]),-(Subscript[s, 2])≤x-y≤(Subscript[s, 2]):

ConicOptimization[s1+s2,{{x,y}∈RegularPolygon[5],-s1≤x+1≤s1,-s2≤x-y≤s2},{x,y,s1,s2}]

Minimize ||a.x-b||. Using auxiliary variable t, the objective is transformed to minimize t subject to the constraint ||a.x-b||≤t:

{a1,b1}=;

ConicOptimization[t,{a==a1,b==b1,Norm[a.x-b]≤ t},{t,x}]

Minimize ||x||+||y|| subject to x+y≤0, y≥1. Using two auxiliary variables (Subscript[t, 1]),(Subscript[t, 2]), transform the problem to minimize (Subscript[t, 1])+(Subscript[t, 2]) subject to x+y≤0,y≥1,||x||≤(Subscript[t, 1]),||y||≤(Subscript[t, 2]):

ConicOptimization[t1+t2,{Norm[{x}]≤t1,Norm[{y}]≤t2,x+y≤0,y≥1},{x,y,t1,t2}]

Minimize ||a.x-b(Subscript[||, ∞]). Using auxiliary variable t, convert the problem to minimize t subject to the constraints ||(Subscript[a, i]).x-(Subscript[b, i])||≤t, i=1,2,..n:

{a1,b1}=;

ConicOptimization[t,{a==a1,b==b1,Norm[a.x-b]≤t},{x,t}]

Minimize f(c.x) subject to (Subscript[a, 0])+(∑_(i=1))(Subscript[a, i])(Subscript[x, i])≥0, where f is a nondecreasing function, by instead minimizing c.x. The primal minimizer (SuperStar[x]) will remain the same for both problems. Consider minimizing f(z)=(Sqrt[z]), z=x+y, z≥0 subject to  (({{x, 1}, {1, y}}))⪰0:

f=Function[{s},Sqrt[s]];

{minval, (Subscript[z, min])}=ConicOptimization[x+y,{(({{x, 1}, {1, y}}))(Underscript[\[VectorGreaterEqual], (SemidefiniteConeList[2])])0,x+y≥0},{x,y},{"PrimalMinimumValue","PrimalMinimizerRules"}]

The true minimum value can be obtained by applying f to the minimum value of  z=x+y:

f[minval]

Minimize -log(x+y) over a disk centered at {2,2} with radius 1.` Using the auxiliary variable t, the objective is transformed to minimizing -t with the additional constraint  -log(x+y)≤-t:

ConicOptimization[-t,{{x,y}∈Disk[{2,2}], -Log[x+y]≤-t},{x,y,t}]

The constraint -log(x+y)≤-t is equivalent to the exponential cone constraint exp(t)≤x+y iff {t,1,x+y}(Underscript[\[VectorGreaterEqual], (ExponentialConeString)])0:

ConicOptimization[-t,{{x,y}∈Disk[{2,2}], {t,1,x+y}(Underscript[\[VectorGreaterEqual], (ExponentialConeString)])0},{x,y,t}]

Minimize ((Abs[x+y])^1.5) over a disk centered at {1,1} with radius 1. Using auxiliary variable t, convert the problem to minimize t subject to the constraint ((Abs[x+ y])^1.5)≤t:

ConicOptimization[t,{{x,y}∈Disk[{1,1}], ((Abs[x+y])^1.5)≤t},{x,y,t}]

The constraint ((Abs[x+ y])^1.5)≤t is equivalent to  (Abs[x+y])≤(t^((1/1.5)))⟺ (Abs[x+y])≤(t^((1/1.5)))(1^((1-1/1.5))). This can be represented using "PowerCone" by  {t,1,x+y}(Underscript[\[VectorGreaterEqual], (PowerConeList[1/1.5])])0:

ConicOptimization[t,{{x,y}∈Disk[{1,1}], {t,1,x+y}(Underscript[\[VectorGreaterEqual], (PowerConeList[1/1.5])])0},{x,y,t}]

Find x that minimizes ||a.x-b(Subscript[||, 1.5]):

{a,b}=;

Using auxiliary variable t, convert the problem to minimize t subject to the constraint ||a.x-b(Subscript[||, 1.5])≤t:

ConicOptimization[t,{ap==a,bp==b,Norm[ap.x-bp, 1.5]≤t},{x,t}]

This can be represented using "PowerCone" constraints. Since ||a.x-b(Subscript[||, 1.5])= ((((∑_(i=1)^n)((Abs[(Subscript[a, i])x-(Subscript[b, i])])^1.5)))^(1/1.5))≤t iff (∑_(i=1)^n)(((Abs[(Subscript[a, i])x-(Subscript[b, i])])^1.5)/(t^(1.5-1)))≤t, bounding (((Abs[(Subscript[a, i])x-(Subscript[b, i])])^1.5)/(t^(1.5-1))) with (Subscript[s, i]) where (∑_(i=1)^n)(Subscript[s, i])=t gives {(Subscript[s, i]),t,(Subscript[a, i])x-(Subscript[b, i])}(Underscript[\[VectorGreaterEqual], (PowerConeList[1/1.5])])0, i=1,…,n:

sol=ConicOptimization[t,{{s1,t,a[[1]].x -b[[1]]}(Underscript[\[VectorGreaterEqual], (PowerConeList[1/1.5])])0,{s2,t,a[[2]].x -b[[2]]}(Underscript[\[VectorGreaterEqual], (PowerConeList[1/1.5])])0,s1+s2==t},{x∈Vectors[2],t,s1,s2}]

Find {x,y} that minimizes the largest eigenvalue of a symmetric matrix that depends linearly on the decision variables {x,y}, A(x,y) =(Subscript[a, 0])+(Subscript[a, 1])x+(Subscript[a, 2])y. The problem can be formulated as linear matrix inequality since λℐ⪰A(x,y) is equivalent to λ≥(Subscript[λ, 1]),…,λ≥(Subscript[λ, n]), where (Subscript[λ, i]) is the i(^th) eigenvalue of A(x,y). Define the linear matrix function A(x,y):

A[x_,y_]:=(({{2, -3}, {-3, 4}}))+(({{1, 2}, {2, 3}})) x+(({{4, 5}, {5, 6}})) y

A[x,y]//MatrixForm

A real symmetric matrix A can be diagonalized with an orthogonal matrix Q so (Q^T).A.Q=diag({(Subscript[λ, 1]),…,(Subscript[λ, n])}). Hence (Q^T).(λ ℐ-A).Q=diag({λ-(Subscript[λ, 1]),…,λ-(Subscript[λ, n])})⪰0 iff λ≥(Subscript[λ, 1]),…,λ≥(Subscript[λ, n]). Since any u = Q .(Q^T)u, taking v = (Q^T).u, (u^T).(λ ℐ-A). u=(v^T).(Q^T).(λ ℐ-A). Q .v≥0, hence λ ℐ-A⪰0 iff λ≥(Subscript[λ, 1]),…,λ≥(Subscript[λ, n]). Numerically simulate to show that these formulations are equivalent:

eigs=Eigenvalues[A[1.,2.]]

data=Table[{λ,λ (({{1, 0}, {0, 1}})) (Underscript[\[VectorGreaterEqual], (SemidefiniteConeList[2])])A[1.,2.]},{λ,RandomReal[{0,35},100]}];
{true,false}={Cases[data,{λ_,True}:>λ],Cases[data,{λ_,False}:>λ]};

NumberLinePlot[{eigs,true,false},]

The resulting problem:

res=ConicOptimization[λ,λ (({{1, 0}, {0, 1}})) (Underscript[\[VectorGreaterEqual], (SemidefiniteConeList[2])])A[x,y],{λ,x,y}]

Run a Monte Carlo simulation to check the plausibility of the result:

Min[Table[Max[Eigenvalues[A@@RandomReal[{-10000,10000},2]]],10000]]

Minimize (((α.x+β))^2)/(γ.x+δ) subject to a.x+b≥0, assuming γ.x+δ>0 when a.x+b≥0. Using the auxiliary variable t, the objective is to minimize t such that (((α.x+β))^2)/(γ.x+δ)≤t:

{α,β,γ,δ}={{1,2},1,{-3,4},2};
{a,b}={{{1,-2},{-3,4}},{-5,-1}};

Check that a.x+b≥0 implies γ.x+δ>0:

Reduce[Implies[a.{(IndexedDefault[x, 1]), (IndexedDefault[x, 2])}+b>=0, γ.{(IndexedDefault[x, 1]), (IndexedDefault[x, 2])}+δ>0],Reals]

A Schur complement condition says that if C\[VectorGreater]0, a block matrix (({{A, B}, {(B^T), C}}))\[VectorGreaterEqual]0 iff A-B.(C^(-1)).(B^T)\[VectorGreaterEqual]0. Therefore (((α.x+β))^2)/(γ.x+δ)≤t iff (({{t, α.x+β}, {α.x+β, γ.x+δ }}))⪰0. Use (RefLink[Inactive, paclet:ref/Inactive]) (RefLink[Plus, paclet:ref/Plus]) for constructing the constraints to avoid threading:

ConicOptimization[t,{(({{t, α.x+β}, {α.x+β, γ.x+δ}}))(Underscript[\[VectorGreaterEqual], (SemidefiniteConeList[2])])0, a.x+b\[VectorGreaterEqual]0},{t,x∈Vectors[2]}]

For quadratic sets  (Subscript[𝒬, i])={x∈(ℝ^n)|(x^T).(Subscript[a, i]) .x+2 x.(Subscript[b, i]^T)+(Subscript[c, i])≤0}, which include ellipsoids, quadratic cones and paraboloids, determine whether (Subscript[𝒬, 1])⊆(Subscript[𝒬, 2]), where (Subscript[a, i]) are symmetric matrices, (Subscript[b, i]) are vectors and (Subscript[c, i]) scalars:

{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]]

Assuming that the sets (Subscript[𝒬, i]) are full dimensional, the S-procedure says that  (Subscript[𝒬, 1])⊆(Subscript[𝒬, 2]) iff there exists some non-negative number λ such that λ (({{(Subscript[a, 1]), (Subscript[b, 1])}, {(Subscript[b, 1]^T), (Subscript[c, 1])}})) ⪰ (({{(Subscript[a, 2]), (Subscript[b, 2])}, {(Subscript[b, 2]^T), (Subscript[c, 2])}})). Visually see that there exists a non-negative λ:

m1=ArrayFlatten[{{a1,{b1}\[Transpose]},{{b1},{{c1}}}}];
m2=ArrayFlatten[{{a2,{b2}\[Transpose]},{{b2},{{c2}}}}];
Plot[Boole[λm1(Underscript[\[VectorGreaterEqual], (SemidefiniteConeList[3])])m2],{λ,0,5},ImageSize->Small]

Since λ≥0, it follows that (Subscript[𝒬, 1])⊆(Subscript[𝒬, 2]):

ConicOptimization[0, λ(({{a1, b1}, {b1, c1}}))(Underscript[\[VectorGreaterEqual], (SemidefiniteConeList[3])])(({{a2, b2}, {b2, c2}})),λ]

OpenersExampleSubsection9(Spacer1)Data-Fitting Problems  (4)

Minimize ||a.x-b|| subject to the constraints (Subscript[x, i])≥1, i=1,2,..,m:

{a,b}= ;

Using auxiliary variable t, the transformed objective is to minimize t subject to ||a.x-b||≤t:

ConicOptimization[t,{Norm[Inactive[Plus][a.x,-b]]≤t,x\[VectorGreaterEqual]1},{t,x}]

Fit a cubic curve to discrete data such that the first and last points of the data lie on the curve:

data=;

Construct the matrix using (RefLink[DesignMatrix, paclet:ref/DesignMatrix]):

a=DesignMatrix[data,{1,x,(x^2),(x^3)},x];
b=data[[All,2]];

Define the constraint so that the first and last points must lie on the curve:

pointConstraints={a[[1]].λ==b[[1]],a[[-1]].λ==b[[-1]]};

Find the coefficients λ by minimizing ||a.λ-b||. Using auxiliary variable t, the transformed objective is to minimize t subject to ||a.λ-b||≤t:

res=ConicOptimization[t,{Norm[Inactive[Plus][a.λ,-b]]≤t,pointConstraints},{t,λ}]

Compare fit with data:

Show[Plot[Evaluate[{1,x,(x^2),(x^3)}.λ/.res],{x,0,1},],ListPlot[data]]

Find a robust fit to nonlinear discrete data by minimizing ||a.λ-b(Subscript[||, 1]):

data=;

Fit the data using the bases (Subscript[ϕ, i])(x)=(((1+(((x-(Subscript[c, i])))^2)))^(1/2)). The interpolating function will be s(x)=(∑_(i=1))(Subscript[λ, i])(Subscript[ϕ, i])(x):

bases = Sqrt[1+(x-#)^2]&/@Subdivide[-3,3,10];
input=DesignMatrix[data,bases,x,IncludeConstantBasis->False];
output=data[[All,2]];

Since ||a.λ-b(Subscript[||, 1])=(∑_i)|(Subscript[a, i]).λ-(Subscript[b, i])|, using auxiliary variables (Subscript[s, i])=|(Subscript[a, i]).λ-(Subscript[b, i])|. The problem is transformed to minimize (∑_i)(Subscript[s, i]) subject to the constraints -(Subscript[s, i])≤(Subscript[a, i]).λ-b≤(Subscript[s, i]):

res=ConicOptimization[Total[s],{a==input,b==output,-s\[VectorLessEqual]a.λ-b\[VectorLessEqual]s}, {λ,s}];

Visualize the fit:

Plot[Evaluate[bases.λ/.res],{x,-3,3},Epilog->{PointSize[0.008],Point[data]}]

Compare interpolating function with reference function:

Plot[{Sin[2x]+Cos[x^2],Evaluate[bases.λ/.res]},{x,-3,3}, PlotLegends->{"Reference","(Subscript[L, 1])fit"}]

Represent a given polynomial p(x) in terms of sum-of-squares polynomial (∑_(i=1))(((Subscript[g, i])(x))^2):

poly=2+4 x+6 (x^2)+4 (x^3)+(x^4);

The objective is to find Q such that p(x)=(v(x).L).((L^Τ).v(x))=v.Q.v, where v(x) is a vector of monomials:

v={1,x,(x^2)};

Construct the symmetric matrix Q:

n=Length[v];
mat = Array[Indexed[q, {##}] &, {n, n}];
Q = UpperTriangularize[mat] + Transpose[UpperTriangularize[mat, 1]];

Find the polynomial coefficients of p(x) and v(x).Q.v(x) and make sure they are equal:

coeffs =Map[#==0&,DeleteCases[Flatten[CoefficientList[v.Q.v-poly,{x}]],0]]

Find the elements of Q:

res=ConicOptimization[0,{coeffs ,q(Underscript[\[VectorGreaterEqual], (SemidefiniteConeList[n])])0},q]

The quadratic term v.Q.v = (v.L).((L^T)v)=g.g, where L is a lower-triangular matrix obtained from the Cholesky decomposition of Q:

L=CholeskyDecomposition[(Q/.res)];
g=L.v;
Expand[Sum[((g[[i]])^2),{i,Length[g]}]]

Compare the sum-of-squares polynomial to the given polynomial:

Chop[Expand[Total[g^2]] - poly,(10^(-7))]

OpenersExampleSubsection10(Spacer1)Geometry Problems  (5)

Find the minimum distance between two disks of radius 1 centered at (Subscript[c, 1])={0,0} and (Subscript[c, 2])={2,1}. Let (Subscript[p, 1]) be a point on disk 1. Let (Subscript[p, 2]) be a point on disk 2. The objective is to minimize ||(Subscript[p, 1])-(Subscript[p, 2])||. Using auxiliary variable t, the transformed objective is to minimize t subject to ||(Subscript[p, 1])-(Subscript[p, 2])||≤t, ||(Subscript[p, 1])||≤1,||(Subscript[p, 2])-(Subscript[c, 2])||≤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]}]

Visualize the position of the two points:

Graphics[{{Lighter[Blue],Disk[]},{Lighter[Red],Disk[{2,1}]},  {Green,PointSize[0.03],Point[{p1,p2}/.res]}}]

The auxiliary variable t gives the distance between the points:

{t,EuclideanDistance[p1,p2]}/.res

Find the radius r and center c of a minimal enclosing ball that encompasses a given region:

region=;

Minimize the radius r subject to the constraints ||(Subscript[p, i])-c||≤r,i=1,2,..,n:

constraints=Table[Norm[Inactive[Plus][pi,-c]]≤r,{pi,MeshCoordinates[region]}];

res=ConicOptimization[r,constraints,{r,c∈Vectors[3]}]

Visualize the enclosing ball:

Show[Graphics3D[{Opacity[0.2],Red,Ball[c,r]/.res}], region]

The minimal enclosing ball can be found efficiently using (RefLink[BoundingRegion, paclet:ref/BoundingRegion]):

BoundingRegion[region,"MinBall"]

Find the plane that separates two non-intersecting convex polygons:

{(Subscript[Ω, 1]),(Subscript[Ω, 2])} = ;

Let (Subscript[p, 1]) be a point on (Subscript[Ω, 1]). Let (Subscript[p, 2]) be a point on (Subscript[Ω, 2]). The objective is to minimize ||(Subscript[p, 1])-(Subscript[p, 2])||. Using auxiliary variable t, the transformed objective is to minimize t subject to ||(Subscript[p, 1])-(Subscript[p, 2])||≤t, (Subscript[p, 1])∈(Subscript[Ω, 1]),(Subscript[p, 2])∈(Subscript[Ω, 2]):

res=ConicOptimization[t,{p1∈(Subscript[Ω, 1]),p2∈(Subscript[Ω, 2]),Norm[p1-p2]≤t},{p1,p2,t}]

According to the separating hyperplane theorem, the dual associated with the constraint ||(Subscript[p, 1])-(Subscript[p, 2])||≤t will give the normal of the hyperplane:

{dual,cones}=ConicOptimization[t,{p1∈(Subscript[Ω, 1]),p2∈(Subscript[Ω, 2]),Norm[p1-p2]≤t},{p1,p2,t},{"DualMaximizer","ConicConstraintConeSpecifications"}];

The dual associated with the "NormCone" is:

pos=Position[cones, {"NormCone",_}];
planeNormal=First@Extract[dual,pos]

The hyperplane is constructed as:

plane=Hyperplane[Most[planeNormal],(p1+p2)/2/.res]

Visualize the plane separating the two polygons:

Show[(Subscript[Ω, 1]),(Subscript[Ω, 2]), Graphics[{{Point[{p1,p2}/.res]},{Red,plane}}]]

Find the maximum area ellipse parametrized as {x=C.y+d :||y||≤1} that can be fitted into a convex polygon:

cmesh=ConvexHullMesh[];

Each segment of the convex polygon can be represented as intersections of half-planes (Subscript[a, i]).x≤ (Subscript[b, i]),i=1,2,…,n. Extract the linear inequalities:

segs=MeshPrimitives[cmesh,1][[All,1]];
a=segs/.{p_,q_}:> {-1,1}*Reverse[p-q];
b=MapThread[#1.#2&,{a,segs[[All,1]]}];

Applying the parametrization to the half-planes gives sup{((Subscript[a, i]).C).y:||y||≤1}+(Subscript[a, i]).d≤(Subscript[b, i]). The term sup{((Subscript[a, i]).C).y:||y||≤1}=sup{||(Subscript[a, i]).C||||y||Cos(θ):||y||≤1}=||(Subscript[a, i]).C||. Thus, the constraints are ||(Subscript[a, i]).C||+(Subscript[a, i]).d≤(Subscript[b, i]):

constraints=Table[Norm[a[[i]].c]+a[[i]].d≤b[[i]],{i,Length[a]}];

Minimizing the area is equivalent to minimizing -log (det(C)), which is equivalent to minimizing -Tr(C):

res=ConicOptimization[-Tr[c],constraints,{c∈Matrices[{2,2}],d}]

Convert the parameterized ellipse into the explicit form as (x-d).((((C^Τ).C))^(-1)).(x-d)≤1:

inscribedEllipse=Ellipsoid[d,Transpose[c].c] /.res

Show[cmesh,Graphics[{LightRed,inscribedEllipse}]]

Find the analytic center of a convex polygon. The analytic center is a point that maximizes the product of distances to the constraints:

cmesh=ConvexHullMesh[];

Each segment of the convex polygon can be represented as intersections of half-planes (Subscript[a, i]).x+(Subscript[b, i])≥0,i=1,2,…,n. Extract the linear inequalities:

{a,b}=LinearOptimization[0,x∈cmesh,x,"LinearInequalityConstraints"];

The objective is to maximize (∏_(i=1)^n)(Subscript[a, i]).x+(Subscript[b, i]). Taking log and negating the objective, the transformed objective is -(∑_(i=1)^m)log((Subscript[a, i]).x+(Subscript[b, i])):

obj=Total[Table[-Log[a[[i]].x+b[[i]]],{i,Length[a]}]];

Using auxiliary variable t, the transformed objective is t subject to the constraint -(∑_(i=1)^m)log((Subscript[a, i]).x+(Subscript[b, i]))≤t:

res=ConicOptimization[t,obj≤t,{t,x}, Method->{"SCS", Tolerance->10^-7}]

Visualize the location of the center:

Show[cmesh, Graphics[{PointSize[0.02],Point[x/.res]}]]

OpenersExampleSubsection11(Spacer1)Classification Problems  (3)

Find a line a.x+b that separates two groups of points P={(Subscript[p, 1]),(Subscript[p, 2]),..(Subscript[p, n])} and Q={(Subscript[q, 1]),(Subscript[q, 2]),..(Subscript[q, m])}:

{set1,set2}=;

For separation, set 1 must satisfy a.(Subscript[p, i])+b≥1 and set 2 must satisfy a.(Subscript[q, j])+b≤-1:

constraints={set1.a+b\[VectorGreaterEqual]1,set2.a+b\[VectorLessEqual]-1};

The objective is to minimize ||a||, which gives twice the thickness between a.x+b=-1 and a.x+b=1. Using the auxiliary variable t, the objective function is transformed to the constraint ||a||≤ t:

res=ConicOptimization[t,{Norm[a]≤t,constraints},{t,a,b}]

The separating line is:

line=a.{x,y}+b /. res

Show[RegionPlot[line≤0,{x,0,1},{y,0,1}],ListPlot[{set1,set2},PlotMarkers->{Automatic,PointSize[0.025]}]]

Find a quadratic polynomial that separates two groups of 3D points P={(Subscript[p, 1]),(Subscript[p, 2]),..(Subscript[p, n])} and Q={(Subscript[q, 1]),(Subscript[q, 2]),..(Subscript[q, m])}:

{set1,set2}=;
dataplot=ListPointPlot3D[{set1,set2}, ]

Construct the quadratic polynomial data matrices for the two sets using (RefLink[DesignMatrix, paclet:ref/DesignMatrix]):

{data1,data2}=DesignMatrix[#,{x,(x^2),y,(y^2),x y},{x,y}]&/@{set1,set2};

For separation, set 1 must satisfy a.(Subscript[p, i])+b≥1 and set 2 must satisfy a.(Subscript[q, j])+b≤-1:

constraints={data1.a +b\[VectorGreaterEqual]1,data2.a+b\[VectorLessEqual]-1};

Find the separating polynomial by minimizing ||a||. Using auxiliary variable t, the transformed objective is to minimize t with the additional constraint ||a||≤t:

res=ConicOptimization[t,{Norm[a]≤t,constraints},{t,a,b}]

The polynomial separating the two groups of points is:

poly=(a.{1,x,(x^2),y,(y^2),x y}+b)/.res

Plot the polynomial separating the two datasets:

Show[dataplot, ContourPlot3D[poly==0,{x,-1.5,1.5},{y,-1.5,1.5},{z,-1,1},]]

Separate a given set of points (Subscript[x, j]),j=1,2,...,n into different groups. This is done by finding the centers (Subscript[μ, i]) for each group by minimizing (1/2)(∑_(j=1)^( n))||(Subscript[x, j])-(Subscript[μ, j])((||)^2)+λ(∑_(j=1)^( n))(∑_( i<j))κ((Subscript[x, i]),(Subscript[x, j]))||(Subscript[μ, i])-(Subscript[μ, j])(Subscript[||, 1]), where κ((Subscript[x, i]),(Subscript[x, j])) is a given local kernel and λ=10 is a given penalty parameter:

x = ;
{n,dim}=Dimensions[x];
centers=Array[c,n];

The kernel κ((Subscript[x, i]),(Subscript[x, j])) is a k-nearest neighbor (kNN) function such that κ((Subscript[x, i]),(Subscript[x, j]))=1 if (Subscript[x, i])∈kNN((Subscript[x, j])) ∨(Subscript[x, j])∈kNN((Subscript[x, i])), else κ((Subscript[x, i]),(Subscript[x, j]))=0. For this problem, k=10 nearest neighbors are selected:

kNN = Nearest[x->Automatic][x,10];
κ=SparseArray[Join@@Table[Thread[{i,kNN[[i]]}],{i,n}]->1,{n,n}];

Using the auxiliary variable t, the objective is transformed to minimize t subject to the constraint (1/2)(∑_(j=1)^( n))||(Subscript[x, j])-(Subscript[μ, j])((||)^2)+λ(∑_(j=1)^( n))(∑_( i<j))κ((Subscript[x, i]),(Subscript[x, j]))||(Subscript[μ, i])-(Subscript[μ, j])(Subscript[||, 1])≤t:

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;

Find the group centers:

vars=Join[{t},Table[c[i]∈Vectors[dim,Reals],{i,n}]];
res=ConicOptimization[t, constraint, vars,PerformanceGoal->"Speed"];

For each data point there exists a corresponding center. Data belonging to the same group will have the same center value:

allCenters=centers/.res;
cvals=Map[First,Gather[allCenters,Norm[#1-#2]≤0.001&]]

Extract and plot the grouped points:

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],Black}]]

OpenersExampleSubsection12(Spacer1)Optimal Control Problems  (1)

Minimize ((∫_0)^(2π))(((g(t)-x(t)))^T).(g(t)-x(t)) dt subject to x'(t)=A.x(t) + u(t), -2≤u(t)≤2,  x(0)=(0,0) and g(t)={Cos(t),Sin(t)}:

A=(({{2, -0.5}, {-0.3, 2}}));
g[t_]:={Cos[t],Sin[t]};

The minimizing function integral can be approximated using the trapezoidal rule. The discretized objective function will be y.W.y +z.W.z subject to additional constraints  y=(Subscript[g, 1])-(Subscript[x, 1]),z=(Subscript[g, 2])-(Subscript[x, 2]):

{ti,wts}= 2Pi Most[];
W=DiagonalMatrix[SparseArray[wts]];
n=Length[ti];

The time derivative in x'(t)=A.x(t) + u(t) is discretized using finite differences:

dTMat = ;
ode1=dTMat.x1== A[[1]].{x1,x2}+u1;
ode2=dTMat.x2== A[[2]].{x1,x2}+u2;

The initial condition constraints  x(0)=(0,0) can be specified using (RefLink[Indexed, paclet:ref/Indexed]):

ics = {Indexed[x1,1]==0,Indexed[x2,1]==0};

Using auxiliary variable t, the objective is transformed to minimize t subject to y.W.y +z.W.z≤t:

{g1,g2}=g[ti];
res=ConicOptimization[t,{ode1,ode2,ics,y.W.y+z.W.z\[VectorLessEqual]t,y==Inactive[Plus][g1,-x1],z==Inactive[Plus][g2,-x2],-2\[VectorLessEqual]u1\[VectorLessEqual]2,-2\[VectorLessEqual]u2\[VectorLessEqual]2},{u1∈Vectors[n],u2∈Vectors[n],x1,x2,y,z,t}];

Convert the discretized result into (RefLink[InterpolatingFunction, paclet:ref/InterpolatingFunction]):

{u1sol,u2sol,x1sol,x2sol}=Map[ListInterpolation[#,ti]&,{u1,u2,x1,x2}/.res];

Plot the control variables:

Plot[{u1sol[t],u2sol[t]},{t,0,2Pi}]

Plot the state variables. The state variables try and track the function g(t):

{Plot[{x1sol[t],Cos[t]},{t,0,2Pi},ImageSize->200], Plot[{x2sol[t],Sin[t]},{t,0,2Pi},ImageSize->200]}

OpenersExampleSection4(Spacer1)Properties & Relations  (8)

(RefLink[ConicOptimization, paclet:ref/ConicOptimization]) gives the global minimum of the objective function:

res=ConicOptimization[2(Subscript[x, 1])+3(Subscript[x, 2]),(({{(Subscript[x, 1]), 1}, {1, (Subscript[x, 2])}}))(Underscript[\[VectorGreaterEqual], (SemidefiniteConeList[2])])0,{(Subscript[x, 1]),(Subscript[x, 2])}]

Plot the objective function with the minimum value over the feasible region:

Show[Plot3D[2(Subscript[x, 1])+3(Subscript[x, 2]),{(Subscript[x, 1]),(Subscript[x, 2])}∈], ]

(RefLink[Minimize, paclet:ref/Minimize]) gives global exact results for conic problems:

Minimize[{2(Subscript[x, 1])+3(Subscript[x, 2]),(({{(Subscript[x, 1]), 1}, {1, (Subscript[x, 2])}}))(Underscript[\[VectorGreaterEqual], (SemidefiniteConeList[2])])0},{(Subscript[x, 1]),(Subscript[x, 2])}]

%//N

(RefLink[NMinimize, paclet:ref/NMinimize]) can be used to obtain approximate results using global methods:

NMinimize[{2(Subscript[x, 1])+3(Subscript[x, 2]),(({{(Subscript[x, 1]), 1}, {1, (Subscript[x, 2])}}))(Underscript[\[VectorGreaterEqual], (SemidefiniteConeList[2])])0},{(Subscript[x, 1]),(Subscript[x, 2])}]

(RefLink[FindMinimum, paclet:ref/FindMinimum]) can be used to obtain approximate results using local methods:

FindMinimum[{2(Subscript[x, 1])+3(Subscript[x, 2]),(({{(Subscript[x, 1]), 1}, {1, (Subscript[x, 2])}}))(Underscript[\[VectorGreaterEqual], (SemidefiniteConeList[2])])0},{(Subscript[x, 1]),(Subscript[x, 2])}]

(RefLink[SemidefiniteOptimization, paclet:ref/SemidefiniteOptimization]) is a special case of (RefLink[ConicOptimization, paclet:ref/ConicOptimization]):

SemidefiniteOptimization[10x+11y,{x+y≥2,(({{x, 1}, {1, y}}))(Underscript[\[VectorGreaterEqual], (SemidefiniteConeList[2])])0},{x,y}]

ConicOptimization[10x+11y,{x+y≥2,(({{x, 1}, {1, y}}))(Underscript[\[VectorGreaterEqual], (SemidefiniteConeList[2])])0},{x,y}]

(RefLink[SecondOrderConeOptimization, paclet:ref/SecondOrderConeOptimization]) is a special case of (RefLink[ConicOptimization, paclet:ref/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}]

(RefLink[QuadraticOptimization, paclet:ref/QuadraticOptimization]) is a special case of (RefLink[ConicOptimization, paclet:ref/ConicOptimization]):

obj=2(x^2)+20(y^2)+6x y+5x;
cons={-x+y≥2,y≥0};

QuadraticOptimization[obj,cons,{x,y}]

Use auxiliary variable t and minimize t with additional constraint 2(x^2)+20(y^2)+6x y+5x≤t:

ConicOptimization[t,{obj≤t,cons},{x,y,t}]

(RefLink[LinearOptimization, paclet:ref/LinearOptimization]) is a special case of (RefLink[ConicOptimization, paclet:ref/ConicOptimization]):

LinearOptimization[10.x+11.y,{x,y}∈RegularPolygon[4],{x,y}]

ConicOptimization[10.x+11.y,{x,y}∈RegularPolygon[4],{x,y}]

OpenersExampleSection5(Spacer1)Possible Issues  (4)

The constraints at the optimal point are expected to be satisfied up to some tolerance:

res=ConicOptimization[x+y,{(x^2) +(y^2)≤ 1},{x,y}]

(x^2) +(y^2)≤ 1/.res

(x^2) +(y^2)- 1/.res

The constraint violation can often be controlled with the (RefLink[Tolerance, paclet:ref/Tolerance]) option:

res=ConicOptimization[x+y,{(x^2) +(y^2)≤ 1},{x,y}, Tolerance->10^-8]

(x^2) +(y^2)- 1/.res

The minimum value of an empty set or infeasible problem is defined to be ∞:

ConicOptimization[x,{x≤0,x≥1},x,"PrimalMinimumValue"]

The minimizer is (RefLink[Indeterminate, paclet:ref/Indeterminate]):

ConicOptimization[x,{x≤0,x≥1},x]

The minimum value for an unbounded set or unbounded problem is -∞:

ConicOptimization[-(x+y),x+y≥1,{x,y},"PrimalMinimumValue"]

The minimizer is (RefLink[Indeterminate, paclet:ref/Indeterminate]):

ConicOptimization[-(x+y),x+y≥1,{x,y}]

Badly scaled problems can produce results with large error:

ConicOptimization[x+y+z,{x^2+y^2+z^2≤10^20,x>5,y>5},{x,y,z}]

The correct result is:

Minimize[{x+y+z,{x^2+y^2+z^2≤10^20,x≥ 5,y≥ 5}},{x,y,z}][[2]]//N

After scaling {x,y,z} by (10^(-10)), this is mathematically equivalent to the following problem:

ConicOptimization[x+y+z,{x^2+y^2+z^2≤1,x>5*^-10,y>5*^-10},{x,y,z}]

Any result for x, y within ±(10^(-6)) of 5*(10^(-10)) will fall within the tolerance of (10^(-6)) and when scaled back can produce an error of up to:

10^10*10^-6

You could solve the preceding scaled problem or try to tighten the default tolerance:

ConicOptimization[x+y+z,{x^2+y^2+z^2≤10^20,x>5,y>5},{x,y,z}, Tolerance->10^-13]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[LinearOptimization, paclet:ref/LinearOptimization])  ▪  (RefLink[SecondOrderConeOptimization, paclet:ref/SecondOrderConeOptimization])  ▪  (RefLink[SemidefiniteOptimization, paclet:ref/SemidefiniteOptimization])  ▪  (RefLink[QuadraticOptimization, paclet:ref/QuadraticOptimization])  ▪  (RefLink[LinearFractionalOptimization, paclet:ref/LinearFractionalOptimization])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Optimization, paclet:guide/Optimization])}, {▪(RefLinkPlain[Convex Optimization, paclet:guide/ConvexOptimization])}})}})