Convert a networkx graph to my graph representation
(G_nx)
| 223 | |
| 224 | |
| 225 | def from_networkx(G_nx): |
| 226 | """Convert a networkx graph to my graph representation""" |
| 227 | V = list(G_nx.nodes) |
| 228 | edges = list(G_nx.edges) |
| 229 | is_weighted = "weight" in G_nx[edges[0][0]][edges[0][1]] |
| 230 | |
| 231 | E = [] |
| 232 | for e in edges: |
| 233 | if is_weighted: |
| 234 | E.append(Edge(e[0], e[1], G_nx[e[0]][e[1]]["weight"])) |
| 235 | else: |
| 236 | E.append(Edge(e[0], e[1])) |
| 237 | |
| 238 | return DiGraph(V, E) if nx.is_directed(G_nx) else UndirectedGraph(V, E) |
| 239 | |
| 240 | |
| 241 | def to_networkx(G): |
nothing calls this directly
no test coverage detected