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>

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
  • Constructor Details

    • ClingoSolver

      public ClingoSolver(String pathToClingo, Shell bash)
      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 (see ASPSolver.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

      public ClingoSolver(String pathToClingo)
      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 (see ASPSolver.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

      public ClingoSolver(String pathToClingo, int maxNOfModels)
      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

      public String getOptimumString() throws SolverException
      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

      public List<Integer> getOptimum(String p)
      Parameters:
      p - problem to be solved
      Returns:
      optima
    • 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.
    • getModels

      public List<AnswerSet> getModels(Program p)
      Description copied from interface: ModelProvider
      Returns a characterizing model of the given belief base
      Specified by:
      getModels in interface ModelProvider<ASPRule,Program,AnswerSet>
      Specified by:
      getModels in class ASPSolver
      Parameters:
      p - some belief base
      Returns:
      the (selected) models of the belief base
    • getModels

      public List<AnswerSet> getModels(String s)
      Description copied from class: ASPSolver
      Returns a characterizing model (answer set) of the given belief base.
      Specified by:
      getModels in class ASPSolver
      Parameters:
      s - containing belief base
      Returns:
      AnswerSet
    • getModels

      public List<AnswerSet> getModels(File file)
      Description copied from class: ASPSolver
      Returns a characterizing model (answer set) of the given belief base.
      Specified by:
      getModels in class ASPSolver
      Parameters:
      file - containing belief base
      Returns:
      AnswerSet
    • getOptimum

      public List<Integer> getOptimum(Program p)
      Computes the optimum of a program that contains optimization statements, if there is one. Note: This methods calculates only the optimum and returns no answer sets.
      Parameters:
      p - ASP program
      Returns:
      list of calculated optima
    • query

      public Boolean query(Program beliefbase, ASPLiteral formula)
      Description copied from interface: Reasoner
      Queries the given belief base for the given formula.
      Specified by:
      query in interface QualitativeReasoner<Program,ASPLiteral>
      Specified by:
      query in interface Reasoner<Boolean,Program,ASPLiteral>
      Specified by:
      query in class ASPSolver
      Parameters:
      beliefbase - a belief base
      formula - a formula
      Returns:
      the answer to the query
    • query

      public Boolean query(Program beliefbase, ASPLiteral formula, InferenceMode inferenceMode)
    • 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(String options)
      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

      public void setPathToClingo(String path)
      Sets the location of the Clingo solver on the hard drive.
      Parameters:
      path - path to Clingo
    • isInstalled

      public boolean isInstalled()
      Returns:
      if the solver is installed