Class LinearOptimizationEngine

LinearOptimizationEngine

लीनियर प्रोग्राम को मॉडल बनाने और हल करने के लिए इस्तेमाल किया जाने वाला इंजन. नीचे दिए गए उदाहरण में, इस लीनियर प्रोग्राम को हल किया गया है:

दो वैरिएबल, x और y:
0 ≤ x ≤ 10
0 ≤ y ≤ 5

पाबंदियां:
0 ≤ 2 * x + 5 * y ≤ 10
0 ≤ 10 * x + 3 * y ≤ 20

लक्ष्य:
x + y को ज़्यादा से ज़्यादा करना

const engine = LinearOptimizationService.createEngine();

// Add variables, constraints and define the objective with addVariable(),
// addConstraint(), etc Add two variables, 0 <= x <= 10 and 0 <= y <= 5
engine.addVariable('x', 0, 10);
engine.addVariable('y', 0, 5);

// Create the constraint: 0 <= 2 * x + 5 * y <= 10
let constraint = engine.addConstraint(0, 10);
constraint.setCoefficient('x', 2);
constraint.setCoefficient('y', 5);

// Create the constraint: 0 <= 10 * x + 3 * y <= 20
constraint = engine.addConstraint(0, 20);
constraint.setCoefficient('x', 10);
constraint.setCoefficient('y', 3);

// Set the objective to be x + y
engine.setObjectiveCoefficient('x', 1);
engine.setObjectiveCoefficient('y', 1);

// Engine should maximize the objective
engine.setMaximization();

// Solve the linear program
const solution = engine.solve();
if (!solution.isValid()) {
  Logger.log(`No solution ${solution.getStatus()}`);
} else {
  Logger.log(`Value of x: ${solution.getVariableValue('x')}`);
  Logger.log(`Value of y: ${solution.getVariableValue('y')}`);
}

तरीके

तरीकारिटर्न टाइपसंक्षिप्त विवरण
addConstraint(lowerBound, upperBound)LinearOptimizationConstraintमॉडल में नई लीनियर कंस्ट्रेंट जोड़ता है.
addConstraints(lowerBounds, upperBounds, variableNames, coefficients)LinearOptimizationEngineमॉडल में बैच के हिसाब से शर्तें जोड़ता है.
addVariable(name, lowerBound, upperBound)LinearOptimizationEngineमॉडल में एक नया कंटीन्यूअस वैरिएबल जोड़ता है.
addVariable(name, lowerBound, upperBound, type)LinearOptimizationEngineमॉडल में एक नया वैरिएबल जोड़ता है.
addVariable(name, lowerBound, upperBound, type, objectiveCoefficient)LinearOptimizationEngineमॉडल में एक नया वैरिएबल जोड़ता है.
addVariables(names, lowerBounds, upperBounds, types, objectiveCoefficients)LinearOptimizationEngineइस तरीके का इस्तेमाल करके, मॉडल में एक साथ कई वैरिएबल जोड़े जा सकते हैं.
setMaximization()LinearOptimizationEngineइस विकल्प का इस्तेमाल, लीनियर ऑब्जेक्टिव फ़ंक्शन को ज़्यादा से ज़्यादा करने के लिए ऑप्टिमाइज़ेशन की दिशा सेट करने के लिए किया जाता है.
setMinimization()LinearOptimizationEngineइस विकल्प का इस्तेमाल, लीनियर ऑब्जेक्टिव फ़ंक्शन को कम करने के लिए ऑप्टिमाइज़ेशन की दिशा सेट करने के लिए किया जाता है.
setObjectiveCoefficient(variableName, coefficient)LinearOptimizationEngineयह फ़ंक्शन, लीनियर ऑब्जेक्टिव फ़ंक्शन में किसी वैरिएबल के कोएफ़िशिएंट को सेट करता है.
solve()LinearOptimizationSolutionयह फ़ंक्शन, मौजूदा लीनियर प्रोग्राम को 30 सेकंड की डिफ़ॉल्ट समयसीमा में हल करता है.
solve(seconds)LinearOptimizationSolutionइससे मौजूदा लीनियर प्रोग्राम हल किया जाता है.

ज़्यादा जानकारी वाला दस्तावेज़

addConstraint(lowerBound, upperBound)

मॉडल में नई लीनियर कंस्ट्रेंट जोड़ता है. कॉन्स्ट्रेंट की ऊपरी और निचली सीमा, कॉन्स्ट्रेंट बनाते समय तय की जाती है. वैरिएबल के लिए कोएफ़िशिएंट, LinearOptimizationConstraint.setCoefficient(variableName, coefficient) को कॉल करके तय किए जाते हैं.

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

पैरामीटर

नामटाइपब्यौरा
lowerBoundNumberबाधा की निचली सीमा
upperBoundNumberशर्त की ऊपरी सीमा

वापसी का टिकट

LinearOptimizationConstraint — यह पाबंदी बनाई गई


addConstraints(lowerBounds, upperBounds, variableNames, coefficients)

मॉडल में बैच के हिसाब से शर्तें जोड़ता है.

