pmneila/PyMaxflow

3D graph grid construction

Rowandish opened this issue · 3 comments

Hi Pmneila, sorry for this further question, I'd like to build a 3D graph like the the following one:
screen shot 2014-10-19 at 12 11 32 copia

Is it possible using your library?

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:
screen shot 2014-10-23 at 02 51 48
(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!