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

Adds a rule the solution must satisfy.

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.

Better Sheets tutorials

No tagged tutorials yet. Fetch Apps Script from the harvest table and this page fills automatically.

Big Year 2027 calendar: the whole year on one Google Sheet

Free 2027 calendar.Plan all of 2027 on one Google Sheet, free.

Copy it to your Google Drive.

Free. No password, no card. The sheet link shows up right here.