Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make hexagonal_lattice_graph more consistent between periodic and non-periodic #57

Closed
mtfishman opened this issue Apr 15, 2024 · 4 comments

Comments

@mtfishman
Copy link
Member

Changing the setting of periodic in hexagonal_lattice_graph changes the lattice size:

julia> using NamedGraphs

julia> nv(hexagonal_lattice_graph(2, 2; periodic=false))
16

julia> nv(hexagonal_lattice_graph(2, 2; periodic=true))
8

I think instead it should output graphs with the same number of vertices and structure, just with extra periodic edges if periodic=true. It is implemented that way right now because the periodic graphs are constructed by first constructing the corresponding non-periodic version of the lattice and then merging vertices, it could still be implemented that way with some code restructuring, for example having an inner non-periodic version which the periodic version calls. The current design makes it difficult to reason about what size lattice will get output. (@JoeyT1994)

@JoeyT1994
Copy link
Contributor

The current design is based off of Networkx in Python: https://networkx.org/documentation/stable/reference/generated/networkx.generators.lattice.hexagonal_lattice_graph.html

So you get the same output there:

image

I agree it would be better to just have a non-periodic version and then a periodic version that calls that and adds edges and still has the same number of vertices.

Unlike the square lattice, however, I think it is a bit more tricky to do that because there is a slight complexity of which vertices should actually wrap around to which ones in the periodic case in order to preserve the hexagonal structure. This is why n (the second argument) must be even for when you set the flag periodic=true and you can't do hexagonal_lattice_graph(1,1; periodic = true) (because neighboring columns of the lattice need to be shifted relative to each other).

Hence, as far as I understand, you can't just take the open boundary version and add edges (it would break the properties of the hexagonal lattice). You would need to create a new open boundary version which looks slightly weird because the right side of the right-most column would be broken and have some `dangling' vertices.

@mtfishman
Copy link
Member Author

You're probably right. I think I was partially confused by #59, and not being sure how to interpret m and n in hexagonal_lattice_graph(m, n; periodic) in the case of periodic=true. Can I think of m and n as the number of rows and columns of hexagons, whether or not periodic=true? I can see why, in that case, the number of vertices won't be the same between periodic=true and false, since there are boundary vertices that are shared across the periodic boundary.

@JoeyT1994
Copy link
Contributor

JoeyT1994 commented Apr 15, 2024

Yeah m and n are the numbers of rows and columns of hexagons. If you then set the periodic flag to true it will build the m rows and n columns of hexagons but then "fuse" (merge vertices) the right-most column with the left-most one and "fuse" the top-most row with the bottom-most one

@mtfishman
Copy link
Member Author

Makes sense, thanks for the clarification, I think besides #59 the behavior makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants