def solve(self, problem: QuadraticProgram) -> OptimizationResult:
    'Tries to solve the given problem using the recursive optimizer.\n\n        Runs the optimizer to try to solve the optimization problem.\n\n        Args:\n            problem: The problem to be solved.\n\n        Returns:\n            The result of the optimizer applied to the problem.\n\n        Raises:\n            QiskitOptimizationError: Incompatible problem.\n            QiskitOptimizationError: Infeasible due to variable substitution\n        '
    self._verify_compatibility(problem)
    problem_ = self._qubo_converter.convert(problem)
    problem_ref = deepcopy(problem_)
    replacements = {}
    min_eigen_results = []
    while (problem_.get_num_vars() > self._min_num_vars):
        res = self._min_eigen_optimizer.solve(problem_)
        if (self._history == IntermediateResult.ALL_ITERATIONS):
            min_eigen_results.append(res)
        correlations = res.get_correlations()
        (i, j) = self._find_strongest_correlation(correlations)
        x_i = problem_.variables[i].name
        x_j = problem_.variables[j].name
        if (correlations[(i, j)] > 0):
            problem_ = problem_.substitute_variables(variables={i: (j, 1)})
            if (problem_.status == QuadraticProgram.Status.INFEASIBLE):
                raise QiskitOptimizationError('Infeasible due to variable substitution')
            replacements[x_i] = (x_j, 1)
        else:
            constant = problem_.objective.constant
            constant += problem_.objective.linear[i]
            constant += problem_.objective.quadratic[(i, i)]
            problem_.objective.constant = constant
            for k in range(problem_.get_num_vars()):
                coeff = problem_.objective.linear[k]
                if (k == i):
                    coeff += (2 * problem_.objective.quadratic[(i, k)])
                else:
                    coeff += problem_.objective.quadratic[(i, k)]
                if (np.abs(coeff) > 1e-10):
                    problem_.objective.linear[k] = coeff
                else:
                    problem_.objective.linear[k] = 0
            problem_ = problem_.substitute_variables(variables={i: (j, (- 1))})
            if (problem_.status == QuadraticProgram.Status.INFEASIBLE):
                raise QiskitOptimizationError('Infeasible due to variable substitution')
            replacements[x_i] = (x_j, (- 1))
    result = self._min_num_vars_optimizer.solve(problem_)
    var_values = {}
    for (i, x) in enumerate(problem_.variables):
        var_values[x.name] = result.x[i]

    def find_value(x, replacements, var_values):
        if (x in var_values):
            return var_values[x]
        elif (x in replacements):
            (y, sgn) = replacements[x]
            value = find_value(y, replacements, var_values)
            var_values[x] = (value if (sgn == 1) else (1 - value))
            return var_values[x]
        else:
            raise QiskitOptimizationError('Invalid values!')
    for x_i in problem_ref.variables:
        if (x_i.name not in var_values):
            find_value(x_i.name, replacements, var_values)
    history = (min_eigen_results, (None if (self._history == IntermediateResult.NO_ITERATIONS) else result))
    x_v = [var_values[x_aux.name] for x_aux in problem_ref.variables]
    fval = result.fval
    result = OptimizationResult(x=x_v, fval=fval, variables=problem_ref.variables)
    result = self._qubo_converter.interpret(result)
    return RecursiveMinimumEigenOptimizationResult(x=result.x, fval=result.fval, variables=result.variables, replacements=replacements, history=history)
Tries to solve the given problem using the recursive optimizer.

Runs the optimizer to try to solve the optimization problem.

Args:
    problem: The problem to be solved.

Returns:
    The result of the optimizer applied to the problem.

Raises:
    QiskitOptimizationError: Incompatible problem.
    QiskitOptimizationError: Infeasible due to variable substitution
def solve(self, problem: QuadraticProgram) -> OptimizationResult:
    'Tries to solve the given problem using the recursive optimizer.\n\n        Runs the optimizer to try to solve the optimization problem.\n\n        Args:\n            problem: The problem to be solved.\n\n        Returns:\n            The result of the optimizer applied to the problem.\n\n        Raises:\n            QiskitOptimizationError: Incompatible problem.\n            QiskitOptimizationError: Infeasible due to variable substitution\n        '
    self._verify_compatibility(problem)
    problem_ = self._qubo_converter.convert(problem)
    problem_ref = deepcopy(problem_)
    replacements = {}
    min_eigen_results = []
    while (problem_.get_num_vars() > self._min_num_vars):
        res = self._min_eigen_optimizer.solve(problem_)
        if (self._history == IntermediateResult.ALL_ITERATIONS):
            min_eigen_results.append(res)
        correlations = res.get_correlations()
        (i, j) = self._find_strongest_correlation(correlations)
        x_i = problem_.variables[i].name
        x_j = problem_.variables[j].name
        if (correlations[(i, j)] > 0):
            problem_ = problem_.substitute_variables(variables={i: (j, 1)})
            if (problem_.status == QuadraticProgram.Status.INFEASIBLE):
                raise QiskitOptimizationError('Infeasible due to variable substitution')
            replacements[x_i] = (x_j, 1)
        else:
            constant = problem_.objective.constant
            constant += problem_.objective.linear[i]
            constant += problem_.objective.quadratic[(i, i)]
            problem_.objective.constant = constant
            for k in range(problem_.get_num_vars()):
                coeff = problem_.objective.linear[k]
                if (k == i):
                    coeff += (2 * problem_.objective.quadratic[(i, k)])
                else:
                    coeff += problem_.objective.quadratic[(i, k)]
                if (np.abs(coeff) > 1e-10):
                    problem_.objective.linear[k] = coeff
                else:
                    problem_.objective.linear[k] = 0
            problem_ = problem_.substitute_variables(variables={i: (j, (- 1))})
            if (problem_.status == QuadraticProgram.Status.INFEASIBLE):
                raise QiskitOptimizationError('Infeasible due to variable substitution')
            replacements[x_i] = (x_j, (- 1))
    result = self._min_num_vars_optimizer.solve(problem_)
    var_values = {}
    for (i, x) in enumerate(problem_.variables):
        var_values[x.name] = result.x[i]

    def find_value(x, replacements, var_values):
        if (x in var_values):
            return var_values[x]
        elif (x in replacements):
            (y, sgn) = replacements[x]
            value = find_value(y, replacements, var_values)
            var_values[x] = (value if (sgn == 1) else (1 - value))
            return var_values[x]
        else:
            raise QiskitOptimizationError('Invalid values!')
    for x_i in problem_ref.variables:
        if (x_i.name not in var_values):
            find_value(x_i.name, replacements, var_values)
    history = (min_eigen_results, (None if (self._history == IntermediateResult.NO_ITERATIONS) else result))
    x_v = [var_values[x_aux.name] for x_aux in problem_ref.variables]
    fval = result.fval
    result = OptimizationResult(x=x_v, fval=fval, variables=problem_ref.variables)
    result = self._qubo_converter.interpret(result)
    return RecursiveMinimumEigenOptimizationResult(x=result.x, fval=result.fval, variables=result.variables, replacements=replacements, history=history)