private String checkAskedDiscreteDomain(Attribute askedAttribute, String value) {
      List askedValues = askedAttribute.getDiscreteDomain();
      for (int i = 0; i < askedValues.size(); i++) {
        if (askedValues.get(i).equals(value)) {
          return value;
        }
      }

      return String.valueOf(askedValues.get((int) (askedValues.size() * Math.random())));
    }
Esempio n. 2
0
  protected void startNode()
      throws IMTPException, ProfileException, ServiceException, JADESecurityException,
          NotFoundException {
    // Initialize all services (without activating them)
    List services = new ArrayList();
    initMandatoryServices(services);

    List l = myProfile.getSpecifiers(Profile.SERVICES);
    myProfile.setSpecifiers(Profile.SERVICES, l); // Avoid parsing services twice
    initAdditionalServices(l.iterator(), services);

    // Register with the platform
    ServiceDescriptor[] descriptors = new ServiceDescriptor[services.size()];
    for (int i = 0; i < descriptors.length; ++i) {
      descriptors[i] = (ServiceDescriptor) services.get(i);
    }
    if (theBEManager != null) {
      myNodeDescriptor.setParentNode(theBEManager.getNode());
    }
    // Actually join the platform (this call can modify the name of this container)
    getServiceManager().addNode(myNodeDescriptor, descriptors);
    if (theBEManager != null) {
      theBEManager.register(myNodeDescriptor);
    }

    // Once we are connected, boot all services
    bootAllServices(services);
  }
Esempio n. 3
0
  public weka.core.Instances toWekaInstances() {
    // attributes
    FastVector wattrs = new FastVector();
    Iterator itr = attributes.iterator();
    while (itr.hasNext()) {
      Attribute attr = (Attribute) itr.next();
      wattrs.addElement(attr.toWekaAttribute());
    }
    // data instances
    weka.core.Instances winsts = new weka.core.Instances(name, wattrs, instances.size());
    itr = instances.iterator();

    while (itr.hasNext()) {
      Instance inst = (Instance) itr.next();
      Iterator itrval = inst.getValues().iterator();
      Iterator itrmis = inst.getMissing().iterator();
      double[] vals = new double[wattrs.size()];
      for (int i = 0; i < wattrs.size(); i++) {
        double val = (Double) itrval.next();
        if ((Boolean) itrmis.next()) {
          vals[i] = weka.core.Instance.missingValue();
        } else {
          vals[i] = val;
        }
      }
      weka.core.Instance winst = new weka.core.Instance(1, vals);
      winst.setDataset(winsts);
      winsts.add(winst);
    }
    winsts.setClassIndex(this.class_index);
    return winsts;
  }
 /**
  * Get the current child
  *
  * @see CompositeBehaviour#getCurrent
  */
 protected Behaviour getCurrent() {
   Behaviour b = null;
   if (subBehaviours.size() > current) {
     b = (Behaviour) subBehaviours.get(current);
   }
   return b;
 }
