存储 lowerBound ≤ Sum(a(i) x(i)) ≤ upperBound
形式的线性约束条件的对象,其中 lowerBound
和 upperBound
为常量,a(i)
为常数系数,x(i)
为变量(未知)。
以下示例创建了一个值介于 0
和 5
之间的变量 x
,并创建限制条件 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
- 此线性优化约束条件