Class Generator

  • All Implemented Interfaces:
    LPAgendaEntry, LPInterpreterContext, LPInterpreterState

    public class Generator
    extends java.lang.Object
    implements LPAgendaEntry, LPInterpreterContext
    A generator represents a set of memoized results for a single tabled subgoal. The generator may be complete (in which case it just contains the complete cached set of results for a goal), ready (not complete but likely to product more results if called) or blocked (not complete and awaiting results from a dependent generator).

    Each generator may have multiple associated consumer choice points representing different choices in satisfying the generator's goal.

    • Constructor Detail

      • Generator

        public Generator​(LPInterpreter interpreter,
                         TriplePattern goal)
        Constructor.
        Parameters:
        interpreter - an initialized interpreter instance that will answer results for this generator.
    • Method Detail

      • numResults

        public int numResults()
        Return the number of results available from this context.
      • isReady

        public boolean isReady()
        Return true if the generator is ready to be scheduled (i.e. it is not known to be complete and not known to be waiting for a dependent generator).
        Specified by:
        isReady in interface LPAgendaEntry
        Specified by:
        isReady in interface LPInterpreterContext
      • isComplete

        public boolean isComplete()
        Return true if the generator is complete.
      • setComplete

        public void setComplete()
        Signal that this generator is complete, no more results can be created.
      • addConsumer

        public void addConsumer​(ConsumerChoicePointFrame ccp)
        Add a new client choince point to consume results from this generator.
      • removeConsumer

        public void removeConsumer​(ConsumerChoicePointFrame ccp)
        Remove a terminated consuming choice point from the state set.
      • notifyResults

        public void notifyResults()
        Signal dependents that we have new results.
      • pump

        public void pump()
        Start this generator running for the first time. Should be called from within an appropriately synchronized block.
        Specified by:
        pump in interface LPAgendaEntry
      • pump

        public void pump​(LPInterpreterState context)
        Start this generator running from the given previous blocked generating choice point. Should be called from within an appropriately synchronized block.
      • getGenerator

        public Generator getGenerator()
        Return the generator associated with this entry (might be the entry itself)
        Specified by:
        getGenerator in interface LPAgendaEntry
      • checkForCompletions

        public void checkForCompletions()
        Check for deadlocked states where none of the generators we are (indirectly) dependent on can run.
      • checkForCompletions

        public static void checkForCompletions​(java.util.Collection<? extends Generator> completions)
        Check for deadlocked states across a collection of generators which have been run.