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;
    }
  private CarOntology() {

    super(ONTOLOGY_NAME, BasicOntology.getInstance());

    try {

      add(new ConceptSchema(CAR), Car.class);
      add(new ConceptSchema(ENGINE), Engine.class);
      add(new PredicateSchema(AVAILABLE), Available.class);
      add(new ConceptSchema(COST), Cost.class);
      add(new ConceptSchema(AUTOMOBILE), AutoMobile.class);
      add(new ConceptSchema(CREDITCARD), CreditCard.class);
      add(new AgentActionSchema(RENT), Rent.class);
      add(new ConceptSchema(CATALOG), Catalog.class);

      ConceptSchema cs1 = (ConceptSchema) getSchema(CAR);
      cs1.add(BRAND, (PrimitiveSchema) getSchema(BasicOntology.STRING));
      cs1.add(MODEL, (PrimitiveSchema) getSchema(BasicOntology.STRING));
      cs1.add(COLOR, (PrimitiveSchema) getSchema(BasicOntology.STRING));
      cs1.add(YEAR, (PrimitiveSchema) getSchema(BasicOntology.INTEGER));

      ConceptSchema cs2 = (ConceptSchema) getSchema(ENGINE);
      cs2.add(CAPACITY, (PrimitiveSchema) getSchema(BasicOntology.INTEGER));
      cs2.add(HORSEPOWER, (PrimitiveSchema) getSchema(BasicOntology.INTEGER));
      cs2.add(MILEAGE, (PrimitiveSchema) getSchema(BasicOntology.INTEGER));

      ConceptSchema cs3 = (ConceptSchema) getSchema(COST);
      cs3.add(PRIZE, (PrimitiveSchema) getSchema(BasicOntology.INTEGER));
      cs3.add(AUTOMOBILE, (PrimitiveSchema) getSchema(BasicOntology.INTEGER));

      ConceptSchema cs4 = (ConceptSchema) getSchema(AUTOMOBILE);
      cs4.add(SERIALID, (PrimitiveSchema) getSchema(BasicOntology.INTEGER));

      ConceptSchema cs5 = (ConceptSchema) getSchema(CREDITCARD);
      cs5.add(TYPE, (PrimitiveSchema) getSchema(BasicOntology.STRING));
      cs5.add(NUMBER, (PrimitiveSchema) getSchema(BasicOntology.INTEGER));
      cs5.add(DATE, (PrimitiveSchema) getSchema(BasicOntology.DATE));

      ConceptSchema cs6 = (ConceptSchema) getSchema(CATALOG);
      cs6.add(CARS, (PrimitiveSchema) getSchema(AUTOMOBILE), 1, ObjectSchema.UNLIMITED);

      AgentActionSchema aas1 = (AgentActionSchema) getSchema(RENT);
      aas1.add(AID, (PrimitiveSchema) getSchema(BasicOntology.AID));
      aas1.add(AUTOMOBILE, (PrimitiveSchema) getSchema(BasicOntology.INTEGER));
      aas1.add(CREDITCARD, (PrimitiveSchema) getSchema(BasicOntology.STRING));

      PredicateSchema ps1 = (PredicateSchema) getSchema(AVAILABLE);
      ps1.add(AID, (PrimitiveSchema) getSchema(BasicOntology.AID));
      ps1.add(AUTOMOBILE, (PrimitiveSchema) getSchema(BasicOntology.INTEGER));

    } catch (OntologyException oe) {

      oe.printStackTrace();
    }
  }
