Class LinearOptimizationConstraint

LinearOptimizationConstraint

ออบเจ็กต์ที่จัดเก็บข้อจำกัดเชิงเส้นในรูปแบบ lowerBound ≤ Sum(a(i) x(i)) ≤ upperBound โดยที่ lowerBound และ upperBound เป็นค่าคงที่ a(i) เป็นค่าคงที่ สัมประสิทธิ์ และ x(i) เป็นตัวแปร (ค่าที่ไม่รู้จัก)

ตัวอย่างด้านล่างสร้างตัวแปร x ที่มีค่าระหว่าง 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 — ข้อจํากัดการเพิ่มประสิทธิภาพเชิงเส้นนี้