Esempio n. 5
0
 public List removePendingMessages(MessageTemplate template, boolean notifyFailure) {
   List pendingMsg = ((jade.imtp.leap.FrontEndStub) myFrontEnd).removePendingMessages(template);
   if (pendingMsg.size() > 0) {
     myLogger.log(
         Logger.INFO, "Removed " + pendingMsg.size() + " pending messages from BackEnd queue.");
   }
   if (notifyFailure) {
     Iterator it = pendingMsg.iterator();
     while (it.hasNext()) {
       try {
         Object[] removed = (Object[]) it.next();
         ACLMessage msg = (ACLMessage) removed[0];
         AID receiver = new AID((String) removed[1], AID.ISLOCALNAME);
         ServiceFinder myFinder = getServiceFinder();
         MessagingService msgSvc = (MessagingService) myFinder.findService(MessagingSlice.NAME);
         msgSvc.notifyFailureToSender(
             new GenericMessage(msg), receiver, new InternalError("Agent dead"));
       } catch (Exception e) {
         myLogger.log(Logger.WARNING, "Cannot send AMS FAILURE. " + e);
       }
     }
   }
   return pendingMsg;
 }
    /**
     * Creates a counterproposal, based on qualitative feedback on the previous proposal. According
     * to the feedback received (on each AttributeValue of the Proposal), the enterpriseAgent
     * generates a new value for each proposal's attribute. Calculating a new value for an attribute
     * depends on the classification ("excellent", "sufficient", "bad", "very bad") and direction
     * ("up", "down") feedback elements at an AttributeValue. In this implementation:
     *
     * <ul>
     *   <li>For discrete attributes, a new random value is selected within the domain of values for
     *       this attribute.
     *   <li>For continuous attributes:
     *       <ul>
     *         <li>If classification = "very bad", the value is changed in 10% towards the indicated
     *             direction.
     *         <li>If classification = "bad", the value is changed in 5% towards the indicated
     *             direction.
     *         <li>If classification = "sufficient", the value is changed in 0.5% towards the
     *             indicated direction.
     *         <li>If classification = "excellent", the value is not changed.
     *       </ul>
     * </ul>
     */
    public Proposal createCounterProposal(
        ProposalEvaluation feedback, Need need, Competence competence) {
      //			final float DELTA_EXCELLENT = 0.0f;
      //			final float DELTA_SUFFICIENT = 0.005f;
      //			final float DELTA_BAD = 0.5f;
      //			final float DELTA_VERYBAD = 3f;

      final float DELTA_EXCELLENT = 0.0f;
      final float DELTA_SUFFICIENT = 0.5f;
      final float DELTA_BAD = 0.7f;
      final float DELTA_VERYBAD = 1.2f;

      //			final float DELTA_SUFFICIENT = 0.05f;
      //			final float DELTA_BAD = 0.5f;
      //			final float DELTA_VERYBAD = 1.5f;

      Proposal proposal = new Proposal(myAgent.getAID());
      proposal.setNeedType(feedback.getNeedType());

      for (int i = 0; i < feedback.getAttributeValueEvaluations().size(); i++) {
        AttributeValueEvaluation attributeValueEvaluation =
            (AttributeValueEvaluation) feedback.getAttributeValueEvaluations().get(i);
        Attribute askedAttribute = need.getAttribute(attributeValueEvaluation.getName());
        Attribute ownAttribute = competence.getAttribute(attributeValueEvaluation.getName());
        AttributeValue valueToPropose = new AttributeValue();
        valueToPropose.setName(attributeValueEvaluation.getName());
        valueToPropose.setType(attributeValueEvaluation.getType());

        if (attributeValueEvaluation.isDiscrete()) { // discrete attribute
          if (attributeValueEvaluation.getClassif()
                  == AttributeValueEvaluation.AttributeClassification.BAD
              || attributeValueEvaluation.getClassif()
                  == AttributeValueEvaluation.AttributeClassification.VERY_BAD) {
            // propose a new random value for this attribute
            List domain = ownAttribute.getDiscreteDomain();

            String proposedValue =
                (String)
                    domain.get(
                        (int)
                            (domain.size()
                                * Math
                                    .random())); // FIXME: may get the same value or a previously
                                                 // proposed one!
            valueToPropose.setValue(proposedValue);
          } else {
            // maintain previous value
            valueToPropose.setValue(attributeValueEvaluation.getValue());
          }
        } else { // continuous attribute
          float floatValue =
              Float.parseFloat(attributeValueEvaluation.getValue()); // treat as float
          float difToMaxEdge =
              Float.parseFloat((String) askedAttribute.getContinuousDomainMax()) - floatValue;
          float difToMinEdge =
              floatValue - Float.parseFloat((String) askedAttribute.getContinuousDomainMin());

          switch (attributeValueEvaluation.getClassif()) {
            case EXCELLENT:
              floatValue += DELTA_EXCELLENT * floatValue;
              break;
            case SUFFICIENT:
              if (attributeValueEvaluation.getDirection()
                  == AttributeValueEvaluation.AttributeDirection.UP) {
                floatValue += DELTA_SUFFICIENT * difToMaxEdge;
              } else {
                floatValue -= DELTA_SUFFICIENT * difToMinEdge;
              }
              break;
            case BAD:
              if (attributeValueEvaluation.getDirection()
                  == AttributeValueEvaluation.AttributeDirection.UP) {
                floatValue += DELTA_BAD * difToMaxEdge;
              } else if (attributeValueEvaluation.getDirection()
                  == AttributeValueEvaluation.AttributeDirection.DOWN) {
                floatValue -= DELTA_BAD * difToMinEdge;
              }
              break;
            case VERY_BAD:
              if (attributeValueEvaluation.getDirection()
                  == AttributeValueEvaluation.AttributeDirection.UP) {
                floatValue += DELTA_VERYBAD * difToMaxEdge;
              } else if (attributeValueEvaluation.getDirection()
                  == AttributeValueEvaluation.AttributeDirection.DOWN) {
                floatValue -= DELTA_VERYBAD * difToMinEdge;
              }
              break;
          }

          floatValue = checkOwnContinuousDomain(ownAttribute, floatValue);
          floatValue = checkAskedContinuousDomain(askedAttribute, floatValue);

          if (attributeValueEvaluation
              .getType()
              .equals("float")) { // check if this is really of type float, or integer
            valueToPropose.setValue(String.valueOf(floatValue));
          } else {
            valueToPropose.setValue(String.valueOf(Math.round(floatValue)));
          }
        }

        proposal.getAttributeValues().add(valueToPropose);
      }

      return proposal;
    }
 /**
  * Check whether this <code>SequentialBehaviour</code> must terminate.
  *
  * @return true when the last child has terminated. false otherwise
  * @see CompositeBehaviour#checkTermination
  */
 protected boolean checkTermination(boolean currentDone, int currentResult) {
   return (currentDone && current >= (subBehaviours.size() - 1));
 }
 public void skipNext() {
   current = subBehaviours.size();
 }