Class SatSolver

  • All Implemented Interfaces:
    net.sf.tweety.logics.commons.analysis.BeliefSetConsistencyTester<PlFormula>, net.sf.tweety.logics.commons.analysis.ConsistencyTester<net.sf.tweety.commons.BeliefSet<PlFormula,​?>>, net.sf.tweety.logics.commons.analysis.ConsistencyWitnessProvider<PlBeliefSet,​PlFormula>
    Direct Known Subclasses:
    LingelingSolver, MaxSatSolver, Sat4jSolver, SimpleDpllSolver

    public abstract class SatSolver
    extends Object
    implements net.sf.tweety.logics.commons.analysis.BeliefSetConsistencyTester<PlFormula>, net.sf.tweety.logics.commons.analysis.ConsistencyWitnessProvider<PlBeliefSet,​PlFormula>
    Abstract class for specifying SAT solvers.
    Author:
    Matthias Thimm
    • Constructor Detail

      • SatSolver

        public SatSolver()
    • Method Detail

      • setDefaultSolver

        public static void setDefaultSolver​(SatSolver solver)
        Sets the default SAT solver.
        Parameters:
        solver - some SAT solver
      • setTempFolder

        public static void setTempFolder​(File tempFolder)
        Set the folder for temporary files created by SAT solver.
        Parameters:
        tempFolder - some temp folder.
      • hasDefaultSolver

        public static boolean hasDefaultSolver()
        Returns "true" if a default SAT solver is configured.
        Returns:
        "true" if a default SAT solver is configured.
      • getDefaultSolver

        public static SatSolver getDefaultSolver()
        Returns the default SAT solver.

        If a default SAT solver has been configured this solver is returned by this method. If no default solver is configured, the Sat4j solver (net.sf.tweety.pl.sat.Sat4jSolver) is returned as a fallback and a message is printed to stderr pointing out that no default SAT solver is configured.
        Returns:
        the default SAT solver.
      • convertToDimacs

        public static String convertToDimacs​(Collection<PlFormula> formulas,
                                             List<Proposition> props)
        Converts the given set of formulas to their string representation in Dimacs CNF. Note that a single formula may be represented as multiple clauses, so there is no simple correspondence between the formulas of the set and the Dimacs representation. Use convertToDimacs(.) for obtaining a map between those.
        Parameters:
        formulas - a collection of formulas
        props - a list of propositions (=signature) where the indices are used for writing the clauses.
        Returns:
        a string in Dimacs CNF.
      • convertToDimacs

        public static net.sf.tweety.commons.util.Pair<String,​List<PlFormula>> convertToDimacs​(Collection<PlFormula> formulas)
        Converts the given set of formulas to their string representation in Dimacs CNF. The return value is a pair of
        1.) the string representation
        2.) a list of collections of formulas (all from the given set); the interpretation of this list is that the generated clause no K originated from the propositional formula given at index k.
        Parameters:
        formulas - a collection of formulas.
        Returns:
        a string in Dimacs CNF and a mapping between clauses and original formulas.
      • createTmpDimacsFile

        protected static File createTmpDimacsFile​(Collection<PlFormula> formulas,
                                                  List<Proposition> props)
                                           throws IOException
        Creates a temporary file in Dimacs format with the given proposition2variable mapping.
        Parameters:
        formulas - a collection of formulas
        props - a list of propositions (=signature) where the indices are used for writing the clauses.
        Returns:
        the file handler.
        Throws:
        IOException - if something went wrong while creating a temporary file.
      • createTmpDimacsFile

        protected static net.sf.tweety.commons.util.Pair<File,​List<PlFormula>> createTmpDimacsFile​(Collection<PlFormula> formulas)
                                                                                                  throws IOException
        Creates a temporary file in Dimacs format and also returns a mapping between formulas and clauses.
        Parameters:
        formulas - a collection of formulas
        Returns:
        the file handler and a mapping between clauses and original formulas.
        Throws:
        IOException - if something went wrong while creating a temporary file.
      • getWitness

        public abstract net.sf.tweety.commons.Interpretation<PlBeliefSet,​PlFormula> getWitness​(Collection<PlFormula> formulas)
        If the collection of formulas is consistent this method returns some model of it or, if it is inconsistent, null.
        Specified by:
        getWitness in interface net.sf.tweety.logics.commons.analysis.ConsistencyWitnessProvider<PlBeliefSet,​PlFormula>
        Returns:
        some model of the formulas or null.
      • isSatisfiable

        public abstract boolean isSatisfiable​(Collection<PlFormula> formulas)
        Checks whether the given set of formulas is satisfiable.
        Parameters:
        formulas - a set of formulas.
        Returns:
        "true" if the set is consistent.
      • isConsistent

        public boolean isConsistent​(net.sf.tweety.commons.BeliefSet<PlFormula,​?> beliefSet)
        Specified by:
        isConsistent in interface net.sf.tweety.logics.commons.analysis.BeliefSetConsistencyTester<PlFormula>
        Specified by:
        isConsistent in interface net.sf.tweety.logics.commons.analysis.ConsistencyTester<net.sf.tweety.commons.BeliefSet<PlFormula,​?>>
      • isConsistent

        public boolean isConsistent​(Collection<PlFormula> formulas)
        Specified by:
        isConsistent in interface net.sf.tweety.logics.commons.analysis.BeliefSetConsistencyTester<PlFormula>
      • isConsistent

        public boolean isConsistent​(PlFormula formula)
        Specified by:
        isConsistent in interface net.sf.tweety.logics.commons.analysis.BeliefSetConsistencyTester<PlFormula>
      • getWitness

        public net.sf.tweety.commons.Interpretation<PlBeliefSet,​PlFormula> getWitness​(PlFormula formula)
        Specified by:
        getWitness in interface net.sf.tweety.logics.commons.analysis.ConsistencyWitnessProvider<PlBeliefSet,​PlFormula>
      • getWitness

        public net.sf.tweety.commons.Interpretation<PlBeliefSet,​PlFormula> getWitness​(net.sf.tweety.commons.BeliefSet<PlFormula,​?> bs)
        Specified by:
        getWitness in interface net.sf.tweety.logics.commons.analysis.ConsistencyWitnessProvider<PlBeliefSet,​PlFormula>