code: def __init__(
      self,
      G,
      multigraph,
      demand="demand",
      capacity="capacity",
      weight="weight",
  ):
      # Number all nodes and edges and hereafter reference them using ONLY their numbers
      self.node_list = list(G)  # nodes
      self.node_indices = {
          u: i for i, u in enumerate(self.node_list)
      }  # node indices
      self.node_demands = [
          G.nodes[u].get(demand, 0) for u in self.node_list
      ]  # node demands
  
      self.edge_sources = []  # edge sources
      self.edge_targets = []  # edge targets
      if multigraph:
          self.edge_keys = []  # edge keys
      self.edge_indices = {}  # edge indices
      self.edge_capacities = []  # edge capacities
      self.edge_weights = []  # edge weights
  
      if not multigraph:
          edges = G.edges(data=True)
      else:
          edges = G.edges(data=True, keys=True)
  
      inf = float("inf")
      edges = (
          e
          for e in edges
          if e[0] != e[1] and e[-1].get(capacity, inf) != 0
      )
      for i, e in enumerate(edges):
          self.edge_sources.append(self.node_indices[e[0]])
          self.edge_targets.append(self.node_indices[e[1]])
          if multigraph:
              self.edge_keys.append(e[2])
          self.edge_indices[e[:-1]] = i
          self.edge_capacities.append(e[-1].get(capacity, inf))
          self.edge_weights.append(e[-1].get(weight, 0))
  
      # spanning tree specific data to be initialized
  
      self.edge_count = None  # number of edges
      self.edge_flow = None  # edge flows
      self.node_potentials = None  # node potentials
      self.parent = None  # parent nodes
      self.parent_edge = None  # edges to parents
      self.subtree_size = None  # subtree sizes
      self.next_node_dft = None  # next nodes in depth-first thread
      self.prev_node_dft = None  # previous nodes in depth-first thread
      self.last_descendent_dft = (
          None  # last descendants in depth-first thread
      )
      self._spanning_tree_initialized = (
          False  # False until initialize_spanning_tree() is called
      )
  
imports: from itertools import chain, islice, repeat
  from math import ceil, sqrt
  import networkx
  from networkx.utils import not_implemented_for
label_desc: Use image node_id 1 to create a new _DataEssentialsAndFunctions object  with example: obj = _DataEssentialsAndFunctions(G, multigraph, demand, capacity, weight)