def _reset_problem_type(self):
        """Reset problem type to whatever is appropriate."""

        # Only need to reset the type after the first solve. This also works
        # around a bug in Cplex where get_num_binary() is some rare cases
        # causes a segfault.
        if self._solve_count > 0:
            integer_count = 0
            for func in (self._cp.variables.get_num_binary,
                         self._cp.variables.get_num_integer,
                         self._cp.variables.get_num_semicontinuous,
                         self._cp.variables.get_num_semiinteger):
                integer_count += func()

            integer = integer_count > 0
            quad_constr = self._cp.quadratic_constraints.get_num() > 0
            quad_obj = self._cp.objective.get_num_quadratic_variables() > 0

            if not integer:
                if quad_constr:
                    new_type = self._cp.problem_type.QCP
                elif quad_obj:
                    new_type = self._cp.problem_type.QP
                else:
                    new_type = self._cp.problem_type.LP
            else:
                if quad_constr:
                    new_type = self._cp.problem_type.MIQCP
                elif quad_obj:
                    new_type = self._cp.problem_type.MIQP
                else:
                    new_type = self._cp.problem_type.MILP

            logger.debug('Setting problem type to {}...'.format(
                self._cp.problem_type[new_type]))
            self._cp.set_problem_type(new_type)
        else:
            logger.debug('Problem type is {}'.format(
                self._cp.problem_type[self._cp.get_problem_type()]))

        # Force QP/MIQP solver to look for global optimum. We set it here only
        # for QP/MIQP problems to avoid the warnings generated for other
        # problem types when this parameter is set.
        quad_obj = self._cp.objective.get_num_quadratic_variables() > 0

        if hasattr(self._cp.parameters, 'optimalitytarget'):
            target_param = self._cp.parameters.optimalitytarget
        else:
            target_param = self._cp.parameters.solutiontarget

        if quad_obj:
            target_param.set(target_param.values.optimal_global)
        else:
            target_param.set(target_param.values.auto)
Reset problem type to whatever is appropriate.