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