import sys from gPy.Variables import declare_variable from gPy.Models import FR from gPy.Parameters import Factor from math import exp from gPy import Parameters Parameters.precision = 6 values = 0,1 wcnf = open(sys.argv[1]) n = int(wcnf.readline().split()[2]) for i in range(1,n+1): declare_variable('x%d' % i,values) highest = 0 wclauses = [] for line in wcnf: lits = line.split() cost = int(lits[0]) if cost > highest: highest = cost lits = [int(i) for i in lits[1:-1]] wclauses.append((cost,lits)) fr = FR() for (cost,clause) in wclauses: factor = Factor( variables = ['x%d' % abs(lit) for lit in clause], ) breaking_inst = {} tautology = False for lit in clause: v = 'x%d' % abs(lit) val = int(lit<0) try: if breaking_inst[v] != val: tautology = True break except KeyError: breaking_inst[v] = val if tautology: continue if cost == highest: factor[breaking_inst] = 0 else: factor[breaking_inst] = exp(float(-cost)) fr *= factor print fr