From 9a8c908eaead09de45ce081b688917f9826fea03 Mon Sep 17 00:00:00 2001 From: Tom Date: Fri, 5 Apr 2019 13:07:38 +0200 Subject: [PATCH] randomSAT: fixed random sat generation; satlabcxx: fixed *2bson converters --- src/util/ksatModel2bson.h | 2 +- src/util/minisatResult2bson.h | 2 +- src/util/minisatStats2bson.h | 2 +- test_data_extraction.py | 10 +++++----- test_sat_to_qubo_workflow.py | 2 +- util/randomSAT.py | 5 ++++- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/util/ksatModel2bson.h b/src/util/ksatModel2bson.h index 6464908..eb5ded4 100644 --- a/src/util/ksatModel2bson.h +++ b/src/util/ksatModel2bson.h @@ -13,7 +13,7 @@ namespace satlab template void convert(bsoncxx::builder::stream::array& builder, const KSATinstance::MODEL& model) { - builder = bsoncxx::builder::stream::array(); + builder.clear(); for(auto& lit : model) { diff --git a/src/util/minisatResult2bson.h b/src/util/minisatResult2bson.h index 99d5152..ce5d34a 100644 --- a/src/util/minisatResult2bson.h +++ b/src/util/minisatResult2bson.h @@ -18,7 +18,7 @@ void convert(bsoncxx::builder::stream::document& builder, const MinisatResult& r using ARRAY_BUILDER = bsoncxx::builder::stream::array; using DOCUMENT_BUILDER = bsoncxx::builder::stream::document; - builder = DOCUMENT_BUILDER(); + builder.clear(); ARRAY_BUILDER model; DOCUMENT_BUILDER stats; diff --git a/src/util/minisatStats2bson.h b/src/util/minisatStats2bson.h index 5de31f3..2d523c8 100644 --- a/src/util/minisatStats2bson.h +++ b/src/util/minisatStats2bson.h @@ -13,7 +13,7 @@ namespace satlab template void convert(bsoncxx::builder::stream::document& builder, const MinisatStats& stats) { - builder = bsoncxx::builder::stream::document(); + builder.clear(); builder << "solves" << static_cast(stats.getSolves()) << "starts" << static_cast(stats.getStarts()) diff --git a/test_data_extraction.py b/test_data_extraction.py index 30753be..778571d 100755 --- a/test_data_extraction.py +++ b/test_data_extraction.py @@ -4,6 +4,8 @@ import util.script as script import util.queries as queries import dimod +from tqdm import tqdm + def main(): wmis_siman_results_alpha_num_of_assignments() #wmis_siman_results() @@ -30,9 +32,9 @@ def wmis_siman_results_alpha_num_of_assignments(): idb = script.connect_to_instance_pool() q = queries.WMIS_result_scope_query_raw(idb) - q.query("c42_v[5-42]_1", "wmis_siman_results") + q.query("c42_v[5-84]_1", "wmis_siman_results") - insert_row = ("INSERT INTO c42_v5to42_1_wmis_results " + insert_row = ("INSERT INTO c42_v5to84_1_wmis_results " "(result_id, " " number_of_clauses, " " number_of_variables, " @@ -42,7 +44,7 @@ def wmis_siman_results_alpha_num_of_assignments(): " energy) " "VALUES (%s, %s, %s, %s, %s, %s, %s) ") - for result in q: + for result in tqdm(q): sample_set = queries.read_raw_wmis_sample_set(result["data"]) data = script.analyze_wmis_sample(sample_set.first) @@ -57,8 +59,6 @@ def wmis_siman_results_alpha_num_of_assignments(): int(data["num_occurrences"]), int(data["energy"]))) - print(data) - edb.commit() edb_cursor.close() edb.close() diff --git a/test_sat_to_qubo_workflow.py b/test_sat_to_qubo_workflow.py index 151f431..dfd3ba9 100755 --- a/test_sat_to_qubo_workflow.py +++ b/test_sat_to_qubo_workflow.py @@ -63,7 +63,7 @@ def __wmis3(): nx.node_link_data(target_graph)) solver_input_query = queries.WMIS_solver_input_scope_query(db) - solver_input_query.query("c42_v[5-42]_1", target_graph_id) + solver_input_query.query("c42_v[5-84]_1", target_graph_id) base_sampler = SimulatedAnnealingSampler() chimera_sampler = dimod.StructureComposite(base_sampler, diff --git a/util/randomSAT.py b/util/randomSAT.py index d3cf0b7..9988d79 100644 --- a/util/randomSAT.py +++ b/util/randomSAT.py @@ -24,6 +24,9 @@ def generateRandomKSAT(numberOfClauses, clauses[clauseIndex].append(varIndex + 1) + for i in range(len(clauses)): + clauses[i].sort() + #fill in the missing bindings for clauseIndex, clause in enumerate(clauses): tmpClause = [] @@ -45,7 +48,7 @@ def generateRandomKSAT(numberOfClauses, for i in range(len(tmpClause)): tmpClause[i] *= random.choice([-1, 1]) - tmpClause = list(np.sort(tmpClause)) + tmpClause.sort() if tmpClause not in clauses: clauseIsUnique = True