lp.trans
Class Solver<M>

java.lang.Object
  extended by lp.trans.Solver<M>
Direct Known Subclasses:
DlpSolver, EvolpSolver, LpSolver

public abstract class Solver<M>
extends Object

An abstract class that contains common functionality of classes used to compute stable models of grounded logic programs (LpSolver, DlpSolver and EvolpSolver). The inheriting classes differ in the way they interprete the resulting models (they may throw some computed atoms away or transform them to different atoms).

Version:
1.0.0
Author:
Martin Slota
See Also:
LpSolver, DlpSolver, EvolpSolver

Field Summary
private  LparseWrapper lw
          An LparseWrapper instance used to execute lparse before executing smodels.
private  int modelCount
          Number of models that were computed.
private  LpPrinter<Writer> printer
          The printer used to write a logic program to the LparseWrapper.
private  SmodelsWrapper sw
          An SmodelsWrapper instance used to compute the stable models.
 
Constructor Summary
Solver(LparseWrapper lparseWrapper, SmodelsWrapper smodelsWrapper)
          Creates a new instance of that uses the given objects to invoke lparse and smodels when computing the stable models.
 
Method Summary
 int getModelCount()
          Returns the number of models that were computed.
protected static String getNextModelString(BufferedReader smodelsOutput)
          Returns the string containing space-separated atoms in the next model computed by smodels.
protected abstract  M parseModel(String modelString)
          Parses modelString and returns the model that it represents.
 void setLparsePath(String lparsePath)
          Sets the path to lparse binary that is used to invoke lparse.
 void setModelLimit(int modelLimit)
          Sets the maximum number of stable models that should be computed by smodels.
 void setSmodelsPath(String smodelsPath)
          Sets the path to smodels binary that is used to invoke smodels.
 void solve(LogicProgram program, Consumer<M> consumer)
          Computes the stable models of the grounded logic program program and passes them to consumer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lw

private final LparseWrapper lw
An LparseWrapper instance used to execute lparse before executing smodels.


sw

private final SmodelsWrapper sw
An SmodelsWrapper instance used to compute the stable models.


printer

private final LpPrinter<Writer> printer
The printer used to write a logic program to the LparseWrapper.


modelCount

private int modelCount
Number of models that were computed.

Constructor Detail

Solver

public Solver(LparseWrapper lparseWrapper,
              SmodelsWrapper smodelsWrapper)
Creates a new instance of that uses the given objects to invoke lparse and smodels when computing the stable models.

Parameters:
lparseWrapper - the object used to execute lparse
smodelsWrapper - the object used to execute smodels
Method Detail

setLparsePath

public void setLparsePath(String lparsePath)
Sets the path to lparse binary that is used to invoke lparse.

Parameters:
lparsePath - path to the lparse binary
Throws:
IllegalArgumentException - if lparsePath is null or an empty string

setSmodelsPath

public void setSmodelsPath(String smodelsPath)
Sets the path to smodels binary that is used to invoke smodels.

Parameters:
smodelsPath - path to the smodels binary
Throws:
IllegalArgumentException - if smodelsPath is null or an empty string

setModelLimit

public void setModelLimit(int modelLimit)
Sets the maximum number of stable models that should be computed by smodels. If set to zero, all models will be computed.

Parameters:
modelLimit - the maximum number of stable models that should be computed by smodels.
Throws:
IllegalArgumentException - if modelLimit is negative

solve

public void solve(LogicProgram program,
                  Consumer<M> consumer)
Computes the stable models of the grounded logic program program and passes them to consumer.

Parameters:
program - logic program whose stable models should be computed
consumer - object that processes the resulting models
Throws:
IllegalArgumentException - if program has not been grounded yet
IOException - (wrapped in an ExceptionAdapter) if an I/O error occurs while manipulating the standard input and output streams of an lparse process
WrapperException - if an error occurs while calling lparse or smodels, see LparseWrapper.waitFor() and SmodelsWrapper.waitFor().
LpParserException - if an error occurs while the resulting models are being converted to their object representation (probably indicates a bug in this class)

getModelCount

public int getModelCount()
Returns the number of models that were computed.

Returns:
as specified above

getNextModelString

protected static String getNextModelString(BufferedReader smodelsOutput)
                                    throws IOException
Returns the string containing space-separated atoms in the next model computed by smodels.

Parameters:
smodelsOutput - reader of the output of smodels
Returns:
as specified above
Throws:
IOException

parseModel

protected abstract M parseModel(String modelString)
Parses modelString and returns the model that it represents.

Parameters:
modelString - a string representation of a model returned by smodels
Returns:
the object representation of the model
Throws:
LpParserException - if an error occurs while the resulting models are being converted to their object representation (probably indicates a bug in this class)