Module logicng

Class MiniSat2Solver

  • Direct Known Subclasses:
    DnnfMiniSatStyleSolver

    public class MiniSat2Solver
    extends MiniSatStyleSolver
    A solver based on MiniSAT 2.2.0. If the incremental mode is deactivated, this version should behave exactly like the C++ version.

    If the incremental mode is activated, this solver allows to save and load the solver state in an efficient manner. Therefore, clause deletion and simplifications are deactivated in this mode. This mode is most efficient on small to mid-size industrial formulas (up to 50,000 variables, 100,000 clauses). Whenever you have lots of small formulas to solve or need the ability to add and delete formulas from the solver, we recommend to consider this mode.

    Since:
    1.0
    Version:
    2.1.0
    • Constructor Detail

      • MiniSat2Solver

        public MiniSat2Solver()
        Constructs a new MiniSAT 2 solver with the default values for solver configuration. By default, incremental mode is activated.
      • MiniSat2Solver

        public MiniSat2Solver​(MiniSatConfig config)
        Constructs a new MiniSAT 2 solver with a given solver configuration.
        Parameters:
        config - the solver configuration
    • Method Detail

      • initializeMiniSAT

        protected void initializeMiniSAT()
        Initializes the additional parameters.
      • newVar

        public int newVar​(boolean sign,
                          boolean dvar)
        Description copied from class: MiniSatStyleSolver
        Adds a new variable to the solver.
        Specified by:
        newVar in class MiniSatStyleSolver
        Parameters:
        sign - the initial polarity of the new variable, true if negative, false if positive
        dvar - true if this variable can be used as a decision variable, false if it should not be used as a decision variable
        Returns:
        the index of the new variable
      • addClause

        public boolean addClause​(LNGIntVector ps,
                                 Proposition proposition)
        Description copied from class: MiniSatStyleSolver
        Adds a clause to the solver.
        Specified by:
        addClause in class MiniSatStyleSolver
        Parameters:
        ps - the literals of the clause
        proposition - a proposition (if required for proof tracing)
        Returns:
        true if the clause was added successfully, false otherwise
      • saveState

        public int[] saveState()
        Saves and returns the solver state expressed as an integer array which stores the length of the internal data structures. The array has length 5 and has the following layout:

        | current solver state | #vars | #clauses | #learnt clauses | #unit clauses | #pg original | #pg proof

        Specified by:
        saveState in class MiniSatStyleSolver
        Returns:
        the current solver state
      • loadState

        public void loadState​(int[] state)
        Description copied from class: MiniSatStyleSolver
        Loads a given state in the solver.

        ATTENTION: You can only load a state which was created by this instance of the solver before the current state. Only the sizes of the internal data structures are stored, meaning you can track back in time and restore a solver state with fewer variables and/or fewer clauses. It is not possible to import a solver state from another solver or another solving execution.

        Specified by:
        loadState in class MiniSatStyleSolver
        Parameters:
        state - the solver state to load
      • uncheckedEnqueue

        protected void uncheckedEnqueue​(int lit,
                                        MSClause reason)
        Description copied from class: MiniSatStyleSolver
        Assigns a literal (= a variable to the respective value).
        Specified by:
        uncheckedEnqueue in class MiniSatStyleSolver
        Parameters:
        lit - the literal
        reason - the reason clause of the assignment (conflict resolution) or null if it was a decision
      • attachClause

        protected void attachClause​(MSClause c)
        Description copied from class: MiniSatStyleSolver
        Attaches a given clause to the solver (i.e. the watchers for this clause are initialized).
        Specified by:
        attachClause in class MiniSatStyleSolver
        Parameters:
        c - the clause
      • propagate

        protected MSClause propagate()
        Description copied from class: MiniSatStyleSolver
        Performs unit propagation.
        Specified by:
        propagate in class MiniSatStyleSolver
        Returns:
        the conflicting clause if a conflict arose during unit propagation or null if there was none
      • litRedundant

        protected boolean litRedundant​(int p,
                                       int abstractLevels)
        Description copied from class: MiniSatStyleSolver
        Returns true if a given literal is redundant in the current conflict analysis, false otherwise.
        Specified by:
        litRedundant in class MiniSatStyleSolver
        Parameters:
        p - the literal
        abstractLevels - an abstraction of levels
        Returns:
        true if a given literal is redundant in the current conflict analysis
      • analyzeFinal

        protected void analyzeFinal​(int p,
                                    LNGIntVector outConflict)
        Description copied from class: MiniSatStyleSolver
        Analysis the final conflict if there were assumptions.
        Specified by:
        analyzeFinal in class MiniSatStyleSolver
        Parameters:
        p - the conflicting literal
        outConflict - the vector to store the final conflict
      • reduceDB

        protected void reduceDB()
        Description copied from class: MiniSatStyleSolver
        Reduces the database of learnt clauses. Only clauses of the first half of the clauses with the most activity are possibly removed. A clause is only removed if it is not locked, i.e. is the reason of an assignment for a variable.
        Specified by:
        reduceDB in class MiniSatStyleSolver
      • satisfied

        protected boolean satisfied​(MSClause c)
        Description copied from class: MiniSatStyleSolver
        Returns true if a given clause is satisfied under the current assignment, false otherwise.
        Specified by:
        satisfied in class MiniSatStyleSolver
        Parameters:
        c - the clause
        Returns:
        true if a given clause is satisfied under the current assignment
      • simplify

        protected boolean simplify()
        Description copied from class: MiniSatStyleSolver
        Simplifies the database of clauses. This method is only executed on level 0. All learnt clauses which are satisfied on level 0 are removed. Depending on the configuration of the solver, also original clauses which are satisfied at level 0 are removed.
        Specified by:
        simplify in class MiniSatStyleSolver
        Returns:
        true if simplification was successful and no conflict was found, false if a conflict was found during the simplification
      • search

        protected Tristate search​(int nofConflicts)
        The main search procedure of the CDCL algorithm.
        Parameters:
        nofConflicts - the number of conflicts till the next restart
        Returns:
        a Tristate representing the result. FALSE if the formula is UNSAT, TRUE if the formula is SAT, and UNDEF if the state is not known yet (restart) or the handler canceled the computation
      • analyze

        protected void analyze​(MSClause conflictClause,
                               LNGIntVector outLearnt)
        Analyzes a given conflict clause wrt. the current solver state. A 1-UIP clause is created during this procedure and the new backtracking level is stored in the solver state.
        Parameters:
        conflictClause - the conflict clause to start the resolution analysis with
        outLearnt - the vector where the new learnt 1-UIP clause is stored
      • simplifyClause

        protected void simplifyClause​(LNGIntVector outLearnt)
        Minimizes a given learnt clause depending on the minimization method of the solver configuration.
        Parameters:
        outLearnt - the learnt clause which should be minimized
      • completeBacktrack

        protected void completeBacktrack()
        Performs an unconditional backtrack to level zero.
      • simpleRemoveClause

        protected void simpleRemoveClause​(MSClause c)
        Performs a simple removal of clauses used during the loading of an older state.
        Parameters:
        c - the clause to remove