Module logicng

Class MiniSat


  • public class MiniSat
    extends SATSolver
    Wrapper for the MiniSAT-style SAT solvers.
    Since:
    1.0
    Version:
    2.4.0
    • Method Detail

      • miniSat

        public static MiniSat miniSat​(FormulaFactory f)
        Returns a new MiniSat solver with the MiniSat configuration from the formula factory.
        Parameters:
        f - the formula factory
        Returns:
        the solver
      • miniSat

        public static MiniSat miniSat​(FormulaFactory f,
                                      MiniSatConfig config)
        Returns a new MiniSat solver with a given configuration.
        Parameters:
        f - the formula factory
        config - the configuration, must not be null
        Returns:
        the solver
      • glucose

        public static MiniSat glucose​(FormulaFactory f)
        Returns a new Glucose solver with the MiniSat and Glucose configuration from the formula factory.
        Parameters:
        f - the formula factory
        Returns:
        the solver
      • glucose

        public static MiniSat glucose​(FormulaFactory f,
                                      MiniSatConfig miniSatConfig,
                                      GlucoseConfig glucoseConfig)
        Returns a new Glucose solver with a given configuration.
        Parameters:
        f - the formula factory
        miniSatConfig - the MiniSat configuration, must not be null
        glucoseConfig - the Glucose configuration, must not be null
        Returns:
        the solver
      • miniCard

        public static MiniSat miniCard​(FormulaFactory f)
        Returns a new MiniCard solver with the MiniSat configuration from the formula factory.
        Parameters:
        f - the formula factory
        Returns:
        the solver
      • miniCard

        public static MiniSat miniCard​(FormulaFactory f,
                                       MiniSatConfig config)
        Returns a new MiniCard solver with a given configuration.
        Parameters:
        f - the formula factory
        config - the configuration, must not be null
        Returns:
        the solver
      • mk

        public static MiniSat mk​(FormulaFactory f,
                                 MiniSat.SolverStyle style)
        Returns a new solver depending on the given solver style with the configuration from the formula factory.
        Parameters:
        f - the formula factory
        style - the solver style, must not be null
        Returns:
        the solver
      • mk

        public static MiniSat mk​(FormulaFactory f,
                                 MiniSat.SolverStyle solverStyle,
                                 MiniSatConfig miniSatConfig,
                                 GlucoseConfig glucoseConfig)
        Returns a new solver depending on the given solver style with the given configuration.
        Parameters:
        f - the formula factory
        solverStyle - the solver style, must not be null
        miniSatConfig - the configuration, must not be null
        glucoseConfig - the Glucose configuration, must not be null for solver type MiniSat.SolverStyle.GLUCOSE
        Returns:
        the solver
      • add

        public void add​(Formula formula,
                        Proposition proposition)
        Description copied from class: SATSolver
        Adds a formula to the solver. The formula is first converted to CNF.
        Specified by:
        add in class SATSolver
        Parameters:
        formula - the formula
        proposition - the proposition of this formula
      • addFormulaAsCNF

        protected void addFormulaAsCNF​(Formula formula,
                                       Proposition proposition)
      • addWithoutUnknown

        public void addWithoutUnknown​(Formula formula)
        Description copied from class: SATSolver
        Adds a formula to the solver, but sets all variables to false which are not known to the solver.
        Specified by:
        addWithoutUnknown in class SATSolver
        Parameters:
        formula - the formula
      • addIncrementalCC

        public CCIncrementalData addIncrementalCC​(CardinalityConstraint cc)
        Description copied from class: SATSolver
        Adds a cardinality constraint and returns its incremental data in order to refine the constraint on the solver.

        Usage constraints: - "<": Cannot be used with right-hand side 2, returns null for right-hand side 1, but constraint is added to solver. - "<=": Cannot be used with right-hand side 1, returns null for right-hand side 0, but constraint is added to solver. - ">": Returns null for right-hand side 0 or number of variables -1, but constraint is added to solver. Adds false to solver for right-hand side >= number of variables. - ">=": Returns null for right-hand side 1 or number of variables, but constraint is added to solver. Adds false to solver for right-hand side > number of variables.

        Specified by:
        addIncrementalCC in class SATSolver
        Parameters:
        cc - the cardinality constraint
        Returns:
        the incremental data of this constraint, or null if the right-hand side of cc is 1
      • addClause

        protected void addClause​(Formula formula,
                                 Proposition proposition)
        Description copied from class: SATSolver
        Adds a formula which must be a clause to the solver.
        Specified by:
        addClause in class SATSolver
        Parameters:
        formula - the clause
        proposition - a proposition (if required for proof tracing)
      • sat

        public Tristate sat​(SATHandler handler)
        Description copied from class: SATSolver
        Returns Tristate.TRUE if the current formula in the solver is satisfiable, @{code Tristate.FALSE} if it is unsatisfiable, or UNDEF if the solving process was aborted.
        Specified by:
        sat in class SATSolver
        Parameters:
        handler - the SAT handler
        Returns:
        the satisfiability of the formula in the solver
      • sat

        public Tristate sat​(SATHandler handler,
                            Literal literal)
        Description copied from class: SATSolver
        Returns Tristate.TRUE if the current formula in the solver and a given literal are satisfiable, Tristate.FALSE if it is unsatisfiable, or UNDEF if the solving process was aborted.
        Specified by:
        sat in class SATSolver
        Parameters:
        handler - the SAT handler
        literal - the assumed literal
        Returns:
        the satisfiability of the formula in the solver
      • sat

        public Tristate sat​(SATHandler handler,
                            Collection<? extends Literal> assumptions)
        Description copied from class: SATSolver
        Returns Tristate.TRUE if the current formula in the solver and a given collection of assumed literals are satisfiable, Tristate.FALSE if it is unsatisfiable, or UNDEF if the solving process was aborted. The assumptions can be seen as an additional conjunction of literals. Note: Use ordered collections to ensure determinism in the solving process and thus in the resulting model or conflict.
        Specified by:
        sat in class SATSolver
        Parameters:
        handler - the SAT handler
        assumptions - a collection of literals
        Returns:
        the satisfiability of the formula in the solver
      • reset

        public void reset()
        Description copied from class: SATSolver
        Resets the SAT solver.
        Specified by:
        reset in class SATSolver
      • model

        public Assignment model​(Collection<Variable> variables)
        Description copied from class: SATSolver
        Returns a model of the current formula on the solver wrt. a given set of variables. If the set is null, all variables are considered relevant. If the formula is UNSAT, null will be returned.
        Specified by:
        model in class SATSolver
        Parameters:
        variables - the set of variables
        Returns:
        a model of the current formula
      • execute

        public <RESULT> RESULT execute​(SolverFunction<RESULT> function)
        Description copied from class: SATSolver
        Executes a solver function on this solver.
        Specified by:
        execute in class SATSolver
        Type Parameters:
        RESULT - the result type of the function
        Parameters:
        function - the solver function
        Returns:
        the result of executing the solver function on the current solver
      • saveState

        public SolverState saveState()
        Description copied from class: SATSolver
        Saves the current solver state.
        Specified by:
        saveState in class SATSolver
        Returns:
        the current solver state
      • loadState

        public void loadState​(SolverState state)
        Description copied from class: SATSolver
        Loads a given solver state.
        Specified by:
        loadState in class SATSolver
        Parameters:
        state - the solver state
      • knownVariables

        public SortedSet<Variable> knownVariables()
        Description copied from class: SATSolver
        Returns the set of variables currently known by the solver. NOTE: Due to the incremental/decremental interface of some solvers, this set is generated each time, the method is called. So if you can maintain a list of relevant/known variables in your own application, this is recommended.
        Specified by:
        knownVariables in class SATSolver
        Returns:
        the set of variables currently known by the solver
      • generateClauseVector

        protected LNGIntVector generateClauseVector​(Collection<? extends Literal> literals)
        Generates a clause vector of a collection of literals.
        Parameters:
        literals - the literals
        Returns:
        the clause vector
      • getOrAddIndex

        protected int getOrAddIndex​(Literal lit)
      • createAssignment

        public Assignment createAssignment​(LNGBooleanVector vec,
                                           LNGIntVector relevantIndices)
        Creates an assignment from a Boolean vector of the solver. The created assignment is not fast evaluable.
        Parameters:
        vec - the vector of the solver
        relevantIndices - the solver's indices of the relevant variables for the model. If null, all variables are relevant.
        Returns:
        the assignment
      • createAssignment

        public Assignment createAssignment​(LNGBooleanVector vec,
                                           LNGIntVector relevantIndices,
                                           boolean fastEvaluable)
        Creates an assignment from a Boolean vector of the solver. The flag fastEvaluable determines if the created assignment is fast evaluable assignment.
        Parameters:
        vec - the vector of the solver
        relevantIndices - the solver's indices of the relevant variables for the model. If null, all variables are relevant.
        fastEvaluable - true if the created assignment should be fast evaluable, otherwise false
        Returns:
        the assignment
      • isRelevantVariable

        public boolean isRelevantVariable​(String name)
        Returns whether a variable on the solver is relevant or an auxiliary variable.
        Parameters:
        name - the name of the variable
        Returns:
        true if it is relevant, false if it is an auxiliary variable
      • underlyingSolver

        public MiniSatStyleSolver underlyingSolver()
        Returns the underlying core solver.

        ATTENTION: by influencing the underlying solver directly, you can mess things up completely! You should really know what you are doing.

        Returns:
        the underlying core solver
      • initialPhase

        public boolean initialPhase()
        Returns the initial phase of literals of this solver.
        Returns:
        the initial phase of literals of this solver
      • lastResultIsUsable

        protected boolean lastResultIsUsable()
      • getConfig

        public MiniSatConfig getConfig()
        Returns this solver's configuration.
        Returns:
        this solver's configuration
      • setSelectionOrder

        public void setSelectionOrder​(List<? extends Literal> selectionOrder)
        Description copied from class: SATSolver
        Sets the selection order of the variables and their polarity.

        Specified by:
        setSelectionOrder in class SATSolver
        Parameters:
        selectionOrder - the variable order and their polarity that should be checked first
      • resetSelectionOrder

        public void resetSelectionOrder()
        Description copied from class: SATSolver
        Resets the selection order on the solver. The internal activity heuristics for the variable ordering will be used again.
        Specified by:
        resetSelectionOrder in class SATSolver
      • canSaveLoadState

        public boolean canSaveLoadState()
        Description copied from class: SATSolver
        Returns whether this solver instance can save and load solver states.
        Specified by:
        canSaveLoadState in class SATSolver
        Returns:
        true when the solver can save and load states, false otherwise
      • canGenerateProof

        public boolean canGenerateProof()
        Description copied from class: SATSolver
        Returns whether this solver instance can generate proofs.
        Specified by:
        canGenerateProof in class SATSolver
        Returns:
        true when the solver can generate proofs, false otherwise
      • getStyle

        public MiniSat.SolverStyle getStyle()
        Returns this solver's style.
        Returns:
        this solver's style
      • isIncremental

        public boolean isIncremental()
        Returns whether this solver is incremental
        Returns:
        true if this solver is incremental, false otherwise
      • getResult

        public Tristate getResult()
        Returns the current result, e.g. the result of the last SATSolver.sat() call.
        Returns:
        the current result
      • setResult

        protected void setResult​(Tristate tristate)
      • isLastComputationWithAssumptions

        public boolean isLastComputationWithAssumptions()
        Returns whether the last computation was using assumption literals.
        Returns:
        true if the last computation used assumption literals, false otherwise