Class LinearOptimizationSolution

LinearOptimizationSolution

लीनियर प्रोग्राम का समाधान. नीचे दिए गए उदाहरण में, इस लीनियर प्रोग्राम को हल किया गया है:

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

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

मकसद:
x + y बढ़ाएं

var 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
var constraint = engine.addConstraint(0, 10);
constraint.setCoefficient('x', 2);
constraint.setCoefficient('y', 5);

// Create the constraint: 0 <= 10 * x + 3 * y <= 20
var 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
var 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'));
}

तरीके

तरीकारिटर्न टाइपसंक्षिप्त विवरण
getObjectiveValue()Numberमौजूदा सलूशन में मकसद फ़ंक्शन की वैल्यू हासिल करता है.
getStatus()Statusसमाधान की स्थिति की जानकारी मिलती है.
getVariableValue(variableName)NumberLinearOptimizationEngine.solve() पर किए गए आखिरी कॉल से बनाए गए समाधान में, वैरिएबल की वैल्यू हासिल करता है.
isValid()Booleanयह तय करता है कि समाधान संभव है या बेहतर है.

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

getObjectiveValue()

मौजूदा सलूशन में मकसद फ़ंक्शन की वैल्यू हासिल करता है.

var engine = LinearOptimizationService.createEngine();

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

// ...

// Solve the linear program
var solution = engine.solve();
Logger.log('ObjectiveValue: ' + solution.getObjectiveValue());

रिटर्न

Number — मकसद फ़ंक्शन की वैल्यू


getStatus()

समाधान की स्थिति की जानकारी मिलती है. किसी सवाल को हल करने से पहले, स्टेटस NOT_SOLVED होगा.

var engine = LinearOptimizationService.createEngine();

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

// ...

// Solve the linear program
var solution = engine.solve();
if (solution.getStatus() != LinearOptimizationService.Status.FEASIBLE &&
    solution.getStatus() != LinearOptimizationService.Status.OPTIMAL) {
  throw 'No solution ' + status;
}
Logger.log('Status: ' + solution.getStatus());

रिटर्न

Status — सॉल्वर का स्टेटस


getVariableValue(variableName)

LinearOptimizationEngine.solve() पर किए गए आखिरी कॉल से बनाए गए समाधान में, वैरिएबल की वैल्यू हासिल करता है.

var engine = LinearOptimizationService.createEngine();

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

// ...

// Solve the linear program
var solution = engine.solve();
Logger.log('Value of x: ' + solution.getVariableValue('x'));

पैरामीटर

नामTypeब्यौरा
variableNameStringवैरिएबल का नाम

रिटर्न

Number — सलूशन में वैरिएबल की वैल्यू


isValid()

यह तय करता है कि समाधान संभव है या बेहतर है.

var engine = LinearOptimizationService.createEngine();

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

// ...

// Solve the linear program
var solution = engine.solve();
if (!solution.isValid()) {
  throw 'No solution ' + status;
}

रिटर्न

Booleantrue, अगर समाधान मान्य है (Status.FEASIBLE या Status.OPTIMAL); अगर नहीं है, तो false