ออบเจ็กต์ที่จัดเก็บข้อจำกัดเชิงเส้นในรูปแบบ lower
โดยที่ lower
และ upper
เป็นค่าคงที่ 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);
เมธอด
วิธีการ | ประเภทการแสดงผล | รายละเอียดแบบย่อ |
---|---|---|
set | Linear | ตั้งค่าสัมประสิทธิ์ของตัวแปรในข้อจำกัด |
เอกสารประกอบโดยละเอียด
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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
variable | String | ชื่อตัวแปรที่จะตั้งค่าสัมประสิทธิ์ |
coefficient | Number | ค่าสัมประสิทธิ์ที่ตั้งไว้ |
รีเทิร์น
Linear
— ข้อจำกัดการเพิ่มประสิทธิภาพเชิงเส้นนี้