Optimization Service

Optimization

The linear optimization service, used to model and solve linear and mixed-integer linear programs.

Classes

NameBrief description
LinearOptimizationConstraintObject storing a linear constraint of the form lowerBound ≤ Sum(a(i) x(i)) ≤ upperBound where lowerBound and upperBound are constants, a(i) are constant coefficients and x(i) are variables (unknowns).
LinearOptimizationEngineThe engine used to model and solve a linear program.
LinearOptimizationServiceThe linear optimization service, used to model and solve linear and mixed-integer linear programs.
LinearOptimizationSolutionThe solution of a linear program.
StatusStatus of the solution.
VariableTypeType of variables created by the engine.

LinearOptimizationConstraint

Methods

MethodReturn typeBrief description
setCoefficient(variableName, coefficient)LinearOptimizationConstraintSets the coefficient of a variable in the constraint.

LinearOptimizationEngine

Methods

MethodReturn typeBrief description
addConstraint(lowerBound, upperBound)LinearOptimizationConstraintAdds a new linear constraint in the model.
addVariable(name, lowerBound, upperBound)LinearOptimizationEngineAdds a new continuous variable to the model.
addVariable(name, lowerBound, upperBound, type)LinearOptimizationEngineAdds a new variable to the model.
addVariable(name, lowerBound, upperBound, type, objectiveCoefficient)LinearOptimizationEngineAdds a new variable to the model.
setMaximization()LinearOptimizationEngineSets the optimization direction to maximizing the linear objective function.
setMinimization()LinearOptimizationEngineSets the optimization direction to minimizing the linear objective function.
setObjectiveCoefficient(variableName, coefficient)LinearOptimizationEngineSets the coefficient of a variable in the linear objective function.
solve()LinearOptimizationSolutionSolves the current linear program with the default deadline of 30 seconds.
solve(seconds)LinearOptimizationSolutionSolves the current linear program.

LinearOptimizationService

Properties

PropertyTypeDescription
StatusStatusStatus of the solver.
VariableTypeVariableTypeType of variables created by the solver.

Methods

MethodReturn typeBrief description
createEngine()LinearOptimizationEngineCreates an engine to to solve linear programs (potentially mixed-integer programs).

LinearOptimizationSolution

Methods

MethodReturn typeBrief description
getObjectiveValue()NumberGets the value of the objective function in the current solution.
getStatus()StatusGets the status of the solution.
getVariableValue(variableName)NumberGets the value of a variable in the solution created by the last call to LinearOptimizationEngine.solve().
isValid()BooleanDetermines whether the solution is either feasible or optimal.

Status

Properties

PropertyTypeDescription
OPTIMALEnumStatus when an optimal solution has been found.
FEASIBLEEnumStatus when a feasible (not necessarily optimal) solution has been found.
INFEASIBLEEnumStatus when the current model is unfeasible (has no solution).
UNBOUNDEDEnumStatus when the current model is unbound.
ABNORMALEnumStatus when it failed to find a solution for unexpected reasons.
MODEL_INVALIDEnumStatus when the model is invalid.
NOT_SOLVEDEnumStatus when LinearOptimizationEngine.solve() has not been called yet.

VariableType

Properties

PropertyTypeDescription
INTEGEREnumType of variable that can only take integer values.
CONTINUOUSEnumType of variable that can take any real value.

发送以下问题的反馈:

此网页
Apps Script
Apps Script