code: def balanced_scheduling(
      time_cost_pred, n_estimators, n_jobs, verbose=False
  ):
      """Conduct balanced scheduling based on the sum of rank, for both train
      and prediction. The algorithm will enforce the equal sum of ranks among
      workers.
  
      Parameters
      ----------
      time_cost_pred : list
          The list of time cost by the cost predictor. The length is equal to
          the number of base detectors.
  
      n_estimators : int
          The number of base estimators.
  
      n_jobs : optional (default=1)
          The number of jobs to run in parallel for both `fit` and
          `predict`. If -1, then the number of jobs is set to the
          number of cores.
  
      verbose : bool, optional (default=False)
          Controls the verbosity of the building process.
  
      Returns
      -------
      n_estimators_list : list
          The number of estimators for each worker
  
      starts : list
          The actual index of base detectors to be scheduled. For instance,
          starts[k, k+1] base detectors will be assigned to worker k.
  
      n_jobs :
          The actual usable number of jobs to run in parallel.
      """
      # get the number of usable workers
      n_jobs = min(effective_n_jobs(n_jobs), n_estimators)
  
      # conduct Balanced Task Scheduling
      n_estimators_list = (
          []
      )  # track the number of estimators for each worker
      ranks = rankdata(time_cost_pred)
      ##########################################
      # #todo: the fastest is at most 2 times costly than the slowest
      # enable a parameter for the rank strength
      ranks = 1 + ranks / n_estimators
      ##########################################
      rank_sum = np.sum(ranks)
      chunk_sum = rank_sum / n_jobs
  
      starts_orig = [0]
      index_track = 0
      sum_check = []
  
      for i in range(len(ranks) + 1):
          if np.sum(ranks[starts_orig[index_track] : i]) >= chunk_sum:
              starts_orig.append(i)
              index_track += 1
      starts_orig.append(len(ranks))
  
      starts = starts_orig
  
      # # offset for the last worker's load
      # starts = [0]
      # for k in range(1, n_jobs+1):
      #     starts.append(starts_orig[k]-np.random.randint(low=1, high=k+1))
  
      # print(starts)
      # starts[-1] = n_estimators
      # print(starts)
  
      for j in range(n_jobs):
          sum_check.append(np.sum(ranks[starts[j] : starts[j + 1]]))
          if verbose:
              print("Worker", j + 1, "sum of ranks:", sum_check[j])
          n_estimators_list.append(starts[j + 1] - starts[j])
  
      print()
  
      # Confirm the length of the estimators is consistent
      assert np.sum(n_estimators_list) == n_estimators
      assert np.abs(rank_sum - np.sum(sum_check)) < 0.1
  
      xdiff = [starts[n] - starts[n - 1] for n in range(1, len(starts))]
  
      if verbose:
          print("Split among workers BPS:", starts, xdiff)
      return n_estimators_list, starts, n_jobs
  
file_path: SUOD/suod/models/parallel_processes.py
imports: from sklearn.base import clone
  import numpy
  from scipy.stats import rankdata
  from joblib import effective_n_jobs
  from sklearn.utils import check_array
  from sklearn.utils.validation import check_is_fitted
  from pyod.utils.utility import score_to_label
  from .jl_projection import jl_fit_transform, jl_transform
  from ..utils.utility import raw_score_to_proba
label_desc: Use image node_id 2 for calling a global function with example usage: balanced_scheduling(time_cost_pred, n_estimators, n_jobs, verbose) and returns: n_estimators_list,  starts,  n_jobs