IntegerConstraint - Indices of extended integer variables - MATLAB (original) (raw)
Indices of extended integer variables
Since R2025a
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
Syntax
Description
`intcon` = integerConstraint([Name=Value](#namevaluepairarguments))
specifies that variables passed to intlinprog
in theintcon
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 asName1=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 variablex
, then this constraint means the variablesx(1)
, x(3)
, x(5)
, …,x(21)
have integer values.
The Integer
, SemiContinuous
, andSemiInteger
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 theintegerConstraint
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. Note that the intlinprog
solver uses the "highs"
algorithm by default, so accepts an IntegerConstraint
object.
lb = [4 10 3/2 5/2 7/2 zeros(1,5)]; ub = 10*(1:10); rng default f = 10randn(10,1) + 12; A = 10rand(20,10) - 15; b = 10*rand(20,1); [x,fval,eflag,output] = intlinprog(f,intcon,A,b,[],[],lb,ub)
Running HiGHS 1.7.1: Copyright (c) 2024 HiGHS under MIT licence terms 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
Solving report Status Optimal Primal bound -382.267036084 Dual bound -382.267036084 Gap 0% (tolerance: 0.01%) Solution status feasible -382.267036084 (objective) 0 (bound viol.) 0 (int. viol.) 0 (row viol.) Timing 0.00 (total) 0.00 (presolve) 0.00 (postsolve) Nodes 0 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
output = struct with fields: relativegap: 0 absolutegap: 0 numfeaspoints: 1 numnodes: 0 constrviolation: 0 algorithm: 'highs' 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
0
or 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
0
or any integer value from the lower bound to the upper bound. The bounds must be strictly positive and no more than1e5
.
The intlinprog
solver with the default"highs"
algorithm 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