Class LinearOptimizationConstraint

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

var 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
var 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

var engine = LinearOptimizationService.createEngine();
// Create a linear constraint with the bounds 0 and 10
var 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);

พารามิเตอร์

ชื่อTypeคำอธิบาย
variableNameStringชื่อของตัวแปรที่กำหนดสัมประสิทธิ์
coefficientNumberกำลังตั้งสัมประสิทธิ์

รีเทิร์น

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