Exemple #1
0
  /**
   * Joins two vectors
   *
   * @param a First vector
   * @param b Second vector
   * @return The joint of both vectors
   */
  public static Vector<Integer> unionVectores(Vector<Integer> a, Vector<Integer> b) {

    int i;

    for (i = 0; i < b.size(); i++) {
      if (a.contains(new Integer((Integer) (b.elementAt(i)))) == false) {
        a.addElement(b.elementAt(i));
      }
    }

    return a;
  } // end-method
Exemple #2
0
  /**
   * Computes the trueHShaffer distribution from a given parameter.
   *
   * @param k K parameter
   * @param n M value
   * @return The trueHShaffer distribution
   */
  public static Vector<Integer> trueHShaffer(int k) {

    Vector<Integer> number;
    int j;
    Vector<Integer> tmp, tmp2;
    int p;

    number = new Vector<Integer>();
    tmp = new Vector<Integer>();
    if (k <= 1) {
      number.addElement(new Integer(0));
    } else {
      for (j = 1; j <= k; j++) {
        tmp = trueHShaffer(k - j);
        tmp2 = new Vector<Integer>();
        for (p = 0; p < tmp.size(); p++) {
          tmp2.addElement(((Integer) (tmp.elementAt(p))).intValue() + (int) combinatoria(2, j));
        }
        number = unionVectores(number, tmp2);
      }
    }

    return number;
  } // end-method
Exemple #3
0
  /**
   * Obtain all exhaustive comparisons possible from an array of indexes
   *
   * @param indices A verctos of indexes.
   * @return A vector with vectors containing all the possible relations between the indexes
   */
  @SuppressWarnings("unchecked")
  public static Vector<Vector<Relation>> obtainExhaustive(Vector<Integer> indices) {

    Vector<Vector<Relation>> result = new Vector<Vector<Relation>>();
    int i, j, k;
    String binario;
    boolean[] number = new boolean[indices.size()];
    Vector<Integer> ind1, ind2;
    Vector<Relation> set = new Vector<Relation>();
    Vector<Vector<Relation>> res1, res2;
    Vector<Relation> temp;
    Vector<Relation> temp2;
    Vector<Relation> temp3;

    ind1 = new Vector<Integer>();
    ind2 = new Vector<Integer>();
    temp = new Vector<Relation>();
    temp2 = new Vector<Relation>();
    temp3 = new Vector<Relation>();

    for (i = 0; i < indices.size(); i++) {
      for (j = i + 1; j < indices.size(); j++) {
        set.addElement(
            new Relation(
                ((Integer) indices.elementAt(i)).intValue(),
                ((Integer) indices.elementAt(j)).intValue()));
      }
    }
    if (set.size() > 0) result.addElement(set);

    for (i = 1; i < (int) (Math.pow(2, indices.size() - 1)); i++) {
      Arrays.fill(number, false);
      ind1.removeAllElements();
      ind2.removeAllElements();
      temp.removeAllElements();
      temp2.removeAllElements();
      temp3.removeAllElements();
      binario = Integer.toString(i, 2);
      for (k = 0; k < number.length - binario.length(); k++) {
        number[k] = false;
      }
      for (j = 0; j < binario.length(); j++, k++) {
        if (binario.charAt(j) == '1') number[k] = true;
      }
      for (j = 0; j < number.length; j++) {
        if (number[j] == true) {
          ind1.addElement(new Integer(((Integer) indices.elementAt(j)).intValue()));
        } else {
          ind2.addElement(new Integer(((Integer) indices.elementAt(j)).intValue()));
        }
      }
      res1 = obtainExhaustive(ind1);
      res2 = obtainExhaustive(ind2);
      for (j = 0; j < res1.size(); j++) {
        result.addElement(new Vector<Relation>((Vector<Relation>) res1.elementAt(j)));
      }
      for (j = 0; j < res2.size(); j++) {
        result.addElement(new Vector<Relation>((Vector<Relation>) res2.elementAt(j)));
      }
      for (j = 0; j < res1.size(); j++) {
        temp = (Vector<Relation>) ((Vector<Relation>) res1.elementAt(j)).clone();
        for (k = 0; k < res2.size(); k++) {
          temp2 = (Vector<Relation>) temp.clone();
          temp3 = (Vector<Relation>) ((Vector<Relation>) res2.elementAt(k)).clone();
          if (((Relation) temp2.elementAt(0)).i < ((Relation) temp3.elementAt(0)).i) {
            temp2.addAll((Vector<Relation>) temp3);
            result.addElement(new Vector<Relation>(temp2));
          } else {
            temp3.addAll((Vector<Relation>) temp2);
            result.addElement(new Vector<Relation>(temp3));
          }
        }
      }
    }
    for (i = 0; i < result.size(); i++) {
      if (((Vector<Relation>) result.elementAt(i)).toString().equalsIgnoreCase("[]")) {
        result.removeElementAt(i);
        i--;
      }
    }
    for (i = 0; i < result.size(); i++) {
      for (j = i + 1; j < result.size(); j++) {
        if (((Vector<Relation>) result.elementAt(i))
            .toString()
            .equalsIgnoreCase(((Vector<Relation>) result.elementAt(j)).toString())) {
          result.removeElementAt(j);
          j--;
        }
      }
    }
    return result;
  } // end-method