- java.lang.Object
-
- org.logicng.solvers.MaxSATSolver
-
public class MaxSATSolver extends Object
A wrapper for the OpenWBO solver.- Since:
- 1.0
- Version:
- 2.4.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classMaxSATSolver.Algorithm
-
Field Summary
Fields Modifier and Type Field Description protected MaxSATSolver.Algorithmalgorithmprotected MaxSATConfigconfigurationprotected FormulaFactoryfprotected SortedMap<Integer,Variable>index2varprotected MaxSAT.MaxSATResultresultprotected SortedSet<Variable>selectorVariablesprotected MaxSATsolverprotected SortedMap<Variable,Integer>var2index
-
Constructor Summary
Constructors Modifier Constructor Description protectedMaxSATSolver(FormulaFactory f, MaxSATConfig configuration, MaxSATSolver.Algorithm algorithm)Constructs a new MaxSAT solver with a given configuration.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidaddClause(Formula formula, int weight)Adds a clause to the solver.protected voidaddCNF(Formula formula, int weight)Adds a formula which is already in CNF to the solver.voidaddHardFormula(Formula formula)Adds a new hard formula to the solver.voidaddSoftFormula(Formula formula, int weight)Adds a new soft formula to the solver.protected AssignmentcreateAssignment(LNGBooleanVector vec)Creates an assignment from a Boolean vector of the solver.FormulaFactoryfactory()Returns the formula factory for this solver.MaxSATSolver.AlgorithmgetAlgorithm()Returns the algorithm for this solver.static MaxSATSolverincWBO()Deprecated.this factory method without parameter will be removed in the future, useincWBO(FormulaFactory)insteadstatic MaxSATSolverincWBO(FormulaFactory f)Returns a new MaxSAT solver using incremental WBO as algorithm with the MaxSAT configuration from the formula factory.static MaxSATSolverincWBO(FormulaFactory f, MaxSATConfig config)Returns a new MaxSAT solver using incremental WBO as algorithm with the given configuration.static MaxSATSolverincWBO(MaxSATConfig config)Deprecated.this factory method without formula factory will be removed in the future, useincWBO(FormulaFactory, MaxSATConfig)insteadbooleanisWeighted()Returns whether this solver can handle weighted instances or not.static MaxSATSolverlinearSU()Deprecated.this factory method without parameter will be removed in the future, uselinearSU(FormulaFactory)insteadstatic MaxSATSolverlinearSU(FormulaFactory f)Returns a new MaxSAT solver using LinearSU as algorithm with the MaxSAT configuration from the formula factory.static MaxSATSolverlinearSU(FormulaFactory f, MaxSATConfig config)Returns a new MaxSAT solver using LinearSU as algorithm with the given configuration.static MaxSATSolverlinearSU(MaxSATConfig config)Deprecated.this factory method without formula factory will be removed in the future, uselinearSU(FormulaFactory, MaxSATConfig)insteadstatic MaxSATSolverlinearUS()Deprecated.this factory method without parameter will be removed in the future, uselinearUS(FormulaFactory)insteadstatic MaxSATSolverlinearUS(FormulaFactory f)Returns a new MaxSAT solver using LinearUS as algorithm with the MaxSAT configuration from the formula factory.static MaxSATSolverlinearUS(FormulaFactory f, MaxSATConfig config)Returns a new MaxSAT solver using LinearUS as algorithm with the given configuration.static MaxSATSolverlinearUS(MaxSATConfig config)Deprecated.this factory method without formula factory will be removed in the future, uselinearUS(FormulaFactory, MaxSATConfig)insteadAssignmentmodel()Returns the model of the current result.static MaxSATSolvermsu3()Deprecated.this factory method without parameter will be removed in the future, usemsu3(FormulaFactory)insteadstatic MaxSATSolvermsu3(FormulaFactory f)Returns a new MaxSAT solver using MSU3 as algorithm with the MaxSAT configuration from the formula factory.static MaxSATSolvermsu3(FormulaFactory f, MaxSATConfig config)Returns a new MaxSAT solver using MSU3 as algorithm with the given configuration.static MaxSATSolvermsu3(MaxSATConfig config)Deprecated.this factory method without formula factory will be removed in the future, usemsu3(FormulaFactory, MaxSATConfig)insteadstatic MaxSATSolveroll(FormulaFactory f)Returns a new MaxSAT solver using weighted OLL as algorithm with the MaxSAT configuration from the formula factory.static MaxSATSolveroll(FormulaFactory f, MaxSATConfig config)Returns a new MaxSAT solver using weighted OLL as algorithm with the given configuration.voidreset()Resets the solver.intresult()Returns the minimum weight (or number of clauses if unweighted) of clauses which have to be unsatisfied.MaxSAT.MaxSATResultsolve()Solves the formula on the solver and returns the result.MaxSAT.MaxSATResultsolve(MaxSATHandler handler)Solves the formula on the solver and returns the result.MaxSAT.Statsstats()Returns the stats of the underlying solver.StringtoString()static MaxSATSolverwbo()Deprecated.this factory method without parameter will be removed in the future, usewbo(FormulaFactory)insteadstatic MaxSATSolverwbo(FormulaFactory f)Returns a new MaxSAT solver using WBO as algorithm with the MaxSAT configuration from the formula factory.static MaxSATSolverwbo(FormulaFactory f, MaxSATConfig config)Returns a new MaxSAT solver using MSU3 as algorithm with the given configuration.static MaxSATSolverwbo(MaxSATConfig config)Deprecated.this factory method without formula factory will be removed in the future, usewbo(FormulaFactory, MaxSATConfig)insteadstatic MaxSATSolverwmsu3()Deprecated.this factory method without parameter will be removed in the future, usewmsu3(FormulaFactory)insteadstatic MaxSATSolverwmsu3(FormulaFactory f)Returns a new MaxSAT solver using weighted MSU3 as algorithm with the MaxSAT configuration from the formula factory.static MaxSATSolverwmsu3(FormulaFactory f, MaxSATConfig config)Returns a new MaxSAT solver using weighted MSU3 as algorithm with the given configuration.static MaxSATSolverwmsu3(MaxSATConfig config)Deprecated.this factory method without formula factory will be removed in the future, usewmsu3(FormulaFactory, MaxSATConfig)instead
-
-
-
Field Detail
-
configuration
protected final MaxSATConfig configuration
-
algorithm
protected final MaxSATSolver.Algorithm algorithm
-
f
protected FormulaFactory f
-
result
protected MaxSAT.MaxSATResult result
-
solver
protected MaxSAT solver
-
-
Constructor Detail
-
MaxSATSolver
protected MaxSATSolver(FormulaFactory f, MaxSATConfig configuration, MaxSATSolver.Algorithm algorithm)
Constructs a new MaxSAT solver with a given configuration.- Parameters:
f- the formula factoryconfiguration- the configurationalgorithm- the algorithm- Throws:
IllegalArgumentException- if the algorithm was unknown
-
-
Method Detail
-
incWBO
@Deprecated public static MaxSATSolver incWBO()
Deprecated.this factory method without parameter will be removed in the future, useincWBO(FormulaFactory)insteadReturns a new MaxSAT solver using incremental WBO as algorithm with the default configuration.- Returns:
- the MaxSAT solver
-
incWBO
public static MaxSATSolver incWBO(FormulaFactory f)
Returns a new MaxSAT solver using incremental WBO as algorithm with the MaxSAT configuration from the formula factory.- Parameters:
f- the formula factory- Returns:
- the MaxSAT solver
-
incWBO
@Deprecated public static MaxSATSolver incWBO(MaxSATConfig config)
Deprecated.this factory method without formula factory will be removed in the future, useincWBO(FormulaFactory, MaxSATConfig)insteadReturns a new MaxSAT solver using incremental WBO as algorithm with the given configuration.- Parameters:
config- the configuration- Returns:
- the MaxSAT solver
-
incWBO
public static MaxSATSolver incWBO(FormulaFactory f, MaxSATConfig config)
Returns a new MaxSAT solver using incremental WBO as algorithm with the given configuration.- Parameters:
f- the formula factoryconfig- the configuration- Returns:
- the MaxSAT solver
-
linearSU
@Deprecated public static MaxSATSolver linearSU()
Deprecated.this factory method without parameter will be removed in the future, uselinearSU(FormulaFactory)insteadReturns a new MaxSAT solver using LinearSU as algorithm with the default configuration.- Returns:
- the MaxSAT solver
-
linearSU
public static MaxSATSolver linearSU(FormulaFactory f)
Returns a new MaxSAT solver using LinearSU as algorithm with the MaxSAT configuration from the formula factory.- Parameters:
f- the formula factory- Returns:
- the MaxSAT solver
-
linearSU
@Deprecated public static MaxSATSolver linearSU(MaxSATConfig config)
Deprecated.this factory method without formula factory will be removed in the future, uselinearSU(FormulaFactory, MaxSATConfig)insteadReturns a new MaxSAT solver using LinearSU as algorithm with the given configuration.- Parameters:
config- the configuration- Returns:
- the MaxSAT solver
-
linearSU
public static MaxSATSolver linearSU(FormulaFactory f, MaxSATConfig config)
Returns a new MaxSAT solver using LinearSU as algorithm with the given configuration.- Parameters:
config- the configurationf- the formula factory- Returns:
- the MaxSAT solver
-
linearUS
@Deprecated public static MaxSATSolver linearUS()
Deprecated.this factory method without parameter will be removed in the future, uselinearUS(FormulaFactory)insteadReturns a new MaxSAT solver using LinearUS as algorithm with the default configuration.- Returns:
- the MaxSAT solver
-
linearUS
public static MaxSATSolver linearUS(FormulaFactory f)
Returns a new MaxSAT solver using LinearUS as algorithm with the MaxSAT configuration from the formula factory.- Parameters:
f- the formula factory- Returns:
- the MaxSAT solver
-
linearUS
@Deprecated public static MaxSATSolver linearUS(MaxSATConfig config)
Deprecated.this factory method without formula factory will be removed in the future, uselinearUS(FormulaFactory, MaxSATConfig)insteadReturns a new MaxSAT solver using LinearUS as algorithm with the given configuration.- Parameters:
config- the configuration- Returns:
- the MaxSAT solver
-
linearUS
public static MaxSATSolver linearUS(FormulaFactory f, MaxSATConfig config)
Returns a new MaxSAT solver using LinearUS as algorithm with the given configuration.- Parameters:
config- the configurationf- the formula factory- Returns:
- the MaxSAT solver
-
msu3
@Deprecated public static MaxSATSolver msu3()
Deprecated.this factory method without parameter will be removed in the future, usemsu3(FormulaFactory)insteadReturns a new MaxSAT solver using MSU3 as algorithm with the default configuration.- Returns:
- the MaxSAT solver
-
msu3
public static MaxSATSolver msu3(FormulaFactory f)
Returns a new MaxSAT solver using MSU3 as algorithm with the MaxSAT configuration from the formula factory.- Parameters:
f- the formula factory- Returns:
- the MaxSAT solver
-
msu3
@Deprecated public static MaxSATSolver msu3(MaxSATConfig config)
Deprecated.this factory method without formula factory will be removed in the future, usemsu3(FormulaFactory, MaxSATConfig)insteadReturns a new MaxSAT solver using MSU3 as algorithm with the given configuration.- Parameters:
config- the configuration- Returns:
- the MaxSAT solver
-
msu3
public static MaxSATSolver msu3(FormulaFactory f, MaxSATConfig config)
Returns a new MaxSAT solver using MSU3 as algorithm with the given configuration.- Parameters:
config- the configurationf- the formula factory- Returns:
- the MaxSAT solver
-
wbo
@Deprecated public static MaxSATSolver wbo()
Deprecated.this factory method without parameter will be removed in the future, usewbo(FormulaFactory)insteadReturns a new MaxSAT solver using WBO as algorithm with the default configuration.- Returns:
- the MaxSAT solver
-
wbo
public static MaxSATSolver wbo(FormulaFactory f)
Returns a new MaxSAT solver using WBO as algorithm with the MaxSAT configuration from the formula factory.- Parameters:
f- the formula factory- Returns:
- the MaxSAT solver
-
wbo
@Deprecated public static MaxSATSolver wbo(MaxSATConfig config)
Deprecated.this factory method without formula factory will be removed in the future, usewbo(FormulaFactory, MaxSATConfig)insteadReturns a new MaxSAT solver using MSU3 as algorithm with the given configuration.- Parameters:
config- the configuration- Returns:
- the MaxSAT solver
-
wbo
public static MaxSATSolver wbo(FormulaFactory f, MaxSATConfig config)
Returns a new MaxSAT solver using MSU3 as algorithm with the given configuration.- Parameters:
config- the configurationf- the formula factory- Returns:
- the MaxSAT solver
-
wmsu3
@Deprecated public static MaxSATSolver wmsu3()
Deprecated.this factory method without parameter will be removed in the future, usewmsu3(FormulaFactory)insteadReturns a new MaxSAT solver using weighted MSU3 as algorithm with the default configuration.- Returns:
- the MaxSAT solver
-
wmsu3
public static MaxSATSolver wmsu3(FormulaFactory f)
Returns a new MaxSAT solver using weighted MSU3 as algorithm with the MaxSAT configuration from the formula factory.- Parameters:
f- the formula factory- Returns:
- the MaxSAT solver
-
wmsu3
@Deprecated public static MaxSATSolver wmsu3(MaxSATConfig config)
Deprecated.this factory method without formula factory will be removed in the future, usewmsu3(FormulaFactory, MaxSATConfig)insteadReturns a new MaxSAT solver using weighted MSU3 as algorithm with the given configuration.- Parameters:
config- the configuration- Returns:
- the MaxSAT solver
-
wmsu3
public static MaxSATSolver wmsu3(FormulaFactory f, MaxSATConfig config)
Returns a new MaxSAT solver using weighted MSU3 as algorithm with the given configuration.- Parameters:
config- the configurationf- the formula factory- Returns:
- the MaxSAT solver
-
oll
public static MaxSATSolver oll(FormulaFactory f)
Returns a new MaxSAT solver using weighted OLL as algorithm with the MaxSAT configuration from the formula factory.- Parameters:
f- the formula factory- Returns:
- the MaxSAT solver
-
oll
public static MaxSATSolver oll(FormulaFactory f, MaxSATConfig config)
Returns a new MaxSAT solver using weighted OLL as algorithm with the given configuration.- Parameters:
config- the configurationf- the formula factory- Returns:
- the MaxSAT solver
-
isWeighted
public boolean isWeighted()
Returns whether this solver can handle weighted instances or not.- Returns:
- whether this solver can handle weighted instances or not
-
reset
public void reset()
Resets the solver.- Throws:
IllegalArgumentException- if the algorithm was unknown
-
addHardFormula
public void addHardFormula(Formula formula)
Adds a new hard formula to the solver. Hard formulas must always be true.- Parameters:
formula- the formula- Throws:
IllegalStateException- if a formula is added to a solver which is already solved.
-
addSoftFormula
public void addSoftFormula(Formula formula, int weight)
Adds a new soft formula to the solver.- Parameters:
formula- the formulaweight- the weight- Throws:
IllegalStateException- if a formula is added to a solver which is already solved.IllegalArgumentException- if the weight is <1
-
addCNF
protected void addCNF(Formula formula, int weight)
Adds a formula which is already in CNF to the solver.- Parameters:
formula- the formula in CNFweight- the weight of this CNF (or -1 for a hard constraint)
-
addClause
protected void addClause(Formula formula, int weight)
Adds a clause to the solver.- Parameters:
formula- the clauseweight- the weight of the clause (or -1 for a hard clause)
-
solve
public MaxSAT.MaxSATResult solve()
Solves the formula on the solver and returns the result.- Returns:
- the result (SAT, UNSAT, Optimum found)
-
solve
public MaxSAT.MaxSATResult solve(MaxSATHandler handler)
Solves the formula on the solver and returns the result.- Parameters:
handler- a MaxSAT handler- Returns:
- the result (SAT, UNSAT, Optimum found, or UNDEF if canceled by the handler)
-
result
public int result()
Returns the minimum weight (or number of clauses if unweighted) of clauses which have to be unsatisfied. Therefore, if the minimum number of weights is 0, the formula is satisfiable.- Returns:
- the minimum weight of clauses which have to be unsatisfied
- Throws:
IllegalStateException- if the formula is not yet solved
-
model
public Assignment model()
Returns the model of the current result.- Returns:
- the model of the current result
- Throws:
IllegalStateException- if the formula is not yet solved
-
createAssignment
protected Assignment createAssignment(LNGBooleanVector vec)
Creates an assignment from a Boolean vector of the solver.- Parameters:
vec- the vector of the solver- Returns:
- the assignment
-
stats
public MaxSAT.Stats stats()
Returns the stats of the underlying solver.- Returns:
- the stats of the underlying solver
-
getAlgorithm
public MaxSATSolver.Algorithm getAlgorithm()
Returns the algorithm for this solver.- Returns:
- the algorithm
-
factory
public FormulaFactory factory()
Returns the formula factory for this solver.- Returns:
- the formula factory
-
-