Main Content

integerConstraint

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

Description

intcon = integerConstraint(Name=Value) specifies that variables passed to 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).

example

Name-Value Arguments

expand all

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

expand all

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

collapse all

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 = 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.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

fval = 
-382.2670
eflag = 
1
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

expand all

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