Main Content

OptimizationVariable

説明

OptimizationVariable オブジェクトには最適化式用の変数が含まれます。式を使用して、目的関数、制約、または方程式を表します。変数はシンボリックな性質をもち、任意のサイズの配列にすることができます。

ヒント

完全なワークフローについては、問題ベースの最適化ワークフローまたは方程式を解くための問題ベースのワークフローを参照してください。

作成

optimvar を使用して、OptimizationVariable オブジェクトを作成します。

プロパティ

すべて展開する

配列全体のプロパティ

この プロパティ は読み取り専用です。

変数名。string または文字ベクトルとして指定します。

Name は、showwrite などで表示される変数ラベルです。Name は、solve が返す解の構造体のフィールド名にもなります。

ヒント

混乱を避けるために、name を MATLAB® 変数名になるように設定します。たとえば、

metal = optimvar('metal')

データ型: char | string

変数の型。'continuous' または 'integer' で指定します。

  • 'continuous' - 実数値

  • 'integer' - 整数値

変数の型は、配列のすべての変数に適用されます。複数の変数の型をもつには、複数の変数を作成します。

ヒント

2 値変数を指定するには、'integer' 型を使用して、LowerBound = 0UpperBound = 1 を指定します。

データ型: char | string

インデックスの名前。string の cell 配列または文字ベクトルを指定します。インデックス名の使用法の詳細については、最適化変数の名前付きインデックスを参照してください。

データ型: cell

要素単位のプロパティ

下限。実数スカラーまたは OptimizationVariable オブジェクトと同じ次元をもつ実数配列として指定します。スカラー値は変数のすべての要素に適用されます。

LowerBound プロパティは常に配列として表示されます。ただし、プロパティをすべての要素に適用されるスカラーとして設定できます。たとえば、

var.LowerBound = 0

データ型: double

上限。実数スカラーまたは OptimizationVariable オブジェクトと同じ次元をもつ実数配列として指定します。スカラー値は変数のすべての要素に適用されます。

UpperBound プロパティは常に配列として表示されます。ただし、プロパティをすべての要素に適用されるスカラーとして設定できます。たとえば、

var.UpperBound = 1

データ型: double

オブジェクト関数

show最適化オブジェクトの情報表示
showbounds変数範囲の表示
write最適化オブジェクトの説明の保存
writebounds変数範囲の説明の保存

すべて折りたたむ

dollars という名前のスカラー最適化変数を作成します。

dollars = optimvar('dollars')
dollars = 
  OptimizationVariable with properties:

          Name: 'dollars'
          Type: 'continuous'
    IndexNames: {{}  {}}
    LowerBound: -Inf
    UpperBound: Inf

  See variables with show.
  See bounds with showbounds.

x という名前の 3 行 1 列の最適化変数ベクトルを作成します。

x = optimvar('x',3)
x = 
  3x1 OptimizationVariable array with properties:

  Array-wide properties:
          Name: 'x'
          Type: 'continuous'
    IndexNames: {{}  {}}

  Elementwise properties:
    LowerBound: [3x1 double]
    UpperBound: [3x1 double]

  See variables with show.
  See bounds with showbounds.

"brass""stainless"、および "galvanized" という string によってインデックス付けされる bolts という名前の整数最適化変数ベクトルを作成します。bolts のインデックスを使用して最適化式を作成し、さらに、文字配列を使用して、または異なる方向で bolts の作成を試します。

行方向で string を使用して bolts を作成します。

bnames = ["brass","stainless","galvanized"];
bolts = optimvar('bolts',bnames,'Type','integer')
bolts = 
  1x3 OptimizationVariable array with properties:

  Array-wide properties:
          Name: 'bolts'
          Type: 'integer'
    IndexNames: {{}  {1x3 cell}}

  Elementwise properties:
    LowerBound: [-Inf -Inf -Inf]
    UpperBound: [Inf Inf Inf]

  See variables with show.
  See bounds with showbounds.

