Returns the reverse of the graph. The reverse is a graph with the same nodes and edges but with the directions of the edges reversed. Parameters ---------- copy : bool optional (default=True) If True, return a new DiGraph holding the reversed edg
(self, copy=True)
| 393 | return G |
| 394 | |
| 395 | def reverse(self, copy=True): |
| 396 | """Returns the reverse of the graph. |
| 397 | |
| 398 | The reverse is a graph with the same nodes and edges |
| 399 | but with the directions of the edges reversed. |
| 400 | |
| 401 | Parameters |
| 402 | ---------- |
| 403 | copy : bool optional (default=True) |
| 404 | If True, return a new DiGraph holding the reversed edges. |
| 405 | If False, the reverse graph is created using a view of |
| 406 | the original graph. |
| 407 | """ |
| 408 | if copy: |
| 409 | H = self.__class__() |
| 410 | H.graph.update(deepcopy(self.graph)) |
| 411 | H.add_nodes_from((n, deepcopy(d)) for n, d in self._node.items()) |
| 412 | H.add_edges_from( |
| 413 | (v, u, k, deepcopy(d)) |
| 414 | for u, v, k, d in self.edges(keys=True, data=True) |
| 415 | ) |
| 416 | return H |
| 417 | return eg.graphviews.reverse_view(self) |
no test coverage detected