1
0

Format python files

This commit is contained in:
Jip J. Dekker 2021-06-16 10:22:47 +10:00
parent b3e1dfe446
commit c6a6b1795f
No known key found for this signature in database
GPG Key ID: 517DF4A00618C9C3
2 changed files with 45 additions and 29 deletions

View File

@ -13,6 +13,7 @@ import os
import re import re
import sys import sys
def compute_area(file, time): def compute_area(file, time):
area = -1 area = -1
@ -25,28 +26,29 @@ def compute_area(file, time):
# if match: # if match:
# objectives.append(int(match[1])) # objectives.append(int(match[1]))
# continue # continue
match = re.match(r'objective\s=\s(\d+)', line) match = re.match(r"objective\s=\s(\d+)", line)
if match: if match:
objectives.append(int(match[1])) objectives.append(int(match[1]))
continue continue
match = re.match(r'%\stime elapsed:\s(\d+)\sms', line) match = re.match(r"%\stime elapsed:\s(\d+)\sms", line)
if match: if match:
times.append(int(match[1])) times.append(int(match[1]))
continue continue
times.append(time) times.append(time)
assert(len(objectives) > 0) assert len(objectives) > 0
assert(len(objectives)+1 == len(times)) assert len(objectives) + 1 == len(times)
area = 0 area = 0
for i in range(len(objectives)): for i in range(len(objectives)):
area += ((times[i + 1] - times[i]) / 1000) * objectives[i] area += ((times[i + 1] - times[i]) / 1000) * objectives[i]
return int(area) return int(area)
folder = sys.argv[1] folder = sys.argv[1]
stats = {} stats = {}
for root, dirs, files in os.walk(folder): for root, dirs, files in os.walk(folder):
for name in files: for name in files:
if name.endswith('.sol'): if name.endswith(".sol"):
seed = 1 seed = 1
match = re.search(r"\.(\d+)\.sol", name) match = re.search(r"\.(\d+)\.sol", name)
if match: if match:
@ -59,29 +61,35 @@ for root, dirs, files in os.walk(folder):
# Nodes # Nodes
match = re.search(r"nodes:\s+(\d+)", line) match = re.search(r"nodes:\s+(\d+)", line)
if match: if match:
statistics['nodes'] = int(match.group(1)) statistics["nodes"] = int(match.group(1))
continue continue
# Solve time # Solve time
match = re.search(r"search time:\s+(\d+\.\d+)\s*seconds", line) match = re.search(r"search time:\s+(\d+\.\d+)\s*seconds", line)
if match: if match:
statistics['search_time'] = int(float(match.group(1))*1000) statistics["search_time"] = int(float(match.group(1)) * 1000)
continue continue
# Restarts # Restarts
match = re.search(r"restart count:\s+(\d+)", line) match = re.search(r"restart count:\s+(\d+)", line)
if match: if match:
statistics['restarts'] = int(match.group(1)) statistics["restarts"] = int(match.group(1))
continue continue
for line in contents[::-1]: for line in contents[::-1]:
# Best objective # Best objective
match = re.match(r'objective\s=\s(\d+)', line) match = re.match(r"objective\s=\s(\d+)", line)
if match: if match:
statistics['objective'] = int(match[1]) statistics["objective"] = int(match[1])
break break
# Area # Area
area = compute_area(contents, statistics['search_time']) area = compute_area(contents, statistics["search_time"])
stats[name[:-(4)].replace(".", ",")] = (area, statistics['objective'], statistics['search_time'], statistics['restarts'], statistics['nodes']) stats[name[:-(4)].replace(".", ",")] = (
area,
statistics["objective"],
statistics["search_time"],
statistics["restarts"],
statistics["nodes"],
)
sorted_stats = sorted(stats.items()) sorted_stats = sorted(stats.items())
a = sorted_stats[0][0][: sorted_stats[0][0].find(",")] a = sorted_stats[0][0][: sorted_stats[0][0].find(",")]

View File

@ -13,6 +13,7 @@ import os
import re import re
import sys import sys
def compute_area(file): def compute_area(file):
area = -1 area = -1
@ -25,11 +26,11 @@ def compute_area(file):
# if match: # if match:
# objectives.append(int(match[1])) # objectives.append(int(match[1]))
# continue # continue
match = re.match(r'objective\s=\s(\d+)', line) match = re.match(r"objective\s=\s(\d+)", line)
if match: if match:
objectives.append(int(match[1])) objectives.append(int(match[1]))
continue continue
match = re.match(r'%\stime elapsed:\s(\d+)\sms', line) match = re.match(r"%\stime elapsed:\s(\d+)\sms", line)
if match: if match:
times.append(int(match[1])) times.append(int(match[1]))
continue continue
@ -38,18 +39,19 @@ def compute_area(file):
times.append(int(match.group(1))) times.append(int(match.group(1)))
continue continue
assert(len(objectives) > 0) assert len(objectives) > 0
assert(len(objectives)+1 == len(times)) assert len(objectives) + 1 == len(times)
area = 0 area = 0
for i in range(len(objectives)): for i in range(len(objectives)):
area += ((times[i + 1] - times[i]) / 1000) * objectives[i] area += ((times[i + 1] - times[i]) / 1000) * objectives[i]
return int(area) return int(area)
folder = sys.argv[1]
foler = sys.argv[1]
statistics = {} statistics = {}
for root, dirs, files in os.walk(folder): for root, dirs, files in os.walk(folder):
for name in files: for name in files:
if name.endswith('.sol'): if name.endswith(".sol"):
seed = 1 seed = 1
match = re.search(r"\.(\d+)\.sol", name) match = re.search(r"\.(\d+)\.sol", name)
if match: if match:
@ -59,10 +61,10 @@ for root, dirs, files in os.walk(folder):
# Area # Area
area = compute_area(contents) area = compute_area(contents)
objective = 'UNSAT' objective = "UNSAT"
for line in contents[::-1]: for line in contents[::-1]:
# Best objective # Best objective
match = re.match(r'objective\s=\s(\d+)', line) match = re.match(r"objective\s=\s(\d+)", line)
if match: if match:
objective = int(match[1]) objective = int(match[1])
break break
@ -86,7 +88,13 @@ for root, dirs, files in os.walk(folder):
if match: if match:
restarts = int(match.group(1)) restarts = int(match.group(1))
continue continue
statistics[name[:-(4)].replace(".", ",")] = (area, objective, solvetime, restarts, nodes) statistics[name[:-(4)].replace(".", ",")] = (
area,
objective,
solvetime,
restarts,
nodes,
)
sorted_stats = sorted(statistics.items()) sorted_stats = sorted(statistics.items())
a = sorted_stats[0][0][: sorted_stats[0][0].find(",")] a = sorted_stats[0][0][: sorted_stats[0][0].find(",")]