Example #1
0
  /**
   * Add an itemset to the CFI-Tree
   *
   * @param itemset the itemset
   * @param itemsetLength the length of the itemset
   * @param support the support of the itemset
   */
  public void addCFI(int[] itemset, int itemsetLength, int support) {

    CFINode currentNode = root;
    // For each item in the itemset
    for (int i = 0; i < itemsetLength; i++) {
      int item = itemset[i];

      // look if there is a node already in the FP-Tree
      CFINode child = currentNode.getChildWithID(item);
      if (child == null) {
        // there is no node, we create a new one
        CFINode newNode = new CFINode();
        newNode.itemID = item;
        newNode.parent = currentNode;
        // remember at which level in the tree that node appears
        newNode.level = i + 1;
        newNode.counter = support; // NEW BY PHILIPPE 2015
        // we link the new node to its parrent
        currentNode.childs.add(newNode);

        // we take this node as the current node for the next for loop iteration
        currentNode = newNode;

        // We update the header table.
        // We check if there is already a node with this id in the header table
        fixNodeLinks(item, newNode);
      } else {
        // FPCLOSE:
        // If there is a node already, we update it
        // with the maximum of the support already in the path
        // and the support of the current itemset
        child.counter = Math.max(support, child.counter);
        currentNode = child;
      }
    }

    //		 SET THE SUPPORT OF THE CFI (the last item)
    //		currentNode.counter = support;

    // remember that this is the last added itemset
    lastAddedItemsetNode = currentNode;
  }