qiskit_addon_opt_mapper.solvers.CplexSolver¶
- class CplexSolver(disp=False, cplex_parameters=None)[source]¶
 Bases:
OptimizationSolverThe CPLEX optimizer wrapped as a
OptimizationSolver.This class provides a wrapper for
cplex.Cplex(https://pypi.org/project/cplex/) to be used within the optimization module.Examples
>>> from qiskit_addon_opt_mapper.problems import OptimizationProblem >>> from qiskit_addon_opt_mapper.solvers import CplexSolver >>> problem = OptimizationProblem() >>> # specify problem here, if cplex is installed >>> optimizer = CplexSolver() if CplexSolver.is_cplex_installed() else None >>> if optimizer: result = optimizer.solve(problem)
Initializes the CplexSolver.
- Parameters:
 disp (bool) – Whether to print CPLEX output or not.
cplex_parameters (dict[str, Any] | None) – The parameters for CPLEX. See https://www.ibm.com/docs/en/icos/20.1.0?topic=cplex-parameters for details.
- __init__(disp=False, cplex_parameters=None)[source]¶
 Initializes the CplexSolver.
- Parameters:
 disp (bool) – Whether to print CPLEX output or not.
cplex_parameters (dict[str, Any] | None) – The parameters for CPLEX. See https://www.ibm.com/docs/en/icos/20.1.0?topic=cplex-parameters for details.
- Return type:
 None
Methods
__init__([disp, cplex_parameters])Initializes the CplexSolver.
get_compatibility_msg(problem)Checks whether a given problem can be solved with this optimizer.
is_compatible(problem)Checks whether a given problem can be solved with the optimizer implementing this method.
Returns True if cplex is installed.
solve(problem)Tries to solves the given problem using the optimizer.
Attributes
Returns parameters for CPLEX.
Returns the display setting.
- property disp: bool¶
 Returns the display setting.
- Returns:
 Whether to print CPLEX information or not.
- get_compatibility_msg(problem)[source]¶
 Checks whether a given problem can be solved with this optimizer.
Returns
''since CPLEX accepts all problems that can be modeled using theOptimizationProblem. CPLEX may throw an exception in case the problem is determined to be non-convex.- Parameters:
 problem (OptimizationProblem) – The optimization problem to check compatibility.
- Returns:
 An empty string.
- Return type:
 
- is_compatible(problem)[source]¶
 Checks whether a given problem can be solved with the optimizer implementing this method.
- Parameters:
 problem (OptimizationProblem) – The optimization problem to check compatibility.
- Returns:
 Returns True if the problem is compatible, False otherwise.
- Return type:
 
- 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.
- Parameters:
 problem (OptimizationProblem) – The problem to be solved.
- Returns:
 The result of the optimizer applied to the problem.
- Raises:
 QiskitOptimizationError – If the problem is incompatible with the optimizer.
- Return type: