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.

157 lines
4.8 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
  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. instance_parameters()
  8. #wmis_results()
  9. #wmis_siman_results_alpha_num_of_assignments()
  10. #wmis_siman_results()
  11. #minisat_runs()
  12. def instance_parameters():
  13. edb = script.connect_to_experimetns_db()
  14. edb_cursor = edb.cursor()
  15. idb = script.connect_to_instance_pool()
  16. instances = queries.Instance_scope_query(idb)
  17. instances.query("c42_vLogistic_1")
  18. insert_row = ("INSERT INTO c42_vLogistic_1_instances "
  19. "(instance_id, "
  20. " number_of_clauses, "
  21. " number_of_variables) "
  22. "VALUES (%s, %s, %s)")
  23. for instance, instance_id in instances:
  24. edb_cursor.execute(insert_row, (str(instance_id),
  25. int(instance.getNumberOfClauses()),
  26. int(instance.getNumberOfVariables())))
  27. edb.commit()
  28. edb_cursor.close()
  29. edb.close()
  30. def wmis_siman_results():
  31. db = script.connect_to_instance_pool()
  32. q = queries.WMIS_result_scope_query_raw(db)
  33. q.query("c45_v[5-45]_1", "wmis_siman_results")
  34. for i in range(2):
  35. result = q.__next__()
  36. sample_set = queries.read_raw_wmis_sample_set(result["data"])
  37. data = script.analyze_wmis_sample(sample_set.first)
  38. print(data)
  39. def wmis_siman_results_alpha_num_of_assignments():
  40. edb = script.connect_to_experimetns_db()
  41. edb_cursor = edb.cursor()
  42. idb = script.connect_to_instance_pool()
  43. q = queries.WMIS_result_scope_query_raw(idb)
  44. q.query("c42_v[5-84]_1", "wmis_qbsolv_results")
  45. insert_row = ("INSERT INTO c42_v5to84_1_wmis_qbsolv_results "
  46. "(result_id, "
  47. " instance_id, "
  48. " number_of_clauses, "
  49. " number_of_variables, "
  50. " number_of_found_assignments, "
  51. " chain_break_fraction, "
  52. " num_occurrences, "
  53. " energy, "
  54. " satisfiable) "
  55. "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s) ")
  56. for result in tqdm(q):
  57. sample_set = queries.read_raw_wmis_sample_set(result["data"])
  58. data = script.analyze_wmis_sample(sample_set.first)
  59. sat = queries.get_instance_by_id(idb["instances"], result["instance"])
  60. model = script.majority_vote_sample(sample_set.first.sample)
  61. isSatisfiable = sat.checkAssignment(model)
  62. edb_cursor.execute(insert_row, (str(result["_id"]),
  63. str(result["instance"]),
  64. int(sat.getNumberOfClauses()),
  65. int(sat.getNumberOfVariables()),
  66. int(data["number_of_assignments"]),
  67. float(data["chain_break_fraction"]),
  68. int(data["num_occurrences"]),
  69. int(data["energy"]),
  70. isSatisfiable))
  71. edb.commit()
  72. edb_cursor.close()
  73. edb.close()
  74. def minisat_runs():
  75. edb = script.connect_to_experimetns_db()
  76. edb_cursor = edb.cursor();
  77. idb = script.connect_to_instance_pool()
  78. runs = queries.Minisat_run_scope_query_raw(idb)
  79. runs.query("c42_v[5-84]_1", "minisat_runs")
  80. insert_row = ("INSERT INTO c42_v5to84_1_minisat_runs "
  81. "(run_id, "
  82. " instance_id, "
  83. " satisfiable) "
  84. "VALUES (%s, %s, %s) ")
  85. for run in tqdm(runs):
  86. data = script.analyde_minisat_run(run)
  87. edb_cursor.execute(insert_row, (str(run["_id"]),
  88. str(run["instance"]),
  89. int(data["satisfiable"])))
  90. edb.commit()
  91. edb_cursor.close()
  92. edb.close()
  93. def wmis_results():
  94. edb = script.connect_to_experimetns_db()
  95. edb_cursor = edb.cursor();
  96. idb = script.connect_to_instance_pool()
  97. q = queries.WMIS_result_scope_query_raw(idb)
  98. q.query("c42_v[5-84]_1", "wmis_qbsolv_results")
  99. for i in range(501):
  100. q.__next__()
  101. res = q.__next__()
  102. sample_set = queries.read_raw_wmis_sample_set(res["data"])
  103. model = script.majority_vote_sample(sample_set.first.sample)
  104. sat = queries.get_instance_by_id(idb["instances"], res["instance"])
  105. print(model)
  106. print(sat.getNumberOfVariables())
  107. print(sat.checkAssignment(model))
  108. if __name__ == "__main__":
  109. main()