当前位置: 首页>>代码示例>>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;未经允许,请勿转载。