OptimizationInequality - Inequality constraints - MATLAB (original) (raw)

Description

An OptimizationInequality object contains an inequality constraint in terms of OptimizationVariable objects or OptimizationExpression objects. An inequality constraint uses the comparison operator <= or >=.

A single statement can represent an array of inequalities. For example, you can express the inequalities that each row of a matrix variable x sums to no more than one in this single statement:

constrsum = sum(x,2) <= 1

Use OptimizationInequality objects as constraints in an OptimizationProblem.

Creation

Create an inequality using optimization expressions with the comparison operator<= or >=.

Include inequalities in the Constraints property of an optimization problem by using dot notation.

prob = optimproblem; x = optimvar('x',4,6); SumLessThanOne = sum(x,2) <= 1; prob.Constraints.SumLessThanOne = SumLessThanOne;

You can also create an empty optimization inequality by using optimineq oroptimconstr. Typically, you then set the inequalities in a loop. For an example, see Create Inequalities in Loop. However, for the most efficient problem formulation, avoid setting inequalities in loops. See Create Efficient Optimization Problems.

Properties

expand all

This property is read-only.

Optimization variables in the object, specified as a structure of OptimizationVariable objects.

Data Types: struct

Object Functions

evaluate Evaluate optimization expression or objectives and constraints in problem
infeasibility Constraint violation at a point
issatisfied Constraint satisfaction of an optimization problem at a set of points
show Display information about optimization object
write Save optimization object description

Examples

collapse all

Create a 4-by-6 optimization variable matrix named x.

Create the inequalities that each row of x sums to no more than one.

constrsum = sum(x,2) <= 1

constrsum = 4×1 Linear OptimizationInequality array with properties:

IndexNames: {{}  {}}
 Variables: [1×1 struct] containing 1 OptimizationVariable

See inequality formulation with show.

View the inequalities.

(1, 1)

x(1, 1) + x(1, 2) + x(1, 3) + x(1, 4) + x(1, 5) + x(1, 6) <= 1

(2, 1)

x(2, 1) + x(2, 2) + x(2, 3) + x(2, 4) + x(2, 5) + x(2, 6) <= 1

(3, 1)

x(3, 1) + x(3, 2) + x(3, 3) + x(3, 4) + x(3, 5) + x(3, 6) <= 1

(4, 1)

x(4, 1) + x(4, 2) + x(4, 3) + x(4, 4) + x(4, 5) + x(4, 6) <= 1

To include the inequalities in an optimization problem, set a Constraints property to constrsum by using dot notation.

prob = optimproblem; prob.Constraints.constrsum = constrsum

prob = OptimizationProblem with properties:

   Description: ''
ObjectiveSense: 'minimize'
     Variables: [1×1 struct] containing 1 OptimizationVariable
     Objective: [0×0 OptimizationExpression]
   Constraints: [1×1 struct] containing 1 OptimizationConstraint

See problem formulation with show.

Create the constraint that a two-element variable x must lie in the intersections of a number of disks whose centers and radii are in the arrays centers and radii.

x = optimvar('x',1,2); centers = [1 -2;3 -4;-2 3]; radii = [6 7 8]; constr = optimineq(length(radii)); for i = 1:length(constr) constr(i) = sum((x - centers(i,:)).^2) <= radii(i)^2; end

View the inequality expressions.

arg_LHS <= arg_RHS

where:

    arg1 = zeros(3, 1);
    arg1(1) = sum((x - extraParams{1}).^2);
    arg1(2) = sum((x - extraParams{2}).^2);
    arg1(3) = sum((x - extraParams{3}).^2);
    arg_LHS = arg1(:);
    arg1 = zeros(3, 1);
    arg1(1) = 36;
    arg1(2) = 49;
    arg1(3) = 64;
    arg_RHS = arg1(:);

extraParams

Instead of using a loop, you can create the same constraints by using matrix operations on the variables.

constr2 = sum(([x;x;x] - centers).^2,2) <= radii'.^2;

Creating inequalities in a loop can be more time consuming than creating inequalities by using matrix operations.

Check the value of an inequality constraint and satisfaction of an equality constraint at a point specified by a structure.

x = optimvar("x"); y = optimvar("y"); ineq = x^2 + y^2/4 <= 2; eq = 4*x^2 + y^2 == 5; x0.x = 1; x0.y = 1; evaluate(ineq,x0) % Value = L - R, where L = x^2 + y^2/4 and R = 2

issatisfied(eq,x0) % Checks whether 4*x^2 + y^2 = 5

Version History

Introduced in R2019b

expand all

You can now evaluate optimization expressions and constraints using evaluate and issatisfied for OptimizationInequality objects.

The value of a constraint depends on the constraint type. An equation is equivalent to an == constraint. For expressions L and R:

Constraint Type Value
L <= R L – R
L >= R R – L
L == R abs(L – R)

For details, see the evaluate andissatisfied reference pages.