عنصر يخزِّن قيدًا خطيًا على شكل lower
حيث يكون lower
وupper
ثابتَين، و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);
الطُرق
الطريقة | نوع القيمة التي يتم عرضها | وصف قصير |
---|---|---|
set | Linear | تُستخدَم لضبط معامل متغيّر في القيود. |
مستندات تفصيلية
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);
المعلمات
الاسم | النوع | الوصف |
---|---|---|
variable | String | اسم المتغيّر الذي يتمّ ضبط المُعامل له |
coefficient | Number | المُعامل الذي يتم ضبطه |
الإرجاع
Linear
- قيد التحسين الخطي هذا