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.

155 lines
4.6 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
  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_6")
  18. insert_row = ("INSERT INTO c42_vLogistic_6_instances "
  19. "(instance_id, "
  20. " number_of_clauses, "
  21. " number_of_variables) "
  22. "VALUES (%s, %s, %s)")
  23. for instance, instance_id in tqdm(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_vLogistic_6", "wmis_siman_results")
  45. insert_row = ("INSERT INTO c42_vLogistic_6_wmis_siman_results "
  46. "(result_id, "
  47. " run, "
  48. " instance_id, "
  49. " number_of_found_assignments, "
  50. " chain_break_fraction, "
  51. " num_occurrences, "
  52. " energy, "
  53. " satisfiable) "
  54. "VALUES (%s, %s, %s, %s, %s, %s, %s, %s) ")
  55. for result in tqdm(q):
  56. sample_set = queries.read_raw_wmis_sample_set(result["data"])
  57. data = script.analyze_wmis_sample(sample_set.first)
  58. sat = queries.get_instance_by_id(idb["instances"], result["instance"])
  59. model = script.majority_vote_sample(sample_set.first.sample)
  60. isSatisfiable = sat.checkAssignment(model)
  61. edb_cursor.execute(insert_row, (str(result["_id"]),
  62. int(result["run"]),
  63. str(result["instance"]),
  64. int(data["number_of_assignments"]),
  65. float(data["chain_break_fraction"]),
  66. int(data["num_occurrences"]),
  67. int(data["energy"]),
  68. isSatisfiable))
  69. edb.commit()
  70. edb_cursor.close()
  71. edb.close()
  72. def minisat_runs():
  73. edb = script.connect_to_experimetns_db()
  74. edb_cursor = edb.cursor();
  75. idb = script.connect_to_instance_pool()
  76. runs = queries.Minisat_run_scope_query_raw(idb)
  77. runs.query("c42_vLogistic_6", "minisat_runs")
  78. insert_row = ("INSERT INTO c42_vLogistic_6_minisat_runs "
  79. "(run_id, "
  80. " instance_id, "
  81. " satisfiable) "
  82. "VALUES (%s, %s, %s) ")
  83. for run in tqdm(runs):
  84. data = script.analyde_minisat_run(run)
  85. edb_cursor.execute(insert_row, (str(run["_id"]),
  86. str(run["instance"]),
  87. int(data["satisfiable"])))
  88. edb.commit()
  89. edb_cursor.close()
  90. edb.close()
  91. def wmis_results():
  92. edb = script.connect_to_experimetns_db()
  93. edb_cursor = edb.cursor();
  94. idb = script.connect_to_instance_pool()
  95. q = queries.WMIS_result_scope_query_raw(idb)
  96. q.query("c42_v[5-84]_1", "wmis_qbsolv_results")
  97. for i in range(501):
  98. q.__next__()
  99. res = q.__next__()
  100. sample_set = queries.read_raw_wmis_sample_set(res["data"])
  101. model = script.majority_vote_sample(sample_set.first.sample)
  102. sat = queries.get_instance_by_id(idb["instances"], res["instance"])
  103. print(model)
  104. print(sat.getNumberOfVariables())
  105. print(sat.checkAssignment(model))
  106. if __name__ == "__main__":
  107. main()