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

Methods

שיטהסוג הערך המוחזרתיאור קצר
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 – האילוץ הזה של אופטימיזציה לינארית