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
Generators for chessboard graphs: King, Queen, Knight, Bishop, Rooks #13306
Comments
This comment has been minimized.
This comment has been minimized.
comment:2
Two comments:
|
comment:3
Replying to @sagetrac-sluther:
Why not, but what would be the definition of valid movements?
Yes, that's much better. Thanks, |
comment:4
I'd think in directions. There are two types. The first type is defined by the nearest neighbours in the d-dimensional lattice, i.e. those points that change one coordinate by one. The allowed directions then are: King: 1 + 2 Rook: 1 Bishop: 2 Queen: 1 + 2 Your definition for the knight makes sense. |
comment:5
I found a nice and generic way to implement all the chessboard graphs. I'm using a hidden function that takes many parameters and allows to add edges to all vertices along one dimension and/or on the diagonals of any pairs of dimensions and/or knight-like movements in any pairs of dimensions. The function also allows to control the radius of the visibility ball (could be useful). Hope you'll like it. |
This comment has been minimized.
This comment has been minimized.
comment:6
Excellent idea to organize it that way! Some coding comments though.
I hope I don't discourage you with my nitpicking. Most the comments concern only style and efficiency, the only show stopper is 3). |
comment:7
Thanks for the propositions. I have incorporated all of them but the following which causes a type error
Instead, I use the following code which is in fact easier:
This is much better now ! |
comment:8
but the result is 18. This is because the second nearest neighbors in the third dimension are missing. |
comment:9
Replying to @sagetrac-sluther:
Removed. Why isn't it automatic :(
I disagree. The correct result is 18.
|
comment:10
Replying to @dcoudert:
In general I would expect |
comment:11
We said before (#comment:4) that the Queen could move either in 1 dimension or in 2 dimensions, and adding an edge from (1,1,1) to (2,2,2) means moving in the 3 dimensions. That's why 8 points are not reachable from (1,1,1).
I don't understand. |
comment:12
Replying to @dcoudert:
You're right that's what I said, but not what I meant. Sorry.
A point in the d-dimensional lattice has d integer coordinates, say x_i (i=1..d). This hypercube:
Now define a valid direction as the vector from the origin (0,0,...,0) to any other of the And here is the fun question: Which definition makes more sense? I'd propse the following: If you don't feel like putting more work into this, we'll leave it as is. If you're willing to work on it: What about adding a parameter, say 'higher_diagonals' that switches between the two definitions? |
comment:13
I prefer to let the patch as it is for now. If one needs it, we can latter add this "super-queen" definition. Also, your alternative definition should also be used for bishops and it would make bishops much more powerful than rooks (only able to move along one dimension at a time). And what about knights? |
Reviewer: Sebastian Luther |
comment:14
The Once this is fixed, I'll give it a positive review. |
comment:15
I changed it to |
comment:16
Tests good, docs good -> positive review |
comment:27
Addition of line |
comment:28
Could anyone review this patch ? |
comment:29
(cc me) |
comment:30
Do we really need to import sage.graphs.generators.chessboard at startup? |
comment:31
Replying to @robertwb:
I don't know. Following Jeroen's suggestion, I have created a new directory to store graph generators instead of continuously increasing the size of sage.graphs.graph_generators.py. Later, we could split the graph_generators file and create smaller files, easier to read, faster to test, etc. in the generators directory. Now, the question is how to make these functions accessible from graphs (e.g., graphs.QueenGraph()) without importing the file at startup. Is there a way to import them the first time they are used? or any other interesting trick I'm not aware of? |
comment:32
You could try using lazy import. However, ignore that for now, as I think all of graph_generators should be lazily imported. #13562 |
comment:33
Mostly looks good, but I would remove the double underscores around |
Attachment: trac_13306-queen-king-knight-graphs-v2.patch.gz |
comment:34
Done. |
comment:35
Helloooooooooooooooooooooooooooooo !! Well, that patch was muuuuuuch cleaner than I feared, given its size Here is a list of comments, and a small innocent reviewer's patch.
Nathann |
This comment has been minimized.
This comment has been minimized.
comment:37
I'm unable to install the review patch. Have you make it using the file I have uploaded this morning in which I have removed double underscores ?
That way the default behavior is QueenGraph, which is the most common chessboard graph. But all default parameters are OK for me.
That's right. Can you insert this in the review patch?
I didn't know that command. Very nice.
|
comment:38
Just set them all to
Done. Patch updated ! Nathann |
Attachment: trac_13306-review.patch.gz |
comment:39
Now it's working and the doc is nicer. Thanks. |
comment:40
Well.. Then "if you agree with those changes", let's get this ticket in Nathann |
comment:41
I agree with your changes. Thanks. |
comment:42
Arf. I thought you would change the ticket's status Nathann |
Changed reviewer from Sebastian Luther to Sebastian Luther, Nathann Cohen |
comment:43
Thanks! |
Merged: sage-5.5.beta0 |
This patch implements generators for multi-dimensional chessboard graphs: Queen, King, Knight, Bishop, and Rook graphs. Variations of these graphs can be constructed changing the radius of the ball in which a chess piece can move.
These graphs are useful for testing graph coloring algorithms, hamiltonian cycles, etc.
In addition, this patch creates directory
sage/graphs/generators/
to store new generators. The new functions of this patch are located in filesage/graphs/generators/chessboard.py
. The functions are then included inside theGraphGenerators
class and so accessible likegraphs.QueenGraph(...)
.APPLY:
Component: graph theory
Keywords: generator
Author: David Coudert
Reviewer: Sebastian Luther, Nathann Cohen
Merged: sage-5.5.beta0
Issue created by migration from https://trac.sagemath.org/ticket/13306
The text was updated successfully, but these errors were encountered: