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

#!/usr/bin/env python3
import util.script as script
import util.queries as queries
import dimod
from tqdm import tqdm
def main():
instance_parameters()
#wmis_results()
#wmis_siman_results_alpha_num_of_assignments()
#wmis_siman_results()
#minisat_runs()
def instance_parameters():
edb = script.connect_to_experimetns_db()
edb_cursor = edb.cursor()
idb = script.connect_to_instance_pool()
instances = queries.Instance_scope_query(idb)
instances.query("c42_vLogistic_1")
insert_row = ("INSERT INTO c42_vLogistic_1_instances "
"(instance_id, "
" number_of_clauses, "
" number_of_variables) "
"VALUES (%s, %s, %s)")
for instance, instance_id in instances:
edb_cursor.execute(insert_row, (str(instance_id),
int(instance.getNumberOfClauses()),
int(instance.getNumberOfVariables())))
edb.commit()
edb_cursor.close()
edb.close()
def wmis_siman_results():
db = script.connect_to_instance_pool()
q = queries.WMIS_result_scope_query_raw(db)
q.query("c45_v[5-45]_1", "wmis_siman_results")
for i in range(2):
result = q.__next__()
sample_set = queries.read_raw_wmis_sample_set(result["data"])
data = script.analyze_wmis_sample(sample_set.first)
print(data)
def wmis_siman_results_alpha_num_of_assignments():
edb = script.connect_to_experimetns_db()
edb_cursor = edb.cursor()
idb = script.connect_to_instance_pool()
q = queries.WMIS_result_scope_query_raw(idb)
q.query("c42_v[5-84]_1", "wmis_qbsolv_results")
insert_row = ("INSERT INTO c42_v5to84_1_wmis_qbsolv_results "
"(result_id, "
" instance_id, "
" number_of_clauses, "
" number_of_variables, "
" number_of_found_assignments, "
" chain_break_fraction, "
" num_occurrences, "
" energy, "
" satisfiable) "
"VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s) ")
for result in tqdm(q):
sample_set = queries.read_raw_wmis_sample_set(result["data"])
data = script.analyze_wmis_sample(sample_set.first)
sat = queries.get_instance_by_id(idb["instances"], result["instance"])
model = script.majority_vote_sample(sample_set.first.sample)
isSatisfiable = sat.checkAssignment(model)
edb_cursor.execute(insert_row, (str(result["_id"]),
str(result["instance"]),
int(sat.getNumberOfClauses()),
int(sat.getNumberOfVariables()),
int(data["number_of_assignments"]),
float(data["chain_break_fraction"]),
int(data["num_occurrences"]),
int(data["energy"]),
isSatisfiable))
edb.commit()
edb_cursor.close()
edb.close()
def minisat_runs():
edb = script.connect_to_experimetns_db()
edb_cursor = edb.cursor();
idb = script.connect_to_instance_pool()
runs = queries.Minisat_run_scope_query_raw(idb)
runs.query("c42_v[5-84]_1", "minisat_runs")
insert_row = ("INSERT INTO c42_v5to84_1_minisat_runs "
"(run_id, "
" instance_id, "
" satisfiable) "
"VALUES (%s, %s, %s) ")
for run in tqdm(runs):
data = script.analyde_minisat_run(run)
edb_cursor.execute(insert_row, (str(run["_id"]),
str(run["instance"]),
int(data["satisfiable"])))
edb.commit()
edb_cursor.close()
edb.close()
def wmis_results():
edb = script.connect_to_experimetns_db()
edb_cursor = edb.cursor();
idb = script.connect_to_instance_pool()
q = queries.WMIS_result_scope_query_raw(idb)
q.query("c42_v[5-84]_1", "wmis_qbsolv_results")
for i in range(501):
q.__next__()
res = q.__next__()
sample_set = queries.read_raw_wmis_sample_set(res["data"])
model = script.majority_vote_sample(sample_set.first.sample)
sat = queries.get_instance_by_id(idb["instances"], res["instance"])
print(model)
print(sat.getNumberOfVariables())
print(sat.checkAssignment(model))
if __name__ == "__main__":
main()