JADE

ComplexBehaviourAgent

package examples.behaviours;

import jade.core.Agent;
import jade.core.behaviours.OneShotBehaviour;
import jade.core.behaviours.SequentialBehaviour;
import jade.core.behaviours.Behaviour;

/**
   This is an example of recursive aggregation of composite agent behaviours.
   A composite behaviour is created, composed of some Sequential Behaviours, 
   and OneShot behaviours.
   @author Giovanni Rimassa - Università di Parma
   @version  $Date: 2001/08/06 14:10:07 $ $Revision: 2.2 $  
*/

// 
public class ComplexBehaviourAgent extends Agent {

  class Behaviour3Step extends OneShotBehaviour {

    private String myCode;

    public Behaviour3Step(Agent a, String code) {
      super(a);
      myCode = code;
    }

    public void action() {
      System.out.println("Agent " + getName() + ": Step " + myCode);
    }

  }


  protected void setup() {

    SequentialBehaviour myBehaviour1 = new SequentialBehaviour(this) {
      
        public int onEnd() {
          reset();
          return super.onEnd();
        }
      };

    SequentialBehaviour myBehaviour2 = new SequentialBehaviour(this);

    SequentialBehaviour myBehaviour2_1 = new SequentialBehaviour(this);
    SequentialBehaviour myBehaviour2_2 = new SequentialBehaviour(this);

    myBehaviour2_1.addSubBehaviour(new Behaviour3Step(this,"2.1.1"));
    myBehaviour2_1.addSubBehaviour(new Behaviour3Step(this,"2.1.2"));
    myBehaviour2_1.addSubBehaviour(new Behaviour3Step(this,"2.1.3"));

    myBehaviour2_2.addSubBehaviour(new Behaviour3Step(this,"2.2.1"));
    myBehaviour2_2.addSubBehaviour(new Behaviour3Step(this,"2.2.2"));
    Behaviour b = new Behaviour3Step(this,"2.2.3");
    myBehaviour2_2.addSubBehaviour(b);

    myBehaviour1.addSubBehaviour(new Behaviour3Step(this,"1.1"));
    myBehaviour1.addSubBehaviour(new Behaviour3Step(this,"1.2"));
    myBehaviour1.addSubBehaviour(new Behaviour3Step(this,"1.3"));

    myBehaviour2.addSubBehaviour(myBehaviour2_1);
    myBehaviour2.addSubBehaviour(myBehaviour2_2);

    myBehaviour2.addSubBehaviour(new Behaviour3Step(this,"2.3"));
    myBehaviour2.addSubBehaviour(new Behaviour3Step(this,"2.4"));
    myBehaviour2.addSubBehaviour(new Behaviour3Step(this,"2.5"));

    addBehaviour(myBehaviour1);
    addBehaviour(myBehaviour2);

  }


}

José M. Vidal .

10 of 21