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.

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

פרמטרים

שםתיאורהתיאור
variableNameStringשם המשתנה שעבורו נקבע המקדם
coefficientNumberמגדיר את המקדם

החזרות

LinearOptimizationConstraint – המגבלה הלינארית הזו על האופטימיזציה