コード例 #1
0
  /** entry point of agent */
  protected void setup() {
    claimDropdownID = false;
    holdingItem = new Point(0, 0);
    // nextDestination.add(IDLE);
    movementVerified = false;
    awaitingRelease = false;
    // uiMap = new Map();
    updateGuiAgents(); // Robot agent wont start without an active GuiAgent
    if (guiAgents.length == 0) {
      /*System.out.println("No gui agent found, robot agent is terminating");*/
      doDelete();
    }

    // RobotAgent wont start without coordination arguments (looks like: 1,1
    // ) on startup
    Object[] args = getArguments();
    if (args != null && args.length > 0) {
      location = new Point(Integer.parseInt((String) args[0]), Integer.parseInt((String) args[1]));
      /*System.out.println(getAID().getName() + " is positioned at "
      + location.x + "," + location.y);*/
    } else {
      // Make the agent terminate
      /*System.out.println("No position defined, closing down");*/
      doDelete();
    }

    //		System.out.println("Hallo! Robot-agent " + getAID().getName()
    //				+ " is ready.");

    // register at yellow pages serivce
    DFAgentDescription dfd = new DFAgentDescription();
    dfd.setName(getAID());
    ServiceDescription sd = new ServiceDescription();
    sd.setType("Warehouse-RobotAgent");
    sd.setName("Warehouse-RobotAutomation");
    dfd.addServices(sd);
    try {
      DFService.register(this, dfd);

    } catch (FIPAException e) {
      //			System.out.println("catch");
      e.printStackTrace();
    }

    addBehaviour(new OfferRequestsServer()); // bid on current requests
    addBehaviour(new AcceptRequestServer()); // accept an incomming request
    addBehaviour(new MapReceiver()); // awaits a map message from guiAgent
    addBehaviour(new MapRequest()); // one shot behaviour to load the map
    addBehaviour(new MovementBehaviour(this, 500)); // every second the
    // robot is allowed to
    // move a spot
    addBehaviour(new HopReply()); // Behaviour which awaits incomming
    // accept/decline after a hop claim
    // request
    addBehaviour(new ArrivalReply()); // Behaviour which awaits incomming go
    // after arriving at a storage agent

    this.calculateNextHopSetup();
  }
コード例 #2
0
 private void register() {
   DFAgentDescription dfd = new DFAgentDescription();
   dfd.setName(getAID());
   ServiceDescription sd = new ServiceDescription();
   sd.setType("Publish-chessboard");
   sd.setName("Chessboard");
   dfd.addServices(sd);
   try {
     DFService.register(this, dfd);
   } catch (FIPAException e) {
     log.severe(e.getMessage());
   }
 }
コード例 #3
0
 /** Registers a WSIG into a DF */
 private void registerIntoDF() {
   DFAgentDescription dfad = new DFAgentDescription();
   dfad.setName(this.getAID());
   dfad.addLanguages(FIPANames.ContentLanguage.FIPA_SL);
   dfad.addProtocols(FIPANames.InteractionProtocol.FIPA_REQUEST);
   ServiceDescription sd = new ServiceDescription();
   sd.setType(AGENT_TYPE);
   sd.setName(getLocalName());
   dfad.addServices(sd);
   try {
     DFService.register(this, dfad);
   } catch (Exception e) {
     log.error("Agent " + getLocalName() + " - Error during DF registration", e);
   }
 }
コード例 #4
0
ファイル: SuperAgent.java プロジェクト: Ralys/M2SID-POA
  /**
   * Enregistrement des services
   *
   * @param type le type de son agent (TypeAgent)
   */
  protected void registerService(String type) {
    DFAgentDescription dfd = new DFAgentDescription();
    dfd.setName(this.getAID());

    ServiceDescription sd = new ServiceDescription();
    sd.setType(type);
    sd.setName(type);

    dfd.addServices(sd);

    try {
      DFService.register(this, dfd);
    } catch (FIPAException e) {
      System.err.println(
          getLocalName() + " registration with DF unsucceeded. Reason: " + e.getMessage());
      doDelete();
    }
  }
コード例 #5
0
ファイル: TourGuideAgent.java プロジェクト: johnny-h4wk/DAIIA
    public void action() {

      ServiceDescription sd = new ServiceDescription();
      sd.setType(TOUR_GUIDE_AGENT);
      sd.setName(getName());
      DFAgentDescription dfd = new DFAgentDescription();
      dfd.setName(getAID());
      dfd.addServices(sd);
      try {
        DFAgentDescription[] dfds = DFService.search(myAgent, dfd);
        if (dfds.length > 0) {
          DFService.deregister(myAgent, dfd);
        }
        DFService.register(myAgent, dfd);
        System.out.println(getLocalName() + " is ready.");
      } catch (Exception ex) {
        System.out.println("Failed registering with DF! Shutting down...");
        ex.printStackTrace();
        doDelete();
      }
    }
