繁体   English   中英

如何为JADE Agent设置AID?

[英]How to set AID for JADE Agent?

我只是从基于JADE代理的建模开始。 我的hello world示例看起来像这样-

public class HelloWorldAgent extends Agent {
 protected void setup() {
  System.out.println("Hello World! My AID is "+this.getAID());
 }
}

我这样叫外面

public class Main {
  public static void main(String[] args) {
    HelloWorldAgent helloWorldAgent = new HelloWorldAgent();
    helloWorldAgent.setup();
  }
}

我看到的输出是-

Hello World! My AID is null

现在,我的问题是如何设置AID,因为只有get方法,而没有“ set”方法。 由于不可用,我怀疑AID是自动分配的。 是这样吗? 如果是,如何确定座席获得AID? 谢谢。

我建议您首先创建一个容器。 您可以在主要方法中尝试这种方式:

public static void main(String[] args) throws Exception {
    ProfileImpl p = new ProfileImpl();
    p.setParameter(Profile.MAIN_HOST, "localhost");
    p.setParameter(Profile.GUI, "true");

    ContainerController cc = Runtime.instance().createMainContainer(p);

    AgentController ac = cc.createNewAgent("myAgent", "HelloWorldAgent", new Object[] { });
    ac.start();
}

在这种情况下,getAID()。getLocalName()将返回“ myAgent”。

从我所看到的,您并没有真正使用JADE框架。 您只是在调用helloWorldAgent.setup()方法。 尝试启动JADE,注意只有引导选项0,1和2是必需的。

public static void main(String[] args) {
        // TODO code application logic here
        String[] bootOptions = new String[7]; 
        bootOptions[0] = "-gui"; 
        bootOptions[1] = "-local-port";
        bootOptions[2] = "1111";
        bootOptions[3] = "-container-name";
        bootOptions[4] = "Launch container";
        bootOptions[5] = "-agents";
        bootOptions[6] = "myFirstAgent:package.HelloWorldAgent";
        jade.Boot.main(bootOptions);


    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM