|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectDLV.DlvHandler
This is a wrapper class that allows to call DLV from a Java program.
Three methods of invocation are supplied: synchronous, model synchronous and asynchronous mode.
In the first method, the thread that starts DLV is blocked until DLV finishes computation and then it is possible to get the output.
In the second and in the third method, we don't wait until DLV terminated computation, but we can check dynamically whether dlv outputs further models.
In the model synchronous case the calling thread is blocked until a new model is computed by dlv or until dlv ends.
In the asynchronous case the calling thread is never blocked.
This class allows to set all DLV invocation parameters.
When a Dlv object is created default DLV invocation parameters are automatically set.
Ex. How to do a model synchronous dlv invocation // prepare input Program p=new Program(); // creates a new program p.addString(":- a, not b."); // adds a constraint using a String object p.addProgramFile("c:\myProgramFile.dl"); // adds a text file containing a program // build a manager (a Dlv instance) Dlv dlv=new Dlv("c:\dl.exe"); // builds a manager object and set the dlv executable full pathname dlv.setProgram(p); // sets input (contained in a Program object) // set invocation parameters dlv.setNumberOfModels(2); // sets the number of models to be generated by DLV dlv.setFilter(new String[]{"a"}); // sets a -filter=a option dlv.setIncludeFacts(false); // sets -nofacts option ... // call DLV try {dlv.run(Dlv.MODEL_SYNCHRONOUS); // run a DLV process and set the output handling method. while(dlv.hasMoreModels()) // waits while DLV outputs a new model { Model m=dlv.nextModel(); // gets a Model object if(!m.isNoModel()) { while(m.hasMorePredicates()) // work with Predicates contained in m { Predicate p=m.nextPredicate() // gets a Predicate object ... // do something with p } } ... // do something else with m } ... } catch(DLVException d) { d.printStackTrace(); } catch(DLVExceptionUncheked d) { d.printStackTrace(); } finally { System.err.println(dlv.getWarnings()); // handle DLV errors ... // do some other error handling operation } ...
Program
,
Model
,
Predicate
,
OutputDescriptor
Field Summary | |
static byte |
ASYNCHRONOUS
This constant indicates a kind of synchronization method of a DlvHandler instance. |
static byte |
FINISHED
The status of a DlvHandler instance when DLV process terminates a computation. |
static byte |
FREEZED
The status of a DlvHandler instance when DLV process was freezed. |
static byte |
KILLED
The status of a DlvHandler instance when DLV process was killed. |
static byte |
MODEL_SYNCHRONOUS
This constant indicates a kind of synchronization method of a DlvHandler instance. |
static byte |
READY
The status of a DlvHandler instance when DLV is running. |
static byte |
RUNNING
The status of a DlvHandler instance when DLV process is running. |
static byte |
SYNCHRONOUS
This constant indicates a kind of synchronization method of a DlvHandler instance. |
Constructor Summary | |
DlvHandler(DLV.core.AbstractIOImplementation implementation)
Constructs a Dlvhandler object that uses the specified implementation. |
|
DlvHandler(java.lang.String DLV_Path)
Constructs a Dlvhandler object that uses the standard Input Output implementation. |
Method Summary | |
void |
addModel(Model m)
|
void |
deFreeze()
This function deFreezes the current DLV process. |
void |
freeze()
This function freezes the current DLV process. |
int |
getCursor()
Returns the current cursor position. |
static java.lang.String |
getDLVWrapperInfo()
Returns name and version of this version of the DLV Wrapper. |
java.lang.String |
getEncoding()
Returns the encoding used to exchange data with DLV. |
java.lang.String[] |
getInvocationParameters()
|
byte |
getMethod()
Gets the method used in the last invocation of this Dlvhandler instance (see static constants). |
Model |
getModel()
If exists, returns the Model object currently pointed by the cursor, null otherwise. |
Model |
getModel(int i)
Returns the i-th Model object if exists null otherwise. |
OutputDescriptor |
getOutputDescriptor()
This function allows to get the OutputDescriptor object which describe how to process the output of DLV. |
java.lang.String |
getPath()
Get the current pathname of DLV. |
Program |
getProgram()
This function allows to get the Program object that is the input of DLV. |
int |
getSize()
Returns the current number of models computed by DLV. |
byte |
getStatus()
Gets the status of this DlvHandler instance (see static constants). |
java.lang.String |
getVersion()
This function asks the selected DLV implementation for version information. |
java.lang.String |
getWarnings()
After a DLV invocation, this function returns the warning messages. |
boolean |
hasMoreModels()
Tests If there are more Model object available. |
boolean |
isFirst()
Returns true if the cursor is on the first position, false otherwise. |
boolean |
isLast()
Returns true if the cursor is currently on the last position, false otherwise. |
void |
kill()
This function kills the current DLV process. |
Model |
nextModel()
Returns The next Model object available with respect to the current cursor position. |
Model |
previousModel()
Returns The previous Model object available with respect to the current cursor position. |
void |
removeModel()
This function allows to discard the current Model. |
void |
removeModel(int i)
This function allows to discard the i-th Model object. |
void |
reset()
This function resets the current DlvHandler instance. |
void |
run()
// *************************************** FUNZIONI DI INVOCAZIONE ********************************** /** This function starts DLV in MODEL_SYNCHRONOUS mode. |
void |
run(byte method)
This function starts DLV in "method" mode. |
void |
setCostBound(java.lang.String costbound)
Set the value of costbound option. |
void |
setCursor(int i)
Sets the cursor position. 0 is the first position. |
void |
setDeterministicConsequences(boolean dc)
If set, DLV only computes deterministic consequences. |
void |
setEncoding(java.lang.String encoding)
Sets the encoding used to exchange data with DLV. |
void |
setFilter(java.lang.String[] filter)
Includes only instances of the predicate specified in the filter parameter in output. |
void |
setFrontEnd(java.lang.String frontend)
Set the DLV frontend parameters. |
void |
setGenerateAllPossibilyModels(boolean pm)
If set, DLV outputs all (possibly not optimal) models ignoring weak constraints. |
void |
setIncludeFacts(boolean ifact)
If set, DLV includes facts as part of the output. |
void |
setInstantiate(boolean i)
If set, DLV only ground and out the instantiation. |
void |
setMaxint(int N)
Limit integers to [0,N]. |
void |
setNumberOfModels(int N)
If set, DLV computes at most N stable models. |
void |
setOptimizationOptions(java.lang.String opt)
Set the DLV Optimization Options parameters. |
void |
setOutputDescriptor(OutputDescriptor outputDescriptor)
This function allows to set the OutputDescriptor object which describe how to process the output of DLV. |
void |
setPath(java.lang.String DLV_Path)
Set the full pathname of DLV for the next invocation. |
void |
setPFilter(java.lang.String[] filter)
Includes only positive instances of the predicate specified in the filter parameter in output. |
void |
setProgram(Program p)
This function allows to set the Program object that is the input of DLV. |
void |
signalDlvDeFreeze()
|
void |
signalDlvEnd()
|
void |
signalDlvFreeze()
|
void |
signalDlvKill()
|
void |
signalError(java.lang.Throwable t)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final byte READY
public static final byte RUNNING
public static final byte FINISHED
public static final byte KILLED
public static final byte FREEZED
public static final byte SYNCHRONOUS
public static final byte MODEL_SYNCHRONOUS
public static final byte ASYNCHRONOUS
Constructor Detail |
public DlvHandler(java.lang.String DLV_Path)
DLV_Path
- Is the DLV's pathname.public DlvHandler(DLV.core.AbstractIOImplementation implementation)
implementation
- An I/O Implementation.Method Detail |
public static java.lang.String getDLVWrapperInfo()
public java.lang.String[] getInvocationParameters()
getInvocationParameters
in interface DLV.core.DlvIOHandler
public void addModel(Model m)
addModel
in interface DLV.core.DlvIOHandler
public void signalDlvEnd()
signalDlvEnd
in interface DLV.core.DlvIOHandler
public void signalDlvKill()
signalDlvKill
in interface DLV.core.DlvIOHandler
public void signalDlvFreeze()
signalDlvFreeze
in interface DLV.core.DlvIOHandler
public void signalDlvDeFreeze()
signalDlvDeFreeze
in interface DLV.core.DlvIOHandler
public void signalError(java.lang.Throwable t)
signalError
in interface DLV.core.DlvIOHandler
public java.lang.String getEncoding()
getEncoding
in interface DLV.core.DlvIOHandler
public void setEncoding(java.lang.String encoding)
encoding
- he name of a supported character encoding.public void run() throws DLVInvocationException
DLVInvocationException
- If any error is occurred during DLV invocation.public void run(byte method) throws DLVInvocationException
run
in interface DLV.core.DlvIOHandler
method
- a byte which set the invocation method (see static constants).
DLVInvocationException
- If any error is occurred during DLV invocation.public void kill() throws DLVInvocationException
DLVInvocationException
- If any error is occurred during function call.public void freeze() throws DLVInvocationException
DLVInvocationException
- If any error is occurred during function call.public void deFreeze() throws DLVInvocationException
DLVInvocationException
- If any error is occurred during function call.public void reset() throws DLVInvocationException
DLVInvocationException
- If any error is occurred during function call.public java.lang.String getWarnings() throws DLVInvocationException
DLVInvocationException
- If some error is occurred during DLV invocation.public void setPath(java.lang.String DLV_Path)
DLV_Path
- Is the full pathname of DLV.public java.lang.String getPath()
public java.lang.String getVersion() throws DLVInvocationException
DLVInvocationException
- If some error is occurred during DLV invocation.public byte getStatus()
public byte getMethod()
getMethod
in interface DLV.core.DlvIOHandler
public boolean hasMoreModels() throws DLVInvocationException
If there are more models (with respect to the current cursor position) this method returns true; false otherwise.
If the current program is inconsistent (the program hasn't models) this function returns true.
In this case a NO_MODEL object (which is a Model object) is returned by calling nextModel();
If DLV has been freezed and (with respect to the current cursor position) there are no models availables
the java thread calling this method is blocked until deFreeze() method or reset() method is called.
(Be cautious using freeze() deadlock scenarios could occurr)
DLVInvocationException
- If any error occurs while DLV is running.
NoModelsComputed
- If DLV has been never executed.public Model nextModel() throws DLVInvocationException
DLVInvocationException
- If any error occurs while DLV is running.
NoModelsComputed
- If DLV has been never executed.
NoSuchModelException
- If you try to get a Model which doesn't exist and DLV status il FINISHED or KILLED.public Model previousModel()
NoModelsComputed
- If DLV has been never executed.
NoSuchModelException
- If you try to get a Model which doesn't exist.public Model getModel(int i)
NoSuchModelException
- Is thrown if the i-th isn't a valid position.
NoModelsComputed
- If DLV has been never executed.public Model getModel()
NoModelsComputed
- If DLV has been never executed.
NoSuchModelException
- Is thrown if the cursor isn't in a valid position.public void removeModel(int i)
NoSuchModelException
- Is thrown if the i-th is not a valid position.
NoModelsComputed
- If DLV has been never executed.public void removeModel()
NoSuchModelException
- Is thrown if, at the moment, there are no currrent models for this program.
NoModelsComputed
- If DLV has been never executed.public int getCursor()
public void setCursor(int i)
i
- the new cursor position.
NoSuchModelException
- Is thrown if the i-th isn't a valid position.
NoModelsComputed
- If DLV has been never executed.public boolean isFirst()
NoModelsComputed
- If DLV has been never executed.public boolean isLast()
NoModelsComputed
- If DLV has been never executed.public int getSize()
NoModelsComputed
- If DLV has been never executed.public OutputDescriptor getOutputDescriptor()
getOutputDescriptor
in interface DLV.core.DlvIOHandler
OutputDescriptor
public void setOutputDescriptor(OutputDescriptor outputDescriptor)
outputDescriptor
- an OutputDescriptor objectOutputDescriptor
public Program getProgram()
getProgram
in interface DLV.core.DlvIOHandler
public void setProgram(Program p)
p
- A program object which will be the input of DLV.public void setFrontEnd(java.lang.String frontend)
frontend
- Is a String written with DLV invocation syntax.public void setCostBound(java.lang.String costbound)
costbound
- is a string like N,...,N.public void setDeterministicConsequences(boolean dc)
dc
- if true the -det option is setpublic void setInstantiate(boolean i)
i
- if true the -instantiate option is setpublic void setNumberOfModels(int N)
N
- Maximum number of stable models.public void setMaxint(int N)
N
- Is maxint.public void setOptimizationOptions(java.lang.String opt)
opt
- is a String in DLV invocation syntaxpublic void setFilter(java.lang.String[] filter)
filter
- Is an array of predicate names.public void setPFilter(java.lang.String[] filter)
filter
- Is an array of predicate names.public void setIncludeFacts(boolean ifact)
ifact
- If true the -facts option is set else -nofacts option is set-public void setGenerateAllPossibilyModels(boolean pm)
pm
- If true the -wctrace option is set.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |