Optimization Service

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

  • Key classes for this service include LinearOptimizationConstraint, LinearOptimizationEngine, LinearOptimizationService, and LinearOptimizationSolution.

  • The LinearOptimizationEngine is used to build the linear program model by adding constraints and variables, and setting the optimization direction.

  • The LinearOptimizationSolution provides methods to retrieve the objective value, the status of the solution, and the values of the variables.

  • The Status property indicates the result of the solve operation, such as OPTIMAL, FEASIBLE, or INFEASIBLE.

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

Classes

LinearOptimizationConstraint

LinearOptimizationEngine

Methods

MethodReturn typeBrief description
addConstraint(lowerBound, upperBound)LinearOptimizationConstraintAdds a new linear constraint in the model.
addConstraints(lowerBounds, upperBounds, variableNames, coefficients)LinearOptimizationEngineAdds constraints in batch to 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.
addVariables(names, lowerBounds, upperBounds, types, objectiveCoefficients)LinearOptimizationEngineAdds variables in batch 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

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.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-11 UTC.