-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostopt.py
More file actions
executable file
·36 lines (26 loc) · 1.16 KB
/
postopt.py
File metadata and controls
executable file
·36 lines (26 loc) · 1.16 KB
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
#! /usr/bin/env python3
import pathlib
import argparse
import tomllib
import json
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('input_dir', type=pathlib.Path, help='directory of solutions files')
parser.add_argument('--config', type=pathlib.Path, help='configuration file')
args = parser.parse_args()
with open(args.config, 'rb') as f:
config = tomllib.load(f)
resnames = [pathlib.Path(exec).stem for exec in config['models']]
for resname in resnames:
for input in args.input_dir.glob('**/*.json'):
with open(input, 'r') as f:
j = json.load(f)
if j[resname]['obj'] == -1:
j[resname]['obj'] = float('nan')
if j[resname]['bound'] == -1:
j[resname]['bound'] = float('nan')
if j[resname]['runtime'] == -1 or j[resname]['runtime'] > config['timelimit']:
j[resname]['runtime'] = float('nan')
j[resname]['gap'] = abs(j[resname]['obj'] - j[resname]['bound']) / abs(j[resname]['obj'])
with open(input, 'w') as f:
json.dump(j, f, indent=4)