A have 3 working agents in written in agentspeak. Two of them have a belief +number(someNumber) and the third is trying to compute the minimum of these two. What I have now is the middle agent receiving both literals from the two agent, but as both are literals, normal math.min() operation cannot be used here:
+!test: iam(root) <-
.send("agent14", askOne, number(RE), L);
.send("agent15", askOne, number(RE2), R);
.print("Both got numbers: ", L, " ", R);
+number(math.min(L, R));
.print("DONE").
here the math.min() function produces an error, as it is not implemented for the data type:
[ArithFunctionTerm] Error in 'math.min(L,R)' (agent.asl:36) -- error in evaluate!
jason.JasonException: math.min is not implemented for type 'number(65)[source(agent14)]'.
Is there a way to compare these two values?
The origin of the problem is the answer of askOne: a literal of the same type as the one used to ask. Thus L unifies with number(65)
and R unifies with number(<somenumber>)
. Since they are literals (and not numbers), they can not be used by math.min
.
The solution is to exploit unification in the fourth arg of .send
:
.send("agent14", askOne, number(RE), number(L));
.send("agent15", askOne, number(RE2), number(R));
now L and R are unified with numbers and math.min
will work.