4

我正在使用 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)
4

1 回答 1

1

如果您想要求代理执行计划(如果您说“+!query_factorial(X)...”时代理1),它应该是一条实现消息。取消注释 "计划" "+fact(X,Y) : true <- .print("factorial ", X, " is ", Y, "谢谢专家")。您应该使用运算符“!” 一开始就制定计划。所以,如果我理解了你的测试项目的总体思路,它可以重写如下:

代理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 工作。

于 2017-08-23T21:56:56.377 回答