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.

131 lines
3.9 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. #!/usr/bin/env python3
  2. import util.script as script
  3. import util.queries as queries
  4. import dimod
  5. from tqdm import tqdm
  6. def main():
  7. #wmis_results()
  8. wmis_siman_results_alpha_num_of_assignments()
  9. #wmis_siman_results()
  10. #minisat_runs()
  11. def wmis_siman_results():
  12. db = script.connect_to_instance_pool()
  13. q = queries.WMIS_result_scope_query_raw(db)
  14. q.query("c45_v[5-45]_1", "wmis_siman_results")
  15. for i in range(2):
  16. result = q.__next__()
  17. sample_set = queries.read_raw_wmis_sample_set(result["data"])
  18. data = script.analyze_wmis_sample(sample_set.first)
  19. print(data)
  20. def wmis_siman_results_alpha_num_of_assignments():
  21. edb = script.connect_to_experimetns_db()
  22. edb_cursor = edb.cursor()
  23. idb = script.connect_to_instance_pool()
  24. q = queries.WMIS_result_scope_query_raw(idb)
  25. q.query("c42_v[5-84]_1", "wmis_qbsolv_results")
  26. insert_row = ("INSERT INTO c42_v5to84_1_wmis_qbsolv_results "
  27. "(result_id, "
  28. " instance_id, "
  29. " number_of_clauses, "
  30. " number_of_variables, "
  31. " number_of_found_assignments, "
  32. " chain_break_fraction, "
  33. " num_occurrences, "
  34. " energy, "
  35. " satisfiable) "
  36. "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s) ")
  37. for result in tqdm(q):
  38. sample_set = queries.read_raw_wmis_sample_set(result["data"])
  39. data = script.analyze_wmis_sample(sample_set.first)
  40. sat = queries.get_instance_by_id(idb["instances"], result["instance"])
  41. model = script.majority_vote_sample(sample_set.first.sample)
  42. isSatisfiable = sat.checkAssignment(model)
  43. edb_cursor.execute(insert_row, (str(result["_id"]),
  44. str(result["instance"]),
  45. int(sat.getNumberOfClauses()),
  46. int(sat.getNumberOfVariables()),
  47. int(data["number_of_assignments"]),
  48. float(data["chain_break_fraction"]),
  49. int(data["num_occurrences"]),
  50. int(data["energy"]),
  51. isSatisfiable))
  52. edb.commit()
  53. edb_cursor.close()
  54. edb.close()
  55. def minisat_runs():
  56. edb = script.connect_to_experimetns_db()
  57. edb_cursor = edb.cursor();
  58. idb = script.connect_to_instance_pool()
  59. runs = queries.Minisat_run_scope_query_raw(idb)
  60. runs.query("c42_v[5-84]_1", "minisat_runs")
  61. insert_row = ("INSERT INTO c42_v5to84_1_minisat_runs "
  62. "(run_id, "
  63. " instance_id, "
  64. " satisfiable) "
  65. "VALUES (%s, %s, %s) ")
  66. for run in tqdm(runs):
  67. data = script.analyde_minisat_run(run)
  68. edb_cursor.execute(insert_row, (str(run["_id"]),
  69. str(run["instance"]),
  70. int(data["satisfiable"])))
  71. edb.commit()
  72. edb_cursor.close()
  73. edb.close()
  74. def wmis_results():
  75. edb = script.connect_to_experimetns_db()
  76. edb_cursor = edb.cursor();
  77. idb = script.connect_to_instance_pool()
  78. q = queries.WMIS_result_scope_query_raw(idb)
  79. q.query("c42_v[5-84]_1", "wmis_qbsolv_results")
  80. for i in range(501):
  81. q.__next__()
  82. res = q.__next__()
  83. sample_set = queries.read_raw_wmis_sample_set(res["data"])
  84. model = script.majority_vote_sample(sample_set.first.sample)
  85. sat = queries.get_instance_by_id(idb["instances"], res["instance"])
  86. print(model)
  87. print(sat.getNumberOfVariables())
  88. print(sat.checkAssignment(model))
  89. if __name__ == "__main__":
  90. main()