メインコンテンツ

integerConstraint

拡張整数変数のインデックス

R2025a 以降

説明

混合整数線形計画法ソルバー intlinprog の拡張整数変数のインデックスを指定します。拡張整数変数の型は整数、半連続、および半整数です。詳細については、拡張整数変数を参照してください。

作成

説明

intcon = integerConstraint(Name=Value) は、intcon 引数の intlinprog に渡される変数が拡張整数変数であると指定します。たとえば、変数 x の最初の 5 つのインデックスが半連続、次の 5 つが整数である場合は、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) が整数値をもつことを意味します。

IntegerSemiContinuous、および SemiInteger ベクトルは異なるエントリをもつ必要があります。変数インデックスを複数のベクトルに含めることはできません。

ヒント

変数の型が 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.01 (total)
                    0.01 (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 で導入