Package net.sf.tweety.lp.asp.reasoner
Class ClingoSolver
- java.lang.Object
-
- net.sf.tweety.lp.asp.reasoner.ASPSolver
-
- net.sf.tweety.lp.asp.reasoner.ClingoSolver
-
- All Implemented Interfaces:
ModelProvider<ASPRule,Program,AnswerSet>
,QualitativeReasoner<Program,ASPLiteral>
,Reasoner<java.lang.Boolean,Program,ASPLiteral>
public class ClingoSolver extends ASPSolver
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
-
-
Field Summary
Fields Modifier and Type Field Description private Shell
bash
Shell to run Clingoprivate java.lang.String
options
Additional command line options for Clingo.protected java.lang.String
pathToSolver
String representation of Clingo binary path, meaning the location of the clingo, clasp and grinco executables on the hard drive.private boolean
usePredicateWhitelist
If activated (toggleOutputWhitelist(boolean)
), output answer sets will only contain atoms over predicates in the program's predicate whitelist.-
Fields inherited from class net.sf.tweety.lp.asp.reasoner.ASPSolver
integerMaximum, maxNumOfModels, outputData
-
-
Constructor Summary
Constructors Constructor Description ClingoSolver(java.lang.String path2clingo)
Constructs a new instance pointing to specific a Clingo solver.ClingoSolver(java.lang.String path2clingo, Shell bash)
Constructs a new instance pointing to a specific Clingo solver.
-
Method Summary
Modifier and Type Method Description AnswerSet
getModel(Program p)
Returns a single (dedicated) model of the given belief base.java.util.List<AnswerSet>
getModels(java.io.File file)
Returns a characterizing model (answer set) of the given belief base.java.util.List<AnswerSet>
getModels(java.lang.String s)
Returns a characterizing model (answer set) of the given belief base.java.util.List<AnswerSet>
getModels(Program p)
Returns a characterizing model of the given belief baseprivate java.util.List<AnswerSet>
parseResult(java.lang.String output)
Parses output from Clingo solver to AnswerSetList.java.lang.Boolean
query(Program beliefbase, ASPLiteral formula)
Queries the given belief base for the given formula.java.lang.Boolean
query(Program beliefbase, ASPLiteral formula, InferenceMode inferenceMode)
void
setOptions(java.lang.String options)
Set additional command line options for Clingo.void
setPathToDLV(java.lang.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 net.sf.tweety.lp.asp.reasoner.ASPSolver
getIntegerMaximum, getMaxNumOfModels, getModel, getModels, getOutput, setIntegerMaximum, setMaxNumOfModels
-
-
-
-
Field Detail
-
pathToSolver
protected java.lang.String pathToSolver
String representation of Clingo binary path, meaning the location of the clingo, clasp and grinco executables on the hard drive.
-
bash
private Shell bash
Shell to run Clingo
-
usePredicateWhitelist
private boolean usePredicateWhitelist
If activated (toggleOutputWhitelist(boolean)
), output answer sets will only contain atoms over predicates in the program's predicate whitelist. This corresponds to the #show statement of the clingo input language.
-
options
private java.lang.String options
Additional command line options for Clingo. Default value is empty.
-
-
Constructor Detail
-
ClingoSolver
public ClingoSolver(java.lang.String path2clingo, Shell bash)
Constructs a new instance pointing to a specific Clingo solver.- Parameters:
path2clingo
- binary location of Clingo on the hard drivebash
- shell to run commands
-
ClingoSolver
public ClingoSolver(java.lang.String path2clingo)
Constructs a new instance pointing to specific a Clingo solver.- Parameters:
path2clingo
- binary location of Clingo on the hard drive
-
-
Method Detail
-
getModels
public java.util.List<AnswerSet> getModels(Program p)
Description copied from interface:ModelProvider
Returns a characterizing model of the given belief base
-
parseResult
private java.util.List<AnswerSet> parseResult(java.lang.String output) throws SolverException, ParseException
Parses output from Clingo solver to AnswerSetList.- Parameters:
output
- the output string- Returns:
- AnswerSetList
- Throws:
SolverException
- if the solver had an issueParseException
- if parsing failed
-
getModels
public java.util.List<AnswerSet> getModels(java.lang.String s)
Description copied from class:ASPSolver
Returns a characterizing model (answer set) of the given belief base.
-
getModels
public java.util.List<AnswerSet> getModels(java.io.File file)
Description copied from class:ASPSolver
Returns a characterizing model (answer set) of the given belief base.
-
query
public java.lang.Boolean query(Program beliefbase, ASPLiteral formula)
Description copied from interface:Reasoner
Queries the given belief base for the given formula.- Specified by:
query
in interfaceQualitativeReasoner<Program,ASPLiteral>
- Specified by:
query
in interfaceReasoner<java.lang.Boolean,Program,ASPLiteral>
- Specified by:
query
in classASPSolver
- Parameters:
beliefbase
- a belief baseformula
- a formula- Returns:
- the answer to the query
-
query
public java.lang.Boolean query(Program beliefbase, ASPLiteral formula, InferenceMode inferenceMode)
-
getModel
public AnswerSet getModel(Program p)
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.
-
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
public void setOptions(java.lang.String options)
Set additional command line options for Clingo.- Parameters:
options
- a string of options
-
setPathToDLV
public void setPathToDLV(java.lang.String path)
Sets the location of the Clingo solver on the hard drive.- Parameters:
path
- path to DLV
-
-