Class 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 — ऑप्टिमाइज़ेशन का समाधान