Package com.tnsai.planning
Record Class PlanningAction
java.lang.Object
java.lang.Record
com.tnsai.planning.PlanningAction
- Record Components:
name- action name (method name)description- human-readable descriptionprecondition- condition that must be true before executionpostcondition- effects after execution (state changes)fulfills- set of goal names this action helps achievemethod- the actual method to invokecost- 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 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:
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionPlanningAction(String name, String description, String precondition, String postcondition, Set<String> fulfills, Method method) Canonical constructor with defaults for backward compatibility.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 aPlanningActionrecord class. -
Method Summary
Modifier and TypeMethodDescriptionstatic PlanningAction.BuilderCreates a builder for PlanningAction.intcost()Returns the value of thecostrecord component.Returns the value of thedescriptionrecord component.final booleanIndicates whether some other object is "equal to" this one.fulfills()Returns the value of thefulfillsrecord component.booleanfulfillsGoal(String goalName) Checks if this action fulfills the specified goal.final inthashCode()Returns a hash code value for this object.booleanChecks if this action has a postcondition.booleanChecks if this action has a precondition.booleanChecks if this action has the specified tag.booleanChecks if this action is executable (has method reference).method()Returns the value of themethodrecord component.name()Returns the value of thenamerecord component.static PlanningActionCreates a PlanningAction without method reference.Returns the value of thepostconditionrecord component.Returns the value of thepreconditionrecord component.tags()Returns the value of thetagsrecord component.final StringtoString()Returns a string representation of this record class.intutility()Calculates simple utility score (value - cost).intvalue()Returns the value of thevaluerecord component.floatweight()Returns the value of theweightrecord component.floatCalculates weighted utility score.
-
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 aPlanningActionrecord class.- Parameters:
name- the value for thenamerecord componentdescription- the value for thedescriptionrecord componentprecondition- the value for thepreconditionrecord componentpostcondition- the value for thepostconditionrecord componentfulfills- the value for thefulfillsrecord componentmethod- the value for themethodrecord componentcost- the value for thecostrecord componentvalue- the value for thevaluerecord componentweight- the value for theweightrecord componenttags- the value for thetagsrecord 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 nameprecondition- precondition expressionpostcondition- postcondition expressionfulfills- goals this action fulfills- Returns:
- new PlanningAction
-
builder
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
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
Checks if this action has the specified tag.- Parameters:
tag- tag to check- Returns:
- true if action has the tag
-
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. -
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. -
equals
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 withObjects::equals(Object,Object); primitive components are compared with '=='. -
name
Returns the value of thenamerecord component.- Returns:
- the value of the
namerecord component
-
description
Returns the value of thedescriptionrecord component.- Returns:
- the value of the
descriptionrecord component
-
precondition
Returns the value of thepreconditionrecord component.- Returns:
- the value of the
preconditionrecord component
-
postcondition
Returns the value of thepostconditionrecord component.- Returns:
- the value of the
postconditionrecord component
-
fulfills
Returns the value of thefulfillsrecord component.- Returns:
- the value of the
fulfillsrecord component
-
method
Returns the value of themethodrecord component.- Returns:
- the value of the
methodrecord component
-
cost
public int cost()Returns the value of thecostrecord component.- Returns:
- the value of the
costrecord component
-
value
public int value()Returns the value of thevaluerecord component.- Returns:
- the value of the
valuerecord component
-
weight
public float weight()Returns the value of theweightrecord component.- Returns:
- the value of the
weightrecord component
-
tags
Returns the value of thetagsrecord component.- Returns:
- the value of the
tagsrecord component
-