यह इंजन, लीनियर प्रोग्राम को मॉडल करने और हल करने के लिए इस्तेमाल किया जाता है. नीचे दिए गए उदाहरण में, यहां दिए गए रेखीय प्रोग्राम को हल किया गया है:
दो वैरिएबल, 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')}`); }
तरीके
ज़्यादा जानकारी वाला दस्तावेज़
add Constraint(lowerBound, upperBound)
मॉडल में एक नई लीनियर कंस्ट्रेंट जोड़ता है. शर्त की ऊपरी और निचली सीमा, तय करने के समय तय की जाती है. वैरिएबल के लिए गुणांक, Linear
को कॉल करके तय किए जाते हैं.
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);
पैरामीटर
नाम | टाइप | ब्यौरा |
---|---|---|
lower | Number | शर्त की निचली सीमा |
upper | Number | शर्त की ऊपरी सीमा |
वापसी का टिकट
Linear
— बनाई गई शर्त
add Constraints(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], ], );
पैरामीटर
नाम | टाइप | ब्यौरा |
---|---|---|
lower | Number[] | सीमाओं की निचली सीमाएं |
upper | Number[] | कंस्ट्रेंट की ऊपरी सीमाएं |
variable | String[][] | उन वैरिएबल के नाम जिनके लिए गुणांक सेट किए जा रहे हैं |
coefficients | Number[][] | कॉफ़िशिएंट सेट किए जा रहे हैं |
वापसी का टिकट
Linear
— लीनियर ऑप्टिमाइज़ेशन इंजन
add Variable(name, lowerBound, upperBound)
मॉडल में एक नया लगातार वैरिएबल जोड़ता है. वैरिएबल का रेफ़रंस उसके नाम से दिया जाता है. टाइप को Variable
पर सेट किया गया है.
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);
पैरामीटर
नाम | टाइप | ब्यौरा |
---|---|---|
name | String | वैरिएबल का यूनीक नाम |
lower | Number | वैरिएबल की निचली सीमा |
upper | Number | वैरिएबल की ऊपरी सीमा |
वापसी का टिकट
Linear
— लीनियर ऑप्टिमाइज़ेशन इंजन
add Variable(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, );
पैरामीटर
नाम | टाइप | ब्यौरा |
---|---|---|
name | String | वैरिएबल का यूनीक नाम |
lower | Number | वैरिएबल की निचली सीमा |
upper | Number | वैरिएबल की ऊपरी सीमा |
type | Variable | वैरिएबल का टाइप, इनमें से कोई एक हो सकता है Variable |
वापसी का टिकट
Linear
— लीनियर ऑप्टिमाइज़ेशन इंजन
add Variable(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.
पैरामीटर
नाम | टाइप | ब्यौरा |
---|---|---|
name | String | वैरिएबल का यूनीक नाम |
lower | Number | वैरिएबल की निचली सीमा |
upper | Number | वैरिएबल की ऊपरी सीमा |
type | Variable | वैरिएबल का टाइप, इनमें से कोई एक हो सकता है Variable |
objective | Number | वैरिएबल का ऑब्जेक्टिव गुणांक |
वापसी का टिकट
Linear
— लीनियर ऑप्टिमाइज़ेशन इंजन
add Variables(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, ], );
पैरामीटर
नाम | टाइप | ब्यौरा |
---|---|---|
names | String[] | वैरिएबल के यूनीक नाम |
lower | Number[] | वैरिएबल की निचली सीमाएं |
upper | Number[] | वेरिएबल की ऊपरी सीमाएं |
types | Variable | वैरिएबल के टाइप, इनमें से कोई एक हो सकते हैं Variable |
objective | Number[] | वैरिएबल के ऑब्जेक्टिव गुणांक |
वापसी का टिकट
Linear
— लीनियर ऑप्टिमाइज़ेशन इंजन
set Maximization()
रैखिक ऑब्जेक्टिव फ़ंक्शन को बढ़ाने के लिए, ऑप्टिमाइज़ेशन डायरेक्शन सेट करता है.
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();
वापसी का टिकट
Linear
— लीनियर ऑप्टिमाइज़ेशन इंजन
set Minimization()
रैखिक ऑब्जेक्टिव फ़ंक्शन को कम करने के लिए, ऑप्टिमाइज़ेशन डायरेक्शन सेट करता है.
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();
वापसी का टिकट
Linear
— लीनियर ऑप्टिमाइज़ेशन इंजन
set Objective Coefficient(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);
पैरामीटर
नाम | टाइप | ब्यौरा |
---|---|---|
variable | String | उस वैरिएबल का नाम जिसके लिए गुणांक सेट किया जा रहा है |
coefficient | Number | मकसद के फ़ंक्शन में वैरिएबल का गुणांक |
वापसी का टिकट
Linear
— लीनियर ऑप्टिमाइज़ेशन इंजन
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')}`);
वापसी का टिकट
Linear
— ऑप्टिमाइज़ेशन का समाधान
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')}`);
पैरामीटर
नाम | टाइप | ब्यौरा |
---|---|---|
seconds | Number | समस्या को हल करने की समयसीमा, सेकंड में; ज़्यादा से ज़्यादा समयसीमा 300 सेकंड है |
वापसी का टिकट
Linear
— ऑप्टिमाइज़ेशन का समाधान