Class LinearOptimizationConstraint
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ข้อจำกัดการเพิ่มประสิทธิภาพเชิงเส้น
ออบเจ็กต์ที่จัดเก็บข้อจำกัดเชิงเส้นในรูปแบบ lowerBound ≤ Sum(a(i) x(i)) ≤ upperBound
โดยที่ lowerBound
และ upperBound
เป็นค่าคงที่ a(i)
เป็นค่าสัมประสิทธิ์คงที่ และ x(i)
เป็นตัวแปร (ค่าที่ไม่รู้จัก)
ตัวอย่างด้านล่างสร้างตัวแปร x
1 ตัวซึ่งมีค่าระหว่าง 0
ถึง 5
และสร้างข้อจำกัด 0 ≤ 2 * x ≤ 5
ซึ่งทำได้โดยสร้างข้อจำกัดที่มีขอบเขตล่าง 5
และขอบเขตบน 5
ก่อน จากนั้นระบบจะตั้งค่าสัมประสิทธิ์ของตัวแปร x
ในข้อจำกัดนี้เป็น 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);
เอกสารประกอบโดยละเอียด
setCoefficient(variableName, coefficient)
ตั้งค่าสัมประสิทธิ์ของตัวแปรในข้อจำกัด โดยค่าเริ่มต้น ตัวแปรจะมีสัมประสิทธิ์เป็น 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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
variableName | String | ชื่อตัวแปรที่จะตั้งค่าสัมประสิทธิ์ |
coefficient | Number | ค่าสัมประสิทธิ์ที่ตั้งไว้ |
รีเทิร์น
LinearOptimizationConstraint
— ข้อจำกัดการเพิ่มประสิทธิภาพเชิงเส้นนี้
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 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"]]