instance creation following a logistic distribution/ inverted qubo weights in SAT2QUBO
This commit is contained in:
@@ -7,11 +7,37 @@ import dimod
|
||||
from tqdm import tqdm
|
||||
|
||||
def main():
|
||||
instance_parameters()
|
||||
#wmis_results()
|
||||
wmis_siman_results_alpha_num_of_assignments()
|
||||
#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()
|
||||
|
||||
|
@@ -5,8 +5,8 @@ from . import kSAT
|
||||
from tqdm import tqdm
|
||||
import math
|
||||
|
||||
__VERTEX_WEIGHT__ = 1
|
||||
__EDGE_WEIGHT__ = -2
|
||||
__VERTEX_WEIGHT__ = -1
|
||||
__EDGE_WEIGHT__ = 2
|
||||
|
||||
def WMISdictQUBO(kSATInstance):
|
||||
quboInstance = {}
|
||||
|
@@ -2,6 +2,12 @@
|
||||
|
||||
from . import randomSAT
|
||||
|
||||
import math
|
||||
import random
|
||||
import numpy as np
|
||||
import seaborn as sns
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
class Random_instance_pool:
|
||||
|
||||
def __init__(self, parameter_range):
|
||||
@@ -83,5 +89,90 @@ class Manual_range:
|
||||
def next(self):
|
||||
return self.__next__()
|
||||
|
||||
class Random_range:
|
||||
|
||||
def __init__(self, random_generator, steps):
|
||||
self.__random_generator = random_generator
|
||||
self.__steps = steps
|
||||
self.__current_step = 0
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def __next__(self):
|
||||
if self.__current_step < self.__steps:
|
||||
self.__current_step += 1
|
||||
return self.__random_generator.random()
|
||||
else:
|
||||
raise StopIteration
|
||||
|
||||
def next(self):
|
||||
return self.__next__()
|
||||
|
||||
class Random_logistic_variable_distribution:
|
||||
|
||||
def __init__(self,
|
||||
number_of_clauses,
|
||||
min_variables,
|
||||
max_variables,
|
||||
alpha_point_of_interest,
|
||||
steepnesss):
|
||||
self.__number_of_clauses = number_of_clauses
|
||||
self.__min_variables = min_variables
|
||||
self.__max_variables = max_variables
|
||||
self.__alpha_point_of_interest = alpha_point_of_interest
|
||||
self.__steepnesss = steepnesss
|
||||
|
||||
def random(self):
|
||||
number_of_variables = 0
|
||||
|
||||
while (number_of_variables < self.__min_variables or
|
||||
number_of_variables > self.__max_variables):
|
||||
|
||||
alpha = inv_logistic(random.random(),
|
||||
1,
|
||||
self.__steepnesss,
|
||||
self.__alpha_point_of_interest)
|
||||
|
||||
number_of_variables = int(self.__number_of_clauses / alpha)
|
||||
|
||||
return number_of_variables
|
||||
|
||||
def inv_logistic(x, L, k, x0):
|
||||
return math.log(math.pow(x / (L-x), 1/k)) + x0
|
||||
|
||||
def test():
|
||||
sns.set()
|
||||
|
||||
data = []
|
||||
|
||||
logistic_distr = Random_logistic_variable_distribution(42, 5, 84, 4.5, 1)
|
||||
rnd_range = Random_range(logistic_distr, 500)
|
||||
|
||||
for i in range(500):
|
||||
#data.append(50/math.exp(random.uniform(5, 50)))
|
||||
#v = 0
|
||||
|
||||
#while v < 5 or v > 84:
|
||||
#v = int(42 / inv_logistic(random.random(), 1, 1, 4.5))
|
||||
|
||||
data.append(rnd_range.next())
|
||||
|
||||
data = np.array(data)
|
||||
|
||||
sns.distplot(data,
|
||||
#bins=30,
|
||||
norm_hist=True)
|
||||
#sns.lineplot(list(range(2, 100)), data)
|
||||
plt.show()
|
||||
|
||||
sns.distplot(42/data,
|
||||
#bins=30,
|
||||
norm_hist=True)
|
||||
#sns.lineplot(list(range(2, 100)), data)
|
||||
plt.show()
|
||||
|
||||
return data
|
||||
|
||||
|
||||
|
||||
|
@@ -10,6 +10,8 @@ from . import graph
|
||||
import minorminer
|
||||
from tqdm import tqdm
|
||||
import numpy as np
|
||||
import random
|
||||
import sys
|
||||
|
||||
def readConfig(configFilePath):
|
||||
config = configparser.ConfigParser()
|
||||
@@ -183,13 +185,22 @@ def __qubo_to_JSON(qubo):
|
||||
|
||||
return quboJSON
|
||||
|
||||
def write_wmis_embedding_to_pool_db(collection, qubo_id, solver_graph_id, embedding):
|
||||
def write_wmis_embedding_to_pool_db(collection, qubo_id, solver_graph_id, seed, embedding):
|
||||
if not __embedding_entry_exists(collection, qubo_id, solver_graph_id):
|
||||
__prepare_new_wmis_embedding_entry(collection, qubo_id, solver_graph_id)
|
||||
|
||||
collection.update_one(
|
||||
{"qubo": qubo_id, "solver_graph": solver_graph_id},
|
||||
{"$push": {"embeddings": __embedding_to_array(embedding)}}
|
||||
{
|
||||
"$push":
|
||||
{
|
||||
"embeddings":
|
||||
{
|
||||
"embedding": __embedding_to_array(embedding),
|
||||
"seed": seed
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
def __embedding_entry_exists(collection, qubo_id, solver_graph_id):
|
||||
@@ -250,20 +261,25 @@ def find_wmis_embeddings_for_scope(db, scope, solver_graph):
|
||||
max_no_improvement = 10
|
||||
for i in range(5):
|
||||
if __embedding_entry_exists(db["embeddings"], qubo_id, solver_graph_id):
|
||||
already_found += 1
|
||||
if i == 0:
|
||||
already_found += 1
|
||||
break;
|
||||
else:
|
||||
nx_qubo = graph.qubo_to_nx_graph(qubo)
|
||||
|
||||
seed = random.randint(0, sys.maxsize)
|
||||
|
||||
emb = minorminer.find_embedding(nx_qubo.edges(),
|
||||
solver_graph.edges(),
|
||||
return_overlap=True,
|
||||
max_no_improvement=max_no_improvement)
|
||||
max_no_improvement=max_no_improvement,
|
||||
random_seed=seed)
|
||||
|
||||
if emb[1] == 1:
|
||||
write_wmis_embedding_to_pool_db(db["embeddings"],
|
||||
qubo_id,
|
||||
solver_graph_id,
|
||||
seed,
|
||||
emb[0])
|
||||
new_embeddings_found += 1
|
||||
|
||||
|
Reference in New Issue
Block a user