-
Notifications
You must be signed in to change notification settings - Fork 6
/
solverRuns.py
66 lines (57 loc) · 2.59 KB
/
solverRuns.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import sys
from multiprocessing import Process, Queue
from smtEncoding.dagSATEncoding import DagSATEncoding
from pytictoc import TicToc
from z3 import *
import pdb
from utils import config
from formulaBuilder.DTFormulaBuilder import DTFormulaBuilder
from formulaBuilder.AtomBuilder import AtomBuilder, AtomBuildingStrategy
from formulaBuilder.satQuerying import get_models
def run_solver(finalDepth, traces, maxNumOfFormulas = 1, startValue=1, step=1, q = None, encoder=DagSATEncoding):
if q is not None:
separate_process = True
else:
separate_process = False
t = TicToc()
t.tic()
results = get_models(finalDepth, traces, startValue, step, encoder, maxNumOfFormulas)
time_passed = t.tocvalue()
if separate_process == True:
q.put([results, time_passed])
else:
return [results, time_passed]
def run_dt_solver(traces, subsetSize=config.DT_SUBSET_SIZE, txtFile="treeRepresentation.txt", strategy=config.DT_SAMPLING_STRATEGY, decreaseRate=config.DT_DECREASE_RATE,\
repetitionsInsideSampling=config.DT_REPETITIONS_INSIDE_SAMPLING, restartsOfSampling=config.DT_RESTARTS_OF_SAMPLING, q = None, encoder=DagSATEncoding,):
#try:
config.encoder = encoder
if q != None:
separateProcess = True
else:
separateProcess = False
ab = AtomBuilder()
ab.getExamplesFromTraces(traces)
#samplingStrategy = config.DT_SAMPLING_STRATEGY
samplingStrategy = strategy
#decreaseRate = config.DT_DECREASE_RATE
decreaseRate = decreaseRate
t = TicToc()
t.tic()
(atoms, atomTraceEvaluation) = ab.buildAtoms(sizeOfPSubset=subsetSize, strategy = samplingStrategy, sizeOfNSubset=subsetSize, probabilityDecreaseRate=decreaseRate,\
numRepetitionsInsideSampling=repetitionsInsideSampling, numRestartsOfSampling = restartsOfSampling)
fb = DTFormulaBuilder(features = ab.atoms, data = ab.getMatrixRepresentation(), labels = ab.getLabels())
fb.createASeparatingFormula()
timePassed = t.tocvalue()
atomsFile = "atoms.txt"
treeTxtFile = txtFile
ab.writeAtomsIntoFile(atomsFile)
numberOfUsedPrimitives = fb.numberOfNodes()
fb.tree_to_text_file(treeTxtFile)
# return (timePassed, len(atoms), numberOfUsedPrimitives)
if separateProcess == True:
q.put([timePassed, len(atoms), numberOfUsedPrimitives])
else:
return [timePassed, len(atoms), numberOfUsedPrimitives]
# except Exception as e:
# print(e)
# sys.exit(1)