-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathwork.sh
More file actions
executable file
·292 lines (269 loc) · 7.24 KB
/
Copy pathwork.sh
File metadata and controls
executable file
·292 lines (269 loc) · 7.24 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#!/bin/sh
# syntax:
# $ ./work.sh <flags>
#
# e.g.
# $ ./work.sh -c ./test_data/ieee14/scenario_1/ -s ./tmpsol/sol1/
#
# c: case_dir - if present copy case from there
# s: sol_dir - if present copy a solution from there - need to edit work.sh copy_sol=0 to =1 by hand for now
# r: scrub_data
# m: modify_mode - if present, do modify
# i: use prior operating point solver to make a new solution
# p: do a platform submission of the prior operating point solver to make a new solution
# e: evaluate solution
# d: division
# n: num_proc
# w: work directory
# x: output a table of solution changes to this file in CSV format
# z:
# default values of flag arguments
case_dir=./test_data/ieee14/scenario_1
sol_dir=
scrub_data=0
modify_load_mode=
modify_data=0
make_new_sol=0
copy_sol=1 # need to edit this by hand for now
do_submission=0
eval_sol=0
division=1
num_proc=1
work_dir=./tmp/
load_min_max_interp=0
load_min_max_tol=0
print_usage() {
echo "Usage:"
echo "$ ./work.sh <flags>"
echo ""
echo "flags:"
echo "-h : help"
echo "-c <case_dir> : if present copy case from there - need to edit work.sh copy_sol=0 to =1 by hand for now"
echo "-s <sol_dir> : if present copy a solution from there"
echo "-r : scrub_data"
echo "-l <modify_load_mode> : if present, do modify with this mode"
echo "-i : use prior operating point solver to make a new solution"
echo "-p : do a platform submission of the prior operating point solver to make a new solution"
echo "-e : evaluate solution"
echo "-d <division> : division = 1, 2, 3, 4"
echo "-n <num_proc> : number of processes in eval, > 1 requires MPI"
echo "-w <work_dir> : work directory. data, solutions, output files land here"
echo "-t <load_min_max_interp> : interpolation parameter between load tmin and tmax when modify_load_mode=='minmax'"
echo "-z <load_min_max_tol> : tolerance on load fixed t implemented as tmin = tfix - tol, tmax = tfix + tol"
}
while getopts 'hc:s:rl:ied:n:w:t:z:' flag; do
case ${flag} in
h) print_usage
exit ;;
c) case_dir="${OPTARG}" ;;
s) sol_dir="${OPTARG}" ;;
r) scrub_data=1 ;;
l) modify_load_mode="${OPTARG}" ;;
i) make_new_sol=1 ;;
p) do_submission=1 ;;
e) eval_sol=1 ;;
d) division=${OPTARG} ;;
n) num_proc=${OPTARG} ;;
w) work_dir=${OPTARG} ;;
t) load_min_max_interp=${OPTARG} ;;
z) load_min_max_tol=${OPTARG} ;;
*) print_usage
exit 1 ;;
esac
done
echo "case_dir: $case_dir"
echo "sol_dir: $sol_dir"
echo "division: $division"
# case_dir=$1 # c
# sol_dir=$2 # s
# # set options
# scrub_data=1
# modify_data=1
# make_new_sol=0
# copy_sol=0
# eval_sol=0
# division=1
# num_proc=1
# if modify then use modify
# if scrub and not modify then use scrub
# if not scrub then use orig
# need to scrub if modifying
# need to check again if scrubbing or modifying
strict_names=1
refresh_data=1
if [ ! -z $modify_load_mode ]
then
scrub_data=1
modify_data=1
fi
if [ $do_submission -gt 0 ]
then
make_new_sol=0
copy_sol=0
fi
if [ $make_new_sol -gt 0 ]
then
copy_sol=0
fi
py_dir=./data_utilities/
# original data
raw1="${work_dir}/case.orig.raw"
sup1="${work_dir}/case.orig.json"
con1="${work_dir}/case.orig.con"
# scrubbed data
raw2="${work_dir}/case.scrubbed.raw"
sup2="${work_dir}/case.scrubbed.json"
con2="${work_dir}/case.scrubbed.con"
# modified data
raw3="${work_dir}/case.mod.raw"
sup3="${work_dir}/case.mod.json"
con3="${work_dir}/case.mod.con"
# data to use in solution and evaluation
raw="${work_dir}/case.raw"
sup="${work_dir}/case.json"
con="${work_dir}/case.con"
echo "case: ${case_dir}"
if [ ! -d "$work_dir" ]
then
mkdir "$work_dir"
fi
# clean up the directory
# just remove everything
# need to copy anything you need from work_dir before calling this script
rm $work_dir/*
# copy to here
if [ $refresh_data -gt 0 ]
then
rm -rf $work_dir/*
#rm $work_dir/*.raw
#rm $work_dir/*.json
#rm $work_dir/*.con
if [ $strict_names -gt 0 ]
then
echo "find case: strict names"
cp "${case_dir}/case.raw" "$raw"
cp "${case_dir}/case.json" "$sup"
cp "${case_dir}/case.con" "$con"
else
echo "find case: arbitrary names"
cp "$case_dir"/*.raw "$work_dir"
cp "$case_dir"/*.json "$work_dir"
cp "$case_dir"/*.con "$work_dir"
# remove the excess stuff
rm $work_dir/*-w.raw
rm $work_dir/*_clean.raw
rm $work_dir/*_clean.json
rm $work_dir/*_clean.con
for i in $work_dir*.raw; do
[ -f "$i" ] || break
#echo "$i"
cp "$i" "$raw"
done
for i in "$work_dir"*.json; do
[ -f "$i" ] || break
#echo "$i"
cp "$i" "$sup"
done
for i in "$work_dir"*.con; do
[ -f "$i" ] || break
#echo "$i"
cp "$i" "$con"
done
fi
fi
# save copy of original data - and check
echo "final data file used in sol and evals:"
echo "$raw"
echo "$sup"
echo "$con"
echo "copy data"
cp "$raw" "$raw1"
cp "$sup" "$sup1"
cp "$con" "$con1"
echo "original (copied) files:"
echo "$raw1"
echo "$sup1"
echo "$con1"
echo "check original data"
python ${py_dir}check_data.py "$raw1" "$sup1" "$con1"
# scrub data - and check
if [ $scrub_data -gt 0 ]
then
echo "scrub data"
python ${py_dir}scrub_data.py "$raw" "$sup" "$con" "$raw2" "$sup2" "$con2"
echo "scrubbed files:"
echo "$raw2"
echo "$sup2"
echo "$con2"
cp "$raw2" "$raw"
cp "$sup2" "$sup"
cp "$con2" "$con"
echo "check scrubbed data"
python ${py_dir}check_data.py "$raw2" "$sup2" "$con2"
else
echo "skip scrub data"
fi
# modify data - and check
if [ $modify_data -gt 0 ]
then
echo "modify data"
python ${py_dir}modify_data.py "$raw" "$sup" "$con" "$raw3" "$sup3" "$con3" "$modify_load_mode" "${sol_dir}/solution_BASECASE.txt" "$load_min_max_interp" "$load_min_max_tol"
echo "modified files:"
echo "$raw3"
echo "$sup3"
echo "$con3"
cp "$raw3" "$raw"
cp "$sup3" "$sup"
cp "$con3" "$con"
echo "check modified data"
python ${py_dir}check_data.py "$raw3" "$sup3" "$con3"
else
echo "skip modify data"
fi
# construct infeasibility solution
if [ $make_new_sol -gt 0 ]
then
echo "construct new infeasibility solution"
rm ${work_dir}/solution_*.txt
python ${py_dir}construct_infeasibility_solution.py "$raw" "$sup" "$con" "$work_dir"
else
echo "skip construct new infeasibility solution"
fi
# copy stored solution
if [ $copy_sol -gt 0 ]
then
echo "copy stored solution"
echo "stored solution directory: ${sol_dir}"
cp ${sol_dir}/solution*.txt $work_dir
else
echo "skip copy stored solution"
fi
# do submission with infeasibility solution
if [ $do_submission -gt 0 ]
then
echo "do submission with infeasibility solution"
rm ./solution_*.txt
reserved=reserved
timelimit=300
network=network
python MyPython1.py "$con" "$sup" "$raw" $reserved $timelimit $division $network
python MyPython2.py "$con" "$sup" "$raw" $reserved $timelimit $division $network
mv ./solution_*.txt "$work_dir"
else
echo "skip submission with infeasibility solution"
fi
# evaluate solution
if [ $eval_sol -gt 0 ]
then
echo "evaluate solution"
if [ $num_proc -gt 1 ]
then
echo "using mpi, np=$num_proc"
mpirun -np $num_proc python ${py_dir}evaluation.py $division "$work_dir" "$work_dir"
else
echo "using serial method"
python ${py_dir}evaluation.py $division "$work_dir" "$work_dir"
fi
else
echo "skip evaluate solution"
fi