const engine = LinearOptimizationService.createEngine();

// Add a boolean variable 'x' (integer >= 0 and <= 1) and a real (continuous >=
// 0 and <= 100) variable 'y'.
engine.addVariables(
    ['x', 'y'],
    [0, 0],
    [1, 100],
    [
      LinearOptimizationService.VariableType.INTEGER,
      LinearOptimizationService.VariableType.CONTINUOUS,
    ],
);

// Adds two constraints:
//   0 <= x + y <= 3
//   1 <= 10 * x - y <= 5
engine.addConstraints(
    [0.0, 1.0],
    [3.0, 5.0],
    [
      ['x', 'y'],
      ['x', 'y'],
    ],
    [
      [1, 1],
      [10, -1],
    ],
);

पैरामीटर

नामटाइपब्यौरा
lowerBoundsNumber[]पाबंदियों की निचली सीमाएं
upperBoundsNumber[]सीमाओं की ऊपरी सीमाएं
variableNamesString[][]उन वैरिएबल के नाम जिनके लिए कोएफ़िशिएंट सेट किए जा रहे हैं
coefficientsNumber[][]गुणांक सेट किए जा रहे हैं

वापसी का टिकट

LinearOptimizationEngine — लीनियर ऑप्टिमाइज़ेशन इंजन


addVariable(name, lowerBound, upperBound)

मॉडल में एक नया कंटीन्यूअस वैरिएबल जोड़ता है. वैरिएबल को उसके नाम से रेफ़र किया जाता है. टाइप को VariableType.CONTINUOUS पर सेट किया गया है.

const engine = LinearOptimizationService.createEngine();
const constraint = engine.addConstraint(0, 10);

// Add a boolean variable (integer >= 0 and <= 1)
engine.addVariable('x', 0, 1, LinearOptimizationService.VariableType.INTEGER);

// Add a real (continuous) variable. Notice the lack of type specification.
engine.addVariable('y', 0, 100);

पैरामीटर

नामटाइपब्यौरा
nameStringवैरिएबल का यूनीक नाम
lowerBoundNumberवैरिएबल की निचली सीमा
upperBoundNumberवैरिएबल की ऊपरी सीमा

वापसी का टिकट

LinearOptimizationEngine — लीनियर ऑप्टिमाइज़ेशन इंजन


addVariable(name, lowerBound, upperBound, type)

मॉडल में एक नया वैरिएबल जोड़ता है. वैरिएबल को उसके नाम से रेफ़र किया जाता है.

const engine = LinearOptimizationService.createEngine();
const constraint = engine.addConstraint(0, 10);

// Add a boolean variable (integer >= 0 and <= 1)
engine.addVariable('x', 0, 1, LinearOptimizationService.VariableType.INTEGER);

// Add a real (continuous) variable
engine.addVariable(
    'y',
    0,
    100,
    LinearOptimizationService.VariableType.CONTINUOUS,
);

पैरामीटर

नामटाइपब्यौरा
nameStringवैरिएबल का यूनीक नाम
lowerBoundNumberवैरिएबल की निचली सीमा
upperBoundNumberवैरिएबल की ऊपरी सीमा
typeVariableTypeवैरिएबल का टाइप, VariableType में से कोई एक हो सकता है

वापसी का टिकट

LinearOptimizationEngine — लीनियर ऑप्टिमाइज़ेशन इंजन


addVariable(name, lowerBound, upperBound, type, objectiveCoefficient)

मॉडल में एक नया वैरिएबल जोड़ता है. वैरिएबल को उसके नाम से रेफ़र किया जाता है.

const engine = LinearOptimizationService.createEngine();
const constraint = engine.addConstraint(0, 10);

// Add a boolean variable (integer >= 0 and <= 1)
engine.addVariable(
    'x',
    0,
    1,
    LinearOptimizationService.VariableType.INTEGER,
    2,
);
// The objective is now 2 * x.

// Add a real (continuous) variable
engine.addVariable(
    'y',
    0,
    100,
    LinearOptimizationService.VariableType.CONTINUOUS,
    -5,
);
// The objective is now 2 * x - 5 * y.

पैरामीटर

नामटाइपब्यौरा
nameStringवैरिएबल का यूनीक नाम
lowerBoundNumberवैरिएबल की निचली सीमा
upperBoundNumberवैरिएबल की ऊपरी सीमा
typeVariableTypeवैरिएबल का टाइप, VariableType में से कोई एक हो सकता है
objectiveCoefficientNumberवैरिएबल का ऑब्जेक्टिव कोएफ़िशिएंट

वापसी का टिकट

LinearOptimizationEngine — लीनियर ऑप्टिमाइज़ेशन इंजन


addVariables(names, lowerBounds, upperBounds, types, objectiveCoefficients)

इस तरीके का इस्तेमाल करके, मॉडल में एक साथ कई वैरिएबल जोड़े जा सकते हैं. वैरिएबल को उनके नाम से रेफ़र किया जाता है.

const engine = LinearOptimizationService.createEngine();

