當前位置: 首頁>>代碼示例>>Python>>正文


Python networkx.OrderedMultiDiGraph方法代碼示例

本文整理匯總了Python中networkx.OrderedMultiDiGraph方法的典型用法代碼示例。如果您正苦於以下問題:Python networkx.OrderedMultiDiGraph方法的具體用法?Python networkx.OrderedMultiDiGraph怎麽用?Python networkx.OrderedMultiDiGraph使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在networkx的用法示例。


在下文中一共展示了networkx.OrderedMultiDiGraph方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_networkxs_to_graphs_tuple_with_none_fields

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import OrderedMultiDiGraph [as 別名]
def test_networkxs_to_graphs_tuple_with_none_fields(self):
    graph_nx = nx.OrderedMultiDiGraph()
    data_dict = utils_np.networkx_to_data_dict(
        graph_nx,
        node_shape_hint=None,
        edge_shape_hint=None)
    self.assertEqual(None, data_dict["edges"])
    self.assertEqual(None, data_dict["globals"])
    self.assertEqual(None, data_dict["nodes"])
    graph_nx.add_node(0, features=None)
    data_dict = utils_np.networkx_to_data_dict(
        graph_nx,
        node_shape_hint=1,
        edge_shape_hint=None)
    self.assertEqual(None, data_dict["nodes"])
    graph_nx.add_edge(0, 0, features=None)
    data_dict = utils_np.networkx_to_data_dict(
        graph_nx,
        node_shape_hint=[1],
        edge_shape_hint=[1])
    self.assertEqual(None, data_dict["edges"])
    graph_nx.graph["features"] = None
    utils_np.networkx_to_data_dict(graph_nx)
    self.assertEqual(None, data_dict["globals"]) 
開發者ID:deepmind,項目名稱:graph_nets,代碼行數:26,代碼來源:utils_np_test.py

示例2: __init__

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import OrderedMultiDiGraph [as 別名]
def __init__(self, model):
        super().__init__()
        self.nx_graph = nx.OrderedMultiDiGraph()
        self._input_names = inputs = model.get('inputs', 'input')
        self._output_names = outputs = model.get('outputs', 'output')
        self._add_module(inputs, outputs, model['name'], model, [])
        self._optimize()
        self._validate()
        # import pdb; pdb.set_trace() 
開發者ID:deep-fry,項目名稱:mayo,代碼行數:11,代碼來源:graph.py

示例3: test_multidigraph

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import OrderedMultiDiGraph [as 別名]
def test_multidigraph():
        G = nx.OrderedMultiDiGraph() 
開發者ID:SpaceGroupUCL,項目名稱:qgisSpaceSyntaxToolkit,代碼行數:4,代碼來源:test_ordered.py

示例4: test_multidigraph

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import OrderedMultiDiGraph [as 別名]
def test_multidigraph(self):
        G = nx.OrderedMultiDiGraph() 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:4,代碼來源:test_ordered.py

示例5: _check_key

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import OrderedMultiDiGraph [as 別名]
def _check_key(node_index, key):
  if node_index != key:
    raise ValueError(
        "Nodes of the networkx.OrderedMultiDiGraph must have sequential "
        "integer keys consistent with the order of the nodes (e.g. "
        "`list(graph_nx.nodes)[i] == i`), found node with index {} and key {}"
        .format(node_index, key))

  return True 
開發者ID:deepmind,項目名稱:graph_nets,代碼行數:11,代碼來源:utils_np.py

示例6: graphs_tuple_to_networkxs

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import OrderedMultiDiGraph [as 別名]
def graphs_tuple_to_networkxs(graphs_tuple):
  """Converts a `graphs.GraphsTuple` to a sequence of networkx graphs.

  Args:
    graphs_tuple: A `graphs.GraphsTuple` instance containing numpy arrays.

  Returns:
    The list of `networkx.OrderedMultiDiGraph`s. The node keys will be the data
    dict integer node indices.
  """
  return [
      data_dict_to_networkx(x) for x in graphs_tuple_to_data_dicts(graphs_tuple)
  ] 
開發者ID:deepmind,項目名稱:graph_nets,代碼行數:15,代碼來源:utils_np.py

示例7: _single_data_dict_to_networkx

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import OrderedMultiDiGraph [as 別名]
def _single_data_dict_to_networkx(data_dict):
  graph_nx = nx.OrderedMultiDiGraph()
  if data_dict["nodes"].size > 0:
    for i, x in enumerate(data_dict["nodes"]):
      graph_nx.add_node(i, features=x)

  if data_dict["edges"].size > 0:
    edge_data = zip(data_dict["senders"], data_dict["receivers"], [{
        "features": x
    } for x in data_dict["edges"]])
    graph_nx.add_edges_from(edge_data)
  graph_nx.graph["features"] = data_dict["globals"]

  return graph_nx 
開發者ID:deepmind,項目名稱:graph_nets,代碼行數:16,代碼來源:utils_np_test.py

示例8: networkxs_to_graphs_tuple

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import OrderedMultiDiGraph [as 別名]
def networkxs_to_graphs_tuple(graph_nxs,
                              node_shape_hint=None,
                              edge_shape_hint=None,
                              data_type_hint=np.float32):
  """Constructs an instance from an iterable of networkx graphs.

   The networkx graph should be set up such that, for fixed shapes `node_shape`,
   `edge_shape` and `global_shape`:
    - `graph_nx.nodes(data=True)[i][-1]["features"]` is, for any node index i, a
      tensor of shape `node_shape`, or `None`;
    - `graph_nx.edges(data=True)[i][-1]["features"]` is, for any edge index i, a
      tensor of shape `edge_shape`, or `None`;
    - `graph_nx.edges(data=True)[i][-1]["index"]`, if present, defines the order
      in which the edges will be sorted in the resulting `data_dict`;
    - `graph_nx.graph["features"] is a tensor of shape `global_shape`, or
      `None`.

  The output data is a sequence of data dicts with fields:
    NODES, EDGES, RECEIVERS, SENDERS, GLOBALS, N_NODE, N_EDGE.

  Args:
    graph_nxs: A container of `networkx.OrderedMultiDiGraph`s. The node keys
      must be sequential integer values following the order in which nodes are
      added to the graph starting from zero. That is
      `list(graph_nx.nodes)[i] == i`.
    node_shape_hint: (iterable of `int` or `None`, default=`None`) If the graph
      does not contain nodes, the trailing shape for the created `NODES` field.
      If `None` (the default), this field is left `None`. This is not used if
      `graph_nx` contains at least one node.
    edge_shape_hint: (iterable of `int` or `None`, default=`None`) If the graph
      does not contain edges, the trailing shape for the created `EDGES` field.
      If `None` (the default), this field is left `None`. This is not used if
      `graph_nx` contains at least one edge.
    data_type_hint: (numpy dtype, default=`np.float32`) If the `NODES` or
      `EDGES` fields are autocompleted, their type.

  Returns:
    The instance.

  Raises:
    ValueError: If `graph_nxs` is not an iterable of networkx instances.
  """
  data_dicts = []
  try:
    for graph_nx in graph_nxs:
      data_dict = networkx_to_data_dict(graph_nx, node_shape_hint,
                                        edge_shape_hint, data_type_hint)
      data_dicts.append(data_dict)
  except TypeError:
    raise ValueError("Could not convert some elements of `graph_nxs`. "
                     "Did you pass an iterable of networkx instances?")

  return data_dicts_to_graphs_tuple(data_dicts) 
開發者ID:deepmind,項目名稱:graph_nets,代碼行數:55,代碼來源:utils_np.py


注:本文中的networkx.OrderedMultiDiGraph方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。