forked from GOCompetition/Evaluation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
146 lines (124 loc) · 4.99 KB
/
test.py
File metadata and controls
146 lines (124 loc) · 4.99 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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
'''
syntax:
from a command prompt:
python test.py raw rop con inl sol1 sol2 summary detail
from a Python interpreter:
import sys
sys.argv = [raw, rop, con, inl, sol1, sol2, summary, detail]
execfile("test.py")
'''
import argparse
#import evaluation1 as evaluation
#import evaluation2 as evaluation # functioning code, with timing prototypes of numpy/scipy method
#import evaluation3 as evaluation # developing numpy/scipy method
import evaluation # current code
import csv
import os
def run_data():
'''read data'''
parser = argparse.ArgumentParser(description='Evaluate a solution to a problem instance')
parser.add_argument('raw', help='raw')
parser.add_argument('rop', help='rop')
parser.add_argument('con', help='con')
parser.add_argument('inl', help='inl')
parser.add_argument('sol1', help='sol1')
parser.add_argument('sol2', help='sol2')
parser.add_argument('summary', help='summary')
parser.add_argument('detail', help='detail')
args = parser.parse_args()
# Check files exist
for f in [args.raw, args.rop, args.con, args.inl]:
if not os.path.isfile(f):
raise Exception("Can't find {}".format(f))
#raise FileNotFoundError("Can't find {}".format(f)) # not in Python 2
try:
#(obj, cost, penalty, max_obj_viol, max_nonobj_viol, infeas) = evaluation.run( # eval return value is a tuple here
eval_return_value = evaluation.run( # eval_return_value is a bool here
args.raw,
args.rop,
args.con,
args.inl,
sol1_name=None,
sol2_name=None,
summary_name=args.summary,
detail_name=args.detail,
)
except:
print("exception in evaluation.run")
raise
else:
"""process obj, cost, penalty, max_obj_viol, max_nonobj_viol, infeas
e.g. add info, e.g. run time or a scenario name, and append to a report file"""
def run_sol1():
'''read data, evaluate solution1'''
parser = argparse.ArgumentParser(description='Evaluate a solution to a problem instance')
parser.add_argument('raw', help='raw')
parser.add_argument('rop', help='rop')
parser.add_argument('con', help='con')
parser.add_argument('inl', help='inl')
parser.add_argument('sol1', help='sol1')
parser.add_argument('sol2', help='sol2')
parser.add_argument('summary', help='summary')
parser.add_argument('detail', help='detail')
args = parser.parse_args()
# Check files exist
for f in [args.raw, args.rop, args.con, args.inl, args.sol1]:
if not os.path.isfile(f):
raise Exception("Can't find {}".format(f))
#raise FileNotFoundError("Can't find {}".format(f)) # not in Python 2
try:
#(obj, cost, penalty, max_obj_viol, max_nonobj_viol, infeas) = evaluation.run( # eval return value is a tuple here
eval_return_value = evaluation.run( # eval_return_value is a bool here
args.raw,
args.rop,
args.con,
args.inl,
sol1_name=args.sol1,
sol2_name=None,
summary_name=args.summary,
detail_name=args.detail,
)
except:
print("exception in evaluation.run")
raise
else:
"""process obj, cost, penalty, max_obj_viol, max_nonobj_viol, infeas
e.g. add info, e.g. run time or a scenario name, and append to a report file"""
def run_all():
''' read data, evaluate solution1, evaluate solution2'''
parser = argparse.ArgumentParser(description='Evaluate a solution to a problem instance')
parser.add_argument('raw', help='raw')
parser.add_argument('rop', help='rop')
parser.add_argument('con', help='con')
parser.add_argument('inl', help='inl')
parser.add_argument('sol1', help='sol1')
parser.add_argument('sol2', help='sol2')
parser.add_argument('summary', help='summary')
parser.add_argument('detail', help='detail')
args = parser.parse_args()
# Check files exist
for f in [args.raw, args.rop, args.con, args.inl, args.sol1, args.sol2]:
if not os.path.isfile(f):
raise Exception("Can't find {}".format(f))
#raise FileNotFoundError("Can't find {}".format(f)) # not in Python 2
try:
(obj, cost, penalty, max_obj_viol, max_nonobj_viol, infeas) = evaluation.run( # eval return value is a tuple here
args.raw,
args.rop,
args.con,
args.inl,
sol1_name=args.sol1,
sol2_name=args.sol2,
summary_name=args.summary,
detail_name=args.detail,
)
except:
print("exception in evaluation.run")
raise
else:
"""process obj, cost, penalty, max_obj_viol, max_nonobj_viol, infeas
e.g. add info, e.g. run time or a scenario name, and append to a report file"""
if __name__ == '__main__':
run_all() # read data, evaluate sol1, evaluate sol2
#run_sol1() # read data, evaluate sol1
#run_data() # read data