예제 #1
0
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
예제 #2
0
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."
예제 #3
0
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
예제 #4
0
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
예제 #5
0
파일: psynth.py 프로젝트: nricci/SATSynth

if __name__ == '__main__':

    assert len(sys.argv) == 2, "usage: {} path_to_alsfile".format(sys.args[0])
    path_als = os.path.abspath(sys.argv[1])
    nodename = platform.node()

    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)
예제 #6
0
	def translate_problem_from_als(self, alspath):
		alloy_output = als2cnfbed(alspath, self.pathmaker('als2cnfbed.log'))
		Log.info("Translated command `%s' (%s)",
			alloy_output.command_label, alloy_output.command_type)
		return alloy_output
예제 #7
0
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