लीनियर प्रोग्राम का समाधान. नीचे दिए गए उदाहरण में, इस लीनियर प्रोग्राम को हल किया गया है:
दो वैरिएबल, 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(`Objective value: ${solution.getObjectiveValue()}`); Logger.log(`Value of x: ${solution.getVariableValue('x')}`); Logger.log(`Value of y: ${solution.getVariableValue('y')}`); }
तरीके
| तरीका | रिटर्न टाइप | संक्षिप्त विवरण |
|---|---|---|
get | Number | मौजूदा समाधान में ऑब्जेक्टिव फ़ंक्शन की वैल्यू मिलती है. |
get | Status | इससे समाधान की स्थिति मिलती है. |
get | Number | Linear को आखिरी बार कॉल करने पर बनाए गए समाधान में, किसी वैरिएबल की वैल्यू मिलती है. |
is | Boolean | यह कुकी तय करती है कि समाधान व्यावहारिक है या सबसे अच्छा है. |
ज़्यादा जानकारी वाला दस्तावेज़
getObjectiveValue()
मौजूदा समाधान में ऑब्जेक्टिव फ़ंक्शन की वैल्यू मिलती है.
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(); Logger.log(`ObjectiveValue: ${solution.getObjectiveValue()}`);
वापसी का टिकट
Number — ऑब्जेक्टिव फ़ंक्शन की वैल्यू
getStatus()
इससे समाधान की स्थिति मिलती है. समस्या हल करने से पहले, स्टेटस NOT_SOLVED होगा.
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(); const status = solution.getStatus(); if (status !== LinearOptimizationService.Status.FEASIBLE && status !== LinearOptimizationService.Status.OPTIMAL) { throw `No solution ${status}`; } Logger.log(`Status: ${status}`);
वापसी का टिकट
Status — समस्या हल करने वाले की स्थिति
getVariableValue(variableName)
LinearOptimizationEngine.solve() को आखिरी बार कॉल करने पर बनाए गए समाधान में, किसी वैरिएबल की वैल्यू मिलती है.
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(); Logger.log(`Value of x: ${solution.getVariableValue('x')}`);
पैरामीटर
| नाम | टाइप | ब्यौरा |
|---|---|---|
variable | String | वैरिएबल का नाम |
वापसी का टिकट
Number — समाधान में वैरिएबल की वैल्यू
isValid()
यह कुकी तय करती है कि समाधान व्यावहारिक है या सबसे अच्छा है.
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()}`; }
वापसी का टिकट
Boolean — true अगर समाधान मान्य है (Status.FEASIBLE या
Status.OPTIMAL); false अगर नहीं