示例#3
0
  /**
   * Construct a schema that vinculates an entity to be a generic variable. Note that there are no
   * different types of variable as it happens for concepts (e.g. Person, Address...), IREs (e.g.
   * IOTA, ANY, ALL...) and the like. Therefore there is no VariableSchema constructor that takes a
   * String parameter. Not also that the type of the values that can be assumed by the variable is
   * another story and is defined by the VARIABLE_VALUE_TYPE slot of the VariableSchema
   */
  private VariableSchema() {
    super(BASE_NAME);

    try {
      add(NAME, BasicOntology.getInstance().getSchema(BasicOntology.STRING));
      add(
          VALUE_TYPE,
          BasicOntology.getInstance().getSchema(BasicOntology.STRING),
          ObjectSchema.OPTIONAL);
    } catch (OntologyException oe) {
      oe.printStackTrace();
    }
  }
  public PeopleOntology(Ontology base) {
    super(ONTOLOGY_NAME, base, new ReflectiveIntrospector());

    try {
      PrimitiveSchema stringSchema = (PrimitiveSchema) getSchema(BasicOntology.STRING);
      PrimitiveSchema integerSchema = (PrimitiveSchema) getSchema(BasicOntology.INTEGER);

      ConceptSchema addressSchema = new ConceptSchema(ADDRESS);
      addressSchema.add(STREET, stringSchema, ObjectSchema.OPTIONAL);
      addressSchema.add(NUMBER, integerSchema, ObjectSchema.OPTIONAL);
      addressSchema.add(CITY, stringSchema);

      ConceptSchema personSchema = new ConceptSchema(PERSON);
      personSchema.add(NAME, stringSchema);
      personSchema.add(ADDRESS, addressSchema, ObjectSchema.OPTIONAL);

      ConceptSchema manSchema = new ConceptSchema(MAN);
      manSchema.addSuperSchema(personSchema);

      ConceptSchema womanSchema = new ConceptSchema(WOMAN);
      womanSchema.addSuperSchema(personSchema);

      add(personSchema, Person.class);
      add(manSchema, Man.class);
      add(womanSchema, Woman.class);
      add(addressSchema, Address.class);

      AggregateSchema childrenSchema = new AggregateSchema(BasicOntology.SEQUENCE);

      PredicateSchema fatherOfSchema = new PredicateSchema(FATHER_OF);
      fatherOfSchema.add(FATHER, manSchema);
      fatherOfSchema.add(CHILDREN, childrenSchema);

      PredicateSchema motherOfSchema = new PredicateSchema(MOTHER_OF);
      motherOfSchema.add(MOTHER, womanSchema);
      motherOfSchema.add(CHILDREN, childrenSchema);

      add(fatherOfSchema, FatherOf.class);
      add(motherOfSchema, MotherOf.class);

      AgentActionSchema marrySchema = new AgentActionSchema(MARRY);
      marrySchema.add(HUSBAND, manSchema);
      marrySchema.add(WIFE, womanSchema);

      add(marrySchema);
    } catch (OntologyException oe) {
      oe.printStackTrace();
    }
  }
