主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

integerConstraint

扩展整数变量索引

自 R2025a 起

说明

为混合整数线性规划求解器 intlinprog 指定扩展整数变量的索引。扩展整数变量的类型包括整数型、半连续型和半整数型。有关详细信息,请参阅扩展整数变量

创建对象

描述

intcon = integerConstraint(Name=Value) 指定传递给 intlinprogintcon 参量中的变量为扩展整数变量。例如,如果变量 x 的前五个索引是半连续的,而接下来的五个是整数,则设置 intcon = integerConstraint(SemiContinuous=1:5,Integer=6:10)

示例

名称-值参数

全部展开

将可选的参量对组指定为 Name1=Value1,...,NameN=ValueN,其中 Name 是参量名称,Value 是对应的值。名称-值参量必须出现在其他参量之后,但参量对组的顺序无关紧要。

示例: intcon = integerConstraint(Integer=1:4,SemiContinuous=5:9) 将索引 1 至 4 指定为整数变量,并将索引 5 至 9 指定为半连续变量。

整数变量的索引,指定为正整数的向量。例如,如果 1 到 21 的奇数索引的变量为整数值,则指定

intcon = integerConstraint(Integer=1:2:21);

换句话说,如果 intcon 适用于变量 x,则此约束意味着变量 x(1)x(3)x(5)、…、x(21) 的值为整数。

向量 IntegerSemiContinuousSemiInteger 必须具有不同的条目。可变索引不能出现在多个向量中。

提示

如果只有 Integer 类型的变量,则无需使用 integerConstraint 函数,即可将索引作为整数向量 intcon 传递。

此参量设置 Integer 属性。

半连续变量的指数,指定为正整数的向量。例如,如果变量 1 到 4 为整数值,变量 5 到 9 为半连续,则指定

intcon = integerConstraint(Integer=1:4,SemiContinuous=5:9);

此参量设置 SemiContinuous 属性。

半整数变量的索引,指定为正整数的向量。例如,如果变量 10 至 20 为半整数,变量 1 至 9 为半连续,则指定

intcon = integerConstraint(SemiInteger=10:20,SemiContinuous=1:9);

此参量设置 SemiInteger 属性。

属性

全部展开

整数索引,以正整数的向量形式返回。

数据类型: double

半连续索引,以正整数的向量形式返回。

数据类型: double

半整数索引,以正整数的向量形式返回。

数据类型: double

示例

全部折叠

指定变量索引 1 和 2 为半整数,变量索引 3 至 5 为半连续,变量索引 10 为整数,其余索引为连续(默认值)。

intcon = integerConstraint(SemiInteger=[1,2],SemiContinuous=3:5,Integer=10)
intcon = 
  IntegerConstraint with properties:

           Integer: 10
    SemiContinuous: [3 4 5]
       SemiInteger: [1 2]

intcon 是一个 IntegerConstraint 对象,其属性是扩展整数变量。

在混合整数线性规划问题中使用这些变量。请注意,intlinprog 求解器默认使用 "highs" 算法,因此接受 IntegerConstraint 对象。

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

详细信息

全部展开

替代功能

基于问题的扩展整数变量方法

对于基于问题的教学方法,在创建变量时,请在 optimvar 中指定变量类型。

x = optimvar("x",Type="semi-continuous",...
    LowerBound=3,UpperBound=10)
y = optimvar("y",2,Type="semi-integer",...
    LowerBound=[3,5],UpperBound=[10,20])

版本历史记录

在 R2025a 中推出