networkx / nx-guides

Examples and Jupyter Notebooks about NetworkX
https://networkx.org/nx-guides/
Creative Commons Zero v1.0 Universal
185 stars 105 forks source link

sudoku example notebook #54

Closed mjhajharia closed 2 years ago

mjhajharia commented 2 years ago

this PR adds a notebook that explains and visualizes sudoku as a graph coloring problem using networkx

Reference: https://github.com/networkx/networkx/discussions/5085#discussioncomment-1435440

from #52

cc: @dschult @rossbar

rossbar commented 2 years ago

Thanks for being flexible and adjusting the PR to better fit the workflow @mjhajharia ! I've gone ahead and added your new notebook to the generators toctree, so the CI should pass now and new page should show up in the build-docs artifact.

I've only had a chance to look briefly over it, but it looks really nice! I'll try to do a more detailed review asap. Thanks again!

rossbar commented 2 years ago

Thanks for this notebook @mjhajharia , the visualizations in particular are really great!

I went ahead and made another change just to get things better integrated into the workflow here: rather than pre-compute and store the images as png's, I've updated the notebook so that it is executed directly as part of the build process, so the images are generated by the code itself each time. One of the advantages of this approach (aside from the fact that it saves storage space) is that it helps us guarantee that the code works as expected as things change in the future.

I made these changes in 9a3126d - I didn't touch the content itself, so everything should look the same in the final website: https://130-40210422-gh.circle-artifacts.com/0/site/_build/html/content/generators/sudoku.html

mjhajharia commented 2 years ago

Hi! @rossbar @MridulS I'm so sorry this PR completely slipped my mind and was buried somewhere in Github notifications, I checked it today and made changes. So i made a lot of changes actually. Since ross mentioned trying to use the actual networkx graph for visualization instead of a custom graph that I generate, which I think is a good idea. I think more polishing will need to be done so just tag me or something when that's needed. I had a very fun time doing this today!

mjhajharia commented 2 years ago

btw a suggestion: not sure what's used for documentation of nx-guides currently, but here at pymc we're doing these couple of events and made executable notebooks, so we decided to to use thebe which works nicely with jupyter-notebooks and renders them as executables, there's no need to even upload a .md file we simply upload notebooks https://pymc-data-umbrella.xyz/en/latest/webinars/probabilistic_programming_with_pymc/notebook.html#probprog-pymc-nb which is easier!!

mjhajharia commented 2 years ago

so i did a couple of stupid things and then realised them, now I changed them and updated the notebook to the best of my abilities!! I'm sorry for the delay, although I'm afraid I might not be active here to do finishing touches if needed because of other work but here's a link for the notebook I added, I think it works now! https://nbviewer.org/gist/mjhajharia/bed5e13ab84660456323648d6d99d2fd

MridulS commented 2 years ago

Thanks @mjhajharia! I made a couple of changes and did some code formatting.

Maybe we should also add a section on using nx.greedy_color to solve a sudoku puzzle too! (But we can't start with a partially colored graph :/)

mjhajharia commented 2 years ago

Thanks @mjhajharia! I made a couple of changes and did some code formatting.

Maybe we should also add a section on using nx.greedy_color to solve a sudoku puzzle too! (But we can't start with a partially colored graph :/)

yes i did try that actually!! it works fine with saturation_largest_first, but yeah same thing in this example i started with a semi-filled one so its not that useful, but it can be used to find a random solved sudoku, like on the base structure of the graph of a sudoku if you want i can add that