Class MaxSatSolver

    • Field Detail

      • tempFolder

        private static java.io.File tempFolder
        For temporary files.
    • Constructor Detail

      • MaxSatSolver

        public MaxSatSolver()
    • Method Detail

      • setTempFolder

        public static void setTempFolder​(java.io.File tempFolder)
        Set the folder for temporary files created by a MaxSAT solver.
        Parameters:
        tempFolder - some temp folder.
      • getWitness

        public abstract Interpretation<PlBeliefSet,​PlFormula> getWitness​(java.util.Collection<PlFormula> hardConstraints,
                                                                               java.util.Map<PlFormula,​java.lang.Integer> softConstraints)
        Returns an interpretation with maximal weight on the soft constraints (or null if the hard constraints are not satisfiable)
        Parameters:
        hardConstraints - a set of propositional formulas
        softConstraints - a map mapping clauses to weights (if there is a formula, which is not a clause, i.e. a disjunction of literals), an exception is thrown.
        Returns:
        an interpretation with maximal weight on the soft constraints (or null if the hard constraints are not satisfiable)
      • isSatisfiable

        public boolean isSatisfiable​(java.util.Collection<PlFormula> formulas)
        Description copied from class: SatSolver
        Checks whether the given set of formulas is satisfiable.
        Specified by:
        isSatisfiable in class SatSolver
        Parameters:
        formulas - a set of formulas.
        Returns:
        "true" if the set is consistent.
      • convertToDimacsWcnf

        protected static java.lang.String convertToDimacsWcnf​(java.util.Collection<PlFormula> hardConstraints,
                                                              java.util.Map<PlFormula,​java.lang.Integer> softConstraints,
                                                              java.util.List<Proposition> props)
                                                       throws java.lang.IllegalArgumentException
        Converts the given MaxSAT instance (i.e. hard and soft constraints, the latter can only be clauses) to their string representation in Dimacs WCNF. 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.
        Parameters:
        hardConstraints - a collection of formulas
        softConstraints - a map mapping clauses to weights
        props - a list of propositions (=signature) where the indices are used for writing the clauses.
        Returns:
        a string in Dimacs CNF.
        Throws:
        java.lang.IllegalArgumentException - if any soft constraint is not a clause.
      • createTmpDimacsWcnfFile

        protected static java.io.File createTmpDimacsWcnfFile​(java.util.Collection<PlFormula> hardConstraints,
                                                              java.util.Map<PlFormula,​java.lang.Integer> softConstraints,
                                                              java.util.List<Proposition> props)
                                                       throws java.io.IOException
        Converts the given MaxSAT instance (i.e. hard and soft constraints, the latter can only be clauses) to their string representation in Dimacs WCNF and writes it to a temporary file. 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.
        Parameters:
        hardConstraints - a collection of formulas
        softConstraints - a map mapping clauses to weights
        props - a list of propositions (=signature) where the indices are used for writing the clauses.
        Returns:
        a string in Dimacs CNF.
        Throws:
        java.io.IOException - if some file issue occurs
        java.lang.IllegalArgumentException - if any soft constraint is not a clause.
      • costOf

        public static int costOf​(Interpretation<PlBeliefSet,​PlFormula> interpretation,
                                 java.util.Collection<PlFormula> hardConstraints,
                                 java.util.Map<PlFormula,​java.lang.Integer> softConstraints)
        Returns the cost of the given interpretation, i.e. the sum of the weights of all violated soft constraints. If the interpretation does not satisfy the hard constraints -1 is returned;
        Parameters:
        interpretation - some interpretation
        hardConstraints - a set of hard constraints
        softConstraints - a set of soft constraints
        Returns:
        the cost of the interpretation