Package net.sf.tweety.logics.pl.sat
Class MaxSatSolver
- java.lang.Object
-
- net.sf.tweety.logics.pl.sat.SatSolver
-
- net.sf.tweety.logics.pl.sat.MaxSatSolver
-
- 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:
OpenWboSolver
public abstract class MaxSatSolver extends SatSolver
Provides a generic class for implementing MaxSAT solvers, i.e. solvers that get as input a set of hard constraints (=propositional formulas that need to be satisfied) and a set of soft constraints (=clauses with weights) whose satisfaction should be maximized (=sum of weights should be maximized).- Author:
- Matthias Thimm
-
-
Constructor Summary
Constructors Constructor Description MaxSatSolver()
-
Method Summary
Modifier and Type Method Description protected static StringconvertToDimacsWcnf(Collection<PlFormula> hardConstraints, Map<PlFormula,Integer> softConstraints, List<Proposition> props)Converts the given MaxSAT instance (i.e.static intcostOf(net.sf.tweety.commons.Interpretation<PlBeliefSet,PlFormula> interpretation, Collection<PlFormula> hardConstraints, Map<PlFormula,Integer> softConstraints)Returns the cost of the given interpretation, i.e.protected static FilecreateTmpDimacsWcnfFile(Collection<PlFormula> hardConstraints, Map<PlFormula,Integer> softConstraints, List<Proposition> props)Converts the given MaxSAT instance (i.e.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.abstract net.sf.tweety.commons.Interpretation<PlBeliefSet,PlFormula>getWitness(Collection<PlFormula> hardConstraints, Map<PlFormula,Integer> softConstraints)Returns an interpretation with maximal weight on the soft constraints (or null if the hard constraints are not satisfiable)booleanisSatisfiable(Collection<PlFormula> formulas)Checks whether the given set of formulas is satisfiable.static voidsetTempFolder(File tempFolder)Set the folder for temporary files created by a MaxSAT solver.-
Methods inherited from class net.sf.tweety.logics.pl.sat.SatSolver
convertToDimacs, convertToDimacs, createTmpDimacsFile, createTmpDimacsFile, getDefaultSolver, getWitness, getWitness, hasDefaultSolver, isConsistent, isConsistent, isConsistent, setDefaultSolver
-
-
-
-
Method Detail
-
setTempFolder
public static void setTempFolder(File tempFolder)
Set the folder for temporary files created by a MaxSAT solver.- Parameters:
tempFolder- some temp folder.
-
getWitness
public abstract net.sf.tweety.commons.Interpretation<PlBeliefSet,PlFormula> getWitness(Collection<PlFormula> hardConstraints, Map<PlFormula,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 formulassoftConstraints- 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)
-
getWitness
public net.sf.tweety.commons.Interpretation<PlBeliefSet,PlFormula> getWitness(Collection<PlFormula> formulas)
Description copied from class:SatSolverIf the collection of formulas is consistent this method returns some model of it or, if it is inconsistent, null.- Specified by:
getWitnessin interfacenet.sf.tweety.logics.commons.analysis.ConsistencyWitnessProvider<PlBeliefSet,PlFormula>- Specified by:
getWitnessin classSatSolver- Returns:
- some model of the formulas or null.
-
isSatisfiable
public boolean isSatisfiable(Collection<PlFormula> formulas)
Description copied from class:SatSolverChecks whether the given set of formulas is satisfiable.- Specified by:
isSatisfiablein classSatSolver- Parameters:
formulas- a set of formulas.- Returns:
- "true" if the set is consistent.
-
convertToDimacsWcnf
protected static String convertToDimacsWcnf(Collection<PlFormula> hardConstraints, Map<PlFormula,Integer> softConstraints, List<Proposition> props) throws 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 formulassoftConstraints- a map mapping clauses to weightsprops- a list of propositions (=signature) where the indices are used for writing the clauses.- Returns:
- a string in Dimacs CNF.
- Throws:
IllegalArgumentException- if any soft constraint is not a clause.
-
createTmpDimacsWcnfFile
protected static File createTmpDimacsWcnfFile(Collection<PlFormula> hardConstraints, Map<PlFormula,Integer> softConstraints, List<Proposition> props) throws 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 formulassoftConstraints- a map mapping clauses to weightsprops- a list of propositions (=signature) where the indices are used for writing the clauses.- Returns:
- a string in Dimacs CNF.
- Throws:
IOException- if some file issue occursIllegalArgumentException- if any soft constraint is not a clause.
-
costOf
public static int costOf(net.sf.tweety.commons.Interpretation<PlBeliefSet,PlFormula> interpretation, Collection<PlFormula> hardConstraints, Map<PlFormula,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 interpretationhardConstraints- a set of hard constraintssoftConstraints- a set of soft constraints- Returns:
- the cost of the interpretation
-
-