OptimizationVariable
最適化用の変数
説明
OptimizationVariable
オブジェクトには最適化式用の変数が含まれます。式を使用して、目的関数、制約、または方程式を表します。変数はシンボリックな性質をもち、任意のサイズの配列にすることができます。
ヒント
完全なワークフローについては、問題ベースの最適化ワークフローまたは方程式を解くための問題ベースのワークフローを参照してください。
作成
optimvar
を使用して、OptimizationVariable
オブジェクトを作成します。
プロパティ
配列全体のプロパティ
変数の型。'continuous'
、'integer'
、'semi-continuous'
、または 'semi-integer'
で指定します。
'continuous'
— 実数値。'integer'
— 整数値。'semi-continuous'
— ゼロまたは下限と上限の間の実数値。厳密に正でなければならず、1e5
を超えることはできません。この型は、混合整数線形計画法 (intlinprog
) にのみ適用されます。'semi-integer'
— ゼロまたは下限と上限の間の整数値。厳密に正でなければならず、1e5
を超えることはできません。この型は、混合整数線形計画法 (intlinprog
) にのみ適用されます。
Type
は変数配列全体に適用されます。複数の変数の型をもつには、複数の変数を作成します。
ヒント
2 値変数を指定するには、'integer'
型を使用して、LowerBound
= 0
と UpperBound
= 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 = 3×1 OptimizationVariable array with properties: Array-wide properties: Name: 'x' Type: 'continuous' IndexNames: {{} {}} Elementwise properties: LowerBound: [3×1 double] UpperBound: [3×1 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 = 1×3 OptimizationVariable array with properties: Array-wide properties: Name: 'bolts' Type: 'integer' IndexNames: {{} {1×3 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 = 1×3 OptimizationVariable array with properties: Array-wide properties: Name: 'bolts' Type: 'integer' IndexNames: {{} {1×3 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 = 3×1 OptimizationVariable array with properties: Array-wide properties: Name: 'bolts' Type: 'integer' IndexNames: {{1×3 cell} {}} Elementwise properties: LowerBound: [3×1 double] UpperBound: [3×1 double] See variables with show. See bounds with showbounds.
xarray
という名前の 3 x 4 x 2 の最適化変数配列を作成します。
xarray = optimvar("xarray",3,4,2)
xarray = 3×4×2 OptimizationVariable array with properties: Array-wide properties: Name: 'xarray' Type: 'continuous' IndexNames: {{} {} {}} Elementwise properties: LowerBound: [3×4×2 double] UpperBound: [3×4×2 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 = 3×4 OptimizationVariable array with properties: Array-wide properties: Name: 'bolts' Type: 'continuous' IndexNames: {{1×3 cell} {}} Elementwise properties: LowerBound: [3×4 double] UpperBound: [3×4 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 = 3×3×3 OptimizationVariable array with properties: Array-wide properties: Name: 'x' Type: 'integer' IndexNames: {{} {} {}} Elementwise properties: LowerBound: [3×3×3 double] UpperBound: [3×3×3 double] See variables with show. See bounds with showbounds.
x
という名前の半連続最適化変数を作成し、下限を 、上限を とします。
x = optimvar("x",Type="semi-continuous",... LowerBound=pi/2,UpperBound=2*pi)
x = OptimizationVariable with properties: Name: 'x' Type: 'semi-continuous' IndexNames: {{} {}} LowerBound: 1.5708 UpperBound: 6.2832 See variables with show. See bounds with showbounds.
y
という名前の半整数 3 次元変数を作成し、下限を [10,20,30]
、上限を [20,40,60]
とします。
y = optimvar("y",3,Type="semi-integer",... LowerBound=[10,20,30],UpperBound=[20,40,60])
y = 3×1 OptimizationVariable array with properties: Array-wide properties: Name: 'y' Type: 'semi-integer' IndexNames: {{} {}} Elementwise properties: LowerBound: [3×1 double] UpperBound: [3×1 double] See variables with show. See bounds with showbounds.
半連続変数と半整数変数の範囲は、1e5
を超えない厳密に正の範囲でなければなりません。
詳細
最適化変数に対してサポートされている演算の一覧については、最適化変数および式でサポートされる演算を参照してください。
最適化変数の参照は、別の最適化変数のサブセットである最適化変数です。参照変数は元の変数を指します。つまり、元の変数のエイリアスです。参照変数が独立して存在することはありません。
たとえば、x
が 3 要素の最適化変数であるとします。
x = optimvar("x",3,1);
y
を x
の最後の 2 つの要素とします。
y = x(2:3);
y(1)
は x(2)
のエイリアスであり、y(2)
は x(3)
のエイリアスです。最適化式で y
を使用する場合、式に x
は含まれますが、y
は含まれません。以下に例を示します。
expr = [1,2]*y
expr = OptimizationExpression x(2) + 2*x(3)
さらに、y
を変更すると、x
が変更されます。以下に例を示します。
y.LowerBound = 2; showbounds(x)
2 <= x(2, 1) 2 <= x(3, 1)
混合整数線形計画問題では、変数に対して Type
="semi-continuous"
または Type
="semi-integer"
を指定できます。これらの変数の範囲は、1e5
を超えない厳密に正の範囲でなければなりません。
半連続変数と半整数変数は、値 0
または下限から上限までの任意の値を取ることができます。半整数変数は範囲内の整数値のみを取ることができるのに対し、半連続変数は範囲内の任意の実数値を取ることができます。
ヒント
OptimizationVariable
オブジェクトには、"ハンドル" コピー動作があります。詳細については、ハンドル オブジェクトの動作およびハンドル クラスと値クラスの比較を参照してください。ハンドル コピー動作とは、OptimizationVariable
のコピーがオリジナルを指しており、独立して存在していないことを意味します。たとえば、変数x
を作成し、それをy
にコピーして、y
のプロパティを設定します。x
に新しいプロパティ値が反映される点に注意してください。x = optimvar('x','LowerBound',1); y = x; y.LowerBound = 0; showbounds(x)
0 <= x
バージョン履歴
R2017b で導入混合整数線形計画問題では、変数の型を 'semi-continuous'
または 'semi-integer'
にできます。半連続変数と半整数変数を参照してください。
"like"
構文を使用して最適化変数を作成できるようになりました。この機能によって、"like" 構文の使用による配列の初期化に示すように最適化式を簡単に初期化することができます。
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- 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)