# Class LinearOptimizationEngine

Mesin Pengoptimalan Linear

Mesin yang digunakan untuk membuat model dan menyelesaikan program linear. Contoh di bawah ini menyelesaikan program linear berikut:

Dua variabel, `x` dan `y`:
`0 ≤ x ≤ 10`
`0 ≤ y ≤ 5`

Batasan:
`0 ≤ 2 * x + 5 * y ≤ 10`
`0 ≤ 10 * x + 3 * y ≤ 20`

Tujuan:
Maksimalkan `x + y`

```var engine = LinearOptimizationService.createEngine();

// Add two variables, 0 <= x <= 10 and 0 <= y <= 5

// Create the constraint: 0 <= 2 * x + 5 * y <= 10
constraint.setCoefficient('x', 2);
constraint.setCoefficient('y', 5);

// Create the constraint: 0 <= 10 * x + 3 * y <= 20
constraint.setCoefficient('x', 10);
constraint.setCoefficient('y', 3);

// Set the objective to be x + y
engine.setObjectiveCoefficient('x', 1);
engine.setObjectiveCoefficient('y', 1);

// Engine should maximize the objective
engine.setMaximization();

// Solve the linear program
var solution = engine.solve();
if (!solution.isValid()) {
Logger.log('No solution ' + solution.getStatus());
} else {
Logger.log('Value of x: ' + solution.getVariableValue('x'));
Logger.log('Value of y: ' + solution.getVariableValue('y'));
}```

### Metode

MetodeJenis hasil yang ditampilkanDeskripsi singkat
`addConstraint(lowerBound, upperBound)``LinearOptimizationConstraint`Menambahkan batasan linear baru dalam model.
`addConstraints(lowerBounds, upperBounds, variableNames, coefficients)``LinearOptimizationEngine`Menambahkan batasan dalam batch ke model.
`addVariable(name, lowerBound, upperBound)``LinearOptimizationEngine`Menambahkan variabel berkelanjutan baru ke model.
`addVariable(name, lowerBound, upperBound, type)``LinearOptimizationEngine`Menambahkan variabel baru ke model.
`addVariable(name, lowerBound, upperBound, type, objectiveCoefficient)``LinearOptimizationEngine`Menambahkan variabel baru ke model.
`addVariables(names, lowerBounds, upperBounds, types, objectiveCoefficients)``LinearOptimizationEngine`Menambahkan variabel dalam batch ke model.
`setMaximization()``LinearOptimizationEngine`Menetapkan arah pengoptimalan untuk memaksimalkan fungsi tujuan linear.
`setMinimization()``LinearOptimizationEngine`Menetapkan arah pengoptimalan untuk meminimalkan fungsi tujuan linear.
`setObjectiveCoefficient(variableName, coefficient)``LinearOptimizationEngine`Menetapkan koefisien variabel dalam fungsi tujuan linear.
`solve()``LinearOptimizationSolution`Menyelesaikan program linear saat ini dengan batas waktu default 30 detik.
`solve(seconds)``LinearOptimizationSolution`Memecahkan program linear saat ini.

## Dokumentasi mendetail

### `addConstraint(lowerBound, upperBound)`

Menambahkan batasan linear baru dalam model. Batas atas dan bawah batasan ditentukan pada waktu pembuatan. Koefisien untuk variabel ditentukan melalui panggilan ke `LinearOptimizationConstraint.setCoefficient(variableName, coefficient)`.

```var engine = LinearOptimizationService.createEngine();

// Create a linear constraint with the bounds 0 and 10

// Create a variable so we can add it to the constraint

// Set the coefficient of the variable in the constraint. The constraint is now:
// 0 <= 2 * x <= 5
constraint.setCoefficient('x', 2);```

#### Parameter

NameJenisDeskripsi
`lowerBound``Number`batas bawah batasan
`upperBound``Number`batas atas batasan

#### Return

`LinearOptimizationConstraint` — batasan yang dibuat

