本文整理汇总了Python中model.Model.parse_dimacs方法的典型用法代码示例。如果您正苦于以下问题:Python Model.parse_dimacs方法的具体用法?Python Model.parse_dimacs怎么用?Python Model.parse_dimacs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Model
的用法示例。
在下文中一共展示了Model.parse_dimacs方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import parse_dimacs [as 别名]
def main():
n = sys.argv[1]
f = Model.parse_dimacs('data/%s.dimacs' % n)
# approx_solve(f)
# analyze_entanglement(f)
entaglement_solve(f)
示例2: main
# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import parse_dimacs [as 别名]
def main():
n = sys.argv[1]
f = Model.parse_dimacs('data/%s.dimacs' % n)
f.unit_propagate()
# create_interactions_graph(f.clauses, abs)
# create_interactions_graph(f.clauses, lambda x: x)
# create_interactions_graph_gt(f.clauses, abs)
# create_interactions_graph_gt(f.clauses, lambda x: x)
create_conflicts_graph(f.clauses)
示例3: main
# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import parse_dimacs [as 别名]
def main():
n = sys.argv[1]
# f = Model.parse_dimacs('data/%s.dimacs' % n)
# f = Model.parse_dimacs('data/5_4_2_1_0.300000.dimacs')
f = Model.parse_dimacs('data/random_240_1000_0.500000.dimacs')
total_conflicts_count = 0
f.unit_propagate()
if f.clauses == []:
print 'SAT'
sys.exit(0)
elif f.clauses == [[]]:
print 'UNSAT'
sys.exit(0)
print 'f.clauses:', f.clauses
forbidden = set()
for clause in f.clauses:
set_from_clause = set()
for lit in clause:
forbidden.add(frozenset([lit, -lit]))
set_from_clause.add(-lit)
forbidden.add(frozenset(set_from_clause))
print 'forbidden:', forbidden
formula_info = FormulaAnalyzer(f.clauses)
variables_count = formula_info.count_variables()
print 'Variables counts: %r' % variables_count
# Gathering info about conflicts
for clause in forbidden:
mult = 1
for lit in clause:
mult *= variables_count[lit]
mult /= fact(len(clause))
print clause, ':', mult
total_conflicts_count += mult
print 'total_conflicts_count:', total_conflicts_count
# sys.exit(0)
# greedy(f, forbidden)
sorted(f, forbidden)
示例4: main
# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import parse_dimacs [as 别名]
def main():
global d, total_conflicts_count
n = sys.argv[1]
f = Model.parse_dimacs('data/%s.dimacs' % n)
f.unit_propagate()
if f.clauses == [[]]:
print 'UNSAT'
sys.exit(0)
shuffle(f)
print 'f:', f
count_literals_top_line(f)
print 'd:', d
calculate_conflicts_count(f)
print 'total_conflicts_count:', total_conflicts_count
while True:
ret_val = swap_first_to_decrease_conflicts_count(f)
if ret_val is None:
break
calculate_conflicts_count(f)
示例5: main
# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import parse_dimacs [as 别名]
def main():
n = sys.argv[1]
f = Model.parse_dimacs('data/%s.dimacs' % n)
f.unit_propagate()
# print 'units:', f.all_units
# print 'clauses:', f.clauses
while True:
if f.clauses == []:
print 'SAT'
break
elif f.clauses == [[]]:
print 'UNSAT'
break
orig_units = f.all_units
all_diff_units_common = set()
for var in f.vars_set():
diff_units_list = []
for lit in [-var, var]:
fc = Model()
fc.clauses = f.clauses[:]
fc.all_units = f.all_units.copy()
fc.evaluation(lit)
fc.unit_propagate()
diff_units = fc.all_units - orig_units
# print 'units on %r = %r' % (lit, diff_units)
diff_units_list.append(diff_units)
diff_units_common = diff_units_list[0] & diff_units_list[1]
# print 'common units on %r = %r' % (var, diff_units_common)
all_diff_units_common |= diff_units_common
# print 'all_diff_units_common:', all_diff_units_common
for lit in all_diff_units_common:
f.evaluation(lit)
f.unit_propagate()
# print 'clauses after evaluating', lit, ':', f.clauses
# print 'clauses:', f.clauses
if len(all_diff_units_common) == 0:
print len(f.clauses)
forbidden = set()
for clause in f.clauses:
set_from_clause = set()
for lit in clause:
forbidden.add(frozenset([lit, -lit]))
set_from_clause.add(-lit)
forbidden.add(frozenset(set_from_clause))
print 'forbidden:', forbidden
s = set()
for lit in f.clauses[0]:
s.add(frozenset([lit]))
# print s
for i in xrange(1, len(f.clauses)):
print 'i:', i
clause = f.clauses[i]
new_s = set()
for lit in clause:
for seq in s:
new_seq = seq | frozenset([lit])
for forbid in forbidden:
if forbid <= new_seq:
# print 'Forbidden clause:', forbid, 'detected inside of:', new_seq
break
else:
for nseq in new_s:
if nseq <= new_seq:
break
else:
new_s.add(new_seq)
s = new_s
print 'len(s):', len(s)
# print 's:', s
print s
break
示例6: main
# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import parse_dimacs [as 别名]
def main():
n = sys.argv[1]
f = Model.parse_dimacs('data/%s.dimacs' % n)
greedy_solve(f)
示例7: main
# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import parse_dimacs [as 别名]
def main():
# f = Model.parse_dimacs('data/binowa1.dimacs')
# f = Model.parse_dimacs('data/5_4_2_1_0.300000.dimacs')
# f = Model.parse_dimacs('data/10_7_4_3_0.300000.dimacs')
# f = Model.parse_dimacs('data/20_12_6_4_0.300000.dimacs')
# f = Model.parse_dimacs('data/random_100_1000_0.500000.dimacs')
# f = Model.parse_dimacs('data/random_170_1000_0.500000.dimacs')
# f = Model.parse_dimacs('data/random_200_1000_0.500000.dimacs')
# f = Model.parse_dimacs('data/random_220_1000_0.500000.dimacs')
# f = Model.parse_dimacs('data/random_230_1000_0.500000.dimacs')
# f = Model.parse_dimacs('data/random_240_1000_0.000000.dimacs')
# f = Model.parse_dimacs('data/random_240_1000_0.200000.dimacs')
# f = Model.parse_dimacs('data/random_240_1000_0.500000.dimacs')
# f = Model.parse_dimacs('data/random_240_1000_0.800000.dimacs')
f = Model.parse_dimacs('data/random_240_1000_1.000000.dimacs')
# f = Model.parse_dimacs('data/random_250_1000_0.500000.dimacs')
# f = Model.parse_dimacs('data/random_500_1000_0.500000.dimacs')
d = defaultdict(int)
c = Counter()
positive_counter = Counter()
avg_positive_count = 0
positive_vec = []
occurences_counter = 0
formula_info = FormulaAnalyzer(f.clauses)
print 'literals_count:', formula_info.count_literals()
variables_count = formula_info.count_variables()
print 'Variables counts: %r' % variables_count
l = len(set([abs(x) for x in variables_count.keys()]))
for i in xrange(l):
positive_counter[i] = 0
fixed_set = set()
total_count = 0
# Number of auxiliary variables that are appearing set the same way (fixed) in all satisfying assignments
fixed_set_count = 0
# Propagating units and adding units as clauses
# f.unit_propagate()
# print 'After unit propagation:'
# print f.clauses
# for unit in f.all_units:
# f.clauses.append([unit])
# print 'number of propagated units: ', len(f.all_units)
for solution in f.itersolve():
sol_tpl = tuple(solution)
d[sol_tpl] += 1
positive_count = len([x for x in sol_tpl if x > 0])
positive_vec.append(positive_count)
avg_positive_count += positive_count
positive_counter[positive_count] += 1
for elem in sol_tpl:
c[elem] += 1
if -elem not in c:
c[-elem] = 0
total_count += 1
if total_count > LIMIT:
break
# print solution
if total_count == 0:
print 'UNSAT'
sys.exit(-1)
for k, v in d.iteritems():
# print k, ':', v
pass
print 'len(d):', len(d)
print 'total_count:', total_count
print 'most_common:'
for k, v in c.most_common():
# print k, ':', v
if v == total_count:
fixed_set.add(k)
fixed_set_count += 1
print 'fixed_set_count:', fixed_set_count
print 'all_literals_count:', (len(c.keys()) + fixed_set_count) / 2
fixed_set_positive_count = len([x for x in fixed_set if x > 0])
print 'fixed_set_positive_count:', fixed_set_positive_count
print 'Average number of positive literals in solution:', float(avg_positive_count) / total_count
print 'min:', np.min(positive_vec)
print 'median:', np.median(positive_vec)
positive_vec_mean = np.mean(positive_vec)
print 'avg:', positive_vec_mean
#.........这里部分代码省略.........
示例8: main
# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import parse_dimacs [as 别名]
def main():
n = sys.argv[1]
f = Model.parse_dimacs("data/%s.dimacs" % n)
products = []
number_of_clauses = []
x_range = []
i = 0
l = len(bin(int(n))[2:])
# for i in xrange(1, 3*l+1):
# i += 1
# x_range.append(i)
# number_of_clauses.append(len(f.clauses))
# f.resolution(i)
# f.unit_propagate()
# f.superset_elimination()
# print 'len(f.clauses):', len(f.clauses)
# print 'f.clauses after resolving N, P, Q variables:', f.clauses
while True:
i += 1
f.unit_propagate()
f.superset_elimination()
x_range.append(i)
number_of_clauses.append(len(f.clauses))
print "len(f.clauses):", len(f.clauses)
# print 'f.clauses:', f.clauses
if f.clauses == []:
print "SAT"
break
elif f.clauses == [[]]:
print "UNSAT"
break
formula_info = FormulaAnalyzer(f.clauses)
variables_count = formula_info.count_variables()
minimal_product = float("inf")
# print 'variables_count:', variables_count
for k in variables_count.keys():
kp = abs(k)
km = -kp
try:
positive_k = variables_count[kp]
except:
positive_k = 0
try:
negative_k = variables_count[km]
except:
negative_k = 0
product_k = negative_k * positive_k
# print k, negative_k, positive_k, product_k
if product_k < minimal_product:
minimal_product = product_k
resolution_var = kp
products.append(minimal_product)
print "Applying resolution on %d with product %d" % (resolution_var, minimal_product)
f.resolution(resolution_var)
# print 'Variables counts: %r' % formula_info.count_variables()
# plt.scatter(x_range[:-1], products)
plt.scatter(x_range, number_of_clauses)
plt.show()
示例9: main
# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import parse_dimacs [as 别名]
def main():
n = sys.argv[1]
f = Model.parse_dimacs('data/%s.dimacs' % n)
print 'vars_count: %d' % f.vars_count()
print 'clauses_count: %d' % f.clauses_count()
print 'clauses/vars ratio: %f' % f.clauses_to_vars_ratio()
sys.exit(0)
# Converting to SAT-3CNF
# print f
# print 'Before conversion to SAT-3CNF:', f.clauses
# f.to_3cnf()
# print 'After conversion to SAT-3CNF:', f.clauses
# sys.exit(0)
d = defaultdict(int)
c = Counter()
positive_counter = Counter()
avg_positive_count = 0
positive_vec = []
decimals = defaultdict(list)
odd_clauses_count = [0] * len(f.clauses)
even_clauses_count = [0] * len(f.clauses)
occurences_counter = 0
intn = int(n)
l = len(bin(intn)[2:])
for i in xrange(4*l*l+3*l-1):
positive_counter[i] = 0
specific_clauses = f.clauses[:l-1]
# f.clauses = f.clauses[l-1:]
fixed_set = set()
total_count = 0
# Number of auxiliary variables that are appearing set the same way (fixed) in all satisfying assignments
fixed_set_count = 0
# Propagating units and adding units as clauses
# f.unit_propagate()
# print 'After unit propagation:'
# print f.clauses
# for unit in f.all_units:
# if abs(unit) >= l:
# f.clauses.append([unit])
# print 'number of propagated units: ', len(f.all_units)
parity_to_assignment = defaultdict(list)
print 'specific_clauses: ', specific_clauses
for solution in f.itersolve():
decval_n = _get_decimal_value(solution[:l])
decval_p = _get_decimal_value(solution[l:2*l])
decval_q = _get_decimal_value(solution[2*l:3*l])
# print decval_n
# sol_tpl = tuple(solution[l:])
sol_tpl = tuple(solution)
sol_set = set(solution)
d[sol_tpl] += 1
positive_count = len([x for x in sol_tpl if x > 0])
positive_vec.append(positive_count)
decimals[positive_count].append((decval_n, decval_p, decval_q))
total_odd = 0
total_even = 0
parity_str = ""
for i, clause in enumerate(f.clauses):
number_of_lits_in_sol = 0
for lit in clause:
if lit in sol_set:
number_of_lits_in_sol += 1
if number_of_lits_in_sol % 2 == 0:
parity_str += '0'
total_even += 1
even_clauses_count[i] += 1
else:
parity_str += '1'
total_odd += 1
odd_clauses_count[i] += 1
parity_to_assignment[parity_str].append(sol_tpl)
# print 'odd: %d, even: %d' % (total_odd, total_even)
avg_positive_count += positive_count
positive_counter[positive_count] += 1
for elem in sol_tpl:
c[elem] += 1
if -elem not in c:
c[-elem] = 0
total_count += 1
#.........这里部分代码省略.........
示例10: destroy
# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import parse_dimacs [as 别名]
def destroy(self, widget, data=None):
gtk.main_quit()
def delete_event(self, widget, event, data=None):
return False
def play(self):
gtk.main()
if __name__ == "__main__":
c0 = [[1, 2], [-1, 2], [3, -4]]
c1 = [[1, 2, 3], [1, 2, -3], [1, -2, 3], [1, -2, -3], [-1, 2, 3], [-1, 2, -3], [-1, -2, 3], [-1, -2, -3]]
c2 = [[1, 2, 3], [1, 2, -3], [1, -2, 3], [-1, 2, 3], [-1, 2, -3], [-1, -2, 3], [-1, -2, -3]]
n = sys.argv[1]
f = Model.parse_dimacs("data/%s.dimacs" % n)
f.unit_propagate()
# from gi.repository import Gdk as gdk
# screen = gdk.Screen.get_default()
# css_provider = gtk.CssProvider()
# css_provider.load_from_path('style.css')
# context = gtk.StyleContext()
# context.add_provider_for_screen(
# screen,
# css_provider,
# gtk.STYLE_PROVIDER_PRIORITY_USER
# )