I am currently using JADE to build an agent-based platform to solve scheduling problems. The case is that, a defined behaviour extends AchieveREInitiator doesn't work properly in some specific state of the programme. This is the behaviour class:
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);
}
}
When the programme is executed, the following results are shown:
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 -----
This is unwanted. Apparently, the two Strings to be printed is the same. That's why every iteration in the solution stage, 2 "Generate solution." are printed. However, in the later simulation stage, only 1 "Generate solution." is printed and the programmes goes to the end. It can be inferred that the "prepareRequests" method in not auto called, as in earlier stage. I'm new to JADE and the problem has bothered me a couple of days. Please help if you are a JADE programmer.