Skip to content

Instantly share code, notes, and snippets.

@RobertTalbert
Created October 2, 2015 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobertTalbert/70bd26194eada8c7739a to your computer and use it in GitHub Desktop.
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.
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