(self)
Main DPLL loop.

        Variables are chosen successively, and assigned to be either
        True or False. If a solution is not found with this setting,
        the opposite is chosen and the search continues. The solver
        halts when every variable has a setting.

        Examples
        ========

        >>> from sympy.logic.algorithms.dpll2 import SATSolver
        >>> SATSolver([set([-1]), set([1])], set([1]), set([]))._find_model()
        False
        >>> SATSolver([set([1]), set([-2])], set([-2, 3]), set([]))._find_model()
        True
Main DPLL loop.
Main DPLL loop .
def _find_model(self):
        """Main DPLL loop.

        Variables are chosen successively, and assigned to be either
        True or False. If a solution is not found with this setting,
        the opposite is chosen and the search continues. The solver
        halts when every variable has a setting.

        Examples
        ========

        >>> from sympy.logic.algorithms.dpll2 import SATSolver
        >>> SATSolver([set([-1]), set([1])], set([1]), set([]))._find_model()
        False
        >>> SATSolver([set([1]), set([-2])], set([-2, 3]), set([]))._find_model()
        True
        """

        # We use this variable to keep track of if we should flip a
        #  variable setting in successive rounds
        flip_var = False

        # Check if unit prop says the theory is unsat right off the bat
        self._simplify()
        if self.is_unsatisfied:
            return False

        # While the theory still has clauses remaining
        while True:
            # Perform cleanup / fixup at regular intervals
            if self.num_decisions % self.INTERVAL == 0:
                for func in self.update_functions:
                    func()

            if flip_var:
                # We have just backtracked and we are trying to opposite literal
                flip_var = False
                lit = self._current_level.decision

            else:
                # Pick a literal to set
                lit = self.heur_calculate()
                self.num_decisions += 1

                # Stopping condition for a satisfying theory
                if 0 == lit:
                    return True

                # Start the new decision level
                self.levels.append(Level(lit))

            # Assign the literal, updating the clauses it satisfies
            self._assign_literal(lit)

            # _simplify the theory
            self._simplify()

            # Check if we've made the theory unsat
            if self.is_unsatisfied:

                self.is_unsatisfied = False

                # We unroll all of the decisions until we can flip a literal
                while self._current_level.flipped:
                    self._undo()

                    # If we've unrolled all the way, the theory is unsat
                    if 1 == len(self.levels):
                        return False

                # Detect and add a learned clause
                self.add_learned_clause(self.compute_conflict())

                # Try the opposite setting of the most recent decision
                flip_lit = -self._current_level.decision
                self._undo()
                self.levels.append(Level(flip_lit, flipped=True))
                flip_var = True
def _find_model ( self ) : # We use this variable to keep track of if we should flip a #  variable setting in successive rounds flip_var = False # Check if unit prop says the theory is unsat right off the bat self . _simplify ( ) if self . is_unsatisfied : return False # While the theory still has clauses remaining while True : # Perform cleanup / fixup at regular intervals if self . num_decisions % self . INTERVAL == 0 : for func in self . update_functions : func ( ) if flip_var : # We have just backtracked and we are trying to opposite literal flip_var = False lit = self . _current_level . decision else : # Pick a literal to set lit = self . heur_calculate ( ) self . num_decisions += 1 # Stopping condition for a satisfying theory if 0 == lit : return True # Start the new decision level self . levels . append ( Level ( lit ) ) # Assign the literal, updating the clauses it satisfies self . _assign_literal ( lit ) # _simplify the theory self . _simplify ( ) # Check if we've made the theory unsat if self . is_unsatisfied : self . is_unsatisfied = False # We unroll all of the decisions until we can flip a literal while self . _current_level . flipped : self . _undo ( ) # If we've unrolled all the way, the theory is unsat if 1 == len ( self . levels ) : return False # Detect and add a learned clause self . add_learned_clause ( self . compute_conflict ( ) ) # Try the opposite setting of the most recent decision flip_lit = - self . _current_level . decision self . _undo ( ) self . levels . append ( Level ( flip_lit , flipped = True ) ) flip_var = True