Class ClingoSolver
java.lang.Object
org.tweetyproject.lp.asp.reasoner.ASPSolver
org.tweetyproject.lp.asp.reasoner.ClingoSolver
- All Implemented Interfaces:
ModelProvider<ASPRule,
,Program, AnswerSet> QualitativeReasoner<Program,
,ASPLiteral> Reasoner<Boolean,
Program, ASPLiteral>
Invokes Clingo (Part of the Potassco
project), an ASP system that grounds and solves logic programs, and
returns computed answer sets.
- Author:
- Nils Geilen, Matthias Thimm, Anna Gessler
-
Constructor Summary
ConstructorDescriptionClingoSolver
(String pathToClingo) Constructs a new instance pointing to a specific Clingo solver.ClingoSolver
(String pathToClingo, int maxNOfModels) Constructs a new instance pointing to a specific Clingo solver.ClingoSolver
(String pathToClingo, Shell bash) Constructs a new instance pointing to a specific Clingo solver. -
Method Summary
Modifier and TypeMethodDescriptionReturns a single (dedicated) model of the given belief base.Returns a characterizing model (answer set) of the given belief base.Returns a characterizing model (answer set) of the given belief base.Returns a characterizing model of the given belief basegetOptimum
(String p) Computes the optimum of a program that contains optimization statements, if there is one.Returns the optimum of the previously solved program, if there is one.boolean
Checks whether the underlying solver or reasoning mechanism used by this reasoner is installed and available for use.query
(Program beliefbase, ASPLiteral formula) Queries the given belief base with the provided formula and returns a boolean result.query
(Program beliefbase, ASPLiteral formula, InferenceMode inferenceMode) Evaluates a query on the given belief base using the specified inference mode.void
setOptions
(String options) Set the command line options for Clingo.void
setPathToClingo
(String path) Sets the location of the Clingo solver on the hard drive.void
toggleOutputWhitelist
(boolean b) Activates or deactivates the option to use a whitelist of predicates.Methods inherited from class org.tweetyproject.lp.asp.reasoner.ASPSolver
getIntegerMaximum, getMaxNumOfModels, getModel, getModels, getOutput, setIntegerMaximum, setMaxNumOfModels
-
Constructor Details
-
ClingoSolver
Constructs a new instance pointing to a specific Clingo solver. The maximum number of models that Clingo will compute is set to the default value (seeASPSolver.maxNumOfModels
).- Parameters:
pathToClingo
- binary location of Clingo on the hard drive. The given location has to contain a binary called "clingo". Do not include the binary itself in the path.bash
- shell to run commands
-
ClingoSolver
Constructs a new instance pointing to a specific Clingo solver. The maximum number of models that Clingo will compute is set to the default value (seeASPSolver.maxNumOfModels
).- Parameters:
pathToClingo
- binary location of Clingo on the hard drive. The given location has to contain a binary called "clingo". Do not include the binary itself in the path.
-
ClingoSolver
Constructs a new instance pointing to a specific Clingo solver.- Parameters:
pathToClingo
- binary location of Clingo on the hard drive. The given location has to contain a binary called "clingo". Do not include the binary itself in the path.maxNOfModels
- the maximum number of models that Clingo will compute. Set it to 0 if you want all models.
-
-
Method Details
-
getOptimumString
Returns the optimum of the previously solved program, if there is one.- Returns:
- optimum of previously solved program in string format, i.e. numbers separated by spaces
- Throws:
SolverException
- SolverException
-
getOptimum
-
getModel
Description copied from interface:ModelProvider
Returns a single (dedicated) model of the given belief base. If the implemented method allows for more than one dedicated model, the selection may be non-deterministic.- Parameters:
p
- some belief base- Returns:
- a selected model of the belief base.
-
getModels
Description copied from interface:ModelProvider
Returns a characterizing model of the given belief base -
getModels
-
getModels
-
getOptimum
-
query
Description copied from interface:QualitativeReasoner
Queries the given belief base with the provided formula and returns a boolean result. The result indicates whether the formula is entailed or satisfied by the belief base according to the qualitative reasoning method implemented by the reasoner.- Specified by:
query
in interfaceQualitativeReasoner<Program,
ASPLiteral> - Specified by:
query
in interfaceReasoner<Boolean,
Program, ASPLiteral> - Specified by:
query
in classASPSolver
- Parameters:
beliefbase
- The belief base to be queried.formula
- The formula for which the query is made.- Returns:
- `TRUE` if the formula is entailed or satisfied by the belief base, `FALSE` otherwise.
-
query
Evaluates a query on the given belief base using the specified inference mode.This method checks whether the given formula is entailed by the belief base under the specified inference mode. It retrieves the answer sets of the belief base and checks the presence of the formula in these sets based on the chosen inference mode, either skeptical or credulous.
- Parameters:
beliefbase
- The program representing the belief base to query.formula
- The formula (literal) to be checked within the answer sets.inferenceMode
- The mode of inference, either skeptical or credulous.- Returns:
true
if the formula is entailed by the belief base under the specified inference mode,false
otherwise.
-
toggleOutputWhitelist
public void toggleOutputWhitelist(boolean b) Activates or deactivates the option to use a whitelist of predicates. If activated, answer sets will only contain atoms over predicates that are part of the whitelist. This corresponds to the #show statement of the clingo input language.- Parameters:
b
- whether to use a whitelist of predicate
-
setOptions
Set the command line options for Clingo.- Parameters:
options
- a string of options in the correct format, e.g. in the form "--opt" and separated by spaces
-
setPathToClingo
Sets the location of the Clingo solver on the hard drive.- Parameters:
path
- path to Clingo
-
isInstalled
public boolean isInstalled()Description copied from interface:QualitativeReasoner
Checks whether the underlying solver or reasoning mechanism used by this reasoner is installed and available for use. This can be helpful when the reasoner depends on external tools or libraries for performing the reasoning tasks.- Returns:
- `true` if the solver is installed and available, `false` otherwise.
-