物件,用於儲存 lowerBound ≤ Sum(a(i) x(i)) ≤ upperBound 形式的線性限制,其中 lowerBound 和 upperBound 是常數,a(i) 是常數係數,x(i) 則是變數 (未知數)。
以下範例會建立一個變數 x,其值介於 0 和 5 之間,並建立限制條件 0 ≤ 2 * x ≤ 5。方法是先建立下限為 5 且上限為 5 的限制。然後,這個限制條件中變數 x 的係數會設為 2。
const engine = LinearOptimizationService.createEngine(); // Create a variable so we can add it to the constraint engine.addVariable('x', 0, 5); // Create a linear constraint with the bounds 0 and 10 const constraint = engine.addConstraint(0, 10); // Set the coefficient of the variable in the constraint. The constraint is now: // 0 <= 2 * x <= 5 constraint.setCoefficient('x', 2);
方法
| 方法 | 傳回類型 | 簡短說明 |
|---|---|---|
set | Linear | 設定限制中變數的係數。 |
內容詳盡的說明文件
setCoefficient(variableName, coefficient)
設定限制中變數的係數。根據預設,變數的係數為 0。
const engine = LinearOptimizationService.createEngine(); // Create a linear constraint with the bounds 0 and 10 const constraint = engine.addConstraint(0, 10); // Create a variable so we can add it to the constraint engine.addVariable('x', 0, 5); // Set the coefficient of the variable in the constraint. The constraint is now: // 0 <= 2 * x <= 5 constraint.setCoefficient('x', 2);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
variable | String | 要設定係數的變數名稱 |
coefficient | Number | 設定的係數 |
回攻員
LinearOptimizationConstraint - 這項線性最佳化限制