示例#5
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;
 }
  private Location parseAMSResponse(ACLMessage response) {
    Result results = null;

    try {
      results = (Result) getContentManager().extractContent(response);
    } catch (UngroundedException e) {
      e.printStackTrace();
    } catch (CodecException e) {
      e.printStackTrace();
    } catch (OntologyException e) {
      e.printStackTrace();
    }

    Iterator it = results.getItems().iterator();

    Location loc = null;

    if (it.hasNext()) loc = (Location) it.next();

    return loc;
  }
  /** Subscriber register */
  public boolean register(Subscription sub) throws RefuseException, NotUnderstoodException {
    Date date = null;
    SubscriptionMessageType type = null;
    //
    try {
      // Unpack message
      ContentElement ce = buildingcs.getContentManager().extractContent(sub.getMessage());
      if (ce instanceof SendSubscriptionMessage) {
        SendSubscriptionMessage smsg = (SendSubscriptionMessage) ce;
        type = smsg.getMessage().getType(); // Subscription type
        date = smsg.getMessage().getSendDate(); // Last message date
      }
    } catch (UngroundedException e) {
      e.printStackTrace();
    } catch (OntologyException e) {
      e.printStackTrace();
    } catch (jade.content.lang.Codec.CodecException e) {
      e.printStackTrace();
    }

    if (type != null) {
      subscribers.add(new Subscriber(sub, type, date));
      this.confirm(sub);
      System.out.println(
          "Agent "
              + buildingcs.getAID().getName()
              + " registered the agent "
              + sub.getMessage().getSender().getName());
      //
      if (subscribers.size() == 1) {
        buildingcs.addBehaviour(tick_behavior); // At first subscriber add tick behavior
      }
    }

    return true;
  }
  private ACLMessage prepareRequest(AID agent) {
    ACLMessage request = new ACLMessage(ACLMessage.REQUEST);
    request.addReceiver(getAMS());
    request.setLanguage(FIPANames.ContentLanguage.FIPA_SL0);
    request.setOntology(MobilityOntology.NAME);
    request.setProtocol(FIPANames.InteractionProtocol.FIPA_REQUEST);

    Action act = new Action();
    act.setActor(getAMS());

    WhereIsAgentAction action = new WhereIsAgentAction();
    action.setAgentIdentifier(agent);
    act.setAction(action);

    try {
      getContentManager().fillContent(request, act);
    } catch (CodecException e) {
      e.printStackTrace();
    } catch (OntologyException e) {
      e.printStackTrace();
    }

    return request;
  }
  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;
    }
  /**
   * @param out
   * @param parser
   * @param sender the sender of the message
   * @param receiver the receiver of the message
   * @param actionName the action requested
   * @param parentDF the df to wich request an action (used for federate action)
   */
  JADEAppletRequestProto(
      DFAppletCommunicator communicator,
      AID receiver,
      String actionName,
      Object description,
      Object parentDF,
      SearchConstraints constraints)
      throws FIPAException {
    super(communicator.getStream(), communicator.getParser(), new ACLMessage(ACLMessage.REQUEST));

    this.gui = communicator.getGUI();
    this.dfApplet = communicator;
    ACLMessage request = new ACLMessage(ACLMessage.REQUEST);
    // request.setSender(sender);
    request.addReceiver(receiver);
    request.setProtocol(FIPANames.InteractionProtocol.FIPA_REQUEST);
    request.setLanguage(FIPANames.ContentLanguage.FIPA_SL);
    request.setOntology(DFAppletOntology.NAME);
    request.setReplyWith("rw" + (new Date()).getTime());
    request.setConversationId("conv" + (new Date()).getTime());

    this.reqMsg = (ACLMessage) request.clone();
    this.action = actionName;
    this.receiver = receiver;
    this.parent = (AID) parentDF;

    Action act = new Action();
    act.setActor(receiver);
    if (actionName.equalsIgnoreCase(DFAppletVocabulary.FEDERATE)) {

      Federate action = new Federate();
      action.setDf((AID) parentDF);
      action.setDescription((DFAgentDescription) description);

      act.setAction(action);

    } else if (actionName.equalsIgnoreCase(DFAppletVocabulary.GETDESCRIPTION))
      act.setAction(new GetDescription());
    else if (actionName.equalsIgnoreCase(DFAppletVocabulary.GETPARENTS))
      act.setAction(new GetParents());
    else if (actionName.equalsIgnoreCase(DFAppletVocabulary.GETDESCRIPTIONUSED)) {
      GetDescriptionUsed action = new GetDescriptionUsed();
      action.setParentDF((AID) parentDF);
      act.setAction(action);
    } else if (actionName.equalsIgnoreCase(DFAppletVocabulary.DEREGISTERFROM)) {
      DeregisterFrom action = new DeregisterFrom();
      action.setDf((AID) parentDF);
      action.setDescription((DFAgentDescription) description);

      act.setAction(action);
    } else if (actionName.equalsIgnoreCase(DFAppletVocabulary.REGISTERWITH)) {
      RegisterWith action = new RegisterWith();
      action.setDf((AID) parentDF);
      action.setDescription((DFAgentDescription) description);

      act.setAction(action);
    } else if (actionName.equalsIgnoreCase(DFAppletVocabulary.SEARCHON)) {
      SearchOn action = new SearchOn();
      action.setDf((AID) parentDF);
      action.setDescription((DFAgentDescription) description);
      action.setConstraints(constraints);

      act.setAction(action);
    } else if (actionName.equalsIgnoreCase(DFAppletVocabulary.MODIFYON)) {
      ModifyOn action = new ModifyOn();
      action.setDf((AID) parentDF);
      action.setDescription((DFAgentDescription) description);

      act.setAction(action);
    } else throw new UnsupportedFunction();

    // initialize SL0 Codec and FIPAAgentManagementOntology
    // FIXME for applet I have not the agent c = sender.lookupLanguage(SL0Codec.NAME);
    // if (c == null)
    c = new SLCodec();

    // Write the action in the :content slot of the request
    List content = new ArrayList();
    content.add(act);

    try {
      String s = ((SLCodec) c).encode(o, (AbsContentElement) o.fromObject(act));
      this.reqMsg.setContent(s);
    } catch (OntologyException oe) {
      oe.printStackTrace();
      throw new FIPAException("Ontology error: " + oe.getMessage());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
示例#12
0
  public BookingOntology(Ontology base) {
    super(ONTOLOGY_NAME, base, new ReflectiveIntrospector());

    try {
      PrimitiveSchema stringSchema = (PrimitiveSchema) getSchema(BasicOntology.STRING);
      PrimitiveSchema dateSchema = (PrimitiveSchema) getSchema(BasicOntology.DATE);
      PrimitiveSchema intSchema = (PrimitiveSchema) getSchema(BasicOntology.INTEGER);
      // ContentElementListSchema listSchema =
      // (ContentElementListSchema)getSchema(BasicOntology.CONTENT_ELEMENT_LIST);

      // Definizione schema Centro Prenotazione
      ConceptSchema centroSchema = new ConceptSchema(CENTRO_PRENOTAZIONE);
      centroSchema.add(NOME, stringSchema, ObjectSchema.MANDATORY);
      centroSchema.add(TELEFONO, stringSchema, ObjectSchema.MANDATORY);
      centroSchema.add(VIA, stringSchema);
      centroSchema.add(PRESTAZIONI, stringSchema, 1, ObjectSchema.UNLIMITED);

      add(centroSchema, CentroPrenotazione.class);

      // Definizione schema Cliente
      ConceptSchema clienteSchema = new ConceptSchema(CLIENTE);
      clienteSchema.add(NOMEC, stringSchema, ObjectSchema.MANDATORY);
      clienteSchema.add(COGNOME, stringSchema, ObjectSchema.MANDATORY);
      clienteSchema.add(TELEFONOC, stringSchema, ObjectSchema.MANDATORY);

      add(clienteSchema, Cliente.class);

      ConceptSchema intervalliSchema = new ConceptSchema(INTERVALLOPRENOTAZIONE);
      intervalliSchema.add(INIZIOPRENOTAZIONE, dateSchema, ObjectSchema.MANDATORY);
      intervalliSchema.add(FINEPRENOTAZIONE, dateSchema, ObjectSchema.MANDATORY);

      add(intervalliSchema, IntervalloPrenotazione.class);

      // Definizione predicati
      PredicateSchema prenotazioneSchema = new PredicateSchema(PRENOTAZIONE);
      prenotazioneSchema.add(CLIENTE, clienteSchema, ObjectSchema.MANDATORY);
      prenotazioneSchema.add(PRESTAZIONE, stringSchema, ObjectSchema.MANDATORY);

      add(prenotazioneSchema, Prenotazione.class);

      PredicateSchema prenotazioneConDataSchema = new PredicateSchema(PRENOTAZIONE_CON_DATA);
      prenotazioneConDataSchema.add(CLIENTE, clienteSchema, ObjectSchema.MANDATORY);
      prenotazioneConDataSchema.add(PRESTAZIONE, stringSchema, ObjectSchema.MANDATORY);
      prenotazioneConDataSchema.add(DATAPRENOTAZIONE, dateSchema, ObjectSchema.OPTIONAL);

      add(prenotazioneConDataSchema, PrenotazioneConData.class);

      PredicateSchema confermaSchema = new PredicateSchema(CONFERMA);
      confermaSchema.add(CENTRO_PRENOTAZIONE, centroSchema, ObjectSchema.MANDATORY);
      confermaSchema.add(INIZIOPRENOTAZIONE, dateSchema, ObjectSchema.MANDATORY);
      confermaSchema.add(FINEPRENOTAZIONE, dateSchema, ObjectSchema.MANDATORY);
      confermaSchema.add(PRESTAZIONE, stringSchema, ObjectSchema.MANDATORY);
      confermaSchema.add(ID_PRENOTAZIONE, intSchema);

      add(confermaSchema, Conferma.class);

      PredicateSchema propostaSchema = new PredicateSchema(PROPOSTAINTERVALLI);
      propostaSchema.add(INTERVALLI, intervalliSchema, 1, ObjectSchema.UNLIMITED);
      propostaSchema.add(CENTRO_PRENOTAZIONE, centroSchema, ObjectSchema.MANDATORY);

      add(propostaSchema, PropostaIntervalli.class);

    } catch (OntologyException oe) {
      oe.printStackTrace();
    }
  }