|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectDLV.Model
This class represents a Model of a logic program (output of DLV).
The class Model allows to handle a collection of Predicate objects.
Two interfaces are provided. The first is java.util.Enumeration like the latter is java.sql.ResultSet like.
Ex. 1 - Enumeration like methods ... // dlv call Model m=dlv.getModel(); // gets a Model object ... while(m.hasMoreModels()) //tests if m has Predicates {Predicate p=m.nextPredicate(); //gets next Predicate ... } ... Ex. 2 - ResultSet like methods ... // dlv call Model m=dlv.getModel(); // gets a Model object ... while(m.next()) //tests if m has Predicates { Predicate p=m.getPredicate(); //gets next Predicate ... } ...
The static constant No_Model allows to represent a program which hasn't models.
If you want to test if a Model instance m is "no nodel" you can call m.isNoModel() or test m==Model.NO_Model.
DlvHandler
,
Predicate
Field Summary | |
static Model |
NO_MODEL
DLV programs may have many models or no model at all. |
Method Summary | |
boolean |
absolute(int position)
Moves the cursor to the given Predicate number in this Model object. |
void |
afterLast()
Moves the cursor to the end of this Model object, just after the last Predicate. |
void |
appendTo(java.io.PrintWriter out)
This method allows to save this Model in the file handled by "out". |
void |
beforeFirst()
Moves the cursor to the front of this Model object, just before the first Predicate. |
boolean |
first()
This method moves the cursor to the first Predicate in this Model object. |
Predicate |
firstPredicate()
This method returns the first predicate and set the cursor at the beginning of this Model. |
int |
getCost()
Returns the cost of this model if the program hasn't weak constraints. |
int[][] |
getCostWithPriority()
Returns the cost of this model if the program has some weak constraints, null otherwise. |
int |
getCursor()
This method returns the position of current predicate. |
Predicate |
getPredicate()
Returns the Predicate currently pointed by the cursor. |
Predicate |
getPredicate(int i)
Returns the i-th predicate. |
Predicate |
getPredicate(java.lang.String name)
Returns, if exists, a Predicate object of name "name", null otherwise. |
java.lang.String[] |
getPredicateNames()
Returns an array which contains the predicate names contained in this model. |
java.util.Enumeration |
getPredicates()
Returns an Enumeration of predicates contained in this model. |
boolean |
hasMorePredicates()
This method returns true if there are more predicates. |
boolean |
isBest()
Returns true if and only if this is a best model. |
boolean |
isEmpty()
Returns true if and only if this is an empty model. |
boolean |
isFirst()
Indicates whether the cursor is on the first Predicate of this Model object. |
boolean |
isLast()
Indicates whether the cursor is on the last Predicate of this Model object. |
boolean |
isNoModel()
Returns true if and only if this object represents the lack of models (no model were computed). |
boolean |
last()
This method moves the cursor to the last Predicate in this Model object. |
Predicate |
lastPredicate()
This method returns the last predicate and set the cursor at the end of this Model. |
boolean |
next()
Moves the cursor down one position from its current. |
Predicate |
nextPredicate()
This method returns the next predicate. |
boolean |
previous()
Moves the cursor to the previous Predicate in this Model object. |
Predicate |
previousPredicate()
This method returns the previous Predicate. |
boolean |
relative(int i)
Moves the cursor a relative number of positions, either positive or negative. |
void |
saveTo(java.lang.String file)
This method allows to save this Model in the file "file". |
int |
size()
Returns the size of this model (The number of predicates it contains). |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final Model NO_MODEL
Method Detail |
public boolean isEmpty()
IsNoModelException
- if this object represents no model.public boolean isBest()
IsNoModelException
- if this object represents no model.public boolean isNoModel()
public int getCost()
IsNoModelException
- if this object represents no model.public int[][] getCostWithPriority()
IsNoModelException
- if this object represents no model.public java.util.Enumeration getPredicates()
IsNoModelException
- if this object represents no model.public java.lang.String[] getPredicateNames()
IsNoModelException
- if this object represents no model.public Predicate getPredicate(java.lang.String name)
name
- A String containing a predicate name.
IsNoModelException
- if this object represents no model.public int size()
IsNoModelException
- if this object represents no model.public Predicate getPredicate()
NoSuchPredicateException
- if you try to get a predicate which doesn't exist.public Predicate getPredicate(int i)
NoSuchPredicateException
- if you try to get a predicate which doesn't exist.public boolean hasMorePredicates()
public Predicate nextPredicate()
NoSuchPredicateException
- if you try to get a predicate which doesn't exist.public Predicate previousPredicate()
NoSuchFactException
- if you try to get a fact which doesn't exist.public Predicate firstPredicate()
NoSuchPredicateException
- if you try to get a predicate which doesn't exist.public Predicate lastPredicate()
NoSuchPredicateException
- if you try to get a predicate which doesn't exist.public int getCursor()
public boolean first()
public boolean last()
public void beforeFirst()
public void afterLast()
public boolean isFirst()
public boolean isLast()
public boolean relative(int i)
public boolean previous()
public boolean next()
public boolean absolute(int position)
If the given position number is negative, the cursor moves to
an absolute position with respect to the end of the Model.
For example, calling the method absolute(-1)
positions the
cursor on the last position; calling the method absolute(-2)
moves the cursor to the next-to-last position, and so on.
An attempt to position the cursor beyond the first/last in the Model leaves the cursor before the first or after the last position.
Note: Calling absolute(1)
is the same
as calling first()
. Calling absolute(-1)
is the same as calling last()
.
position
- the position which the cursor should move to.
A positive number indicates the position counting from the
beginning of the Model; a negative number indicates the
position counting from the end of the Model
true
if the cursor is on the Model;
false
otherwisepublic void saveTo(java.lang.String file) throws java.io.IOException
file
- a String which contains a full file name.
java.io.IOException
- if an error occurs during file creation.public void appendTo(java.io.PrintWriter out) throws java.io.IOException
java.io.IOException
- if an error occurs processing "out".public java.lang.String toString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |