org.deri.iris.graph
Class PredicateGraph

java.lang.Object
  extended by org.deri.iris.graph.PredicateGraph
All Implemented Interfaces:
IPredicateGraph

public class PredicateGraph
extends Object
implements IPredicateGraph

A graph to determine the dependencies of rules and predicates to each other.

$Id$

Version:
$Revision$
Author:
Richard P??ttler (richard dot poettler at deri dot at)

Method Summary
 void addRule(Collection<IRule> r)
          Adds a collection of rules to the graph.
 void addRule(IRule rule)
          Adds a rule to the graph.
 int countNegativesForCycle()
          Returns the number of negative Literals in the cycle.
 boolean detectCycles()
          Determines whether the rules are recursive.
 Set<LabeledEdge<IPredicate,Boolean>> findEdgesForCycle()
          Determines the edges contained in the cycle.
 Set<IPredicate> findVertexesForCycle()
          Determines the vertexes contained in the cycle.
 Set<IPredicate> getDepends(IPredicate p)
          Returns a set of predicates the given one depends on.
 Comparator<IPredicate> getPredicateComparator()
           Returns a compareator which compares two predicates depending on their dependencies of their rules.
 Comparator<IRule> getRuleComparator()
           Returs a comparator which compares two rules depending on their dependencies of each other.
 String toString()
           Computes a short description of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

addRule

public void addRule(IRule rule)
Description copied from interface: IPredicateGraph
Adds a rule to the graph.

Specified by:
addRule in interface IPredicateGraph
Parameters:
rule - the rule to add

addRule

public void addRule(Collection<IRule> r)
Description copied from interface: IPredicateGraph
Adds a collection of rules to the graph.

Specified by:
addRule in interface IPredicateGraph
Parameters:
r - the collection of rules

detectCycles

public boolean detectCycles()
Description copied from interface: IPredicateGraph
Determines whether the rules are recursive.

Specified by:
detectCycles in interface IPredicateGraph
Returns:
true if they are recursive, otherwise false

findVertexesForCycle

public Set<IPredicate> findVertexesForCycle()
Description copied from interface: IPredicateGraph
Determines the vertexes contained in the cycle.

Specified by:
findVertexesForCycle in interface IPredicateGraph
Returns:
a Set containing all the vertexes

findEdgesForCycle

public Set<LabeledEdge<IPredicate,Boolean>> findEdgesForCycle()
Description copied from interface: IPredicateGraph
Determines the edges contained in the cycle.

Specified by:
findEdgesForCycle in interface IPredicateGraph
Returns:
a Set containing all the vertexes

countNegativesForCycle

public int countNegativesForCycle()
Description copied from interface: IPredicateGraph
Returns the number of negative Literals in the cycle.

Specified by:
countNegativesForCycle in interface IPredicateGraph
Returns:
the number of negative literals

getRuleComparator

public Comparator<IRule> getRuleComparator()
Description copied from interface: IPredicateGraph

Returs a comparator which compares two rules depending on their dependencies of each other.

The rules will compared according to their headpredicates.

Specified by:
getRuleComparator in interface IPredicateGraph
Returns:
the comparator
See Also:
IPredicateGraph.getPredicateComparator()

getPredicateComparator

public Comparator<IPredicate> getPredicateComparator()
Description copied from interface: IPredicateGraph

Returns a compareator which compares two predicates depending on their dependencies of their rules.

If one of the compared predicate isn't in the graph, or there isn't a path from one predicate to the other 0 will be returned. If the first predicate depends on the second one, the first one will be determined to be bigger, and vice versa.

Specified by:
getPredicateComparator in interface IPredicateGraph
Returns:
the comparator

getDepends

public Set<IPredicate> getDepends(IPredicate p)
Description copied from interface: IPredicateGraph
Returns a set of predicates the given one depends on.

Specified by:
getDepends in interface IPredicateGraph
Parameters:
p - predicate for which to check for dependencies
Returns:
the predicates the predicate depends on

toString

public String toString()

Computes a short description of this object. The format of the returned string is undocumented and subject to change..

And example return string could be:


 a->(false)->b
 b->(true)->c
 

Overrides:
toString in class Object
Returns:
the string description