无法向另一个Jason代理发送操作

我使用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.

因此,当我在代理1中尝试调用发送操作时,我会得到这个错误,而代理2则会接收到错误信息。

[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.

你可以看到,我没有使用你原始代码中的“开始计划”,因为代理1在执行任务,使代理2在被请求时工作。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注