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 — this linear optimization constraint