Class ConditionEvaluator

java.lang.Object
com.tnsai.planning.ConditionEvaluator

public final class ConditionEvaluator extends Object
Evaluates condition expressions against a state (belief) map.

Supports a simple expression language for goal conditions and action preconditions:

  • Comparison: ==, !=, >, >=, <, <=
  • Logical: &&, ||, !
  • Literals: true, false, numbers, strings

Examples


 Map<String, Object> state = Map.of("health", 80, "state", "ALIVE");

 ConditionEvaluator.evaluate("health > 50", state);        // true
 ConditionEvaluator.evaluate("state == ALIVE", state);     // true
 ConditionEvaluator.evaluate("health > 0 && health < 100", state); // true
 
Author:
TnsAI Team
  • Method Details

    • evaluate

      public static boolean evaluate(String condition, Map<String,Object> state)
      Evaluates a condition expression against the given state.

      A variable the state does not hold is unknown rather than null, and a condition whose value turns on an unknown is not satisfied: negating it does not satisfy it either.

      Parameters:
      condition - expression to evaluate
      state - current state (belief map)
      Returns:
      true if condition is satisfied
    • applyEffects

      public static void applyEffects(String postcondition, Map<String,Object> state)
      Parses and applies postcondition effects to a state map.

      Postcondition syntax: "variable = value" or "var1 = val1, var2 = val2"

      Parameters:
      postcondition - effect expression
      state - state to modify (mutable)