Class CountingAlg<V>

java.lang.Object
tools.refinery.interpreter.rete.itc.alg.counting.CountingAlg<V>
Type Parameters:
V - the type parameter of the nodes in the graph data source
All Implemented Interfaces:
IGraphObserver<V>, ITcDataSource<V>

public class CountingAlg<V> extends Object implements IGraphObserver<V>, ITcDataSource<V>
This class is the optimized implementation of the Counting algorithm.
  • Constructor Details

    • CountingAlg

      public CountingAlg(IGraphDataSource<V> gds)
      Constructs a new Counting algorithm and initializes the transitive closure relation with the given graph data source. Attach itself on the graph data source as an observer.
      Parameters:
      gds - the graph data source instance
  • Method Details

    • edgeInserted

      public void edgeInserted(V source, V target)
      Description copied from interface: IGraphObserver
      Used to notify when an edge is inserted into the graph.
      Specified by:
      edgeInserted in interface IGraphObserver<V>
      Parameters:
      source - the source of the edge
      target - the target of the edge
    • edgeDeleted

      public void edgeDeleted(V source, V target)
      Description copied from interface: IGraphObserver
      Used to notify when an edge is deleted from the graph.
      Specified by:
      edgeDeleted in interface IGraphObserver<V>
      Parameters:
      source - the source of the edge
      target - the target of the edge
    • nodeInserted

      public void nodeInserted(V n)
      Description copied from interface: IGraphObserver
      Used to notify when a node is inserted into the graph.
      Specified by:
      nodeInserted in interface IGraphObserver<V>
      Parameters:
      n - the node
    • nodeDeleted

      public void nodeDeleted(V n)
      Description copied from interface: IGraphObserver
      Used to notify when a node is deleted from the graph.
      Specified by:
      nodeDeleted in interface IGraphObserver<V>
      Parameters:
      n - the node
    • getTcRelation

      public ITcRelation<V> getTcRelation()
    • setTcRelation

      public void setTcRelation(CountingTcRelation<V> tc)
    • isReachable

      public boolean isReachable(V source, V target)
      Description copied from interface: ITcDataSource
      Returns true if the target node is reachable from the source node.
      Specified by:
      isReachable in interface ITcDataSource<V>
      Parameters:
      source - the source node
      target - the target node
      Returns:
      true if target is reachable from source, false otherwise
    • attachObserver

      public void attachObserver(ITcObserver<V> to)
      Description copied from interface: ITcDataSource
      Attach a transitive closure relation observer.
      Specified by:
      attachObserver in interface ITcDataSource<V>
      Parameters:
      to - the observer object
    • detachObserver

      public void detachObserver(ITcObserver<V> to)
      Description copied from interface: ITcDataSource
      Detach a transitive closure relation observer.
      Specified by:
      detachObserver in interface ITcDataSource<V>
      Parameters:
      to - the observer object
    • getAllReachableTargets

      public Set<V> getAllReachableTargets(V source)
      Description copied from interface: ITcDataSource
      Returns all nodes which are reachable from the source node.
      Specified by:
      getAllReachableTargets in interface ITcDataSource<V>
      Parameters:
      source - the source node
      Returns:
      the set of target nodes
    • getAllReachableSources

      public Set<V> getAllReachableSources(V target)
      Description copied from interface: ITcDataSource
      Returns all nodes from which the target node is reachable.
      Specified by:
      getAllReachableSources in interface ITcDataSource<V>
      Parameters:
      target - the target node
      Returns:
      the set of source nodes
    • dispose

      public void dispose()
      Description copied from interface: ITcDataSource
      Call this method to properly dispose the data structures of a transitive closure algorithm.
      Specified by:
      dispose in interface ITcDataSource<V>
    • getPathFinder

      public IGraphPathFinder<V> getPathFinder()
      Description copied from interface: ITcDataSource
      The returned IGraphPathFinder can be used to retrieve paths between nodes using transitive reachability.
      Specified by:
      getPathFinder in interface ITcDataSource<V>
      Returns:
      a path finder for the graph.