0

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.

Mike Causer
  • 8,196
  • 2
  • 43
  • 63

1 Answers1

0

I'm not sure I understand your question or problem but from what I can see the first printout "Generate solution" happens in the constructor:

public ACOInitiator(Agent a, ACLMessage msg) { -> System.out.println(msg.getContent())

the second one in the prepare requests method:

protected Vector prepareRequests(ACLMessage request) {-> System.out.println(msg.getContent()) .

Also remember when interacting with multiple agents the initiator behaviour will wait for a response from all its responder behaviours.

Hope this helps, if it does not, try attaching sniffer diagrams.

Just_Alex
  • 518
  • 1
  • 4
  • 16
  • Sniffer diagrams will help yes! Also a description of what it is supposed to do and what it does. Something more descriptive than does, not work. What is it doing? – Just_Alex Dec 15 '14 at 16:02