### `addConstraints(lowerBounds, upperBounds, variableNames, coefficients)`

Menambahkan batasan dalam batch ke model.

```var engine = LinearOptimizationService.createEngine();

// Add a boolean variable 'x' (integer >= 0 and <= 1) and a real (continuous >= 0 and <= 100)
variable 'y'.
engine.addVariables(['x', 'y'], [0, 0], [1, 100],
[LinearOptimizationService.VariableType.INTEGER,
LinearOptimizationService.VariableType.CONTINUOUS]);

//   0 <= x + y <= 3
//   1 <= 10 * x - y <= 5
engine.addConstraints([0.0, 1.0], [3.0, 5.0], [['x', 'y'], ['x', 'y']], [[1, 1], [10, -1]]);```

#### Parameter

NameJenisDeskripsi
`lowerBounds``Number[]`batas bawah batasan
`upperBounds``Number[]`batas atas batasan
`variableNames``String[][]`nama variabel yang koefisiennya ditetapkan
`coefficients``Number[][]`koefisien yang disetel

#### Return

`LinearOptimizationEngine` — mesin pengoptimalan linear

### `addVariable(name, lowerBound, upperBound)`

Menambahkan variabel berkelanjutan baru ke model. Variabel dirujuk oleh namanya. Jenis ditetapkan ke `VariableType.CONTINUOUS`.

```var engine = LinearOptimizationService.createEngine();

// Add a boolean variable (integer >= 0 and <= 1)

// Add a real (continuous) variable. Notice the lack of type specification.

#### Parameter

NameJenisDeskripsi
`name``String`nama unik variabel
`lowerBound``Number`batas bawah variabel
`upperBound``Number`batas atas variabel

#### Return

`LinearOptimizationEngine` — mesin pengoptimalan linear

### `addVariable(name, lowerBound, upperBound, type)`

Menambahkan variabel baru ke model. Variabel dirujuk oleh namanya.

```var engine = LinearOptimizationService.createEngine();

// Add a boolean variable (integer >= 0 and <= 1)

// Add a real (continuous) variable

#### Parameter

NameJenisDeskripsi
`name``String`nama unik variabel
`lowerBound``Number`batas bawah variabel
`upperBound``Number`batas atas variabel
`type``VariableType`jenis variabel, dapat berupa salah satu dari `VariableType`

#### Return

`LinearOptimizationEngine` — mesin pengoptimalan linear

### `addVariable(name, lowerBound, upperBound, type, objectiveCoefficient)`

Menambahkan variabel baru ke model. Variabel dirujuk oleh namanya.

```var engine = LinearOptimizationService.createEngine();

// Add a boolean variable (integer >= 0 and <= 1)
// The objective is now 2 * x.

// Add a real (continuous) variable
// The objective is now 2 * x - 5 * y.```

#### Parameter

NameJenisDeskripsi
`name``String`nama unik variabel
`lowerBound``Number`batas bawah variabel
`upperBound``Number`batas atas variabel
`type``VariableType`jenis variabel, dapat berupa salah satu dari `VariableType`
`objectiveCoefficient``Number`koefisien objektif dari variabel

#### Return

`LinearOptimizationEngine` — mesin pengoptimalan linear

### `addVariables(names, lowerBounds, upperBounds, types, objectiveCoefficients)`

Menambahkan variabel dalam batch ke model. Variabel dirujuk oleh namanya.

```var engine = LinearOptimizationService.createEngine();

// Add a boolean variable 'x' (integer >= 0 and <= 1) and a real (continuous >=0 and <= 100)
// variable 'y'.
engine.addVariables(['x', 'y'], [0, 0], [1, 100],
[LinearOptimizationService.VariableType.INTEGER,
LinearOptimizationService.VariableType.CONTINUOUS]);```

#### Parameter

