integerConstraint
Description
Specify indices of extended integer variables for the mixed-integer linear
programming solver intlinprog. Extended integer variables have the
types integer, semicontinuous, and semi-integer. For more information, see Extended Integer Variables.
Creation
Description
specifies that variables passed to intcon = integerConstraint(Name=Value)intlinprog in the
intcon argument are extended integer variables. For example, if the
first five indices of a variable x are semicontinuous, and the next
five are integer, set intcon =
integerConstraint(SemiContinuous=1:5,Integer=6:10).
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN, where Name is
the argument name and Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: intcon = integerConstraint(Integer=1:4,SemiContinuous=5:9)
specifies indices 1 through 4 as integer variables, and indices 5 through 9 as
semicontinuous variables.
Indices of integer variables, specified as a vector of positive integers. For example, if the variables with odd indices from 1 through 21 are integer-valued, specify
intcon = integerConstraint(Integer=1:2:21);
In other words, if intcon applies to the variable
x, then this constraint means the variables
x(1), x(3), x(5),
…,x(21) have integer values.
The Integer, SemiContinuous, and
SemiInteger vectors must have distinct entries. A variable
index cannot appear in multiple vectors.
Tip
If you have variables with the Integer type only, you can pass the indices
as an integer vector intcon without using the
integerConstraint function.
This argument sets the Integer property.
Indices of semicontinuous variables, specified as a vector of positive integers. For example, if variables 1 through 4 are integer-valued, and variables 5 through 9 are semicontinuous, specify
intcon = integerConstraint(Integer=1:4,SemiContinuous=5:9);
This argument sets the SemiContinuous property.
Indices of semi-integer variables, specified as a vector of positive integers. For example, if variables 10 through 20 are semi-integer, and variables 1 through 9 are semicontinuous, specify
intcon = integerConstraint(SemiInteger=10:20,SemiContinuous=1:9);
This argument sets the SemiInteger property.
Properties
Integer indices, returned as a vector of positive integers.
Data Types: double
Semicontinuous indices, returned as a vector of positive integers.
Data Types: double
Semi-integer indices, returned as a vector of positive integers.
Data Types: double
Examples
Specify that variable indices 1 and 2 are semi-integer, variable indices 3 through 5 are semicontinuous, variable index 10 is integer, and the remaining indices are continuous (the default).
intcon = integerConstraint(SemiInteger=[1,2],SemiContinuous=3:5,Integer=10)
intcon =
IntegerConstraint with properties:
Integer: 10
SemiContinuous: [3 4 5]
SemiInteger: [1 2]
intcon is an IntegerConstraint object whose properties are extended integer variables.
Use these variables in a mixed-integer linear programming problem.
lb = [4 10 3/2 5/2 7/2 zeros(1,5)];
ub = 10*(1:10);
rng default
f = 10*randn(10,1) + 12;
A = 10*rand(20,10) - 15;
b = 10*rand(20,1);
[x,fval,eflag,output] = intlinprog(f,intcon,A,b,[],[],lb,ub)Running HiGHS 1.11.0: Copyright (c) 2025 HiGHS under MIT licence terms
MIP has 20 rows; 10 cols; 200 nonzeros; 1 integer variables (0 binary); 3 semi-continuous variables; 2 semi-integer variables
Coefficient ranges:
Matrix [5e+00, 1e+01]
Cost [1e+00, 5e+01]
Bound [2e+00, 1e+02]
RHS [1e+00, 1e+01]
Presolving model
10 rows, 10 cols, 20 nonzeros 0s
0 rows, 5 cols, 0 nonzeros 0s
0 rows, 0 cols, 0 nonzeros 0s
Presolve: Optimal
Src: B => Branching; C => Central rounding; F => Feasibility pump; J => Feasibility jump;
H => Heuristic; L => Sub-MIP; P => Empty MIP; R => Randomized rounding; Z => ZI Round;
I => Shifting; S => Solve LP; T => Evaluate node; U => Unbounded; X => User solution;
z => Trivial zero; l => Trivial lower; u => Trivial upper; p => Trivial point
Nodes | B&B Tree | Objective Bounds | Dynamic Constraints | Work
Src Proc. InQueue | Leaves Expl. | BestBound BestSol Gap | Cuts InLp Confl. | LpIters Time
0 0 0 0.00% -382.2670361 -382.2670361 0.00% 0 0 0 0 0.0s
Solving report
Status Optimal
Primal bound -382.267036084
Dual bound -382.267036084
Gap 0% (tolerance: 0.01%)
P-D integral 0
Solution status feasible
-382.267036084 (objective)
0 (bound viol.)
0 (int. viol.)
0 (row viol.)
Timing 0.00 (total)
0.00 (presolve)
0.00 (solve)
0.00 (postsolve)
Max sub-MIP depth 0
Nodes 0
Repair LPs 0 (0 feasible; 0 iterations)
LP iterations 0 (total)
0 (strong br.)
0 (separation)
0 (heuristics)
Optimal solution found.
Intlinprog stopped at the root node because the objective value is within a gap tolerance of the optimal value, options.AbsoluteGapTolerance = 1e-06. The intcon variables are integer within tolerance, options.ConstraintTolerance = 1e-06.
x = 10×1
0
0
30
0
0
60
0
0
0
0
fval = -382.2670
eflag = 1
output = struct with fields:
relativegap: 0
absolutegap: 0
numfeaspoints: 1
numnodes: 0
constrviolation: 0
message: 'Optimal solution found.↵↵Intlinprog stopped at the root node because the objective value is within a gap tolerance of the optimal value, options.AbsoluteGapTolerance = 1e-06. The intcon variables are integer within tolerance, options.ConstraintTolerance = 1e-06.'
More About
An extended integer variable is a variable that is integer-valued, semicontinuous, or semi-integer.
An integer-valued variable can take any integer value represented in a standard double-precision variable, such as –12 or 1234567. You do not need to specify any bounds for an integer variable.
A semicontinuous variable can take the value
0or any real value from the lower bound to the upper bound. The bounds must be strictly positive and no more than1e5.A semi-integer variable is integer-valued and can take the value
0or any integer value from the lower bound to the upper bound. The bounds must be strictly positive and no more than1e5.
The intlinprog solver supports integer variables and
extended integer variables, all of which have the MATLAB® type double. Specify the variable types using the integerConstraint function. Specify the variable indices that are integer or
extended integer using these names:
Integer— Integer variable indicesSemiContinuous— Semicontinuous variable indicesSemiInteger— Semi-integer variable indices
The default type for unspecified variable indices is continuous, meaning variables that can take any real value.
For example, to specify that variables 1 through 5 are integer, 11 through 20 are semicontinuous, and the remainder are continuous:
intcon = integerConstraint(Integer=1:5,SemiContinuous=11:20);
Alternative Functionality
Problem-Based Approach to Extended Integer Variables
For the problem-based approach, specify the variable type in optimvar when
creating variables.
x = optimvar("x",Type="semi-continuous",... LowerBound=3,UpperBound=10) y = optimvar("y",2,Type="semi-integer",... LowerBound=[3,5],UpperBound=[10,20])
Version History
Introduced in R2025a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)