artificial-intelligencemulti-agent

Unable to update a numeric counter in Jason Agent Belief


I managed to create an agent to count how many times actions it performed. Hence, I propose this asl code.

last_time(0).
!start.
/* Plans */
+!start : true <-
    ?last_time(X);
    new_t = X + 1;
    .print("take train " , X);
    -+last_time(new_t);
    !start.

But I am encountering an error.

[test] No failure event was generated for +!start[code((new_t = 1)),code_line(5),code_src("file:src/asl/test.asl"),error(constraint_failed),error_msg("Constraint (new_t = (X+1)); .print("take train ",X); -+last_time(new_t); !start was not satisfied (file:src/asl/test.asl:5) un={X=0}"),source(self)]
intention 1: 
    +!start[source(self)] <- ... (new_t = (X+1)); .print("take train ",X); -+last_time(new_t); !start / {X=0}

I think it may be due to line #5 (new_t = X + 1;) because my code runs well after line #5 is commented out. I am not sure why I can't increase it.

Notes:


Solution

  • Variables in Jason (as in Prolog, which inspired Jason) starts with uppercase letters. In your program, just replace new_t by New_t and it likely works.

    The command new_t = X + 1 fails because new_t is not equals to 1 (the result of evaluation of X+1. The = operator is the unification operator. It returns true if both arguments can be literally equal by some substitution of variables by values. In your program, there is no value for X that makes X+1 equals to new_t. That is the reason we do not find X=X+1 in Jason programs. This expression can not be true because there is no value for X that makes both arguments of the unification equal.