Class LinearOptimizationConstraint
Оптимизируйте свои подборки
Сохраняйте и классифицируйте контент в соответствии со своими настройками.
Ограничение линейной оптимизации Объект, хранящий линейное ограничение вида lower Bound ≤ Sum(a(i) x(i)) ≤ upperBound
, где lower Bound
и upper Bound
— константы, 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 Coefficient(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 Name | String | имя переменной, для которой задается коэффициент |
coefficient | Number | коэффициент устанавливается |
Возвращаться
Linear Optimization Constraint
— это ограничение линейной оптимизации.
Если не указано иное, контент на этой странице предоставляется по лицензии Creative Commons "С указанием авторства 4.0", а примеры кода – по лицензии Apache 2.0. Подробнее об этом написано в правилах сайта. Java – это зарегистрированный товарный знак корпорации Oracle и ее аффилированных лиц.
Последнее обновление: 2025-07-24 UTC.
[null,null,["Последнее обновление: 2025-07-24 UTC."],[[["\u003cp\u003e\u003ccode\u003eLinearOptimizationConstraint\u003c/code\u003e objects define constraints in the form of \u003ccode\u003elowerBound ≤ Sum(a(i) x(i)) ≤ upperBound\u003c/code\u003e, where \u003ccode\u003ea(i)\u003c/code\u003e are coefficients and \u003ccode\u003ex(i)\u003c/code\u003e are variables.\u003c/p\u003e\n"],["\u003cp\u003eYou can set the coefficient of a variable within a constraint using the \u003ccode\u003esetCoefficient(variableName, coefficient)\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eConstraints are created with lower and upper bounds, and variables are added with their own bounds before being incorporated into the constraint.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code example demonstrates creating a variable, adding a constraint, and setting the coefficient for the variable within that constraint.\u003c/p\u003e\n"]]],[],null,["# Class LinearOptimizationConstraint\n\nLinearOptimizationConstraint\n\nObject storing a linear constraint of the form `lower``Bound ≤ Sum(a(i) x(i)) ≤ upperBound`\nwhere `lower``Bound` and `upper``Bound` are constants, `a(i)` are constant\ncoefficients and `x(i)` are variables (unknowns).\n\nThe example below creates one variable `x` with values between `0` and `5`\nand creates the constraint `0 ≤ 2 * x ≤ 5`. This is done by first creating a constraint\nwith the lower bound `5` and upper bound `5`. Then the coefficient for variable\n`x` in this constraint is set to `2`.\n\n```javascript\nconst engine = LinearOptimizationService.createEngine();\n// Create a variable so we can add it to the constraint\nengine.addVariable('x', 0, 5);\n// Create a linear constraint with the bounds 0 and 10\nconst constraint = engine.addConstraint(0, 10);\n// Set the coefficient of the variable in the constraint. The constraint is now:\n// 0 \u003c= 2 * x \u003c= 5\nconstraint.setCoefficient('x', 2);\n``` \n\n### Methods\n\n| Method | Return type | Brief description |\n|-----------------------------------------------------------------------------|-----------------------------------|-------------------------------------------------------|\n| [setCoefficient(variableName, coefficient)](#setCoefficient(String,Number)) | [LinearOptimizationConstraint](#) | Sets the coefficient of a variable in the constraint. |\n\nDetailed documentation\n----------------------\n\n### `set``Coefficient(variableName, coefficient)`\n\nSets the coefficient of a variable in the constraint. By default, variables have a coefficient\nof 0.\n\n```javascript\nconst engine = LinearOptimizationService.createEngine();\n// Create a linear constraint with the bounds 0 and 10\nconst constraint = engine.addConstraint(0, 10);\n// Create a variable so we can add it to the constraint\nengine.addVariable('x', 0, 5);\n// Set the coefficient of the variable in the constraint. The constraint is now:\n// 0 \u003c= 2 * x \u003c= 5\nconstraint.setCoefficient('x', 2);\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|------------------|----------|-------------------------------------------------------------|\n| `variable``Name` | `String` | the name of variable for which the coefficient is being set |\n| `coefficient` | `Number` | coefficient being set |\n\n#### Return\n\n\n[LinearOptimizationConstraint](#) --- this linear optimization constraint"]]