def run_alloy(alloy_model): path_als = os.path.abspath(alloy_model) nodename = platform.node() t0 = time.time() t_before_xlation = time.time() output = als2cnfbed(path_als) t_after_xlation = time.time() xlation_seconds = t_after_xlation - t_before_xlation print 'Time traslation als to cnf:', xlation_seconds path_cnf = output.path_cnf path_rels = output.path_rels print("\nParsing {}".format(path_rels)) rs = Relations(path_rels) wac_list = [] #print("\nCreating native solver instance") kk = minisat.Zolver() rels = rs.rels #print("Parsing {}".format(path_cnf)) kk.read(path_cnf) tiempo = time.time() veredict = kk.solve() tfinal = time.time() - tiempo print 'sat time', tfinal if not veredict: print "Eureka: we found a permanent workaround!!!" else: print "the candidate workaround isn't a permanent workaround." return veredict
def load_problem(self, path_rels, path_bed, path_cnf): self.rp = RelsParser(path_rels) self.vr = VarRange(1, 1 + self.rp.nvars) #self.rels = tuple(self.rp.relinfo(i) for i in range(self.rp.nrels)) self.rels = Relations(tuple(self.rp.relinfo(i) for i in range(self.rp.nrels))) # PEND self.write_relvars_map(self.rels, self.pathmaker('relvars', 'map.txt')) # self.rvalu = valuation.RelsAwareValuation(self.vr, self.rels) self.sproot = Subproblem(name=self.problemname, size=self.rp.nvars) bed.reset(32, 4) bed.load(path_bed) bed.valu = valuation.PartialValuation(self.vr) self.broot = bed.Root(0) self.gator = cnf.Gator(self.vr) self.gator.read(path_cnf)
def run_alloy(alloy_model): path_als = os.path.abspath(alloy_model) nodename = platform.node() t0 = datetime.now() t_before_xlation = datetime.now() output = als2cnfbed(path_als) t_after_xlation = datetime.now() xlation_seconds = t_after_xlation - t_before_xlation print 'Time traslation als to cnf:', xlation_seconds path_cnf = output.path_cnf path_rels = output.path_rels print '------------kkk---------' print path_rels print '---------------------' print("\nParsing {}".format(path_rels)) rs = Relations(path_rels) wac_list = [] #print("\nCreating native solver instance") kk = minisat.Zolver() rels = rs.rels #print("Parsing {}".format(path_cnf)) kk.read(path_cnf) tiempo = datetime.now() veredict = kk.solve() tfinal = datetime.now() - tiempo print 'sat time', tfinal if not veredict: print "Eureka: we found a permanent workaround!!!" ap1.log_file('WAP sat_time % ' + str(tfinal), 'logfile.log') else: ap1.log_file('NO_W sat_time % ' + str(tfinal), 'logfile.log') print "NO_W The candidate workaround isn't a permanent workaround."
def run_incremental_alloy(alloy_models, cant_max, ur, state, accion, filename): total_time_wac = timedelta(0) fname = open(filename, 'w') path_als = os.path.abspath(alloy_models) nodename = platform.node() t0 = datetime.now() t_before_xlation = datetime.now() output = als2cnfbed(path_als) t_after_xlation = datetime.now() xlation_seconds = t_after_xlation - t_before_xlation #print 'Time traslation als to cnf:' , xlation_seconds #sys.exit(0) path_cnf = output.path_cnf path_rels = output.path_rels #print path_rels #print path_rels rs = Relations(path_rels) wac_list = [] #print("\nCreating native solver instance") z = minisat.Zolver() #print "???????????????????" #print rs #print "???????????????????" #sys.exit(0) rels = rs.rels #print("Parsing {}".format(path_cnf)) z.read(path_cnf) i = 0 contador_wac = 0 first = True while True: if i == cant_max: ap1.log_file('Se alcanzo el maximo de wa encontrados', 'logfile.log') break a = datetime.now() inicio = datetime.now() verdict = z.solve() b = datetime.now() total_time_wac = total_time_wac + (b - a) tiempo = datetime.now() - inicio if verdict == True: contador_wac = contador_wac + 1 print 'unroll=' + str(ur) + ' & wac_nro=' + str( contador_wac) + ' % satTime=' + ap1.tiempo_transcurrido(a, b) #ap1.log_file('action:'+str(accion)+' % state:'+str(state)+' % '+'unroll:'+str(ur)+' % wac_nro:'+str(contador_wac)+' % sat_time:'+ap1.tiempo_transcurrido(a,b),'logfile.log') ap1.log_file( ' wac_nro=' + str(contador_wac) + ' % sat_time=' + ap1.tiempo_transcurrido(a, b), 'logfile.log') print 'total_wacs:' + str( contador_wac) + ' % total-sat-time %' + str(total_time_wac) ap1.log_file( 'total_wacs=' + str(contador_wac) + ' % total-sat-time=' + str(total_time_wac), 'logfile.log') print 'Sat time: ', str(tiempo) i = i + 1 cl = [] cadelis = '' fact_candidate = '<INICIO>fact{ ' fact_permanent = 'fact{ ' for j in xrange(len(rels)): r = rels[j] if r.name.find("QF.intJ_1_") == 0 or r.name.find( "QF.intJ_2_") == 0: para1 = r.name[0:11] for v in r.vrange: if z.evalmodel(v) == '1': value = var2element(v, rs) value = value[1:len(value) - 1] #print value #cadelis=cadelis+value+',' fact_permanent = fact_permanent + para1 + '=' + value + ' and ' #cl = [-v] if r.name.find("QF.ac_") == 0: action = r.name[0:7] #print action #print 'accion=>'+action #para cada varible perteneciente a la relacion QF.ac_ que representa a las acciones for v in r.vrange: if z.evalmodel(v) == '1': value = var2element(v, rs) value = value[1:len(value) - 1] cadelis = cadelis + value + ',' fact_candidate = fact_candidate + action + '=' + value + ' and ' fact_permanent = fact_permanent + action + '=' + value + ' and ' cl = [-v] fact_permanent = fact_permanent[:-5] fact_candidate = fact_candidate[:-5] cadelis = cadelis[:-1] fact = fact_candidate + '}?' + cadelis + '?' + fact_permanent + '}<FINAL>\n' z.addclause(cl) #almacena fact el wac en un archivo #print 'wac canditate : \n',cadelis fname.write(fact) wac_list.append(fact) else: #ap1.log_file('unsat.. fin busqueda para el unroll corriente','logfile.log') assert verdict == False, "ERROR: Undefined solver state" break fname.close() return wac_list
def run_incremental_alloy(alloy_models, cant_max, filename): output = open(filename, 'w') path_als = os.path.abspath(alloy_models) nodename = platform.node() t0 = time.time() t_before_xlation = time.time() output = als2cnfbed(path_als) t_after_xlation = time.time() xlation_seconds = t_after_xlation - t_before_xlation print 'Time traslation als to cnf:', xlation_seconds path_cnf = output.path_cnf path_rels = output.path_rels print("\nParsing {}".format(path_rels)) rs = Relations(path_rels) wac_list = [] #print("\nCreating native solver instance") z = minisat.Zolver() rels = rs.rels #print("Parsing {}".format(path_cnf)) z.read(path_cnf) i = 0 while True: if i == cant_max: break verdict = z.solve() if verdict == True: i = i + 1 #print("\nSAT") cl = [] fact = '<INICIO>fact{ ' for j in xrange(len(rels)): r = rels[j] if r.name.find("QF.ac_") == 0: action = r.name[0:7] #para cada varible perteneciente a la relacion QF.ac_ que representa a las acciones for v in r.vrange: if z.evalmodel(v) == '1': value = var2element(v, rs) value = value[1:len(value) - 1] fact = fact + action + '=' + value + '\n' #print v, " : ", var2element(v, rs) cl = [-v] fact = fact + '}<FINAL>\n' z.addclause(cl) #almacena fact el wac en un archivo output.write(fact) wac_list.append(fact) else: assert verdict == False, "ERROR: Undefined solver state" break output.close() return wac_list
print("This is {} running on {}\nExperiment starting at {}".format( VERSION, nodename, time.strftime("%c"))) print("\nTranslating {} to .cnf and .rels... ".format(path_als)) t0 = time.time() t_before_xlation = time.time() output = als2cnfbed(path_als) t_after_xlation = time.time() xlation_seconds = t_after_xlation - t_before_xlation path_cnf = output.path_cnf path_rels = output.path_rels print("\nParsing {}".format(path_rels)) rs = Relations(path_rels) print("\nCreating native solver instance") z = minisat.Zolver() print("Parsing {}".format(path_cnf)) z.read(path_cnf) rels = [ rel for rel in rs.rels if rel.name == "Node.Next" or rel.name == "Node.val" or rel.name == "$Model_s" ] #print "atoms:", rs.atoms #print "hello" #for rel in rels:
def run_incremental_alloy(alloy_models, cant_max, filename): fname = open(filename, 'w') path_als = os.path.abspath(alloy_models) nodename = platform.node() t0 = time.time() t_before_xlation = time.time() output = als2cnfbed(path_als) t_after_xlation = time.time() xlation_seconds = t_after_xlation - t_before_xlation print 'Time traslation als to cnf:', xlation_seconds #ap1.reg('reporte','traslation time: '+str(xlation_seconds)+' ',1) path_cnf = output.path_cnf path_rels = output.path_rels print path_rels print("\nParsing {}".format(path_rels)) rs = Relations(path_rels) wac_list = [] #print("\nCreating native solver instance") z = minisat.Zolver() rels = rs.rels #print("Parsing {}".format(path_cnf)) z.read(path_cnf) i = 0 first = True while True: if i == cant_max: break inicio = time.time() verdict = z.solve() tiempo = time.time() - inicio #ap1.reg('reporte', 'Sat '+str(veredict),1) #ap1.reg('reporte','Sat solver time: '+str(tiempo),1) print 'sat ', str(verdict) if verdict == True: print 'Sat time: ', tiempo i = i + 1 cl = [] cadelis = '' fact = '<INICIO>fact{ ' for j in xrange(len(rels)): r = rels[j] if r.name.find("QF.ac_") == 0: action = r.name[0:7] #print action #para cada varible perteneciente a la relacion QF.ac_ que representa a las acciones for v in r.vrange: if z.evalmodel(v) == '1': value = var2element(v, rs) value = value[1:len(value) - 1] cadelis = cadelis + value + ',' fact = fact + action + '=' + value + ' and ' cl = [-v] fact = fact[:-5] cadelis = cadelis[:-1] fact = fact + '}<FINAL>?' + cadelis + '\n' z.addclause(cl) #almacena fact el wac en un archivo print 'wac canditate : ', cadelis fname.write(fact) wac_list.append(fact) else: assert verdict == False, "ERROR: Undefined solver state" break fname.close() return wac_list