2013年10月31日星期四

Multi-agent platform 之 Jade 学习笔记 1

1. 下载 安装
    http://jade.tilab.com/ 上下载最新的jade4.3.0。有几个文件可以下载,我下的是jadefull。解压缩后选择jade-bin-4.3.0.zip再解压缩,得到jade文件夹。把其中jade.jar和commons-codec-1.3.jar的路径添加到环境变量中的CLASSPATH里。打开cmd,输入命令java jade.Boot -gui,若出现jade控制台就说明配置成功。

2. 在eclipse中使用jade
    解压缩jade-expamples-4.3.0.zip,得到examples文件夹。在eclipse中新建工程(JadeTest),然后把examples文件夹导入到工程src中。这时右键单击JadeTest工程名,选择build path的configure build path, 在library中导入jade.jar和commons-codec-1.3.jar。

    选择examples中的HelloWorldAgent.java,右键单击,选择Run As, 选Run Configurations, 在选项卡中选new launch configuration, 键入名字Run on Jade, Project是JadeTest,Main Class是jade.Boot。左键单击选项卡Arguments,在Program arguments 中填入-gui -agents hello:examples.hello.HelloWorldAgent,之后就可以运行了。(注意:一定要添加带包名的class文件名examples.hello.HelloWorldAgent
    其中-gui是选择是否显示Jade Remote Agent Management GUI; -agents是创建agent,创建方式是<agent-local-name>:<fully-qualified-agent-class>(agent本地名(自己定义):agent class文件的地址(此例中为examples.hello.HelloWorldAgent))。

3. 在agent代码中创建新的agent
  参看examples.thanksAgent.ThanksAgent例子。

public class Starter extends Agent {

private AgentContainer ac = null;
private AgentController t1 = null;
protected void setup() {
try {
// create agent t1 on the same container of the creator agent
AgentContainer container = (AgentContainer)getContainerController(); // get a container controller for creating new agents
t1 = container.createNewAgent("seller", "test.BookSellerAgent", null);
t1.start();
System.out.println(getLocalName()+" CREATED AND STARTED NEW BookSellerAgent:"+ "seller" + " ON CONTAINER "+container.getContainerName());
} catch (Exception any) {
any.printStackTrace();
}
}
// Put agent clean-up operations here
protected void takeDown() {
// Printout a dismissal message
System.out.println("Starter terminating.");
}
}

没有评论:

发表评论