sync
This commit is contained in:
@@ -6,8 +6,11 @@ from tqdm import tqdm
|
||||
import math
|
||||
import random
|
||||
|
||||
__VERTEX_WEIGHT__ = -2#-1
|
||||
__EDGE_WEIGHT__ = 2#2
|
||||
#__VERTEX_WEIGHT__ = -2
|
||||
#__EDGE_WEIGHT__ = 2
|
||||
|
||||
__VERTEX_WEIGHT__ = 1
|
||||
__EDGE_WEIGHT__ = -2
|
||||
|
||||
def WMISdictQUBO(kSATInstance):
|
||||
quboInstance = {}
|
||||
@@ -55,6 +58,68 @@ def WMISdictQUBO_2(kSATInstance):
|
||||
|
||||
|
||||
|
||||
for i in range(varIndexInClause + 1, len(clause)):
|
||||
var2 = abs(clause[i])
|
||||
|
||||
aux2 = "z{}_{}".format(clauseIndex, var2)
|
||||
|
||||
quboInstance[(aux, aux2)] = __EDGE_WEIGHT__
|
||||
|
||||
return quboInstance
|
||||
|
||||
def WMISdictQUBO_3(kSATInstance):
|
||||
quboInstance = {}
|
||||
|
||||
for clauseIndex in range(kSATInstance.getNumberOfClauses()):
|
||||
clause = kSATInstance.getClause(clauseIndex)
|
||||
|
||||
# build triangles
|
||||
for varIndexInClause in range(len(clause)):
|
||||
lit = clause[varIndexInClause]
|
||||
var = abs(lit)
|
||||
|
||||
aux = "z{}_{}".format(clauseIndex, var)
|
||||
var_node = "x{}".format(var)
|
||||
|
||||
if lit < 0:
|
||||
quboInstance[(aux, aux)] = __VERTEX_WEIGHT__
|
||||
quboInstance[(var_node, aux)] = __EDGE_WEIGHT__
|
||||
else:
|
||||
quboInstance[(var_node, aux)] = __VERTEX_WEIGHT__
|
||||
|
||||
|
||||
|
||||
for i in range(varIndexInClause + 1, len(clause)):
|
||||
var2 = abs(clause[i])
|
||||
|
||||
aux2 = "z{}_{}".format(clauseIndex, var2)
|
||||
|
||||
quboInstance[(aux, aux2)] = __EDGE_WEIGHT__ * 2
|
||||
|
||||
return quboInstance
|
||||
|
||||
def WMISdictQUBO_4(kSATInstance):
|
||||
quboInstance = {}
|
||||
|
||||
for clauseIndex in range(kSATInstance.getNumberOfClauses()):
|
||||
clause = kSATInstance.getClause(clauseIndex)
|
||||
|
||||
# build triangles
|
||||
for varIndexInClause in range(len(clause)):
|
||||
lit = clause[varIndexInClause]
|
||||
var = abs(lit)
|
||||
|
||||
aux = "z{}_{}".format(clauseIndex, var)
|
||||
var_node = "x{}".format(var)
|
||||
|
||||
if lit < 0:
|
||||
quboInstance[(aux, aux)] = __VERTEX_WEIGHT__
|
||||
quboInstance[(var_node, aux)] = __EDGE_WEIGHT__ * 2
|
||||
else:
|
||||
quboInstance[(var_node, aux)] = __VERTEX_WEIGHT__
|
||||
|
||||
|
||||
|
||||
for i in range(varIndexInClause + 1, len(clause)):
|
||||
var2 = abs(clause[i])
|
||||
|
||||
|
@@ -77,6 +77,13 @@ def number_of_possible_clauses(number_of_variables, variables_per_clause):
|
||||
return int(__binom(number_of_variables, variables_per_clause)
|
||||
* __number_of_sign_placements(variables_per_clause))
|
||||
|
||||
def number_of_possible_instances(number_of_clauses,
|
||||
number_of_variables,
|
||||
variables_per_clause):
|
||||
return int(__binom(number_of_possible_clauses(number_of_variables,
|
||||
variables_per_clause),
|
||||
number_of_clauses))
|
||||
|
||||
def __binom(n, k):
|
||||
if n == k:
|
||||
return 1
|
||||
|
@@ -196,6 +196,25 @@ def create_wmis_2_qubos_for_scope(db, scope):
|
||||
qubo = SAT2QUBO.WMISdictQUBO_2(instance)
|
||||
|
||||
write_qubo_to_pool_db(db["wmis_2_qubos"], qubo, instance_id)
|
||||
|
||||
def create_wmis_3_qubos_for_scope(db, scope):
|
||||
instances = queries.Instance_scope_query(db)
|
||||
instances.query(scope)
|
||||
|
||||
for instance, instance_id in tqdm(instances):
|
||||
qubo = SAT2QUBO.WMISdictQUBO_3(instance)
|
||||
|
||||
write_qubo_to_pool_db(db["wmis_3_qubos"], qubo, instance_id)
|
||||
|
||||
def create_wmis_4_qubos_for_scope(db, scope):
|
||||
instances = queries.Instance_scope_query(db)
|
||||
instances.query(scope)
|
||||
|
||||
for instance, instance_id in tqdm(instances):
|
||||
qubo = SAT2QUBO.WMISdictQUBO_4(instance)
|
||||
|
||||
write_qubo_to_pool_db(db["wmis_4_qubos"], qubo, instance_id)
|
||||
|
||||
|
||||
def create_primitive_isings_for_scope_2(db, scope):
|
||||
instances = queries.Instance_scope_query(db)
|
||||
@@ -437,7 +456,8 @@ def majority_vote_sample(sample):
|
||||
|
||||
for var, a in assignments.items():
|
||||
assignments[var]["majority"] = 1 if __true_percentage(a["all"]) >= 0.5 else 0
|
||||
|
||||
|
||||
|
||||
assignment = [0 for i in range(len(assignments))]
|
||||
|
||||
for var, a in assignments.items():
|
||||
|
Reference in New Issue
Block a user