edu.udo.cs.ie.cowbots.logic
Class ELPRule

Package class diagram package ELPRule
java.lang.Object
  extended by edu.udo.cs.ie.cowbots.logic.ELPRule
Direct Known Subclasses:
DLPRule

public class ELPRule
extends java.lang.Object

this class models a rule used in extended logics programs. each rule consists of two list: Hl, list of head literals, and Bl, list of body literals. if Bl is empty, we call the rule a fact. if Hl is empty, we call the rule a constraint. Hl is always a (possibly empty) list of positive literals (ELPAtom instances), and if |Hl| > 1 we call the rule (or fact) disjunctive. Hl may not contain any instances derived from ELPArithExpr. Bl is always a list of literals (ELPLiteral instances), and it may contain any meaningful negation or arithmetical expression. Summary: do what you want to do, but make sure it will never ever crash your solver. this class is not designed to catch syntactical errors while building elps.


Field Summary
(package private)  java.util.ArrayList<ELPLiteral> body
           
(package private)  java.util.ArrayList<ELPLiteral> head
           
 
Constructor Summary
ELPRule()
          create a new elp rule
ELPRule(ELPRule other)
          creates new rule based on an existing on.
ELPRule(int maxHead, int maxBody)
          create a rule with preallocated memory for body and head literals.
 
Method Summary
 void addBody(java.util.Collection<ELPLiteral> lits)
           
 void addBody(ELPLiteral l)
          add a literal to Bl
 void addHead(ELPLiteral l)
          add a literal to Hl
protected  java.lang.String dumpLitList(java.util.ArrayList<ELPLiteral> ll, java.lang.String sep)
          internal helper function to dump a list of literals
 java.util.ArrayList<ELPLiteral> getBody()
           
 ELPLiteral getBody(int i)
          return the i-th literal in Bl
 ELPLiteral getHead(int i)
          returns the i-th literal in Hl
 boolean isConstraint()
          returns true if the rule is a constraint (no head literals, and at least on body literal
 boolean isDisjunctive()
          indicated wether there is more than one (or zero) literals in the read of the rule.
 boolean isFact()
          returns true if the rule has at least on head, but no body literals.
 int nBody()
          returns the size of |Bl|, including arithmetical expressions.
 int nHead()
          returns the size of |Hl|
 java.lang.String toString()
          converts the rule into a human readable string representing this rule in a datalog-like syntax.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

head

java.util.ArrayList<ELPLiteral> head

body

java.util.ArrayList<ELPLiteral> body
Constructor Detail

ELPRule

public ELPRule()
create a new elp rule


ELPRule

public ELPRule(int maxHead,
               int maxBody)
create a rule with preallocated memory for body and head literals.

Parameters:
maxHead -
maxBody -

ELPRule

public ELPRule(ELPRule other)
creates new rule based on an existing on. todo: clone literals

Parameters:
other - rule to copy
Method Detail

isFact

public boolean isFact()
returns true if the rule has at least on head, but no body literals.

Returns:

isConstraint

public boolean isConstraint()
returns true if the rule is a constraint (no head literals, and at least on body literal

Returns:

isDisjunctive

public boolean isDisjunctive()
indicated wether there is more than one (or zero) literals in the read of the rule.

Returns:

addHead

public void addHead(ELPLiteral l)
add a literal to Hl

Parameters:
l - atom to add to Hl

addBody

public void addBody(ELPLiteral l)
add a literal to Bl

Parameters:
l -

getBody

public java.util.ArrayList<ELPLiteral> getBody()

addBody

public void addBody(java.util.Collection<ELPLiteral> lits)

toString

public java.lang.String toString()
converts the rule into a human readable string representing this rule in a datalog-like syntax.

Overrides:
toString in class java.lang.Object

dumpLitList

protected java.lang.String dumpLitList(java.util.ArrayList<ELPLiteral> ll,
                                       java.lang.String sep)
internal helper function to dump a list of literals

Parameters:
ll - list of literals
sep - literal separator
Returns:
text representation of ll

nHead

public int nHead()
returns the size of |Hl|

Returns:
number of head literals

nBody

public int nBody()
returns the size of |Bl|, including arithmetical expressions.

Returns:
number of body literals

getHead

public ELPLiteral getHead(int i)
returns the i-th literal in Hl

Parameters:
i - literal index
Returns:
i-th literal in head

getBody

public ELPLiteral getBody(int i)
return the i-th literal in Bl

Parameters:
i - literal index
Returns:
i-th literal in body