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)LinearOptimizationConstraintตั้งค่าสัมประสิทธิ์ของตัวแปรในข้อจำกัด

เอกสารประกอบโดยละเอียด

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
variableNameStringชื่อตัวแปรที่จะตั้งค่าสัมประสิทธิ์
coefficientNumberค่าสัมประสิทธิ์ที่ตั้งไว้

รีเทิร์น

LinearOptimizationConstraint — ข้อจำกัดการเพิ่มประสิทธิภาพเชิงเส้นนี้