// Add a boolean variable 'x' (integer >= 0 and <= 1) and a real (continuous >=0
// and <= 100) variable 'y'.
engine.addVariables(
    ['x', 'y'],
    [0, 0],
    [1, 100],
    [
      LinearOptimizationService.VariableType.INTEGER,
      LinearOptimizationService.VariableType.CONTINUOUS,
    ],
);

पैरामीटर

नामटाइपब्यौरा
namesString[]वैरिएबल के यूनीक नाम
lowerBoundsNumber[]वैरिएबल की निचली सीमाएं
upperBoundsNumber[]वेरिएबल की ऊपरी सीमाएं
typesVariableType[]वैरिएबल के टाइप, इनमें से कोई एक हो सकता है VariableType
objectiveCoefficientsNumber[]वैरिएबल के ऑब्जेक्टिव कोएफ़िशिएंट

वापसी का टिकट

LinearOptimizationEngine — लीनियर ऑप्टिमाइज़ेशन इंजन


setMaximization()

इस विकल्प का इस्तेमाल, लीनियर ऑब्जेक्टिव फ़ंक्शन को ज़्यादा से ज़्यादा करने के लिए ऑप्टिमाइज़ेशन की दिशा सेट करने के लिए किया जाता है.

const engine = LinearOptimizationService.createEngine();

// Add a real (continuous) variable. Notice the lack of type specification.
engine.addVariable('y', 0, 100);

// Set the coefficient of 'y' in the objective.
// The objective is now 5 * y
engine.setObjectiveCoefficient('y', 5);

// We want to maximize.
engine.setMaximization();

वापसी का टिकट

LinearOptimizationEngine — लीनियर ऑप्टिमाइज़ेशन इंजन


setMinimization()

इस विकल्प का इस्तेमाल, लीनियर ऑब्जेक्टिव फ़ंक्शन को कम करने के लिए ऑप्टिमाइज़ेशन की दिशा सेट करने के लिए किया जाता है.

const engine = LinearOptimizationService.createEngine();

// Add a real (continuous) variable. Notice the lack of type specification.
engine.addVariable('y', 0, 100);

// Set the coefficient of 'y' in the objective.
// The objective is now 5 * y
engine.setObjectiveCoefficient('y', 5);

// We want to minimize
engine.setMinimization();

वापसी का टिकट

LinearOptimizationEngine — लीनियर ऑप्टिमाइज़ेशन इंजन


setObjectiveCoefficient(variableName, coefficient)

यह फ़ंक्शन, लीनियर ऑब्जेक्टिव फ़ंक्शन में किसी वैरिएबल के कोएफ़िशिएंट को सेट करता है.

const engine = LinearOptimizationService.createEngine();

// Add a real (continuous) variable. Notice the lack of type specification.
engine.addVariable('y', 0, 100);

// Set the coefficient of 'y' in the objective.
// The objective is now 5 * y
engine.setObjectiveCoefficient('y', 5);

पैरामीटर

नामटाइपब्यौरा
variableNameStringउस वैरिएबल का नाम जिसके लिए कोएफ़िशिएंट सेट किया जा रहा है
coefficientNumberऑब्जेक्टिव फ़ंक्शन में वैरिएबल का कोएफ़िशिएंट

वापसी का टिकट

LinearOptimizationEngine — लीनियर ऑप्टिमाइज़ेशन इंजन


solve()

यह फ़ंक्शन, मौजूदा लीनियर प्रोग्राम को 30 सेकंड की डिफ़ॉल्ट समयसीमा में हल करता है. यह कुकी, खोजे गए समाधान को दिखाती है.

const engine = LinearOptimizationService.createEngine();

// Add variables, constraints and define the objective with addVariable(),
// addConstraint(), etc
engine.addVariable('x', 0, 10);

// ...

// Solve the linear program
const solution = engine.solve();
if (!solution.isValid()) {
  throw `No solution ${solution.getStatus()}`;
}
Logger.log(`Value of x: ${solution.getVariableValue('x')}`);

वापसी का टिकट

LinearOptimizationSolution — ऑप्टिमाइज़ेशन का समाधान


solve(seconds)

इससे मौजूदा लीनियर प्रोग्राम हल किया जाता है. इससे मिला समाधान और यह सबसे सही समाधान है या नहीं, इसकी जानकारी मिलती है.

const engine = LinearOptimizationService.createEngine();

// Add variables, constraints and define the objective with addVariable(),
// addConstraint(), etc
engine.addVariable('x', 0, 10);

// ...

// Solve the linear program
const solution = engine.solve(300);
if (!solution.isValid()) {
  throw `No solution ${solution.getStatus()}`;
}
Logger.log(`Value of x: ${solution.getVariableValue('x')}`);

पैरामीटर

नामटाइपब्यौरा
secondsNumberसमस्या को हल करने की समयसीमा, सेकंड में; ज़्यादा से ज़्यादा समयसीमा 300 सेकंड है

वापसी का टिकट

LinearOptimizationSolution — ऑप्टिमाइज़ेशन का समाधान