Main Content

infeasibility

Constraint violation at a point

Description

Use infeasibility to find the numeric value of a constraint violation at a point.

infeas = infeasibility(constr,pt) returns the amount of violation of the constraint constr at the point pt.

example

infeas = infeasibility(var,pt) returns the violation of bounds and integer constraints at the point pt.

example

Examples

collapse all

Check whether a point satisfies a constraint.

Set up optimization variables and two constraints.

x = optimvar("x");
y = optimvar("y");
cons = x + y <= 2;
cons2 = x + y/4 <= 1;

Check whether the point x = 0, y = 4 satisfies the constraint named cons. A point is feasible when its infeasibility is zero.

pt.x = 0;
pt.y = 4;
infeas = infeasibility(cons,pt)
infeas = 
2

The point is not feasible with respect to this constraint.

Check the feasibility with respect to the other constraint.

infeas = infeasibility(cons2,pt)
infeas = 
0

The point is feasible with respect to this constraint.

Check whether a point satisfies a constraint that has multiple conditions.

Set up an optimization variable and a vector of constraints.

x = optimvar("x",3,2);
cons = sum(x,2) <= [1;3;2];

Check whether the point pt.x = [1,-1;2,3;3,-1] satisfies these constraints.

pt.x = [1,-1;2,3;3,-1];
infeas = infeasibility(cons,pt)
infeas = 3×1

     0
     2
     0

The point is not feasible with respect to the second constraint.

Create optimization variables with bounds, integer, and semicontinuous constraints.

x = optimvar("x",LowerBound=-2,UpperBound=2,Type="integer");
y = optimvar("y",LowerBound=1/2,Type="semi-continuous");

Check the feasibility of some points.

pt.x = 1;
pt.y = 1;
infeasibility(x,pt)
ans = 
0
infeasibility(y,pt)
ans = 
0

Both the x and y variables are feasible at the point x = 1, y = 1.

pt.x = 1.5;
infeasibility(x,pt)
ans = 
0.5000

The x variable has an infeasibility of 1/2 at x = 1.5 because x is an integer variable.

pt.y = 0;
infeasibility(y,pt)
ans = 
0

The y variable has an infeasibility of 0 at y = 0 even though y has a lower bound of 1/2 because y is a semicontinuous variable.

pt.y = -2;
infeasibility(y,pt)
ans = 
2

The y variable has an infeasibility of 2 at y = -2 because y is lower semicontinuous, and is feasible at y = 0.

pt.x = -4;
infeasibility(x,pt)
ans = 
2

The x variable has an infeasibility of 2 at x = -4 because x has a lower bound of -2.

pt.y = 1/4;
infeasibility(y,pt)
ans = 
0.2500

The y variable has an infeasibility of 1/4 at y = 1/4 because y has a lower bound of 1/2.

Input Arguments

collapse all

Optimization constraint, specified as an OptimizationEquality object, OptimizationInequality object, or OptimizationConstraint object. constr can represent a single constraint or an array of constraints.

Example: constr = x + y <= 1 is a single constraint when x and y are scalar variables.

Example: constr = sum(x) == 1 is an array of constraints when x is an array of two or more dimensions.

Optimization variable, specified as an OptimizationVariable object. infeasibility computes bound and integer constraint violations as follows.

Variable TypeInfeasibility for Bounds and Type
Continuousmax(0,lb - x,x - ub)
Integermax(0,lb - x,x - ub,abs(x - round(x)))
Semi-continuousmin(max(0,lb - x,x - ub),abs(x))
Semi-integermin(max(0,lb - x,x - ub,abs(x - round(x))),abs(x))

Example: var = optimvar("var",LowerBound=0,UpperBound=10.5)

Point to evaluate, specified as a structure with field names that match the optimization variable names, for optimization variables in the constraint. The size of each field in pt must match the size of the corresponding optimization variable.

Example: pt.x = 5*eye(3)

Data Types: struct

Output Arguments

collapse all

Infeasibility of constraint or variable, returned as a real array. For constraints, each zero entry represents a feasible constraint, and each positive entry represents an infeasible constraint. The size of infeas is the same as the size of the constraint constr. For an example of nonscalar infeas, see Compute Multiple Constraint Violations.

Beginning in R2026a, infeasibility also computes infeasibility of an optimization variable with respect to bound constraints and integer constraints, depending on the variable type.

Variable TypeInfeasibility for Bounds and Type
Continuousmax(0,lb - x,x - ub)
Integermax(0,lb - x,x - ub,abs(x - round(x)))
Semi-continuousmin(max(0,lb - x,x - ub),abs(x))
Semi-integermin(max(0,lb - x,x - ub,abs(x - round(x))),abs(x))

For example,

x = optimvar("x",Type="integer",LowerBound=6.5,UpperBound=10);
pt.x = 5;
infeasibility(x,pt)
ans =

    1.5000

Warning

The problem-based approach does not support complex values in the following: an objective function, nonlinear equalities, and nonlinear inequalities. If a function calculation has a complex value, even as an intermediate value, the final result might be incorrect.

More About

collapse all

Tips

The toolbox has three functions to compute the feasibility of points.

Version History

Introduced in R2017b

expand all