OptimizationVariable
最適化用の変数
説明
OptimizationVariable
オブジェクトには最適化式用の変数が含まれます。式を使用して、目的関数、制約、または方程式を表します。変数はシンボリックな性質をもち、任意のサイズの配列にすることができます。
ヒント
完全なワークフローについては、問題ベースの最適化ワークフローまたは方程式を解くための問題ベースのワークフローを参照してください。
作成
optimvar
を使用して、OptimizationVariable
オブジェクトを作成します。
プロパティ
配列全体のプロパティ
Type
— 変数の型
'continuous'
(既定値) | 'integer'
変数の型。'continuous'
または 'integer'
で指定します。
'continuous'
- 実数値'integer'
- 整数値
変数の型は、配列のすべての変数に適用されます。複数の変数の型をもつには、複数の変数を作成します。
ヒント
2 値変数を指定するには、'integer'
型を使用して、LowerBound
= 0
と UpperBound
= 1
を指定します。
データ型: char
| string
IndexNames
— インデックス名
''
(既定値) | string の cell 配列 | 文字ベクトルの cell 配列
インデックスの名前。string の cell 配列または文字ベクトルを指定します。インデックス名の使用法の詳細については、最適化変数の名前付きインデックスを参照してください。
データ型: cell
要素単位のプロパティ
LowerBound
— 下限
-Inf
(既定値) | 実数スカラー | 実数配列
下限。実数スカラーまたは OptimizationVariable
オブジェクトと同じ次元をもつ実数配列として指定します。スカラー値は変数のすべての要素に適用されます。
LowerBound
プロパティは常に配列として表示されます。ただし、プロパティをすべての要素に適用されるスカラーとして設定できます。たとえば、
var.LowerBound = 0
データ型: double
UpperBound
— 上限
Inf
(既定値) | 実数スカラー | 実数配列
上限。実数スカラーまたは 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.
string によってインデックス付けされた最適化変数の作成
"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 で導入R2024a: "like"
構文を使用した最適化変数の作成
"like"
構文を使用して最適化変数を作成できるようになりました。この機能によって、"like" 構文の使用による配列の初期化に示すように最適化式を簡単に初期化することができます。
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)