コード例 #6
0
  private void publishServices() {
    /** ************************************************************** */
    /** ************ Publish the two services to DF **************** */
    /** ************************************************************** */
    ServiceDescription artifactInformation = new ServiceDescription();
    artifactInformation.setType("artifact-lookup");
    artifactInformation.setName("get-artifact-info");
    artifactInformation.addOntologies("get-item-information");
    Property args =
        new Property("args", "Send a Profile and use the ontology: get-item-information");
    artifactInformation.addProperties(args);

    ServiceDescription artifactSearch = new ServiceDescription();
    artifactSearch.setType("artifact-search");
    artifactSearch.setName("search-for-artifacts");
    artifactSearch.addOntologies("request-ids");
    args =
        new Property("args", "Send an ArrayList<Integer> of IDs and use the ontology: request-ids");
    artifactSearch.addProperties(args);

    ServiceDescription buyingArtifacts = new ServiceDescription();
    buyingArtifacts.setName("buying-artifacts");
    buyingArtifacts.setType("buying-artifacts");

    DFAgentDescription dfd = new DFAgentDescription();
    dfd.setName(getAID());
    dfd.addServices(artifactInformation);
    dfd.addServices(artifactSearch);
    dfd.addServices(buyingArtifacts);
    try {
      DFService.register(this, dfd);
      // System.out.println(getName() + ": Successfully registered services.");
    } catch (FIPAException e) {
      e.printStackTrace();
    }
    /** ************************************************************* */
  }
コード例 #7
0
  /** Initialization */
  protected void setup() {
    // INitialize the logger
    logger = jade.util.Logger.getMyLogger(this.getClass().getName());
    logger.setLevel(Logger.SEVERE);

    logger.info("Student agent started: " + getLocalName());
    // studentNumber = (String)(String)getArguments()[0];

    /** Register the agent to the directory facilitator */
    DFAgentDescription dfd = new DFAgentDescription();
    dfd.setName(getAID());
    ServiceDescription sd = new ServiceDescription();
    sd.setType(getLocalName());
    sd.setName("Student Agent");
    dfd.addServices(sd);
    try {
      DFService.register(this, dfd);
    } catch (FIPAException fe) {
      fe.printStackTrace();
    }

    // Add main student agent behaviour
    addBehaviour(new StudentAgentBehaviour());
  }
コード例 #8
0
ファイル: Room.java プロジェクト: tnw513/JadeHomeAutomation
  /*
   * Method that register the room agent to the df and defines requests managment
   */
  protected void registerRoom() {
    // Create the agent description.
    DFAgentDescription dfd = new DFAgentDescription();
    dfd.setName(getAID());

    // Create the services description.
    ServiceDescription deviceListSD = new ServiceDescription();
    deviceListSD.setType(HomeAutomation.SERVICE_ROOM_DEVICE_LIST);
    deviceListSD.setName("JADE-room-device-list");

    ServiceDescription deviceRegistrationSD = new ServiceDescription();
    deviceRegistrationSD.setType("room-device-registration");
    deviceRegistrationSD.setType(HomeAutomation.SERVICE_ROOM_DEVICE_REGISTRATION);
    deviceRegistrationSD.setName("JADE-room-device-registration");

    // Add the services description to the agent description.
    // TODO add here other Sevice Descriptions
    dfd.addServices(deviceListSD);
    dfd.addServices(deviceRegistrationSD);

    try {
      // Register the service
      log(
          "Registering '"
              + deviceListSD.getType()
              + "' service named '"
              + deviceListSD.getName()
              + "'"
              + "to the default DF...");

      DFService.register(this, dfd);

      log("Waiting for request...");
    } catch (FIPAException fe) {
      fe.printStackTrace();
    }

    // Add the behaviour serving queries from controller agents.
    MessageTemplate template =
        AchieveREResponder.createMessageTemplate(FIPANames.InteractionProtocol.FIPA_REQUEST);
    addBehaviour(
        new AchieveREResponder(this, template) {

          @Override
          protected ACLMessage handleRequest(ACLMessage request)
              throws NotUnderstoodException, RefuseException {

            log("Handle request with content");
            return new ACLMessage(ACLMessage.AGREE);
          }

          @Override
          protected ACLMessage prepareResultNotification(ACLMessage request, ACLMessage response) {

            //						log("Prepare result notification with content: " + request.getContent());
            response.setPerformative(ACLMessage.INFORM);

            Message message = null;
            try {
              message = (Message) request.getContentObject();

            } catch (UnreadableException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }

            if (message != null) {
              if (message.getService().equals(HomeAutomation.SERVICE_ROOM_DEVICE_LIST)) {
                try {
                  // send device array
                  response.setContentObject(devices);

                } catch (IOException e) {
                  e.printStackTrace();
                }
              } else if (message
                  .getService()
                  .equals(HomeAutomation.SERVICE_ROOM_DEVICE_REGISTRATION)) {
                RegistrationMessage regMessage = (RegistrationMessage) message;

                if (regMessage.getParentId().equals(id)) {
                  AgentMessage agentDesc =
                      new AgentMessage(
                          regMessage.getAid(),
                          regMessage.getParentId(),
                          regMessage.getName(),
                          regMessage.getDescription());
                  devices.add(agentDesc);

                  log(
                      "Device "
                          + request.getSender()
                          + " successfully added to room's device list.");
                } else {
                  // send refuse..
                  log("Wrong room!!");
                  response.setPerformative(ACLMessage.REFUSE);
                }
              }
            }

            return response;
          }
        });
  }