-
Notifications
You must be signed in to change notification settings - Fork 6
/
findDecisionTreesSizes.py
90 lines (71 loc) · 2.86 KB
/
findDecisionTreesSizes.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import glob
import sys
import pdb
from z3 import *
from pytictoc import TicToc
import csv
import os
import json
from smtEncoding.dagSATEncoding import DagSATEncoding
from utils.Traces import ExperimentTraces
from utils.SimpleTree import Formula
from utils import config
from multiprocessing import Process, Queue
import time
import argparse
from _datetime import datetime
from doctest import testfile
from formulaBuilder.AtomBuilder import AtomBuilder, AtomBuildingStrategy
from formulaBuilder.DTFormulaBuilder import DTFormulaBuilder
import logging
from formulaBuilder.AtomBuildingStrategy import AtomBuildingStrategy
def findDTDepth(fileName):
overallSubs = []
overallDepth = 0
with open(fileName) as dtFile:
for line in dtFile:
fText = (line.split(':')[0]).strip()
if fText == '*':
continue
else:
overallDepth += 1
obtainedFormula = Formula.convertTextToFormula(fText)
subs = obtainedFormula.getSetOfSubformulas()
overallSubs += subs
overallSubs = set(overallSubs)
overallDepth += len(overallSubs)
overallDepth -= 1
print(overallDepth, overallSubs)
return overallDepth
def findSizeOfTextFormula(formulaText):
try:
formula = Formula.convertTextToFormula(formulaText)
return len(formula.getSetOfSubformulas())
except:
return "/"
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--input_file", dest="inputFile", default='experiments/dtSubset3Strategy2/statsSubset3Strategy2.csv')
parser.add_argument("--sat_input_file", dest="satInput", default='experiments/satTest5And10/completeStats.csv')
args,unknown = parser.parse_known_args()
outputFolder = os.path.dirname(args.inputFile)
outputFile = outputFolder + "/dtDepths.csv"
satFormulasLengths = {}
with open(args.satInput) as satCsvInput:
satReader = csv.reader(satCsvInput)
satFormulasLengths = { os.path.basename(line[1]) : findSizeOfTextFormula(line[9]) for line in satReader }
with open(args.inputFile) as csvInput:
reader = csv.reader(csvInput)
with open(outputFile, "w") as csvfile:
writer = csv.writer(csvfile)
for line in reader:
try:
dtReprFile = line[12]
dtDepth = findDTDepth(dtReprFile)
formulaDepth = satFormulasLengths[os.path.basename(line[1])]
if not formulaDepth == "/":
writer.writerow([line[1], formulaDepth, dtDepth, dtDepth/(formulaDepth*1.0)])
except:
print("failed with "+ repr(line))
if __name__ == "__main__":
main()