You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.5 KiB

6 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
5 years ago
  1. #!/usr/bin/env python3
  2. from util import randomSAT as rdSAT
  3. import matplotlib.pyplot as plt
  4. import seaborn as sns
  5. import numpy as np
  6. def test1():
  7. kSATInstance = rdSAT.generateRandomKSAT(5, 4, 3)
  8. print(kSATInstance.toString())
  9. print("conflicts:")
  10. for conflict in kSATInstance.getConflicts():
  11. conflictVerified = False
  12. clause1 = kSATInstance.getClause(conflict[0][0])
  13. clause2 = kSATInstance.getClause(conflict[1][0])
  14. for binding in clause2:
  15. if binding == conflict[0][1] * -1:
  16. conflictVerified = True
  17. print(conflict[0], conflict[1], conflictVerified)
  18. def test2():
  19. data = {}
  20. data["clause"] = []
  21. data["num"] = []
  22. data["labels"] = []
  23. for i in range(10000):
  24. sat = rdSAT.generateRandomKSAT(7, 6, 3)
  25. for ci in range(sat.getNumberOfClauses()):
  26. clause = sat.getClause(ci)
  27. clause = list(np.sort(clause))
  28. if clause in data["clause"]:
  29. clauseIndex = data["clause"].index(clause)
  30. data["num"][clauseIndex] += 1
  31. else:
  32. data["clause"].append(clause)
  33. data["labels"].append("[{}, {}, {}]".format(clause[0], clause[1], clause[2]))
  34. data["num"].append(1)
  35. print("done ({}) unique clauses".format(len(data["clause"])))
  36. sns.set()
  37. sns.barplot(x=data["labels"], y=data["num"])
  38. plt.show()
  39. test2()