儲存形式為 lowerBound ≤ Sum(a(i) x(i)) ≤ upperBound
形式線性限制的物件,其中 lowerBound
和 upperBound
是常數,a(i)
是常數係數,x(i)
是變數 (未知)。
以下範例會建立一個變數 x
,且值介於 0
和 5
之間,並建立限制 0 ≤ 2 * x ≤ 5
。方法是先建立具有下限 5
和上限 5
的限制。接著,這項限制中變數 x
的係數會設為 2
。
var 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 var 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);
方法
方法 | 傳回類型 | 簡短說明 |
---|---|---|
setCoefficient(variableName, coefficient) | LinearOptimizationConstraint | 設定限制中變數的係數。 |
內容詳盡的說明文件
setCoefficient(variableName, coefficient)
設定限制中變數的係數。根據預設,變數的係數為 0。
var engine = LinearOptimizationService.createEngine(); // Create a linear constraint with the bounds 0 and 10 var 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);
參數
名稱 | 類型 | 說明 |
---|---|---|
variableName | String | 要設定係數的變數名稱 |
coefficient | Number | 設定係數 |
回攻員
LinearOptimizationConstraint
— 這個線性最佳化限制