Returns a deep copy of graph, with each node switched to its index. Considering that the nodes of your graph may be any possible hashable Python object, you can get an isomorphic graph of the original one, with each node switched to its index. Parameters ----------
(self, begin_index=0)
| 1379 | return self.nodes_subgraph(from_nodes=neighbors_of_center) |
| 1380 | |
| 1381 | def to_index_node_graph(self, begin_index=0): |
| 1382 | """Returns a deep copy of graph, with each node switched to its index. |
| 1383 | |
| 1384 | Considering that the nodes of your graph may be any possible hashable Python object, |
| 1385 | you can get an isomorphic graph of the original one, with each node switched to its index. |
| 1386 | |
| 1387 | Parameters |
| 1388 | ---------- |
| 1389 | begin_index : int |
| 1390 | The begin index of the index graph. |
| 1391 | |
| 1392 | Returns |
| 1393 | ------- |
| 1394 | G : easygraph.Graph |
| 1395 | Deep copy of graph, with each node switched to its index. |
| 1396 | |
| 1397 | index_of_node : dict |
| 1398 | Index of node |
| 1399 | |
| 1400 | node_of_index : dict |
| 1401 | Node of index |
| 1402 | |
| 1403 | Examples |
| 1404 | -------- |
| 1405 | The following method returns this isomorphic graph and index-to-node dictionary |
| 1406 | as well as node-to-index dictionary. |
| 1407 | |
| 1408 | >>> G = eg.Graph() |
| 1409 | >>> G.add_edges([ |
| 1410 | ... ('Jack', 'Maria'), |
| 1411 | ... ('Maria', 'Andy'), |
| 1412 | ... ('Jack', 'Tom') |
| 1413 | ... ]) |
| 1414 | >>> G_index_graph, index_of_node, node_of_index = G.to_index_node_graph() |
| 1415 | |
| 1416 | """ |
| 1417 | G = self.__class__() |
| 1418 | G.graph.update(self.graph) |
| 1419 | index_of_node = dict() |
| 1420 | node_of_index = dict() |
| 1421 | for index, (node, node_attr) in enumerate(self._node.items()): |
| 1422 | G.add_node(index + begin_index, **node_attr) |
| 1423 | index_of_node[node] = index + begin_index |
| 1424 | node_of_index[index + begin_index] = node |
| 1425 | for u, nbrs in self._adj.items(): |
| 1426 | for v, edge_data in nbrs.items(): |
| 1427 | G.add_edge(index_of_node[u], index_of_node[v], **edge_data) |
| 1428 | |
| 1429 | return G, index_of_node, node_of_index |
| 1430 | |
| 1431 | def to_directed_class(self): |
| 1432 | """Returns the class to use for empty directed copies. |
no test coverage detected