gpt4 book ai didi

java - Jade Library-容器之间的代理移动性

转载 作者:行者123 更新时间:2023-12-01 05:24:56 26 4
gpt4 key购买 nike

我使用 jade library 编写了一段代表代理的代码穿越容器。我的代理有一个循环行为,它使用简单的switch-case 语句来跨容器移动。它在“Main-Container”运行,然后转到“Container-1”,然后转到“Container-2”,然后转到“Container-1”,依此类推!问题就在这里,它想回来,却回不来!没有关于未知Container或类似内容的错误。

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package MyAgentPool;

import jade.core.Agent;
import jade.core.ContainerID;
import jade.core.behaviours.CyclicBehaviour;

/**
*
* @author King Hadi
*/
public class MyAgent00 extends Agent {
@Override
protected void takeDown() {
// TODO Auto-generated method stub
super.takeDown();
System.out.print("goodbye!");
}

@Override
protected void setup() {
// TODO Auto-generated method stub
super.setup();
System.out.println("Hello I'm " + this.getLocalName());
this.addBehaviour(new MyBehaviour());
}
}

class MyBehaviour extends CyclicBehaviour {

private int step = 0;

@Override
public void action() {
// TODO Auto-generated method stub
switch (step) {
case 0: {
System.out.println("step variable is: "+ step);
step++;
ContainerID destination = new ContainerID();
destination.setName("Container-2");
System.out.println("waiting 2 seconds! before traveling ... ");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

myAgent.doMove(destination);
break;
}
case 1: {
System.out.println("step variable is: "+ step);
step++;
ContainerID destination1 = new ContainerID();
destination1.setName("Container-1");
System.out.println("waiting 2 seconds! before traveling ... ");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

myAgent.doMove(destination1);
break;
}
case 2: {
System.out.println("step variable is: "+ step);
step--;
ContainerID destination2 = new ContainerID();
destination2.setName("Container-2");
System.out.println("waiting 2 seconds! before traveling ...");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
myAgent.doMove(destination2);
break;
}
default: {
System.out.println("step variable is: "+ step);
step = 0;
ContainerID destination = new ContainerID();
destination.setName("Main-Contianer");
myAgent.doMove(destination);
System.out.println("waiting 2 seconds! before traveling ...");

try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
}
}
}
}

有人知道为什么这段代码不起作用吗?谢谢你! :)

最佳答案

您在 Default Switch 语句中犯了拼写错误:

destination.setName("Main-Contianer");

应该是:

destination.setName("Main-Container");

关于java - Jade Library-容器之间的代理移动性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9821934/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com