Skip to content
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Cannot retrieve contributors at this time
#! /usr/bin/env python
import os, sys
# GPLv3
# lut file is tab separated key:value list
# (value could be inferred from order, but why chance it)
# could be more paranoid, assumes input luts are well formed
# todo: preserve comments across merges
if len(sys.argv) < 4:
print(' output in1 in2 ...')
out_cnf = sys.argv[1] + '.cnf'
out_lut = sys.argv[1] + '.lut'
if os.path.isfile(out_cnf):
print('%s already exists' % out_cnf)
if os.path.isfile(out_lut):
print('%s already exists' % out_lut)
def load_lut(path):
lut = {}
for line in open(path):
line = line.strip()
if line.startswith('#'):
k,v = line.split('\t')
lut[k] = v
return lut
def sorted_keys(lut):
return [vk[1] for vk in sorted((v,k) for k,v in in_lut.items())]
new_cnf = open(out_cnf, 'w')
tmp_lut = {}
for in_name in sys.argv[2:]:
# load lut
in_lut = load_lut(in_name + '.lut')
translate = {}
for k in sorted_keys(in_lut):
if k not in new_lut:
tmp_lut[k] = len(tmp_lut) + 1
translate[in_lut[k]] = tmp_lut[k]
# update cnf
new_cnf.write('c automerge %s\n' % in_name)
for line in open(in_name + '.cnf'):
if line.startswith('c'):
clause = map(int, line.strip().split())
new_clause = []
for term in clause:
sign = term / abs(term)
new_clause.append(sign * translate[abs(term)])
new_cnf.write(' '.join(map(str, new_clause)) + ' 0\n')
new_lut = open(out_lut, 'w')
for k in sorted_keys(tmp_lut):
new_lut.write('%i\t%i\n' % (k, tmp_lut[k]))