/** The main function */
  @Override
  public void run() {
    if (clusterNum > 0 || clusterSize > 0) {
      for (Iterator it = getTaskList().iterator(); it.hasNext(); ) {
        Task task = (Task) it.next();
        int depth = task.getDepth();
        if (!mDepth2Task.containsKey(depth)) {
          mDepth2Task.put(depth, new ArrayList<>());
        }
        List list = mDepth2Task.get(depth);
        if (!list.contains(task)) {
          list.add(task);
        }
      }
    }
    /** if clusters.num is set. */
    if (clusterNum > 0) {
      bundleClustering();
      /** else if clusters.size is set. */
    } else if (clusterSize > 0) {
      collapseClustering();
    }

    updateDependencies();
    addClustDelay();
  }
  /** Add pairs that needs to remove to mRecover. */
  private void remove() {

    for (Task set : this.getTaskList()) {
      if (set.getChildList().size() >= 2) {
        for (int i = 0; i < set.getChildList().size(); i++) {
          Task children = (Task) set.getChildList().get(i);
          for (int j = i + 1; j < set.getChildList().size(); j++) {
            Task another = (Task) set.getChildList().get(j);
            // avoid unnecessary checks
            if (children.getDepth() > another.getDepth()) {
              if (check(another, children)) {
                // remove i
                set.getChildList().remove(children);
                children.getParentList().remove(set);
                i--;
                mRecover.put(set, children);
                // cleanTaskSetChecked();
                break;
              } else {
                // cleanTaskSetChecked();
              }
            }
            if (another.getDepth() > children.getDepth()) {
              if (check(children, another)) {
                set.getChildList().remove(another);
                another.getParentList().remove(set);
                i--;
                mRecover.put(set, another);
                // cleanTaskSetChecked();
                break;
              } else {
                // cleanTaskSetChecked();
              }
            }
          }
        }
      }
    }
  }