Objek yang menyimpan batasan linear bentuk lowerBound ≤ Sum(a(i) x(i)) ≤ upperBound
dengan lowerBound
dan upperBound
adalah konstanta, a(i)
adalah koefisien
konstan, dan x(i)
adalah variabel (tidak diketahui).
Contoh di bawah membuat satu variabel x
dengan nilai antara 0
dan 5
,
lalu membuat batasan 0 ≤ 2 * x ≤ 5
. Hal ini dilakukan dengan membuat batasan terlebih dahulu
dengan 5
batas bawah dan 5
batas atas. Kemudian, koefisien untuk variabel
x
dalam batasan ini ditetapkan ke 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);
Metode
Metode | Jenis hasil yang ditampilkan | Deskripsi singkat |
---|---|---|
setCoefficient(variableName, coefficient) | LinearOptimizationConstraint | Menetapkan koefisien variabel dalam batasan. |
Dokumentasi mendetail
setCoefficient(variableName, coefficient)
Menetapkan koefisien variabel dalam batasan. Secara default, variabel memiliki koefisien 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
Nama | Jenis | Deskripsi |
---|---|---|
variableName | String | nama variabel yang koefisiennya sedang ditetapkan |
coefficient | Number | koefisien yang ditetapkan |
Return
LinearOptimizationConstraint
— batasan pengoptimalan linear ini