Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.