我目前正在使用JADE构建基于代理的平台来解决调度问题。情况是,定义的行为扩展了AchieveREInitiator在程序的某个特定状态下无法正常工作。 这是行为类:
class ACOInitiator extends AchieveREInitiator {
Agent myAgent;
List<Schedule> roundSchedules;
public ACOInitiator(Agent a, ACLMessage msg) {
super(a, msg);
this.myAgent = a;
roundSchedules = new ArrayList<Schedule>();
System.out.println(msg.getContent()); //This is properly printed.
// TODO Auto-generated constructor stub
}
@Override
protected Vector prepareRequests(ACLMessage request) {
System.out.println(request.getContent()); //In some specific state, this is not printed.
Vector v = new Vector(1);
for (int i = 1; i <= Properties.antNum; i++) {
AID aAID = new AID("Ant" + i, AID.ISLOCALNAME);
request.addReceiver(aAID);
aAID = null;
}
v.addElement(request);
return v;
}
@Override
protected void handleAgree(ACLMessage agree) {
try {
roundSchedules.add((Schedule) (agree.getContentObject()));
} catch (UnreadableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
agree = null;
}
@Override
protected void handleAllResponses(Vector responses) {
Collections.sort(roundSchedules);
Environment.iterSolution = roundSchedules.get(0);
roundSchedules = null;
Environment.setState(Environment.STATE_ITERATION_CHECKING);
responses = null;
myAgent.removeBehaviour(this);
}
}
执行程序时,会显示以下结果:
Generate solution.
Generate solution.
Iteration #1: 788.0(0.48s) (New best solution)
Generate solution.
Generate solution.
Iteration #2: 809.0(0.12s) r = 1/2
Generate solution.
Generate solution.
Iteration #3: 793.0(0.08s) r = 2/2
......
----- Simulation starts -----
......
@120
Breakdown machines:
Repaired machines:
Incoming jobs: 2-5;
Generate solution.
----- All schemes finished -----
这是不受欢迎的。显然,要打印的两个字符串是相同的。这就是解决方案阶段每次迭代的原因,2&#34;生成解决方案。&#34;印刷。但是,在后面的模拟阶段,只有1&#34;生成解决方案。&#34;打印出来,程序结束。可以推断出&#34; prepareRequests&#34;方法在非自动调用,如在早期阶段。 我是JADE的新手,这个问题困扰了我几天。如果您是JADE程序员,请提供帮助。
答案 0 :(得分:0)
我不确定我是否了解您的问题或问题,但从我能看到的第一个打印输出&#34;生成解决方案&#34;发生在构造函数中:
public ACOInitiator(Agent a,ACLMessage msg){ - &gt;的System.out.println(msg.getContent())
准备请求方法中的第二个:
protected Vector prepareRequests(ACLMessage request){ - &gt;的System.out.println(msg.getContent())
还要记住,当与多个代理进行交互时,发起者行为将等待来自其所有响应者行为的响应。
希望这有帮助,如果没有,请尝试附加嗅探器图表。