Adds a decision variable to the optimization model.
class LinearOptimizationService method .addVariable()
LinearOptimizationService is the Apps Script service.
.addVariable() is the method name you will see after a dot in your code.
What it does
Why it's used
- Define what the solver can change, like units to ship.
- Each decision gets a variable in the model.
Common errors
- Forgetting parentheses on addVariable. Write LinearOptimizationService.addVariable(), not LinearOptimizationService.addVariable or addVariable by itself.
- Skipping dots between chained calls. Each step needs a dot, like LinearOptimizationService.addVariable().
- Adding spaces where they do not belong. Write LinearOptimizationService.addVariable(), not LinearOptimizationService .addVariable(), LinearOptimizationService.addVariable (), or LinearOptimizationService . addVariable().
- Wrong capitalization. Use LinearOptimizationService and addVariable, not linearoptimizationservice or addvariable.
Explore
Related methods
-
.createEngine()
Creates a solver for a linear optimization problem.
-
.addConstraint()
Adds a rule the solution must satisfy.
-
.solve()
Runs the solver and returns the best solution found.
More Apps Script
Better Sheets tutorials
No tagged tutorials yet. Fetch Apps Script from the harvest table and this page fills automatically.