Class Plan

java.lang.Object
FAtiMA.Core.plans.Plan
All Implemented Interfaces:
Serializable, Cloneable

public class Plan extends Object implements Cloneable, Serializable
Represents a plan and implements part of its functionality
Author:
Joao Dias
See Also:
  • Constructor Details

  • Method Details

    • setDetectThreatStrategy

      public static void setDetectThreatStrategy(IDetectThreatStrategy strat)
    • AddBindingConstraint

      public void AddBindingConstraint(Substitution bind)
      Adds a binding constraint to the plan of the form [X]/John or [X]/[X23] or [X]!=Luke
      Parameters:
      bind - - the binding constraint to add (Substitution)
      See Also:
    • AddBindingConstraints

      public void AddBindingConstraints(ArrayList<Substitution> substs)
      Adds a set of binding constraint to the plan of the form [X]/John or [X]/[X23] or [X]!=Luke
      Parameters:
      substs - - a list of binding constraints to add (Substitutions)
      See Also:
    • AddLink

      public void AddLink(CausalLink l)
      Adds a CausalLink of the Form A--p-->B to the Plan
      Parameters:
      l - - the CausalLink to add
      See Also:
    • AddOrderingConstraint

      public void AddOrderingConstraint(OrderingConstraint order)
      Adds an Ordering Constraint of the Type A > B
      Parameters:
      order - - the OrderConstraint to add
    • AddOperator

      public void AddOperator(IPlanningOperator op)
      Adds a new operator to the plan
      Parameters:
      op - - the operator to add
    • CheckProtectedConstraints

      public void CheckProtectedConstraints()
      Checks if any of the plan's operators has a conflict with a protected condition of an InterestGoal
    • CheckCausalConflicts

      public void CheckCausalConflicts()
      Checks if any of the plan's operators introduced a causal conflict with an existing CausalLink
    • Compare

      public int Compare(IPlanningOperator op1, IPlanningOperator op2)
      Compares two operators, taking into account the existing ordering constraints in the plan, and specifies which one must become after the other
      Parameters:
      op1 - - The left operator to compare
      op2 - - The right operator to compare
      Returns:
      Returns -1 if the operator op1 must become before op2, +1 if op1 must become after op2 and 0 if there is no ordering contraint between the two operators
    • Compare

      public int Compare(Integer op1, Integer op2)
      Compares two Operators, taking into account the existing ordering constraints in the plan, and specifies which one must become after the other
      Parameters:
      op1 - - The id of the left operator to compare
      op2 - - The id of the right operator to compare
      Returns:
      Returns -1 if the operator op1 must become before op2, +1 if op1 must become after op2 and 0 if there is no ordering contraint between the two operators
    • UpdatePlan

      public ArrayList<IPlanningOperator> UpdatePlan(AgentModel am)
      Method that implements the Continuous Planner features. It is responsible for detecting if the plan is not consistent with the world state anymore, and to fix such continuous planning flaws. This method should be called whenever the world changes.
    • CheckRedundantStep

      public boolean CheckRedundantStep(Integer opID)
      Checks if a given Operator is redundant and not needed anymore, because the CausalLinks it establishes are not needed anymore.
      Parameters:
      opID - - the ID in the plan of the operator to remove
      Returns:
      true if the operator is redundant, false otherwise
    • clone

      public Object clone()
      Clones this Plan, returning an equal hard copy. If the new plan is changed afterwards, the original plan remains the same.
      Overrides:
      clone in class Object
      Returns:
      The plan's copy.
    • getID

      public int getID()
    • getFinish

      public Step getFinish()
      Gets the special Finish Step
      Returns:
      the Finish Step
    • getIgnoredConflicts

      public ArrayList<CausalConflictFlaw> getIgnoredConflicts()
      Gets a list of CausalConflicts ignored due to emotion-focused coping strategies (denial or whishfull thinking)
      Returns:
      an ArrayList with ignored CausalConflicts
    • getLinks

      public ArrayList<CausalLink> getLinks()
      Gets the plan CausalLinks
      Returns:
      an ArrayList with all the plan's CausalLinks
    • getOpenPreconditions

      public ArrayList<OpenPrecondition> getOpenPreconditions()
      Gets the plan's OpenPreconditions
      Returns:
      an ArrayList with all the plan's preconditions
    • debug

      public void debug()
    • getOrderingConstraints

      public ArrayList<OrderRelation> getOrderingConstraints()
      Gets the OrderConstraints or OrderRelations in the plan
      Returns:
      an ArrayList with OrderRelations between the distinct steps in the plan
    • getProbability

      public float getProbability(AgentModel am)
      gets the plan's probability of success
      Returns:
      the plan's probability
    • getOperator

      public IPlanningOperator getOperator(Integer stepID)
      Gets the plan's operator who's ID is the received ID
      Parameters:
      stepID - - the ID of the Step in the plan to be searched
      Returns:
      the PlanningOperator that corresponds to the received ID
    • UpdateProbabilities

      public void UpdateProbabilities()
      Requests an explicit recalculation of a plan's probability. This method must be called whenever there is a change in a plan that may lead to different success probability
    • getStart

      public Step getStart()
      Gets the special Start Step
      Returns:
      the Start Step
    • getSteps

      public ArrayList<IPlanningOperator> getSteps()
      Gets all the plan's steps
      Returns:
      an ArrayList with all the plan's steps
    • getThreatenedInterestConstraints

      public ArrayList<GoalThreat> getThreatenedInterestConstraints()
      Gets the plan's threats to InterestGoals
      Returns:
      an ArrayList with the plan's GoalThreats to InterestGoals
    • h

      public float h(AgentModel am)
      Gets a heuristic value H for the plan. Useful for comparing plans. The lowest value of H corresponds to the likely better plan to continue planning.
      Returns:
      the value H
    • IgnoreConflict

      public void IgnoreConflict(AgentModel am, CausalConflictFlaw flaw)
      Ignores a given CausalConflict. This corresponds to the Wishfull thinking/Denial emotion-focused coping strategy.
      Parameters:
      flaw - - the CausalConflictFlaw to ignore
    • isFinished

      public boolean isFinished()
    • isValid

      public boolean isValid()
      indicates if the plan is valid or not
      Returns:
      true if the plan is valid, i.e., it does not have unsolvable causal conflicts and cycles in the OrderRelations
    • NextFlaw

      public CausalConflictFlaw NextFlaw()
      Gets the next CausalConflictFlaw in the plan
      Returns:
      null if there are no CausalConflicts in the plan, otherwise it returns the next CausalConflict in the list
    • NumberOfSourceLinks

      public int NumberOfSourceLinks(Integer stepID)
      Gets the number of CausalLinks where the received Step participates as the Source for the CausalLink, i.e., the method determines how many CausalLinks the Step supports
      Parameters:
      stepID - - the ID of the step to calculate the result
      Returns:
      the number of CausalLinks that the step supports
    • RemoveOperator

      public void RemoveOperator(Integer operatorID)
      Removes an Operator from the plan
      Parameters:
      operatorID - - the ID of the operator to be removed
    • RemoveCausalLink

      public void RemoveCausalLink(CausalLink link)
      Removes a CausalLink from the plan
      Parameters:
      link - - the link to be removed
    • RemoveCausalLinks

      public void RemoveCausalLinks(Integer stepID)
      Removes all the CausalLinks that protected a given step's preconditions
      Parameters:
      stepID - - the ID of the step that we want to remove the CausalLinks
    • RemoveOpenPreconditions

      public void RemoveOpenPreconditions(Integer stepID)
      Remove all OpenPreconditions referenced by a given Step
      Parameters:
      stepID - - the ID of the step that we want to remove its preconditions from the OpenPreconditions list
    • RemoveOrderingConstraint

      public void RemoveOrderingConstraint(OrderingConstraint orderConstraint)
      Removes an OrderingConstraint between two steps (A > B) from the plan
      Parameters:
      orderConstraint - - The ordering constraint to remove
    • RemoveOrderingConstraints

      public void RemoveOrderingConstraints(Integer stepID)
      Removes all OrderingRelations refering to a given Step
      Parameters:
      stepID - - the ID of the step to remove from OrderRelations
    • toString

      public String toString()
      Converts the plan to a String
      Overrides:
      toString in class Object
      Returns:
      the converted String
    • UnexecutedAction

      public IPlanningOperator UnexecutedAction(AgentModel am)
      Gets the next action that we must execute in the plan in order to achieve it
      Returns:
      the next action to execute
    • GetFirstActions

      public ArrayList<IPlanningOperator> GetFirstActions()
      Gets a list with the first actions in a plan - DO NOT USE this method if you want to execute the actions. Use it only to know which ones should be executed first. This is a simpler method that does not guarantee that you can indeed execute the action. If you want to execute an action, use the GetNextAction method instead
      Returns:
      a list with steps that are the first to be executed in a plan
    • AddOrderingConstraint

      public void AddOrderingConstraint(Integer before, Integer after)
      Adds an Ordering Constraint of the Type A > B
      Parameters:
      before - - the id of the step A in A > B
      after - - the id of the step B in A > B
    • ReplaceUnboundVariables

      public void ReplaceUnboundVariables(int variableID)