string インデックスを使用して最適化式を作成します。

y = bolts("brass") + 2*bolts("stainless") + 4*bolts("galvanized")
y = 
  Linear OptimizationExpression

    bolts('brass') + 2*bolts('stainless') + 4*bolts('galvanized')

string の代わりに文字ベクトルの cell 配列を使用して、前出と同じインデックスをもつ変数を取得します。

bnames = {'brass','stainless','galvanized'};
bolts = optimvar('bolts',bnames,'Type','integer')
bolts = 
  1x3 OptimizationVariable array with properties:

  Array-wide properties:
          Name: 'bolts'
          Type: 'integer'
    IndexNames: {{}  {1x3 cell}}

  Elementwise properties:
    LowerBound: [-Inf -Inf -Inf]
    UpperBound: [Inf Inf Inf]

  See variables with show.
  See bounds with showbounds.

1 行 3 列ではなく 3 行 1 列の列方向バージョンの bnames を使用して、bolts もその方向であることを確認します。

bnames = ["brass";"stainless";"galvanized"];
bolts = optimvar('bolts',bnames,'Type','integer')
bolts = 
  3x1 OptimizationVariable array with properties:

  Array-wide properties:
          Name: 'bolts'
          Type: 'integer'
    IndexNames: {{1x3 cell}  {}}

  Elementwise properties:
    LowerBound: [3x1 double]
    UpperBound: [3x1 double]

  See variables with show.
  See bounds with showbounds.

xarray という名前の 3 x 4 x 2 の最適化変数配列を作成します。

xarray = optimvar('xarray',3,4,2)
xarray = 
  3x4x2 OptimizationVariable array with properties:

  Array-wide properties:
          Name: 'xarray'
          Type: 'continuous'
    IndexNames: {{}  {}  {}}

  Elementwise properties:
    LowerBound: [3x4x2 double]
    UpperBound: [3x4x2 double]

  See variables with show.
  See bounds with showbounds.

名前と数値インデックスの混合によってインデックス付けされた多次元変数を作成することもできます。たとえば、最適化変数の 3 行 4 列の配列を作成します。1 番目の次元は string 'brass''stainless'、および 'galvanized' によってインデックス付けされ、2 番目の次元は数値的にインデックス付けされます。

bnames = ["brass","stainless","galvanized"];
bolts = optimvar('bolts',bnames,4)
bolts = 
  3x4 OptimizationVariable array with properties:

  Array-wide properties:
          Name: 'bolts'
          Type: 'continuous'
    IndexNames: {{1x3 cell}  {}}

  Elementwise properties:
    LowerBound: [3x4 double]
    UpperBound: [3x4 double]

  See variables with show.
  See bounds with showbounds.

サイズが 3 x 3 x 3 で 2 値変数を表す x という名前の最適化変数を作成します。

x = optimvar('x',3,3,3,'Type','integer','LowerBound',0,'UpperBound',1)
x = 
  3x3x3 OptimizationVariable array with properties:

  Array-wide properties:
          Name: 'x'
          Type: 'integer'
    IndexNames: {{}  {}  {}}

  Elementwise properties:
    LowerBound: [3x3x3 double]
    UpperBound: [3x3x3 double]

  See variables with show.
  See bounds with showbounds.

詳細

すべて展開する

ヒント

  • OptimizationVariable オブジェクトには、"ハンドル" コピー動作があります。詳細については、ハンドル オブジェクトの動作ハンドル クラスと値クラスの比較を参照してください。ハンドル コピー動作とは、OptimizationVariable のコピーがオリジナルを指しており、独立して存在していないことを意味します。たとえば、変数 x を作成し、それを y にコピーして、y のプロパティを設定します。x に新しいプロパティ値が反映される点に注意してください。

    x = optimvar('x','LowerBound',1);
    y = x;
    y.LowerBound = 0;
    showbounds(x)
        0 <= x

バージョン履歴

R2017b で導入

すべて展開する