NameJenisDeskripsi
`names``String[]`nama unik variabel
`lowerBounds``Number[]`batas bawah variabel
`upperBounds``Number[]`batas atas variabel
`types``VariableType[]`jenis variabel, dapat berupa salah satu dari `VariableType`
`objectiveCoefficients``Number[]`koefisien objektif dari variabel

#### Return

`LinearOptimizationEngine` — mesin pengoptimalan linear

### `setMaximization()`

Menetapkan arah pengoptimalan untuk memaksimalkan fungsi tujuan linear.

```var engine = LinearOptimizationService.createEngine();

// Add a real (continuous) variable. Notice the lack of type specification.

// Set the coefficient of 'y' in the objective.
// The objective is now 5 * y
engine.setObjectiveCoefficient('y', 5);

// We want to maximize.
engine.setMaximization();```

#### Return

`LinearOptimizationEngine` — mesin pengoptimalan linear

### `setMinimization()`

Menetapkan arah pengoptimalan untuk meminimalkan fungsi tujuan linear.

```var engine = LinearOptimizationService.createEngine();

// Add a real (continuous) variable. Notice the lack of type specification.

// Set the coefficient of 'y' in the objective.
// The objective is now 5 * y
engine.setObjectiveCoefficient('y', 5);

// We want to minimize
engine.setMinimization();```

#### Return

`LinearOptimizationEngine` — mesin pengoptimalan linear

### `setObjectiveCoefficient(variableName, coefficient)`

Menetapkan koefisien variabel dalam fungsi tujuan linear.

```var engine = LinearOptimizationService.createEngine();

// Add a real (continuous) variable. Notice the lack of type specification.

// Set the coefficient of 'y' in the objective.
// The objective is now 5 * y
engine.setObjectiveCoefficient('y', 5);```

#### Parameter

NameJenisDeskripsi
`variableName``String`nama variabel yang koefisiennya ditetapkan
`coefficient``Number`koefisien variabel dalam fungsi tujuan

#### Return

`LinearOptimizationEngine` — mesin pengoptimalan linear

### `solve()`

Menyelesaikan program linear saat ini dengan batas waktu default 30 detik. Menampilkan solusi yang ditemukan.

```var engine = LinearOptimizationService.createEngine();

// ...

// Solve the linear program
var solution = engine.solve();
if (!solution.isValid()) {
throw 'No solution ' + solution.getStatus();
}
Logger.log('Value of x: ' + solution.getVariableValue('x'));```

#### Return

`LinearOptimizationSolution` — solusi pengoptimalan

### `solve(seconds)`

Memecahkan program linear saat ini. Menampilkan solusi yang ditemukan, dan jika solusi tersebut optimal.

```var engine = LinearOptimizationService.createEngine();

// ...

// Solve the linear program
var solution = engine.solve(300);
if (!solution.isValid()) {
throw 'No solution ' + solution.getStatus();
}
Logger.log('Value of x: ' + solution.getVariableValue('x'));```

#### Parameter

NameJenisDeskripsi
`seconds``Number`tenggat waktu untuk menyelesaikan soal, dalam detik; tenggat waktu maksimum adalah 300 detik

#### Return

`LinearOptimizationSolution` — solusi pengoptimalan

[{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"Informasi yang saya butuhkan tidak ada" },{ "type": "thumb-down", "id": "tooComplicatedTooManySteps", "label":"Terlalu rumit/langkahnya terlalu banyak" },{ "type": "thumb-down", "id": "outOfDate", "label":"Sudah usang" },{ "type": "thumb-down", "id": "translationIssue", "label":"Masalah terjemahan" },{ "type": "thumb-down", "id": "samplesCodeIssue", "label":"Masalah kode / contoh" },{ "type": "thumb-down", "id": "otherDown", "label":"Lainnya" }]
[{ "type": "thumb-up", "id": "easyToUnderstand", "label":"Mudah dipahami" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"Memecahkan masalah saya" },{ "type": "thumb-up", "id": "otherUp", "label":"Lainnya" }]