Created
October 2, 2015 18:29
-
-
Save RobertTalbert/70bd26194eada8c7739a to your computer and use it in GitHub Desktop.
Sage code for creating an interactive element for determining chromatic number of famous graphs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sage.graphs.graph_coloring import * | |
@interact | |
def _(graph=['Cycle Graph', 'Wheel Graph', 'Complete Graph', 'Cube Graph', 'Random'], | |
n = selector([1..10], nrows = 1), p = selector([10,20,..,100], nrows = 1)): | |
print graph | |
if graph == 'Wheel Graph': | |
print "n = %s (number of vertices)"%n | |
G = graphs.WheelGraph(n) | |
elif graph == 'Cycle Graph': | |
print "n = %s (number of vertices)"%n | |
G = graphs.CycleGraph(n) | |
elif graph == 'Complete Graph': | |
print "n = %s (number of vertices)"%n | |
G = graphs.CompleteGraph(n) | |
elif graph == 'Cube Graph': | |
if n > 8: | |
print "n reduced to 8" | |
n = 8 | |
print "n = %s (dimension)"%n | |
G = graphs.CubeGraph(n) | |
elif graph == 'Random': | |
print "n = %s (number of vertices)"%n | |
print "p = %s%% (edge probability)"%p | |
G = graphs.RandomGNP(n, p/100.0) | |
print "Chromatic number = " + str(G.chromatic_number()) | |
colors = vertex_coloring(G) | |
G.show(partition=colors) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment