Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. from z3 import *
  3. import networkx as nx
  4.  
  5. def colorIt(n,F):
  6. #colors=[0]*n
  7. #colors = [Int('color_%s' % i) for i in range(n)]
  8. colors=[]
  9. colors.append(Int('color_0'))
  10. colors.append(Int('color_1'))
  11. colors.append(Int('color_2'))
  12. colors.append(Int('color_3'))
  13. colorCondition1 = []
  14. colorCondition1.append(And(0 <= colors[0], colors[0] < n))
  15. colorCondition1.append(And(0 <= colors[1], colors[1] < n))
  16. colorCondition1.append(And(0 <= colors[2], colors[2] < n))
  17. colorCondition1.append(And(0 <= colors[3], colors[3] < n))
  18.  
  19.  
  20. colorCondition2 = []
  21. for f in F:
  22. if f[1] > f[0]:
  23. temp = f[1]
  24. f[1] = f[0]
  25. f[0] = temp
  26.  
  27. colorCondition2.append(And(1 <= (colors[F[0][1]] - colors[F[0][0]])))
  28. colorCondition2.append(And(1 <= (colors[F[1][1]] - colors[F[1][0]])))
  29. colorCondition2.append(And(1 <= (colors[F[2][1]] - colors[F[2][0]])))
  30. colorCondition2.append(And(1 <= (colors[F[3][1]] - colors[F[3][0]])))
  31. colorCondition2.append(And(1 <= (colors[F[4][1]] - colors[F[4][0]])))
  32. colorCondition2.append(And(1 <= (colors[F[5][1]] - colors[F[5][0]])))
  33. s=Solver()
  34. s.add(colorCondition1 + colorCondition2)
  35. if s.check() == sat:
  36. for n in range(n):
  37. print("%s" % (s.model()[colors[n]]))
  38. print(s.check())
  39. return colors
  40.  
  41. #
  42. # n = int(raw_input("Enter the nodes in the graph: "))
  43. # print(n)
  44. # G = nx.Graph()
  45. # for i in range(0,n):
  46. # G.add_node(i)
  47. # x1 = int(raw_input("Enter the number of edges in the graph: "))
  48. # E=[]
  49. # for i in range(0,x1):
  50. # e1=int(raw_input("Enter the first node: "))
  51. # e2=int(raw_input("Enter the second node: "))
  52. # E.append([e1,e2])
  53. # G.add_edge(e1,e2)
  54. # print(E)
  55. # F = sorted(E)
  56. E = [(0, 1), (2, 0), (0, 3),(1, 2), (1, 3), (2, 3)]
  57. n = 4
  58.  
  59. print(colorIt(n,E))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement