लीनियर प्रोग्राम का समाधान. नीचे दिए गए उदाहरण में, इस लीनियर प्रोग्राम को हल किया गया है:
दो वैरिएबल, 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)
Linear
को आखिरी बार कॉल करके बनाए गए समाधान में, किसी वैरिएबल की वैल्यू पाता है.
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