original_docstring: 
          according to the arguments of dtype and p to generate subgraphs from graph
          Args:
              graph (nx.Graph): graph to be decomposed
              dtype (string): set "node" or "edge", the ways according to which to decompose the graph
              p (int): the p of subgraphs
          Return:
              subg_dict (dict) form as {node_id : subg, ..., (node_id1, node_id2) : subg, ...}
          
docstring: according to the arguments of dtype and p to generate subgraphs from graph
docstring_tokens: according to the arguments of dtype and p to generate subgraphs from graph
code: def generate_subgraph(self, dtype: str, p):
          """
          according to the arguments of dtype and p to generate subgraphs from graph
          Args:
              graph (nx.Graph): graph to be decomposed
              dtype (string): set "node" or "edge", the ways according to which to decompose the graph
              p (int): the p of subgraphs
          Return:
              subg_dict (dict) form as {node_id : subg, ..., (node_id1, node_id2) : subg, ...}
          """
          if dtype not in ["node", "edge"]:
              print("Error: wrong dtype, dtype should be node or edge")
              return None
  
          if self._nodes_weight == [] or self._edges_weight == []:
              self._nodes_weight, self._edges_weight = self.get_graph_weights()
  
          subg_dict = defaultdict(list)
          if dtype == 'node':
              for node in self.simple_graph.nodes:
                  try:
                      self._simple_graph.nodes[node]["weight"] #nd_w =
                  except KeyError:
                      continue
  
                  node_set = {(node, self._nodes_weight[node])}
                  edge_set = set()
                  for i in range(p):
                      new_nodes = { (nd2, self._nodes_weight[nd2]) for nd1 in node_set for nd2 in self.simple_graph[nd1[0]] }
                      new_edges = {(nd1[0], nd2, self._edges_weight[nd1[0], nd2]) for nd1 in node_set for nd2 in self.simple_graph[nd1[0]]}
                      node_set |= new_nodes
                      edge_set |= new_edges
  
                  subg = self.generate_weighted_graph(node_set, edge_set)
                  subg_dict[node] = subg
          else:
              for edge in self.simple_graph.edges:
                  try:
                      self._simple_graph.edges[edge]["weight"]
                  except KeyError:
                      continue
  
                  node_set = {(edge[0], self._nodes_weight[edge[0]]), (edge[1], self._nodes_weight[edge[1]])}
                  edge_set = {(edge[0], edge[1], self._edges_weight[edge[0], edge[1]])}
  
                  for i in range(p):
                      new_nodes = {(nd2, self._nodes_weight[nd2]) for nd1 in node_set for nd2 in self.simple_graph[nd1[0]]}
                      new_edges = {(nd1[0], nd2, self._edges_weight[nd1[0], nd2]) for nd1 in node_set for nd2 in
                                   self.simple_graph.adj[nd1[0]]}
                      node_set |= new_nodes
                      edge_set |= new_edges
  
                  subg = self.generate_weighted_graph(node_set, edge_set)
                  subg_dict[edge] = subg
          return subg_dict
code_tokens: def generate_subgraph ( self , dtype : str , p ) : if dtype not in [ "node" , "edge" ] : print ( "Error: wrong dtype, dtype should be node or edge" ) return None if self . _nodes_weight == [ ] or self . _edges_weight == [ ] : self . _nodes_weight , self . _edges_weight = self . get_graph_weights ( ) subg_dict = defaultdict ( list ) if dtype == 'node' : for node in self . simple_graph . nodes : try : self . _simple_graph . nodes [ node ] [ "weight" ] except KeyError : continue node_set = { ( node , self . _nodes_weight [ node ] ) } edge_set = set ( ) for i in range ( p ) : new_nodes = { ( nd2 , self . _nodes_weight [ nd2 ] ) for nd1 in node_set for nd2 in self . simple_graph [ nd1 [ 0 ] ] } new_edges = { ( nd1 [ 0 ] , nd2 , self . _edges_weight [ nd1 [ 0 ] , nd2 ] ) for nd1 in node_set for nd2 in self . simple_graph [ nd1 [ 0 ] ] } node_set |= new_nodes edge_set |= new_edges subg = self . generate_weighted_graph ( node_set , edge_set ) subg_dict [ node ] = subg else : for edge in self . simple_graph . edges : try : self . _simple_graph . edges [ edge ] [ "weight" ] except KeyError : continue node_set = { ( edge [ 0 ] , self . _nodes_weight [ edge [ 0 ] ] ) , ( edge [ 1 ] , self . _nodes_weight [ edge [ 1 ] ] ) } edge_set = { ( edge [ 0 ] , edge [ 1 ] , self . _edges_weight [ edge [ 0 ] , edge [ 1 ] ] ) } for i in range ( p ) : new_nodes = { ( nd2 , self . _nodes_weight [ nd2 ] ) for nd1 in node_set for nd2 in self . simple_graph [ nd1 [ 0 ] ] } new_edges = { ( nd1 [ 0 ] , nd2 , self . _edges_weight [ nd1 [ 0 ] , nd2 ] ) for nd1 in node_set for nd2 in self . simple_graph . adj [ nd1 [ 0 ] ] } node_set |= new_nodes edge_set |= new_edges subg = self . generate_weighted_graph ( node_set , edge_set ) subg_dict [ edge ] = subg return subg_dict
short_docstring: according to the arguments of dtype and p to generate subgraphs from graph
short_docstring_tokens: according to the arguments of dtype and p to generate subgraphs from graph
comment: """
          according to the arguments of dtype and p to generate subgraphs from graph
          Args:
              graph (nx.Graph): graph to be decomposed
              dtype (string): set "node" or "edge", the ways according to which to decompose the graph
              p (int): the p of subgraphs
          Return:
              subg_dict (dict) form as {node_id : subg, ..., (node_id1, node_id2) : subg, ...}
          """$SEP$#nd_w =