Class StateMachine

java.lang.Object
edu.tufts.hrilab.action.state.StateMachine

public class StateMachine extends Object
  • Constructor Details

    • StateMachine

      public StateMachine(String[] beliefArgs)
      Create a new state machine. This also creates a BeliefComponent and registers it with TRADE.
    • StateMachine

      public StateMachine(StateMachine original)
      Create a new state machine by branching off of an existing state machine. The new StateMachine creates a new BeliefComponent initialled with the state of other's BeliefComponent. The new BeliefComponent is NOT registered with TRADE.
      Parameters:
      original - StateMachine to branch off.
    • StateMachine

      public StateMachine(StateMachine originalSM, boolean useBelief)
      Create a new state machine by branching off of an existing state machine. If the belief component is not used but the original does, copy all the original's facts to the new state.
      Parameters:
      originalSM - State machine to be copied from
      useBelief - If belief should be used
    • StateMachine

      public StateMachine(State state)
      Creates a new state machine from an initial state
      Parameters:
      state -
  • Method Details

    • createTestStateMachine

      public static StateMachine createTestStateMachine(Set<Predicate> initFacts)
      USE FOR TESTS ONLY. Create a new state machine with an initial set of facts for unit tests.
      Parameters:
      initFacts - initial set of facts
    • mergeBelief

      public void mergeBelief()
      Pulls all the facts from this instance's belief into its current state
    • simulatedStateMachine

      public StateMachine simulatedStateMachine()
    • setSimulationState

      public void setSimulationState(State s)
      Updates the simulation state to the given state
      Parameters:
      s - State to update the simulated SM to
    • setSimulationStateMachine

      public void setSimulationStateMachine(StateMachine simSM)
      Sets the simulated SM to the instance of the SM passed in
      Parameters:
      simSM -
    • getSimulationStateMachine

      public StateMachine getSimulationStateMachine()
      Gets the simulated SM, a standalone instance
      Returns:
      Simulated SM
    • updateSimStateMachine

      public StateMachine updateSimStateMachine()
      Sets the simulated SM's current state to this instance's currrent state
      Returns:
    • update

      public State update(Context context)
      Update the state based on action effects.
      Parameters:
      context - Context for which the update is done
      Returns:
      Next/updated state
    • getRules

      public List<org.apache.commons.lang3.tuple.Pair<Term,List<Term>>> getRules()
      Get all rules from belief
      Returns:
      List of pairs of rule heads and rule bodies
    • getAllFacts

      public List<Term> getAllFacts()
      Get all facts from belief.
      Returns:
    • getAllFactsFromBelief

      public List<Term> getAllFactsFromBelief(MemoryLevel memoryLevel)
      Get all facts from belief from specified memory level.
      Returns:
    • getCurrentState

      public State getCurrentState()
      Get current state from StateMachine. This does not consult belief.
      Returns:
    • holds

      public Justification holds(Predicate predicate)
      Checks that the predicate holds
      Parameters:
      predicate - predicate
      Returns:
      True if the predicate holds.
    • disjunctionHolds

      public OrJustification disjunctionHolds(List<Predicate> predicates)
      Checks that the disjunction of the listed predicates holds
      Parameters:
      predicates - List of predicates
      Returns:
      True if at least one predicate holds (disjunction).
    • disjunctionHolds

      public OrJustification disjunctionHolds(List<Predicate> predicates, List<Predicate> assumption)
      Checks that the disjunction of the listed predicates holds for a specific assumption.
      Parameters:
      predicates - List of predicates, the disjunction of which has to hold
      assumption - List of predicates that are assumed to hold
      Returns:
      True if at least one predicate holds (disjunction).
    • assertBeliefs

      public void assertBeliefs(Collection<Predicate> facts)
    • assertBelief

      @Deprecated public void assertBelief(Predicate fact)
      Deprecated.
    • assertBelief

      @Deprecated public void assertBelief(Predicate fact, MemoryLevel memoryLevel)
      Deprecated.
    • assertBelief

      public void assertBelief(Predicate fact, MemoryLevel memoryLevel, Predicate source)
    • retractBelief

      public void retractBelief(Predicate fact)
    • retractBelief

      public void retractBelief(Predicate fact, MemoryLevel memoryLevel)
    • assertRule

      public void assertRule(Term head, List<Term> body)
    • retractRule

      public void retractRule(Term head, List<Term> body)
    • retractRule

      public void retractRule(Term head)
    • getRule

      public org.apache.commons.lang3.tuple.Pair<Term,List<Term>> getRule(String name)
      Gets a rule from belief whose head matches, without arguments
      Parameters:
      name - Head, without arguments
      Returns:
    • prune

      public void prune(long historyLength)
      Prune old states from the state machine.
      Parameters:
      historyLength - ms of history to keep
    • shutdown

      public void shutdown()
    • updateState

      public void updateState(Map<Predicate,Boolean> facts)
    • getStateChange

      public Set<Predicate> getStateChange(Context startStep, Context endStep)
    • getStateChange

      public Set<Predicate> getStateChange(Context context)
      get how the state changes from the initial state of an action to the completion of an action
      Parameters:
      context - action to get state change
      Returns:
      set of predicates representing the resulting state the initial state
    • findStartingState

      public State findStartingState(Context context)
    • findStartingState

      public State findStartingState(Context context, boolean isTerminated)
    • findResultingState

      public State findResultingState(Context context)