/**
  * Checks the type of all the fuzzy sets.
  *
  * @param l The list where the fuzzy sets are.
  * @return 1 if all discrete, 2 if all piecewise, 3 if all continuous or 0 if all the sets are not
  *     the same type.
  */
 public static int allType(LogoList l) {
   int discrete = 0;
   int piecewise = 0;
   int continuous = 0;
   // Count the type of all the fuzzy sets inside the list
   for (Object o : l) {
     FuzzySet f = (FuzzySet) o;
     if (f.isContinuous()) {
       if (f instanceof PiecewiseLinearSet) {
         piecewise++;
       }
       continuous++;
     } else {
       discrete++;
     }
   }
   // If all the sets of the list are discrete return 1
   if (discrete == l.size()) {
     return 1;
   }
   // If all the sets of the list are piecewise return 2
   // Check first piecewise linear cause piecewise linear is also
   // continuous
   if (piecewise == l.size()) {
     return 2;
   }
   // If all the sets of the list are continuous return 3
   if (continuous == l.size()) {
     return 3;
   }
   // If the sets are mixed return 0;
   return 0;
 }
Exemplo n.º 2
0
  @Override
  public Object report(final org.nlogo.nvm.Context context) throws LogoException {
    LogoList list = argEvalList(context, 0);
    int start = argEvalIntValue(context, 1);
    int stop = argEvalIntValue(context, 2);
    int size = list.size();
    if (start < 0) {
      throw new EngineException(
          context,
          this,
          I18N.errorsJ().getN("org.nlogo.prim.etc._sublist.startIsLessThanZero", start));
    } else if (stop < start) {
      throw new EngineException(
          context,
          this,
          I18N.errorsJ().getN("org.nlogo.prim.etc._sublist.endIsLessThanStart", stop, start));

    } else if (stop > size) {
      throw new EngineException(
          context,
          this,
          I18N.errorsJ().getN("org.nlogo.prim.etc._sublist.endIsGreaterThanListSize", stop, size));
    }
    return list.logoSublist(start, stop);
  }
 /**
  * Build the label of the operation sets.
  *
  * @param l The list with the fuzzy sets.
  * @param operation The string to concatenate the set's label.
  * @return The resulting string.
  */
 public static String buildLabel(LogoList l, String operation) {
   String name = "(" + operation + " of Sets: " + ((FuzzySet) l.first()).getLabel();
   for (int i = 1; i < l.size(); i++) {
     name += "," + ((FuzzySet) l.get(i)).getLabel();
   }
   name += ")";
   return name;
 }
Exemplo n.º 4
0
 @Override
 public Object report(final org.nlogo.nvm.Context context) throws LogoException {
   int index = argEvalIntValue(context, 0);
   Object obj = args[1].report(context);
   if (index < 0) {
     throw new EngineException(
         context, this, I18N.errorsJ().getN("org.nlogo.prim.etc.$common.negativeIndex", index));
   }
   if (obj instanceof LogoList) {
     LogoList list = (LogoList) obj;
     if (index >= list.size()) {
       throw new EngineException(
           context,
           this,
           I18N.errorsJ()
               .getN(
                   "org.nlogo.prim.etc.$common.indexExceedsListSize",
                   index,
                   Dump.logoObject(list),
                   list.size()));
     }
     return list.get(index);
   } else if (obj instanceof String) {
     String string = (String) obj;
     if (index >= string.length()) {
       throw new EngineException(
           context,
           this,
           I18N.errorsJ()
               .getN(
                   "org.nlogo.prim.etc.$common.indexExceedsListSize",
                   index,
                   Dump.logoObject(string),
                   string.length()));
     }
     return string.substring(index, index + 1);
   } else {
     throw new ArgumentTypeException(
         context, this, 1, Syntax.ListType() | Syntax.StringType(), obj);
   }
 }
 /**
  * Calculate the parameters and the universe of continuous sets.
  *
  * @param l Logolist containing all the fuzzysets.
  * @return A tuple containing the resulting parameters(List<FuzzySet>) and the universe(double[]).
  */
 public static Tuple<FuzzySet> continuousParamsUniverse(LogoList l) {
   List<FuzzySet> params = new ArrayList<FuzzySet>();
   // Get and add the first fuzzy set
   FuzzySet f = (FuzzySet) l.first();
   params.add(f);
   // Get the universe of the first fuzzy set
   double[] universe = f.getUniverse();
   // Iterate over all the fuzzy sets
   for (int i = 1; i < l.size(); i++) {
     // Add fuzzy sets as parameters to the new set
     f = (FuzzySet) l.get(i);
     params.add(f);
     // Calculate the new universe
     universe = DegreeOfFulfillment.andInterval(universe, f.getUniverse());
   }
   return new Tuple<FuzzySet>(params, universe);
 }
 /**
  * Calculate the parameters and the universe of discrete operations.
  *
  * @param l the list where the sets are.
  * @param operator The operation to perform.
  * @return A tuple containing the resulting parameters(List<double[]>) and universe(double[]).
  */
 public static Tuple<double[]> discreteOperations(LogoList l, Command operator) {
   // First discrete set and his parameters
   PointSet set = (PointSet) l.first();
   List<double[]> resultParameters = set.getParameters();
   double[] universe = new double[2];
   // Iterate over the sets
   for (int i = 1; i < l.size(); i++) {
     set = (PointSet) l.get(i);
     // Calculate the parameters of two sets
     resultParameters = discretePairOperation(resultParameters, set.getParameters(), operator);
   }
   // Calculate universe
   double[] point = resultParameters.get(0);
   universe[0] = point[0];
   point = resultParameters.get(resultParameters.size() - 1);
   universe[1] = point[0];
   return new Tuple<double[]>(resultParameters, universe);
 }