import random # rndseed = 1 # uncomment for having always the same behavior # random.seed(rndseed) print "*** graph coloring problem ***" print # # uncomment this for a simple test # print "instance randomly created" from graphtools import rnd_adj, rnd_adj_fast, adjacent instance = "randomly created" nodes, adj = rnd_adj_fast(10, .5) print "sequential assignment" color, K = seq_assignment(nodes, adj) print "solution: z =", K print color print print "largest fit" color, K = largest_first(nodes, adj) print "solution: z =", K print color print print "dsatur" color, K = dsatur(nodes, adj) print "solution: z =", K print color
def report_sol(obj, s=""): print("cpu:%g\tobj:%g\t%s" % \ (clock()-init_cpu, obj, s)) print("*** graph coloring problem ***") print() # # uncomment this for a simple test # print("instance randomly created") from graphtools import rnd_adj, rnd_adj_fast, adjacent instance = "randomly created" nodes, adj = rnd_adj_fast(25, .5) K = 3 # tentative number of colors print("tabu search, trying coloring with", K, "colors") color = rsatur(nodes, adj, K) print("starting solution: z =", evaluate(nodes, adj, color)) print("color:", color) print() print("starting tabu search") tabulen = K max_iter = 1000 color, sum_bad_degree = \ tabu_search(nodes, adj, K, color, tabulen, max_iter) print("final solution: z =", sum_bad_degree) print("color:", color) print()