Record Class PlanningAction

java.lang.Object
java.lang.Record
com.tnsai.planning.PlanningAction
Record Components:
name - action name (method name)
description - human-readable description
precondition - condition that must be true before execution
postcondition - effects after execution (state changes)
fulfills - set of goal names this action helps achieve
method - the actual method to invoke
cost - action cost for utility calculation (default: 1)
value - expected value for utility calculation (default: 1)
weight - weight multiplier for utility score (default: 1.0)
tags - tags for filtering/grouping actions

public record PlanningAction(String name, String description, String precondition, String postcondition, Set<String> fulfills, Method method, int cost, int value, float weight, Set<String> tags) extends Record
Runtime representation of a planning action.

Created from ActionSpec annotations at runtime. Contains information needed for planning: preconditions, postconditions, and which goals this action can fulfill.

Utility AI Support

Actions can have cost/value attributes for utility-based planning:


 PlanningAction action = PlanningAction.builder("search")
     .cost(10)
     .value(50)
     .build();
 
Author:
TnsAI Team
See Also:
  • ActionSpec
  • Utility
  • Constructor Details

    • PlanningAction

      public PlanningAction(String name, String description, String precondition, String postcondition, Set<String> fulfills, Method method)
      Canonical constructor with defaults for backward compatibility.
    • PlanningAction

      public PlanningAction(String name, String description, String precondition, String postcondition, Set<String> fulfills, Method method, int cost, int value, float weight, Set<String> tags)
      Creates an instance of a PlanningAction record class.
      Parameters:
      name - the value for the name record component
      description - the value for the description record component
      precondition - the value for the precondition record component
      postcondition - the value for the postcondition record component
      fulfills - the value for the fulfills record component
      method - the value for the method record component
      cost - the value for the cost record component
      value - the value for the value record component
      weight - the value for the weight record component
      tags - the value for the tags record component
  • Method Details

    • of

      public static PlanningAction of(String name, String precondition, String postcondition, String... fulfills)
      Creates a PlanningAction without method reference.

      Useful for testing or simulation.

      Parameters:
      name - action name
      precondition - precondition expression
      postcondition - postcondition expression
      fulfills - goals this action fulfills
      Returns:
      new PlanningAction
    • builder

      public static PlanningAction.Builder builder(String name)
      Creates a builder for PlanningAction.
      Parameters:
      name - action name
      Returns:
      new builder
    • utility

      public int utility()
      Calculates simple utility score (value - cost).
      Returns:
      utility score
    • weightedUtility

      public float weightedUtility()
      Calculates weighted utility score.
      Returns:
      weighted utility
    • fulfillsGoal

      public boolean fulfillsGoal(String goalName)
      Checks if this action fulfills the specified goal.
      Parameters:
      goalName - goal name to check
      Returns:
      true if this action fulfills the goal
    • hasPrecondition

      public boolean hasPrecondition()
      Checks if this action has a precondition.
      Returns:
      true if precondition is specified
    • hasPostcondition

      public boolean hasPostcondition()
      Checks if this action has a postcondition.
      Returns:
      true if postcondition is specified
    • isExecutable

      public boolean isExecutable()
      Checks if this action is executable (has method reference).
      Returns:
      true if method is available
    • hasTag

      public boolean hasTag(String tag)
      Checks if this action has the specified tag.
      Parameters:
      tag - tag to check
      Returns:
      true if action has the tag
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • name

      public String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • description

      public String description()
      Returns the value of the description record component.
      Returns:
      the value of the description record component
    • precondition

      public String precondition()
      Returns the value of the precondition record component.
      Returns:
      the value of the precondition record component
    • postcondition

      public String postcondition()
      Returns the value of the postcondition record component.
      Returns:
      the value of the postcondition record component
    • fulfills

      public Set<String> fulfills()
      Returns the value of the fulfills record component.
      Returns:
      the value of the fulfills record component
    • method

      public Method method()
      Returns the value of the method record component.
      Returns:
      the value of the method record component
    • cost

      public int cost()
      Returns the value of the cost record component.
      Returns:
      the value of the cost record component
    • value

      public int value()
      Returns the value of the value record component.
      Returns:
      the value of the value record component
    • weight

      public float weight()
      Returns the value of the weight record component.
      Returns:
      the value of the weight record component
    • tags

      public Set<String> tags()
      Returns the value of the tags record component.
      Returns:
      the value of the tags record component