- java.lang.Object
-
- org.logicng.solvers.maxsat.algorithms.MaxSAT
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMaxSAT.MaxSATResultThe MaxSAT result type:SATISFIABLE,UNSATISFIABLE,OPTIMUM, orUNDEF.static classMaxSAT.ProblemTypeThe MaxSAT problem type:UNWEIGHTEDorWEIGHTED.classMaxSAT.StatsThe MaxSAT solver statistics.
-
Field Summary
Fields Modifier and Type Field Description protected MaxSATHandlerhandlerprotected LNGBooleanVectormodelprotected MaxSATConfig.Verbosityverbosity
-
Constructor Summary
Constructors Modifier Constructor Description protectedMaxSAT(MaxSATConfig config)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddHardClause(LNGIntVector lits)Adds a new hard clause to the hard clause database.voidaddSoftClause(int weight, LNGIntVector lits)Adds a new soft clause to the soft clause database.voidaddSoftClause(int weight, LNGIntVector lits, LNGIntVector vars)Adds a new soft clause to the soft clause database with predefined relaxation variables.intcomputeCostModel(LNGBooleanVector currentModel, int weight)Computes the cost of a given model.intcurrentWeight()Returns the current weight.booleanisBMO(boolean cache)Tests if the MaxSAT formula has lexicographical optimization criterion.LNGBooleanVectormodel()Returns the model of the solver.intnewLiteral(boolean sign)Creates a new literal to be used in the working MaxSAT formula.MiniSatStyleSolvernewSATSolver()Creates an empty SAT Solver.static voidnewSATVariable(MiniSatStyleSolver s)Creates a new variable in the SAT solver.voidnewVar()Increases the number of variables in the working MaxSAT formula.intnHard()Returns the number of hard clauses in the working MaxSAT formula.intnSoft()Returns the number of soft clauses in the working MaxSAT formula.intnVars()Returns the number of variables in the working MaxSAT formula.intresult()Returns the optimal result of the solver.voidsaveModel(LNGBooleanVector currentModel)Saves the current model found by the SAT solver.abstract MaxSAT.MaxSATResultsearch()The main MaxSAT solving method.MaxSAT.MaxSATResultsearch(MaxSATHandler handler)The main MaxSAT solving method.static TristatesearchSATSolver(MiniSatStyleSolver s, SATHandler satHandler)Solves the formula without assumptions.static TristatesearchSATSolver(MiniSatStyleSolver s, SATHandler satHandler, LNGIntVector assumptions)Solves the formula that is currently loaded in the SAT solver with a set of assumptions.voidsetCurrentWeight(int weight)Initializes the current weight to the maximum weight of the soft clauses.voidsetProblemType(MaxSAT.ProblemType type)Sets the problem type.MaxSAT.Statsstats()Returns the stats of this solver instance.voidupdateSumWeights(int weight)Initializes 'ubCost' to the sum of weights of the soft clauses
-
-
-
Field Detail
-
model
protected final LNGBooleanVector model
-
verbosity
protected MaxSATConfig.Verbosity verbosity
-
handler
protected MaxSATHandler handler
-
-
Constructor Detail
-
MaxSAT
protected MaxSAT(MaxSATConfig config)
Constructor.- Parameters:
config- the solver configuration
-
-
Method Detail
-
newSATVariable
public static void newSATVariable(MiniSatStyleSolver s)
Creates a new variable in the SAT solver.- Parameters:
s- the SAT solver
-
searchSATSolver
public static Tristate searchSATSolver(MiniSatStyleSolver s, SATHandler satHandler, LNGIntVector assumptions)
Solves the formula that is currently loaded in the SAT solver with a set of assumptions.- Parameters:
s- the SAT solversatHandler- a SAT handlerassumptions- the assumptions- Returns:
- the result of the solving process
-
searchSATSolver
public static Tristate searchSATSolver(MiniSatStyleSolver s, SATHandler satHandler)
Solves the formula without assumptions.- Parameters:
s- the SAT solversatHandler- a SAT handler- Returns:
- the result of the solving process
-
search
public final MaxSAT.MaxSATResult search(MaxSATHandler handler)
The main MaxSAT solving method.- Parameters:
handler- a MaxSAT handler- Returns:
- the result of the solving process
- Throws:
IllegalArgumentException- if the configuration was not valid
-
search
public abstract MaxSAT.MaxSATResult search()
The main MaxSAT solving method.- Returns:
- the result of the solving process
- Throws:
IllegalArgumentException- if the configuration was not valid
-
nVars
public int nVars()
Returns the number of variables in the working MaxSAT formula.- Returns:
- the number of variables in the working MaxSAT formula
-
nSoft
public int nSoft()
Returns the number of soft clauses in the working MaxSAT formula.- Returns:
- the number of soft clauses in the working MaxSAT formula
-
nHard
public int nHard()
Returns the number of hard clauses in the working MaxSAT formula.- Returns:
- the number of hard clauses in the working MaxSAT formula
-
newVar
public void newVar()
Increases the number of variables in the working MaxSAT formula.
-
addHardClause
public void addHardClause(LNGIntVector lits)
Adds a new hard clause to the hard clause database.- Parameters:
lits- the literals of the hard clause
-
addSoftClause
public void addSoftClause(int weight, LNGIntVector lits)Adds a new soft clause to the soft clause database.- Parameters:
weight- the weight of the soft clauselits- the literals of the soft clause
-
addSoftClause
public void addSoftClause(int weight, LNGIntVector lits, LNGIntVector vars)Adds a new soft clause to the soft clause database with predefined relaxation variables.- Parameters:
weight- the weight of the soft clauselits- the literals of the soft clausevars- the relaxation variables of the soft clause
-
newLiteral
public int newLiteral(boolean sign)
Creates a new literal to be used in the working MaxSAT formula.- Parameters:
sign- the sign of the literal- Returns:
- the new literal
-
setProblemType
public void setProblemType(MaxSAT.ProblemType type)
Sets the problem type.- Parameters:
type- the problem type
-
updateSumWeights
public void updateSumWeights(int weight)
Initializes 'ubCost' to the sum of weights of the soft clauses- Parameters:
weight- the weight
-
setCurrentWeight
public void setCurrentWeight(int weight)
Initializes the current weight to the maximum weight of the soft clauses.- Parameters:
weight- the weight
-
currentWeight
public int currentWeight()
Returns the current weight.- Returns:
- the current weight
-
newSATSolver
public MiniSatStyleSolver newSATSolver()
Creates an empty SAT Solver.- Returns:
- the empty SAT solver
-
saveModel
public void saveModel(LNGBooleanVector currentModel)
Saves the current model found by the SAT solver.- Parameters:
currentModel- the model found by the solver
-
computeCostModel
public int computeCostModel(LNGBooleanVector currentModel, int weight)
Computes the cost of a given model. The cost of a model is the sum of the weights of the unsatisfied soft clauses. If a weight is specified, then it only considers the sum of the weights of the unsatisfied soft clauses with the specified weight.- Parameters:
currentModel- the modelweight- the weight- Returns:
- the cost of the given model
-
isBMO
public boolean isBMO(boolean cache)
Tests if the MaxSAT formula has lexicographical optimization criterion.- Parameters:
cache- is indicates whether the result should be cached.- Returns:
trueif the formula has lexicographical optimization criterion
-
stats
public MaxSAT.Stats stats()
Returns the stats of this solver instance.- Returns:
- the stats of this solver instance
-
result
public int result()
Returns the optimal result of the solver.- Returns:
- the optimal result of the solver
-
model
public LNGBooleanVector model()
Returns the model of the solver.- Returns:
- the model of the solver
-
-