|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectlp.trans.Solver<M>
public abstract class Solver<M>
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).
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 |
---|
private final LparseWrapper lw
LparseWrapper
instance used to execute lparse before executing
smodels.
private final SmodelsWrapper sw
SmodelsWrapper
instance used to compute the stable models.
private final LpPrinter<Writer> printer
LparseWrapper
.
private int modelCount
Constructor Detail |
---|
public Solver(LparseWrapper lparseWrapper, SmodelsWrapper smodelsWrapper)
lparseWrapper
- the object used to execute lparsesmodelsWrapper
- the object used to execute smodelsMethod Detail |
---|
public void setLparsePath(String lparsePath)
lparsePath
- path to the lparse binary
IllegalArgumentException
- if lparsePath
is null
or
an empty stringpublic void setSmodelsPath(String smodelsPath)
smodelsPath
- path to the smodels binary
IllegalArgumentException
- if smodelsPath
is null
or an empty stringpublic void setModelLimit(int modelLimit)
modelLimit
- the maximum number of stable models that should be
computed by smodels.
IllegalArgumentException
- if modelLimit
is negativepublic void solve(LogicProgram program, Consumer<M> consumer)
program
and passes them to consumer
.
program
- logic program whose stable models should be computedconsumer
- object that processes the resulting models
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)public int getModelCount()
protected static String getNextModelString(BufferedReader smodelsOutput) throws IOException
smodelsOutput
- reader of the output of smodels
IOException
protected abstract M parseModel(String modelString)
modelString
and returns the model that it represents.
modelString
- a string representation of a model returned by smodels
LpParserException
- if an error occurs while the resulting models
are being converted to their object representation (probably indicates a
bug in this class)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |