我正在使用 Jason 语言在两个代理之间进行通信。但我无法使用发送操作,它给出了错误。
这是我的两位经纪人,
代理人1:
// Agent Agent1 in project factorial3.mas2j
/* Initial goals */
!start.
/* Plans */
+!start : true
<- .print("starting..");
!query_factorial(2).
+!query_factorial(X) : true <-
.send(agent2,tell,giveme(X)).
/*+fact(X,Y) : true <-
.print("factorial ", X, " is ", Y, " thank you expert").*/
特工2:
// Agent agent2 in project IdEx.mas2j
/* Initial beliefs and rules */
/* Initial goals */
!begin.
/* Plans */
+!begin : true
<- .print("expert starting.......");
!giveme(X).
+!giveme(X):true
<- !fact(X,Y);
.print("Factorial of ", X, " is ", Y).
//.send(agent1,achive,fact(X,Y)).
+!fact(X,1) : X == 0.
+!fact(X,Y) : X > 0
<- !fact(X-1,Y1);
Y = Y1 * X.
因此,当我尝试在agent1中调用发送操作而agent2给出接收错误时,我收到此错误。
[agent2] *** Error adding var into renamed vars. var=X, value=(_229-1).
java.lang.ClassCastException: jason.asSyntax.ArithExpr cannot be cast to jason.asSyntax.VarTerm
at jason.asSemantics.TransitionSystem.prepareBodyForEvent(TransitionSystem.java:877)
at jason.asSemantics.TransitionSystem.applyExecInt(TransitionSystem.java:728)
at jason.asSemantics.TransitionSystem.applySemanticRule(TransitionSystem.java:222)
at jason.asSemantics.TransitionSystem.reasoningCycle(TransitionSystem.java:1429)
at jason.infra.centralised.CentralisedAgArch.run(CentralisedAgArch.java:205)
at java.lang.Thread.run(Thread.java:745)
如果您想要求代理执行计划(对于代理1,当您说
+!query_factorial(X)...)
时,它应该是一条实现消息。取消注释“计划”+fact(X,Y) : true <- .print("factorial ", X, " is ", Y, " thank you expert")
,您应该在开始时使用运算符!
让它成为一个计划。所以,如果我了解了你的测试项目的总体思路,它可以重写如下:
代理1代码:
!start.
+!start : true
<- .print("starting..");
!query_factorial(2).
+!query_factorial(X) : true <-
.send(agent2,achieve,giveme(X)).
代理2代码:
+!giveme(X):true
<- !fact(X,Y);
.print("Factorial of ", X, " is ", Y).
+!fact(X,1) : X == 0.
+!fact(X,Y) : X > 0
<- !fact(X-1,Y1);
Y = Y1 * X.
您可以看到,我没有使用原始代码的“开始计划”,因为 Agent1 正在执行这项工作,使 Agent2 在被要求时工作。