Closed Rowandish closed 10 years ago
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?
Hi.
Did my answer solve your problem? Do you need more details?
Hi! Sorry, I forgot to answer you, it solved my problem. Thank you!
Hi Pmneila, sorry for this further question, I'd like to build a 3D graph like the the following one:
Is it possible using your library?