ইঞ্জিনটি একটি লিনিয়ার প্রোগ্রাম মডেল করতে এবং সমাধান করতে ব্যবহৃত হয়। নিচের উদাহরণটি নিম্নলিখিত লিনিয়ার প্রোগ্রামটি সমাধান করে:
দুটি চলক, 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.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);
প্যারামিটার
| নাম | প্রকার | বর্ণনা |
|---|---|---|
lower Bound | Number | সীমাবদ্ধতার নিম্ন সীমা |
upper Bound | Number | সীমাবদ্ধতার ঊর্ধ্বসীমা |
ফেরত
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], ], );
প্যারামিটার
| নাম | প্রকার | বর্ণনা |
|---|---|---|
lower Bounds | Number[] | সীমাবদ্ধতার নিম্ন সীমা |
upper Bounds | Number[] | সীমাবদ্ধতার ঊর্ধ্বসীমা |
variable Names | String[][] | যে ভেরিয়েবলগুলোর জন্য সহগ নির্ধারণ করা হচ্ছে তাদের নাম |
coefficients | Number[][] | সহগ নির্ধারণ করা হচ্ছে |
ফেরত
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);
প্যারামিটার
| নাম | প্রকার | বর্ণনা |
|---|---|---|
name | String | ভেরিয়েবলের অনন্য নাম |
lower Bound | Number | চলকের নিম্ন সীমা |
upper Bound | Number | চলকের ঊর্ধ্বসীমা |
ফেরত
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, );
প্যারামিটার
| নাম | প্রকার | বর্ণনা |
|---|---|---|
name | String | ভেরিয়েবলের অনন্য নাম |
lower Bound | Number | চলকের নিম্ন সীমা |
upper Bound | Number | চলকের ঊর্ধ্বসীমা |
type | Variable Type | ভেরিয়েবলের ধরণ, Variable Type মধ্যে একটি হতে পারে। |
ফেরত
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.
প্যারামিটার
| নাম | প্রকার | বর্ণনা |
|---|---|---|
name | String | ভেরিয়েবলের অনন্য নাম |
lower Bound | Number | চলকের নিম্ন সীমা |
upper Bound | Number | চলকের ঊর্ধ্বসীমা |
type | Variable Type | ভেরিয়েবলের ধরণ, Variable Type মধ্যে একটি হতে পারে। |
objective Coefficient | Number | চলকের উদ্দেশ্যমূলক সহগ |
ফেরত
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, ], );
প্যারামিটার
| নাম | প্রকার | বর্ণনা |
|---|---|---|
names | String[] | ভেরিয়েবলগুলির অনন্য নাম |
lower Bounds | Number[] | চলকগুলির নিম্ন সীমা |
upper Bounds | Number[] | চলকগুলির ঊর্ধ্বসীমা |
types | Variable Type[] | ভেরিয়েবলের প্রকারভেদ, Variable Type মধ্যে একটি হতে পারে। |
objective Coefficients | Number[] | চলকগুলির উদ্দেশ্যমূলক সহগ |
ফেরত
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);
প্যারামিটার
| নাম | প্রকার | বর্ণনা |
|---|---|---|
variable Name | String | যে চলকের জন্য সহগ নির্ধারণ করা হচ্ছে তার নাম |
coefficient | Number | উদ্দেশ্যমূলক ফাংশনে চলকের সহগ |
ফেরত
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(); 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')}`);
প্যারামিটার
| নাম | প্রকার | বর্ণনা |
|---|---|---|
seconds | Number | সমস্যাটি সমাধানের জন্য সময়সীমা, সেকেন্ডে; সর্বোচ্চ সময়সীমা হলো ৩০০ সেকেন্ড। |
ফেরত
LinearOptimizationSolution — অপ্টিমাইজেশনের সমাধান