-
Notifications
You must be signed in to change notification settings - Fork 47
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
Add DigraphCartesianProduct and DigraphDirectProduct methods #228
Conversation
f432788
to
49d37ac
Compare
Hi @reiniscirpons, I've been making some fairly major changes to the Digraphs package as part of introducing mutable digraphs and working towards Digraph v1.0. Unfortunately that means that I've created conflicts with this PR, so this will need to be rebased. (However, I'm not finished making the big changes, so you should probably wait until next week before resolving the conflicts.) |
Should be safe to rebase and resolve conflicts now. |
49d37ac
to
4f1ec4f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done a preliminary review - I've made some comments relating to the Cartesian product stuff, but probably the analogous comments apply to the direct product stuff, so if you could make changes in both places that would be great.
… computed for products
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes @reiniscirpons, I have a few more :)
…other confusing points.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work @reiniscirpons, thank you!
Whoops, it seems that GitHub has some key commands that I accidentally pressed, which meant that I accidentally merged this before the tests had finished. Thankfully I'm sure they were going to pass anyway! |
This PR implements two types of digraph product as discussed in #226 for a collection of digraphs.
DigraphCartesianProduct
computes the Cartesian product of a collection of digraphs andDigraphDirectProduct
computes the direct product of a collection of digraphs. It also includes two new attributesDigraphCartesianProductProjections
andDigraphDirectProductProjections
for storing projections onto the coordinates of vertices.Since the vertex set of
DigraphCartesianProduct(G, H)
is the Cartesian product of the vertex sets ofG
andH
, but theDigraphs
package does not permit a vertex set to contain pairs of integers, only integers themselves, then we encode a pair(i, j)
asi + n * (j-1)
wheren = DigraphNrVertices(G)
.If
D = DigraphCartesianProduct(gr_1, gr_2, ...)
thenDigraphCartesianProductProjections(D)
returns a list of transformations, where thei
-th transformation corresponds to a projection onto a copy ofgr_i
contained withinD
. The projections are useful as they allow for us to reconstruct (under some circumstances) the graphs used for creating the product, and also provide for a way of regaining the information of the coordinates of each vertex (which were lost when we decided to encode(i, j)
asi + n * (j-1)
).To make sure my code works with mutable as well as immutable digraphs, I used DigraphJoin as a basis, changing only the moving parts responsible for creating the digraph and leaving the more technical bits untouched. It seems like this has worked, but I would appreciate if someone told me whether everything is sound with regards to mutability.
Not exactly sure about the time complexity. For two graphs I think it should be
O(E_1 + E_2)
for Cartesian product andO(E_1 * E_2)
for Direct product, whereE_1, E_2
is the number of edges of each digraph.