Class LinearOptimizationConstraint
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Giới hạnTối ưu hoá tuyến tính
Đối tượng lưu trữ một quy tắc ràng buộc tuyến tính ở dạng lowerBound ≤ Sum(a(i) x(i)) ≤ upperBound
, trong đó lowerBound
và upperBound
là hằng số, a(i)
là hệ số hằng số và x(i)
là biến (biến chưa xác định).
Ví dụ bên dưới tạo một biến x
có giá trị từ 0
đến 5
và tạo quy tắc ràng buộc 0 ≤ 2 * x ≤ 5
. Việc này được thực hiện bằng cách tạo một điều kiện ràng buộc với giới hạn dưới 5
và giới hạn trên 5
. Sau đó, hệ số cho biến x
trong quy tắc ràng buộc này được đặt thành 2
.
const engine = LinearOptimizationService.createEngine();
// Create a variable so we can add it to the constraint
engine.addVariable('x', 0, 5);
// Create a linear constraint with the bounds 0 and 10
const constraint = engine.addConstraint(0, 10);
// Set the coefficient of the variable in the constraint. The constraint is now:
// 0 <= 2 * x <= 5
constraint.setCoefficient('x', 2);
Tài liệu chi tiết
setCoefficient(variableName, coefficient)
Đặt hệ số của một biến trong quy tắc ràng buộc. Theo mặc định, các biến có hệ số là 0.
const engine = LinearOptimizationService.createEngine();
// Create a linear constraint with the bounds 0 and 10
const constraint = engine.addConstraint(0, 10);
// Create a variable so we can add it to the constraint
engine.addVariable('x', 0, 5);
// Set the coefficient of the variable in the constraint. The constraint is now:
// 0 <= 2 * x <= 5
constraint.setCoefficient('x', 2);
Tham số
Tên | Loại | Mô tả |
variableName | String | tên của biến mà hệ số đang được đặt |
coefficient | Number | hệ số đang được đặt |
Cầu thủ trả bóng
LinearOptimizationConstraint
– quy tắc ràng buộc tối ưu hoá tuyến tính này
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-26 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[[["\u003cp\u003e\u003ccode\u003eLinearOptimizationConstraint\u003c/code\u003e objects define constraints in the form of \u003ccode\u003elowerBound ≤ Sum(a(i) x(i)) ≤ upperBound\u003c/code\u003e, where \u003ccode\u003ea(i)\u003c/code\u003e are coefficients and \u003ccode\u003ex(i)\u003c/code\u003e are variables.\u003c/p\u003e\n"],["\u003cp\u003eYou can set the coefficient of a variable within a constraint using the \u003ccode\u003esetCoefficient(variableName, coefficient)\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eConstraints are created with lower and upper bounds, and variables are added with their own bounds before being incorporated into the constraint.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code example demonstrates creating a variable, adding a constraint, and setting the coefficient for the variable within that constraint.\u003c/p\u003e\n"]]],[],null,["# Class LinearOptimizationConstraint\n\nLinearOptimizationConstraint\n\nObject storing a linear constraint of the form `lower``Bound ≤ Sum(a(i) x(i)) ≤ upperBound`\nwhere `lower``Bound` and `upper``Bound` are constants, `a(i)` are constant\ncoefficients and `x(i)` are variables (unknowns).\n\nThe example below creates one variable `x` with values between `0` and `5`\nand creates the constraint `0 ≤ 2 * x ≤ 5`. This is done by first creating a constraint\nwith the lower bound `5` and upper bound `5`. Then the coefficient for variable\n`x` in this constraint is set to `2`.\n\n```javascript\nconst engine = LinearOptimizationService.createEngine();\n// Create a variable so we can add it to the constraint\nengine.addVariable('x', 0, 5);\n// Create a linear constraint with the bounds 0 and 10\nconst constraint = engine.addConstraint(0, 10);\n// Set the coefficient of the variable in the constraint. The constraint is now:\n// 0 \u003c= 2 * x \u003c= 5\nconstraint.setCoefficient('x', 2);\n``` \n\n### Methods\n\n| Method | Return type | Brief description |\n|-----------------------------------------------------------------------------|-----------------------------------|-------------------------------------------------------|\n| [setCoefficient(variableName, coefficient)](#setCoefficient(String,Number)) | [LinearOptimizationConstraint](#) | Sets the coefficient of a variable in the constraint. |\n\nDetailed documentation\n----------------------\n\n### `set``Coefficient(variableName, coefficient)`\n\nSets the coefficient of a variable in the constraint. By default, variables have a coefficient\nof 0.\n\n```javascript\nconst engine = LinearOptimizationService.createEngine();\n// Create a linear constraint with the bounds 0 and 10\nconst constraint = engine.addConstraint(0, 10);\n// Create a variable so we can add it to the constraint\nengine.addVariable('x', 0, 5);\n// Set the coefficient of the variable in the constraint. The constraint is now:\n// 0 \u003c= 2 * x \u003c= 5\nconstraint.setCoefficient('x', 2);\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|------------------|----------|-------------------------------------------------------------|\n| `variable``Name` | `String` | the name of variable for which the coefficient is being set |\n| `coefficient` | `Number` | coefficient being set |\n\n#### Return\n\n\n[LinearOptimizationConstraint](#) --- this linear optimization constraint"]]