এমআইপি সমাধান উদাহরণ
সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
নিম্নলিখিত উদাহরণটি দেখায় কিভাবে MathOpt ব্যবহার করে একটি গাণিতিক অপ্টিমাইজেশান সমস্যা তৈরি করা যায় এবং OR API ব্যবহার করে একটি দূরবর্তী সমাধান করা যায়। একটি API কী পেতে, প্রথমে সেটআপ গাইড অনুসরণ করুন। 9.9 প্রকাশের পর থেকে OR-Tools- এর অংশ হিসেবে MathOpt উপলব্ধ। আরো তথ্যের জন্য ইনস্টল গাইড দেখুন.
# solve_math_opt_model_via_http.py
"""Example of solving a MathOpt model through the OR API.
The model is built using the Python API, and the corresponding proto is
serialized to JSON to make the HTTP request.
"""
from collections.abc import Sequence
from absl import app
from absl import flags
from ortools.math_opt.python import mathopt
from ortools.math_opt.python.ipc import remote_http_solve
_API_KEY = flags.DEFINE_string("api_key", None, "API key for the OR API")
def request_example() -> None:
"""Run example using MathOpt `remote_http_solve` function."""
# Set up the API key.
api_key = _API_KEY.value
if not api_key:
print(
"API key is required. See"
" https://developers.google.com/optimization/service/setup for"
" instructions."
)
return
# Build a MathOpt model
model = mathopt.Model(name="my_model")
x = model.add_binary_variable(name="x")
y = model.add_variable(lb=0.0, ub=2.5, name="y")
model.add_linear_constraint(x + y <= 1.5, name="c")
model.maximize(2 * x + y)
try:
result, logs = remote_http_solve.remote_http_solve(
model,
mathopt.SolverType.GSCIP,
mathopt.SolveParameters(enable_output=True),
api_key=api_key,
)
print("Objective value: ", result.objective_value())
print("x: ", result.variable_values(x))
print("y: ", result.variable_values(y))
print("\n".join(logs))
except remote_http_solve.OptimizationServiceError as err:
print(err)
def main(argv: Sequence[str]) -> None:
del argv # Unused.
request_example()
if __name__ == "__main__":
app.run(main)
অন্য কিছু উল্লেখ না করা থাকলে, এই পৃষ্ঠার কন্টেন্ট Creative Commons Attribution 4.0 License-এর অধীনে এবং কোডের নমুনাগুলি Apache 2.0 License-এর অধীনে লাইসেন্স প্রাপ্ত। আরও জানতে, Google Developers সাইট নীতি দেখুন। Java হল Oracle এবং/অথবা তার অ্যাফিলিয়েট সংস্থার রেজিস্টার্ড ট্রেডমার্ক।
2024-10-30 UTC-তে শেষবার আপডেট করা হয়েছে।
[[["সহজে বোঝা যায়","easyToUnderstand","thumb-up"],["আমার সমস্যার সমাধান হয়েছে","solvedMyProblem","thumb-up"],["অন্যান্য","otherUp","thumb-up"]],[["এতে আমার প্রয়োজনীয় তথ্য নেই","missingTheInformationINeed","thumb-down"],["খুব জটিল / অনেক ধাপ","tooComplicatedTooManySteps","thumb-down"],["পুরনো","outOfDate","thumb-down"],["অনুবাদ সংক্রান্ত সমস্যা","translationIssue","thumb-down"],["নমুনা / কোড সংক্রান্ত সমস্যা","samplesCodeIssue","thumb-down"],["অন্যান্য","otherDown","thumb-down"]],["2024-10-30 UTC-তে শেষবার আপডেট করা হয়েছে।"],[[["This example demonstrates how to build a mathematical optimization problem with MathOpt and solve it remotely via the OR API."],["It utilizes the `remote_http_solve` function for remote execution, requiring an API key for authentication."],["The example showcases the process of model creation, serialization to JSON for the HTTP request, and result retrieval, including objective value and variable values."],["It's crucial to first obtain an API key through the provided setup guide and ensure you have MathOpt installed (available in OR-Tools since release 9.9)."]]],["This content demonstrates how to solve a mathematical optimization problem remotely using the OR API and MathOpt. First, an API key is required, obtainable via a setup guide. A MathOpt model is then built, including binary and bounded variables, a linear constraint, and an objective function to maximize. Finally, `remote_http_solve` function sends this model to OR API for solving, returning the solution's objective value, variable values, and logs. MathOpt is part of OR-Tools since version 9.9.\n"]]