GurobiOptimizer#
- class GurobiOptimizer(disp=False)[source]#
Bases:
OptimizationAlgorithm
The Gurobi optimizer wrapped as an Qiskit
OptimizationAlgorithm
.This class provides a wrapper for
gurobipy
to be used within the optimization module.Examples
>>> from qiskit_optimization.problems import QuadraticProgram >>> from qiskit_optimization.algorithms import GurobiOptimizer >>> problem = QuadraticProgram() >>> # specify problem here, if gurobi is installed >>> optimizer = GurobiOptimizer() if GurobiOptimizer.is_gurobi_installed() else None >>> # Suppress gurobipy print info to stdout >>> import sys >>> class DevNull: ... def noop(*args, **kwargs): pass ... close = write = flush = writelines = noop >>> sys.stdout = DevNull() >>> result = optimizer.solve(problem)
Initializes the GurobiOptimizer.
- প্যারামিটার:
disp (bool) -- Whether to print Gurobi output or not.
Attributes
- disp#
Returns the display setting.
- রিটার্নস:
Whether to print Gurobi information or not.
Methods
- get_compatibility_msg(problem)[source]#
Checks whether a given problem can be solved with this optimizer.
Returns
''
since Gurobi accepts all problems that can be modeled using theQuadraticProgram
. Gurobi will also solve non-convex problems.- প্যারামিটার:
problem (QuadraticProgram) -- The optimization problem to check compatibility.
- রিটার্নস:
An empty string.
- রিটার্ন টাইপ:
- is_compatible(problem)#
Checks whether a given problem can be solved with the optimizer implementing this method.
- প্যারামিটার:
problem (QuadraticProgram) -- The optimization problem to check compatibility.
- রিটার্নস:
Returns True if the problem is compatible, False otherwise.
- রিটার্ন টাইপ:
- solve(problem)[source]#
Tries to solves the given problem using the optimizer.
Runs the optimizer to try to solve the optimization problem. If problem is not convex, this optimizer may raise an exception due to incompatibility, depending on the settings.
- প্যারামিটার:
problem (QuadraticProgram) -- The problem to be solved.
- রিটার্নস:
The result of the optimizer applied to the problem.
- রেইজেস:
QiskitOptimizationError -- If the problem is incompatible with the optimizer.
- রিটার্ন টাইপ: