嗨,我正在使用Jade撰写我的论文。
我使用ams来发现主容器中的所有jade代理,但是当我尝试创建一些代理容器时,我无法搜索所有容器以获取它们上面的所有代理。
请帮助我修复我的代码,使其可以发现当前容器的ams代理。
以下是我用于在容器下创建代理的代码。
Runtime rt= Runtime.instance();
Profile p=new ProfileImpl();
AgentContainer AgentContainere = rt.createMainContainer(p);
AgentController[] tab=new AgentController[N];
try {
int k=0;
for (int i = 0; i < N; i++) {
if (i % 100 == 0) {
p=new ProfileImpl();
AgentContainere = rt.createMainContainer(p);
}
if ((i+1)%(N/NbrC)==0) {
tab[i] = AgentContainere.createNewAgent(psoeudo+" - "+i, "Agents.KmeanAgent", new Object[]{K,NbrC,true,k});
k++;
}else
tab[i] = AgentContainere.createNewAgent(psoeudo+" - "+i, "Agents.KmeanAgent", new Object[]{K,NbrC,false,N});
}
for (AgentController tab1 : tab) {
tab1.start();
}
我的代理需要广播一个ACL消息:
try {
currentCluster = new Point(p.getX(), p.getY());
tableOfCenters[index] = currentCluster;
AMSAgentDescription[] agents = null;
boolean notstable = true;
int found = 0;
long sleeptime=7000;
while (notstable) {
try {
sleep(sleeptime);
SearchConstraints c = new SearchConstraints();
c.setMaxResults(new Long(-1));
agents = AMSService.search(this, new AMSAgentDescription(), c);
if (agents.length > found) {
found = agents.length;
sleeptime+=5000;
} else {
notstable = false;
}
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println(found + "the found agent");
AID myId = getAID();
ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
int sendloop=0;
msg.setContent(getName() + currentCluster + " index = " + index);
for (AMSAgentDescription agent : agents) {
AID sendTo = agent.getName();
if (!sendTo.equals(myId) && !sendTo.getName().toLowerCase().contains("ams") && !sendTo.getName().toLowerCase().contains("df")) {
msg.addReceiver(sendTo);
sendloop++;
if (sendloop%10==0) {
send(msg);
System.out.println(msg);
msg.clearAllReceiver();
}
}
}
if (sendloop%10!=0) {
send(msg);
System.out.println(msg);
msg.clearAllReceiver();
}
System.out.println("********************");
System.out.println(msg);
System.out.println("********************");
} catch (Exception e) {
e.printStackTrace();
}