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