Example #1
0
  @Override
  public void action() {

    try {
      System.out.println(getBehaviourName() + " msg received");
      EQRRoutingCriteria req = (EQRRoutingCriteria) message.getContentObject();
      EQRRoutingResult res = null;

      ACLMessage reply = message.createReply();
      try {
        System.out.println(getBehaviourName() + " Requesting route from server");
        res = ((GraphHopperServer) router).setCriteria(req).requestRouting().getRoutingResult();
        reply.setPerformative(ACLMessage.INFORM);
      } catch (EQRException e) {
        System.out.println(getBehaviourName() + "Error when requesting route...");
        e.getMessage();
        res = new EQRRoutingError();
        reply.setPerformative(ACLMessage.INFORM); /*
														 * TODO: Change this
														 * later
														 */
      } finally {
        System.out.println("Routing Behaviour: Request completed....Sending reply");
        reply.setContentObject(res);
        myAgent.send(reply);
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Example #2
0
  @Override
  protected ACLMessage handleCfp(ACLMessage cfp)
      throws RefuseException, FailureException, NotUnderstoodException {

    ACLMessage reply = cfp.createReply();
    reply.setPerformative(ACLMessage.PROPOSE);

    if (myAgent.getClass() == AGV.class) {
      try {
        if (cfp.getContentObject().getClass() == Cfp.class)
          reply = getAgvResponseMessage(reply, (Cfp) cfp.getContentObject(), (AGV) myAgent);
      } catch (UnreadableException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
      }
    } else if (myAgent.getClass() == Machine.class) {
      try {
        reply = getMachineMessageContent(reply, (Cfp) cfp.getContentObject());
      } catch (UnreadableException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
      }
    }
    return reply;
  }
Example #3
0
  @Override
  protected ACLMessage handleAcceptProposal(ACLMessage cfp, ACLMessage propose, ACLMessage accept) {
    // TODO Handle the accept
    Cfp content = null;
    try {
      content = (Cfp) accept.getContentObject();
    } catch (UnreadableException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    //		System.out.println(myAgent.getLocalName() + ": proposta aceite:" +
    // propose.getConversationId() + " content = " + content.getOrigin().getLocalName() + " " +
    // content.getDestination().getLocalName() + " " + content.getAgv().getLocalName());
    ACLMessage reply = accept.createReply();
    reply.setPerformative(ACLMessage.INFORM);
    if (myAgent.getClass() == AGV.class) {
      AGV a = (AGV) myAgent;
      AgvTransport t = new AgvTransport((AGV) myAgent, content);
      a.setTransportBehaviour(t);
      a.addBehaviour(new AgvTransport(a, content));
    }

    return reply;
  }
Example #4
0
 // #APIDOC_EXCLUDE_BEGIN
 public static void notifyFailureToSender(ACLMessage msg, String sender, String error) {
   if (myFrontEnd != null) {
     // Send back a failure message
     try {
       Iterator it = msg.getAllReceiver();
       while (it.hasNext()) {
         AID receiver = (AID) it.next();
         // If this receiver is local, the message has certainly been delivered
         // successfully --> Do not send any FAILURE back for this receiver
         if (myFrontEnd.getLocalAgent(receiver.getLocalName()) == null) {
           ACLMessage failure = msg.createReply();
           failure.setPerformative(ACLMessage.FAILURE);
           failure.setSender(myFrontEnd.getAMS());
           failure.setLanguage(FIPANames.ContentLanguage.FIPA_SL);
           String content = "( (action " + sender;
           content = content + " (ACLMessage) ) (MTS-error " + receiver + " \"" + error + "\") )";
           failure.setContent(content);
           myFrontEnd.messageIn(failure, sender);
         }
       }
     } catch (Exception e1) {
       logger.log(Logger.SEVERE, "Error delivering FAILURE message.", e1);
     }
   }
 }
  protected ACLMessage prepareResponse(ACLMessage msg)
      throws NotUnderstoodException, RefuseException {
    boolean agreed = false;
    ContentElement content;
    Concept action = null;
    System.out.println("Message Received");
    try {
      content = myAgent.getContentManager().extractContent(msg);
      action = ((Action) content).getAction();

      if (action instanceof AssignPowerRequest) {
        System.out.println("Received AssignPowerRequest");
        agreed = true;
      } else if (action instanceof BeginPowerTransitionRequest) {
        System.out.println("Received BeginPowerTransitionRequest");
        agreed = true;
      } else {
        System.out.println("Received AnotherAction, but will not perform it");
        agreed = false;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (agreed) {
      ACLMessage agree = msg.createReply();
      agree.setPerformative(ACLMessage.AGREE);
      System.out.println("Sent AGREE");
      return agree;
    } else {
      throw new RefuseException("unknown operation");
    }
  }
  @Override
  public int onEnd() {
    // send to the seller. request was firstly sent by him
    ACLMessage reply = request.createReply();
    reply.setContent("the winner is:");
    reply.setPerformative(ACLMessage.INFORM); // depending if it is failure or ...
    myAgent.send(reply);

    return 0;
  }
 protected ACLMessage prepareResultNotification(ACLMessage request, ACLMessage response) {
   if (request.getOntology().equals("request-ids")) return handleTourGuideRequest(request);
   else if (request.getOntology().equals("get-item-information"))
     return handleProfilerRequest(request);
   else {
     ACLMessage informDone = request.createReply();
     informDone.setPerformative(ACLMessage.NOT_UNDERSTOOD);
     return informDone;
   }
 }
    public ACLMessage handleCfpWithFeedback(ACLMessage newCFP) {
      // receives the content object (a counter proposal)
      ProposalEvaluation feedback = null;
      // extract proposal from the aclmessage
      try {
        ContentElement ce = myAgent.getContentManager().extractContent(newCFP);
        if (ce instanceof ProposalEvaluation) {
          feedback = (ProposalEvaluation) ce;
        }
      } catch (Codec.CodecException cex) {
        cex.printStackTrace();
      } catch (OntologyException oe) {
        oe.printStackTrace();
      }

      if (itemMapping != null) { // using a mapped item - translate proposal into own ontology
        feedback = ((EnterpriseAgent) myAgent).translateToOwnItemOntology(feedback, itemMapping);
      }
      // prepares response
      ACLMessage response = newCFP.createReply();

      Proposal newProposal;
      if (!((EnterpriseAgent) myAgent).isUseQNegotiationStrategy()) {
        newProposal = createCounterProposal(feedback, need, competence);
      } else {
        newProposal =
            qNegotiationStrategies
                .get(competence.getType())
                .createCounterProposal(getNegotiationId(), feedback, need, competence);
      }

      if (newProposal != null) {
        if (itemMapping
            != null) { // using a mapped item - translate proposal back to the foreign ontology
          newProposal =
              ((EnterpriseAgent) myAgent).translateToForeignItemOntology(newProposal, itemMapping);
        }

        response.setPerformative(ACLMessage.PROPOSE);
        try {
          myAgent.getContentManager().fillContent(response, newProposal);
        } catch (OntologyException oe) {
          oe.printStackTrace();
        } catch (Codec.CodecException cex) {
          cex.printStackTrace();
        }
      } else {
        response.setPerformative(ACLMessage.REFUSE);
      }

      return response;
    }
  void replyNotUnderstood(ACLMessage msg) {
    // -----------------------------------------

    try {
      ContentElement content = getContentManager().extractContent(msg);
      ACLMessage reply = msg.createReply();
      reply.setPerformative(ACLMessage.NOT_UNDERSTOOD);
      getContentManager().fillContent(reply, content);
      send(reply);
      System.out.println("Not understood!");
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
Example #10
0
 protected void handleNotUnderstood(ContentException ce, ACLMessage msg) {
   myLogger.log(
       Logger.WARNING,
       "Agent "
           + myAgent.getName()
           + " - Error decoding "
           + ACLMessage.getPerformative(msg.getPerformative())
           + " message. Sender is "
           + msg.getSender().getName(),
       ce);
   if (performativesRequiringReply.contains(msg.getPerformative())) {
     ACLMessage reply = msg.createReply();
     reply.setPerformative(ACLMessage.NOT_UNDERSTOOD);
     myAgent.send(reply);
   }
 }
Example #11
0
 protected void handleUnsupported(Object keyCel, ACLMessage msg) {
   myLogger.log(
       Logger.WARNING,
       "Agent "
           + myAgent.getName()
           + " - Unsupported content-element "
           + keyCel.getClass().getName()
           + ". Sender is "
           + msg.getSender().getName());
   if (performativesRequiringReply.contains(msg.getPerformative())) {
     ACLMessage reply = msg.createReply();
     reply.setPerformative(ACLMessage.REFUSE);
     reply.setContent(
         "((" + ExceptionVocabulary.UNSUPPORTEDACT + " " + keyCel.getClass().getName() + "))");
     myAgent.send(reply);
   }
 }
Example #12
0
 protected void handleServingFailure(Throwable t, Object cel, ACLMessage msg) {
   myLogger.log(
       Logger.SEVERE,
       "Agent "
           + myAgent.getName()
           + " - Unexpected error serving content-element "
           + cel.getClass().getName()
           + ". Sender is "
           + msg.getSender().getName(),
       t);
   if (performativesRequiringReply.contains(msg.getPerformative())) {
     ACLMessage reply = msg.createReply();
     reply.setPerformative(ACLMessage.FAILURE);
     reply.setContent("((" + ExceptionVocabulary.INTERNALERROR + " \"" + t + "\"))");
     myAgent.send(reply);
   }
 }
Example #13
0
    public void action() { // listen to incomming CFP from storageAgents

      MessageTemplate mt = MessageTemplate.MatchPerformative(ACLMessage.CFP);
      ACLMessage msg = myAgent.receive(mt);

      /*System.out.println("REQUEST RECEIVED");
      System.out.println(msg);*/
      if (msg != null) { // only respond to CFP messages
        // CFP Message received. Process it
        // System.out.println("Got request");
        String requestedLocation = msg.getContent();
        ACLMessage reply = msg.createReply(); // add the sender as
        // recipient
        Integer x =
            Integer.parseInt(
                requestedLocation.substring(
                    0, requestedLocation.lastIndexOf(','))); // parse the x of
        // product
        Integer y =
            Integer.parseInt(
                requestedLocation.substring(
                    requestedLocation.lastIndexOf(',') + 1,
                    requestedLocation.length())); // parse the y of product
        Integer price = calculatePathCost(new Point(x, y));
        if (holdingItem.x == x && holdingItem.y == y) { // robot is
          // carrying the
          // requested
          // item
          price = 1;
        }
        if (price != null) {
          reply.setPerformative(ACLMessage.PROPOSE);
          reply.setContent(String.valueOf(price.intValue()));
          // System.out.println(getAID().getName() + ": My cost is " +
          // price + ". To get to location: " +x + ","+y);//debugging
          // purpose
        } else {
          reply.setPerformative(ACLMessage.REFUSE);
          reply.setContent("Pathplanning error");
        }
        myAgent.send(reply);
      } else {
        block();
      }
    }
Example #14
0
 protected ACLMessage prepareResultNotification(ACLMessage request, ACLMessage response) {
   System.out.println(controller.getLocalName() + ": Replying with parameters");
   ACLMessage inform = request.createReply();
   inform.setPerformative(ACLMessage.INFORM);
   // send APS parameters
   try {
     // TODO Check if myParams has been filled
     myAgent.getContentManager().fillContent(inform, controller.getMyParams());
     // subscribing to the Power Producer for daily plans commands
     myAgent.addBehaviour(new PowerPlansSubscriptionBehaviour(controller, request.getSender()));
   } catch (CodecException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (OntologyException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return inform;
 }
Example #15
0
    public void action() {

      try {
        ContentElement content = getContentManager().extractContent(query);
        Information info = (Information) ((Action) content).getAction();
        Object obj = processInformation(info);
        if (obj == null) replyNotUnderstood(query);
        else {
          ACLMessage reply = query.createReply();
          reply.setPerformative(ACLMessage.INFORM);
          Result result = new Result((Action) content, obj);
          getContentManager().fillContent(reply, result);
          send(reply);
          System.out.println("Information processed.");
        }
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
Example #16
0
    public void action() {

      try {
        ContentElement content = getContentManager().extractContent(request);
        CreateAccount ca = (CreateAccount) ((Action) content).getAction();
        Account acc = new Account();
        String id = generateId();
        acc.setId(id);
        acc.setName(ca.getName());
        Result result = new Result((Action) content, acc);
        ACLMessage reply = request.createReply();
        reply.setPerformative(ACLMessage.INFORM);
        getContentManager().fillContent(reply, result);
        send(reply);
        accounts.put(id, acc);
        operations.put(id, new ArrayList());
        System.out.println("Account [" + acc.getName() + " # " + acc.getId() + "] created!");
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
Example #17
0
    public void action() {

      try {
        ContentElement content = getContentManager().extractContent(request);
        CreatePreferences cp = (CreatePreferences) ((Action) content).getAction();
        for (int i = 0; i < artifacts.size(); i++) {
          Artifact a = (Artifact) artifacts.get(i);
          if ((a.getGenre().equals(cp.getGenre())) || (a.getCreator().equals(cp.getCreator()))) {
            l.add(a);
          }
        }
        // System.out.println("Tour-Guide: " + l);
        Result result = new Result((Action) content, l);
        ACLMessage reply = request.createReply();
        reply.setPerformative(ACLMessage.INFORM);
        getContentManager().fillContent(reply, result);
        send(reply);

      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
  protected ACLMessage prepareResultNotification(ACLMessage msg, ACLMessage response)
      throws FailureException {
    boolean performed = false;
    ContentElement content;
    Concept action = null;

    System.out.println("pRN");

    try {
      content = myAgent.getContentManager().extractContent(msg);
      action = ((Action) content).getAction();

      if (action instanceof AssignPowerRequest) {
        AssignPowerRequest apr = (AssignPowerRequest) action;
        System.out.println("Performing AssignPowerRequest");
        System.out.println("Requester assigned power: " + apr.getAssignedPower());
        if (windTurbine.setAssignedPower(apr.getAssignedPower())) {
          System.out.println("Check passed, power assigned");
          performed = true;
        } else {
          System.out.println("Out of bounds, power not assigned");
          performed = false;
        }
      }

      if (action instanceof BeginPowerTransitionRequest) {
        BeginPowerTransitionRequest bptr = (BeginPowerTransitionRequest) action;
        boolean isOk = true;
        System.out.println("Performing BeginPowerTransitionRequest");
        if (bptr.getAssignedPowerIsValid()) {
          System.out.println("Requester assigned power: " + bptr.getAssignedPower());
          if (windTurbine.setAssignedPower(bptr.getAssignedPower())) {
            System.out.println("Check passed, power assigned");
          } else {
            System.out.println("Out of bounds, power not assigned");
            isOk = false;
          }
        } else {
          System.out.println("Requester did not assigned new power");
        }

        if (isOk) {
          windTurbine.change_power();
        }

        performed = isOk;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (performed) {
      ACLMessage inform = msg.createReply();
      Message sm = new Message();
      TimeDelay td = new TimeDelay();
      td.setTime(windTurbine.time_delay());
      System.out.println(
          "Agent "
              + myAgent.getLocalName()
              + ": Action successfully performed, time delay is "
              + windTurbine.time_delay());
      sm.setMsg(td);
      try {
        myAgent.getContentManager().fillContent(inform, new Action(msg.getSender(), sm));
      } catch (CodecException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (OntologyException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      inform.setPerformative(ACLMessage.INFORM);
      return inform;
    } else {
      throw new FailureException("out of bounds");
    }
  }
    /**
     * Handles a CFP message. This method is invoked when the first CFP is received. In this
     * implementation, the need is checked against the competence actually provided by this agent.
     * If it is there, <code>createStartingProposal</code> is used to generate a proposal.
     *
     * @param cfp The CFP message received
     */
    public ACLMessage handleFirstCfp(ACLMessage cfp) {
      ACLMessage response = cfp.createReply();
      try {
        ContentElement ce = myAgent.getContentManager().extractContent(cfp);
        CompetenceCall competenceCall = (CompetenceCall) ce;
        AID requesterAgent = competenceCall.getRequester();

        if (((EnterpriseAgent) myAgent).getNumberOfActiveContracts()
            > ((EnterpriseAgent) myAgent).MAX_NUMBER_OF_ACTIVE_CONTRACTS) {
          response.setPerformative(ACLMessage.REFUSE);
          response.setContent("refused...");
        } else {
          need = competenceCall.getNeed();
          competence = ((EnterpriseAgent) myAgent).findCompetence(need, requesterAgent);

          itemMapping = ((EnterpriseAgent) myAgent).getItemMapping(need, requesterAgent);
          if (itemMapping != null) { // using a mapped item - translate need into own ontology
            need =
                ((EnterpriseAgent) myAgent)
                    .translateToOwnItemOntology(need, requesterAgent, itemMapping);
          }

          if (competence != null) {
            if (((EnterpriseAgent) myAgent)
                .decideOnEnteringNegotiation(competenceCall, competence)) {
              // lets go for it!

              // create the starting proposal
              Proposal proposal = createStartingProposal(need, competence);

              if (itemMapping
                  != null) { // using a mapped item - translate proposal into foreign ontology
                proposal =
                    ((EnterpriseAgent) myAgent)
                        .translateToForeignItemOntology(proposal, itemMapping);
              }

              myAgent.getContentManager().fillContent(response, proposal);

              response.setPerformative(ACLMessage.PROPOSE);

              if (((EnterpriseAgent) myAgent).isUseQNegotiationStrategy()) {
                if (!qNegotiationStrategies.containsKey(competence.getType())) {
                  qNegotiationStrategies.put(competence.getType(), new QNegotiationStrategy());
                }
              }
            } else {
              // not negotiating
              response.setPerformative(ACLMessage.REFUSE);
            }
          } else {
            response.setPerformative(ACLMessage.REFUSE);
          }
        }
      } catch (OntologyException oe) {
        oe.printStackTrace();
        response.setPerformative(ACLMessage.REFUSE);
      } catch (Codec.CodecException ce) {
        ce.printStackTrace();
        response.setPerformative(ACLMessage.REFUSE);
      }

      return response;
    }
Example #20
0
    public void action() { // confirm that this agent will pick up the item
      MessageTemplate mt = MessageTemplate.MatchPerformative(ACLMessage.ACCEPT_PROPOSAL);
      ACLMessage msg = myAgent.receive(mt);
      if (msg != null) { // this agent is chosen to pick up the item
        // ACCEPT_PROPOSAL Message received. Process it
        String requestedLocation = msg.getContent();

        String[] locs = requestedLocation.split(":");

        String[] locItem = locs[0].split(",");
        Integer itemX = Integer.parseInt(locItem[0]);
        Integer itemY = Integer.parseInt(locItem[1]);

        String[] locStor = locs[1].split(",");
        Integer storageAgentX = Integer.parseInt(locStor[0]);
        Integer storageAgentY = Integer.parseInt(locStor[1]);

        /*Integer itemX = Integer.parseInt(requestedLocation.substring(0,
        		requestedLocation.indexOf(',', 1)));
        Integer itemY = Integer.parseInt(requestedLocation.substring(
        		requestedLocation.indexOf(',', 1) + 1,
        		requestedLocation.indexOf(':', 1)));
        Integer storageAgentX = Integer.parseInt(requestedLocation
        		.substring(requestedLocation.indexOf(':', 1) + 1,
        				requestedLocation.indexOf(',', 2)));
        Integer storageAgentY = Integer.parseInt(requestedLocation
        		.substring(requestedLocation.indexOf(',', 2) + 1,
        				requestedLocation.length()));*/

        ACLMessage reply = msg.createReply();

        reply.setPerformative(ACLMessage.INFORM);
        /*System.out.println(getAID().getName()
        + " will pick up the item at " + itemX + "," + itemY
        + " and bring it to storage agent: " + (storageAgentX)
        + "," + storageAgentY);*/
        myAgent.send(reply);

        boolean isAlreadyGoingThere = false;
        for (int i = 0; i < travelPoints.size(); i++) {
          if (travelPoints.get(i).x == itemX && travelPoints.get(i).y == itemY) {
            isAlreadyGoingThere = true;
          }
        }

        if ((holdingItem.x == itemX && holdingItem.y == itemY)) { // robot
          // is
          // carrying
          // the
          // requested
          // item
          if (nextDestination.get(0) == ITEMDROPDOWN) // stop dropdown
          // go deliver
          // the item
          {
            travelPoints.remove(0);
            nextDestination.remove(0);
            travelPoints.add(0, new Point(storageAgentX - 11, storageAgentY));
            travelPoints.add(1, new Point(storageAgentX - 1, storageAgentY));
            travelPoints.add(2, new Point(storageAgentX - 1, storageAgentY - 1));
            travelPoints.add(3, new Point(storageAgentX - 11, storageAgentY - 1));
            travelPoints.add(4, new Point(itemX, itemY));
            nextDestination.add(0, STORAGEAGENT);
            nextDestination.add(1, STORAGEAGENT);
            nextDestination.add(2, ITEMDROPDOWN);
            nextDestination.add(3, ITEMDROPDOWN);
            nextDestination.add(4, ITEMDROPDOWN);

          } else if (nextDestination.get(0) == STORAGEAGENT) {
            System.out.print(travelPoints.size());
            travelPoints.remove(4);
            nextDestination.remove(4);
            travelPoints.add(4, new Point(storageAgentX - 11, storageAgentY));
            travelPoints.add(5, new Point(storageAgentX - 1, storageAgentY));
            travelPoints.add(6, new Point(storageAgentX - 1, storageAgentY - 1));
            travelPoints.add(7, new Point(storageAgentX - 11, storageAgentY - 1));
            travelPoints.add(8, new Point(itemX, itemY));
            nextDestination.add(4, STORAGEAGENT);
            nextDestination.add(5, STORAGEAGENT);
            nextDestination.add(6, ITEMDROPDOWN);
            nextDestination.add(7, ITEMDROPDOWN);
            nextDestination.add(8, ITEMDROPDOWN);
          } else if (nextDestination.get(0) == ITEMPICKUP) {
            // at some unknown time, the robot agent has already planned to pick up the item
            travelPoints.remove(4);
            nextDestination.remove(4);
            travelPoints.add(4, new Point(storageAgentX - 11, storageAgentY));
            travelPoints.add(5, new Point(storageAgentX - 1, storageAgentY));
            travelPoints.add(6, new Point(storageAgentX - 1, storageAgentY - 1));
            travelPoints.add(7, new Point(storageAgentX - 11, storageAgentY - 1));
            travelPoints.add(8, new Point(itemX, itemY));
            nextDestination.add(4, STORAGEAGENT);
            nextDestination.add(5, STORAGEAGENT);
            nextDestination.add(6, ITEMDROPDOWN);
            nextDestination.add(7, ITEMDROPDOWN);
            nextDestination.add(8, ITEMDROPDOWN);
          }
        } else if (isAlreadyGoingThere) {
          boolean isInsert = false;
          for (int i = 0; i < travelPoints.size(); i++) {
            if (isInsert == false) {
              if (travelPoints.get(i).x == itemX && travelPoints.get(i).y == itemY) {
                isInsert = true;
                // travelPoints.remove(4);
                travelPoints.add(i + 5, new Point(storageAgentX - 11, storageAgentY));
                nextDestination.add(i + 5, STORAGEAGENT);
                travelPoints.add(i + 6, new Point(storageAgentX - 1, storageAgentY));
                nextDestination.add(i + 6, STORAGEAGENT);
                travelPoints.add(i + 7, new Point(storageAgentX - 1, storageAgentY - 1));
                nextDestination.add(i + 7, ITEMDROPDOWN);
                travelPoints.add(i + 8, new Point(storageAgentX - 11, storageAgentY - 1));
                nextDestination.add(i + 8, ITEMDROPDOWN);
              }
            }
          }

        } else {
          travelPoints.add(new Point(itemX, itemY));
          travelPoints.add(new Point(storageAgentX - 11, storageAgentY));
          travelPoints.add(new Point(storageAgentX - 1, storageAgentY));
          travelPoints.add(new Point(storageAgentX - 1, storageAgentY - 1));
          travelPoints.add(new Point(storageAgentX - 11, storageAgentY - 1));
          travelPoints.add(new Point(itemX, itemY));
          nextDestination.add(ITEMPICKUP);
          nextDestination.add(STORAGEAGENT);
          nextDestination.add(STORAGEAGENT);
          nextDestination.add(ITEMDROPDOWN);
          nextDestination.add(ITEMDROPDOWN);
          nextDestination.add(ITEMDROPDOWN);
          // nextDestination.add(ITEMDROPDOWN);
        }
      } else {
        block();
      }
    }
    @Override
    public void action() {
      if (queenNo == 0) {
        step = 0;
      } else {
        step = 1;
      }

      while (true) {
        switch (step) {
          case 0:
            if (col != N) {
              isConsistent = enumerate(queenNo);
              msg = new ACLMessage(ACLMessage.INFORM);
              msg.addReceiver(QueenAgents[0]);
              // q[0]=4;
              msg.setContent("" + q[0]);
              msg.setSender(myAgent.getAID());
              myAgent.send(msg);
              step = 2;
              //   System.out.println("The queen positions is " + q[0]);
            } else {
              block();
            }
            break;

          case 1: // message from previous queen...implies
            mt = MessageTemplate.MatchPerformative(ACLMessage.INFORM);
            msg = myAgent.receive(mt);

            if (msg != null) {
              receivedStr = msg.getContent(); // receive the column postions of the previous queens
              for (int i = 0; i < receivedStr.length(); i++) {
                q[i] =
                    Integer.parseInt(
                        receivedStr.substring(i, i + 1)); // put the queens in their positions
              }
              isConsistent = enumerate(queenNo);

              if (isConsistent) { // queen is placed in a valid position
                msg1.setPerformative(ACLMessage.INFORM);

                msg1.addReceiver(QueenAgents[1]); // add next queen as the receiver
                for (int i = 0;
                    i < receivedStr.length() + 1;
                    i++) // concatinate previous queen positions to send to the next queen
                {
                  str1 = str1.concat("" + q[i]);
                }
                msg1.setSender(myAgent.getAID());
                msg1.setContent(str1);
                myAgent.send(msg1); // send message to the next agent
                step = 2;
              } else { // create a refuse message
                // if(queenNo==N-1)System.out.println(" last queen cant be here");
                ACLMessage reply = msg.createReply();
                reply.setPerformative(ACLMessage.REFUSE);
                reply.setSender(myAgent.getAID());
                myAgent.send(reply);
                col = 0;
              }
              str1 = "";
            } else {
              block();
            }
            break;
          case 2:
            mt = MessageTemplate.MatchPerformative(ACLMessage.REFUSE);
            msg = myAgent.receive(mt);
            if (msg != null) {
              if (queenNo == 0) {
                // System.out.println("The queen positions was " + q[0]);
                step = 0;
                break;
              }
              if (enumerate(queenNo)) { // queen is placed in a valid position
                msg1.setPerformative(ACLMessage.INFORM);
                msg1.addReceiver(QueenAgents[1]); // add next queen as the receiver
                for (int i = 0;
                    i < receivedStr.length() + 1;
                    i++) // concatinate previous queen positions to send to the next queen
                {
                  str1 = str1.concat("" + q[i]);
                }
                msg1.setContent(str1);
                msg1.setSender(myAgent.getAID());
                myAgent.send(msg1); // send message to the next agent
                str1 = "";
              } else { // create a refuse message

                ACLMessage reply = new ACLMessage(ACLMessage.REFUSE);
                reply.addReceiver(QueenAgents[0]); // here is my suspecion
                col = 0;
                step = 1;
                reply.setContent(receivedStr);
                reply.setSender(myAgent.getAID());
                myAgent.send(reply);
              }
            } else {
              block();
            }
            break;
        }
      }
    }