3D graph grid construction
Rowandish opened this issue · 3 comments
Rowandish commented
pmneila commented
Hi!
It should be possible.
Note that every node is connected to the nodes (N)orth, (E)ast, (S)outh and (W)est in its own layer, and to the nodes N, E, S, W and (C)enter in the upper and lower layers. You just have to encode that neighborhood structure in the structure
array. Assuming all edges have the same weight, you could get the graph with:
import maxflow
g = maxflow.Graph[float]()
nodeids = g.add_grid_nodes((2, 2, 3))
structure = np.array([ [[0, 1, 0],
[1, 1, 1],
[0, 1, 0]],
[[0, 1, 0],
[1, 0, 1],
[0, 1, 0]],
[[0, 1, 0],
[1, 1, 1],
[0, 1, 0]]])
g.add_grid_edges(nodeids, structure=structure)
You can then plot the graph:
import networkx as nx
nxg = g.get_nx_graph()
nx.draw(nxg)
and you should get:
(terminal nodes omitted)
Is that what you want?
pmneila commented
Hi.
Did my answer solve your problem? Do you need more details?
Rowandish commented
Hi! Sorry, I forgot to answer you, it solved my problem. Thank you!