Class LinearOptimizationConstraint
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Contrainted'optimisationlinéaire
Objet stockant une contrainte linéaire de la forme lowerBound ≤ Sum(a(i) x(i)) ≤ upperBound
, où lowerBound
et upperBound
sont des constantes, a(i)
sont des coefficients constants et x(i)
sont des variables (inconnues).
L'exemple ci-dessous crée une variable x
avec des valeurs comprises entre 0
et 5
, et crée la contrainte 0 ≤ 2 * x ≤ 5
. Pour ce faire, créez d'abord une contrainte avec la limite inférieure 5
et la limite supérieure 5
. Le coefficient de la variable x
dans cette contrainte est ensuite défini sur 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);
Documentation détaillée
setCoefficient(variableName, coefficient)
Définit le coefficient d'une variable dans la contrainte. Par défaut, les variables ont un coefficient de 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);
Paramètres
Nom | Type | Description |
variableName | String | Nom de la variable pour laquelle le coefficient est défini |
coefficient | Number | coefficient défini |
Renvois
LinearOptimizationConstraint
: cette contrainte d'optimisation linéaire
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/07/26 (UTC).
[null,null,["Dernière mise à jour le 2025/07/26 (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"]]