- LocalSolverホーム
- クイックスタートガイド
- 数理的モデリング機能
数理的モデリング機能
LocalSolverは非線形0-1問題を解くことが可能です。全ての意思決定変数はバイナリ変数(0または1)です。
モデル内で宣言された全ての変数を計算することができる値を持つ変数、特に制約式や、オブジェクトで生じる変数に意思決定変数を使用します。
多くの組合せ最適問題が、ピュア0-1モデルとして表現することが可能です。
ナップザック問題は例題の1つです。:中間変数(リュックサックの重量、リュックサックの価値)が整数であると同時に、意思決定変数はバイナリ変数です。
注:正確な精度の10進法を必要とする多くの問題を扱うことができ、このような線形表現は-2^63 to 2^63-1 (> 10^18)により線形変数を取ることが可能です。
ブール意思決定変数は、演算子boolを使用し、宣言されます。
またモデリング表現と呼ばれる中間変数は下記の表で解説されている算術演算子を使用し宣言させることが可能です。
いかなる表現もキーワードconstraint, maximize, またはminimize.を使用し、制約式またはオブジェクトとしてタグ付けすることが可能です。
注:複雑な非線形モデルを宣言するために、これら全ての演算子が使用できます。
従って、LocalSolverは制約式においてだけではなくオブジェクトにおいても非線形、非凸表現式もサポートします。
いかなるブール表現もキーワードconstraint.を表現式の前に付けることで、制約式として表現することができます。
constraint knapsackWeight <= 102;
全ての制約が1の値を取り、コーディングが満たされている場合、意思決定変数のインスタンス化が可能です。LocalSolverは、(および、さらに一般的なローカル・サーチ)厳しい制約を持つ問題の求解に適さないため、出来る限り厳しい制約を排除してください。
特に、現実の現場で確実に満たせない制約は排除する必要があります。理想は、組合せの制約式のみが、設定されることです。(すなわち自身の問題に組合せ構造を帰納するもののみ)
その他、全ての制約は、「緩く」満たす(ゴールプログラミング)ために、主要なオブジェクトを緩和することが可能です。
LocalSolverはこれらの作業を行い易くするために、予約語オブジェクトを提供しています。
少なくても、1つのオブジェクトをキーワードminimize または maximizeを使用して定義します。
複数のオブジェクトが定義された場合、いかなる表現もオブジェクトとして使用でき、
それらは予約語オブジェクト関数として、変換されます。
予約語オーダーはオブジェクトが宣言されたオーダーで帰納します。
下記のような表現は、数理プログラミングで頻繁に出てきます。
maximize 10000 revenus - 100 resources + desiderata;
先ずrevenusを最大化、その後resourceを最小化、そして最終的にdesiderataを最大化する目的で、排除することが可能です。実際に、下記を直接記述することができます。
maximize revenus; minimize resources; maximize desiderata;
Operator | Description | Type | Arity | Symb | |
---|---|---|---|---|---|
Decisional | bool | Boolean decision: decision variable with domain {0,1}. | boolean | 0 | |
Arithmetic | sum | Sum: equal to the sum of all operands. | integer | n > 0 | + |
prod | Product: equal to the product of all operands. | integer | n > 0 | * | |
min | Minimum: equal to the minimum of all operands. | integer | n > 0 | ||
max | Maximum: equal to the maximum of all operands. | integer | n > 0 | ||
div | Integer division: div(a,b) = q such that a = q*b + r with q, r integers and |r| < b. | integer | 2 | / | |
mod | Modulo: mod(a,b) = r such that a = q*b + r with q, r integers and |r| < b. | integer | 2 | % | |
abs | Asolute value: abs(e) = e if e >= 0, -e otherwise. | integer | 1 | ||
dist | Distance between two integers: dist(a,b) = abs(a-b). | integer | 2 | ||
sqrt | Integer square root: sqrt(a) = c with c the largest integer such that c*c <= a. | integer | 1 | ||
Logical | not | Not: not(e) = 1 - e. | boolean | 1 | ! |
and | And: equal to 1 if all operands are 1, and 0 otherwise. | boolean | n > 0 | && | |
or | Or: equal to 0 if all operands are 0, and 1 otherwise. | boolean | n > 0 | || | |
xor | Exclusive or: equal to 0 if the number of operands with value 1 is even, and 1 otherwise. | boolean | n > 0 | ||
Relational | eq | Equal to: eq(a,b) = 1 if a = b, and 0 otherwise. | boolean | 2 | == |
neq | Not equal to: neq(a,b) = 1 if a != b, and 0 otherwise. | boolean | 2 | != | |
geq | Greater than or equal to: geq(a,b) = 1 if a >= b, and 0 otherwise. | boolean | 2 | >= | |
leq | Lower than or equal to: leq(a,b) = 1 if a <= b, and 0 otherwise. | boolean | 2 | <= | |
gt | Strictly greater than : gt(a,b) = 1 if a > b, and 0 otherwise. | boolean | 2 | > | |
lt | Strictly lower than: lt(a,b) = 1 if a < b, and 0 otherwise. | boolean | 2 | < | |
Conditional | iif | Ternary conditional operator: iif(a,b,c) = b if a is equal to 1, and c otherwise. | integer | 3 | ? : |
at | Access to an array: a[b] = the bth value in array a. An array is a map with contiguous elements starting at index 0. This array can contain both constants and expressions. | integer | 2 | [ ] |