Optimization Service
最佳化
線性最佳化服務,用於模擬及解決線性和混合型整數線性程式。
類別
方法
方法 | 傳回類型 | 簡短說明 |
addConstraint(lowerBound, upperBound) | LinearOptimizationConstraint | 在模型中新增線性限制。 |
addConstraints(lowerBounds, upperBounds, variableNames, coefficients) | LinearOptimizationEngine | 將限制條件批次新增至模型。 |
addVariable(name, lowerBound, upperBound) | LinearOptimizationEngine | 在模型中新增連續變數。 |
addVariable(name, lowerBound, upperBound, type) | LinearOptimizationEngine | 在模型中新增變數。 |
addVariable(name, lowerBound, upperBound, type, objectiveCoefficient) | LinearOptimizationEngine | 在模型中新增變數。 |
addVariables(names, lowerBounds, upperBounds, types, objectiveCoefficients) | LinearOptimizationEngine | 將變數批次新增至模型。 |
setMaximization() | LinearOptimizationEngine | 將最佳化方向設為最大化線性目標函式。 |
setMinimization() | LinearOptimizationEngine | 將最佳化方向設為盡量減少線性目標函式。 |
setObjectiveCoefficient(variableName, coefficient) | LinearOptimizationEngine | 設定線性目標函式中變數的係數。 |
solve() | LinearOptimizationSolution | 以預設的 30 秒期限,解決目前的線性程式。 |
solve(seconds) | LinearOptimizationSolution | 解開目前的線性程式。 |
屬性
屬性 | 類型 | 說明 |
OPTIMAL | Enum | 找到最佳解決方案時的狀態。 |
FEASIBLE | Enum | 找到可行 (但不一定是最佳) 解決方案時的狀態。 |
INFEASIBLE | Enum | 當前模型無法實現 (沒有解決方案) 時的狀態。 |
UNBOUNDED | Enum | 當前模型未綁定時的狀態。 |
ABNORMAL | Enum | 因非預期原因無法找到解決方案時的狀態。 |
MODEL_INVALID | Enum | 模型無效時的狀態。 |
NOT_SOLVED | Enum | LinearOptimizationEngine.solve() 尚未呼叫時的狀態。 |
屬性
屬性 | 類型 | 說明 |
INTEGER | Enum | 只能接受整數值的變數類型。 |
CONTINUOUS | Enum | 可接受任何實際值的變數類型。 |
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-12-03 (世界標準時間)。
[null,null,["上次更新時間:2024-12-03 (世界標準時間)。"],[[["The Linear Optimization Service enables the modeling and resolution of linear and mixed-integer linear programs within Apps Script."],["It provides classes like `LinearOptimizationConstraint`, `LinearOptimizationEngine`, and `LinearOptimizationSolution` to define, solve, and retrieve optimization results."],["`LinearOptimizationEngine` allows adding variables, constraints, setting objective functions (maximization or minimization), and solving the linear program."],["Solutions can be evaluated using methods like `getObjectiveValue`, `getStatus`, and `getVariableValue` to understand the optimization outcome."],["The service utilizes various statuses (e.g., `OPTIMAL`, `FEASIBLE`, `INFEASIBLE`) and variable types (`INTEGER`, `CONTINUOUS`) to represent the solution state and variable characteristics."]]],["The linear optimization service models and solves linear and mixed-integer linear programs. Key actions include: creating an engine (`LinearOptimizationEngine`), adding variables with bounds and types, adding constraints to the model, setting the objective function's direction (maximize or minimize), and setting coefficients for variables in the objective function and constraints. The `solve()` method then computes the solution. The `LinearOptimizationSolution` object contains methods to determine solution status, objective value, and variable values.\n"]]