gpt4 book ai didi

containers - 如何获得所有货柜 Jade 的代理?

转载 作者:行者123 更新时间:2023-12-03 08:05:38 25 4
gpt4 key购买 nike

嗨,我在 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();

}

我的经纪人需要广播广告:
     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();
}

最佳答案

您只需要向AMS代理发送请求,然后使用代理列表( Jade 中间件中的当前代理)进行打印或执行所需的任何操作:

步骤1:向AMS发送请求:

    // Required imports

import jade.domain.AMSService;
import jade.domain.FIPAAgentManagement.*;

...
AMSAgentDescription [] agents = null;

try {
SearchConstraints c = new SearchConstraints();
c.setMaxResults ( new Long(-1) );
agents = AMSService.search( this, new AMSAgentDescription (), c );
}
catch (Exception e) { ... }

步骤2:显示要求的结果:
for (int i=0; i<agents.length;i++){
AID agentID = agents[i].getName();
System.out.println(agentID.getLocalName());
}

关于containers - 如何获得所有货柜 Jade 的代理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28652869/

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