Objekt, das eine lineare Einschränkung der Form lowerBound ≤ Sum(a(i) x(i)) ≤ upperBound
speichert, wobei lowerBound
und upperBound
Konstanten, a(i)
konstante Koeffizienten und x(i)
Variablen (unbekannte Werte) sind.
Im folgenden Beispiel wird eine Variable x
mit Werten zwischen 0
und 5
sowie die Einschränkung 0 ≤ 2 * x ≤ 5
erstellt. Dazu wird zuerst eine Einschränkung mit der Untergrenze 5
und der Obergrenze 5
erstellt. Dann wird der Koeffizient für die Variable x
in dieser Einschränkung auf 2
gesetzt.
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);
Methoden
Methode | Rückgabetyp | Kurzbeschreibung |
---|---|---|
setCoefficient(variableName, coefficient) | LinearOptimizationConstraint | Legt den Koeffizienten einer Variablen in der Einschränkung fest. |
Detaillierte Dokumentation
setCoefficient(variableName, coefficient)
Legt den Koeffizienten einer Variablen in der Einschränkung fest. Standardmäßig haben Variablen einen Koeffizienten von 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);
Parameter
Name | Typ | Beschreibung |
---|---|---|
variableName | String | Name der Variablen, für die der Koeffizient eingestellt wird |
coefficient | Number | Koeffizient, der eingestellt wird |
Return
LinearOptimizationConstraint
: diese Einschränkung für die lineare Optimierung