-
Notifications
You must be signed in to change notification settings - Fork 1
/
argue.sh
executable file
·301 lines (275 loc) · 8.98 KB
/
argue.sh
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
293
294
295
296
297
298
299
300
301
#!/bin/bash
TIMESTAMP="# Timestamp: "$(date +'%Y-%m-%d %H:%M:%S %Z')
CBMC='./backends/cbmc'
VERSION="# CBMC Version: "$($CBMC -version)
FILE="arguing.c"
RULES=$1
PROPS=$2
c=$3
v=$4
GLUCOSE=$5
OPT=$6
OPTS=''
while [ -n "$6" ]
do
OPTS=$OPTS" ${6}" && shift;
done
cntOpts=`echo -e "$OPTS" | grep -o - | wc -l`
cntOpts=$(($cntOpts / 2))
if [[ $GLUCOSE != "" ]]
then
cntOpts=$(($cntOpts + 1))
fi
if [[ $cntOpts != "" ]] && (( "1" < "$cntOpts" ))
then
cntOpts="s"
else
cntOpts=""
fi
if [ -n "$OPTS" ]
then
printOpts=`echo -e "?$OPTS" | sed -e 's/?\s--//g'`
if [[ $GLUCOSE != "" ]]
then
printOpts=`echo -e " --$printOpts"`
fi
fi
printOptsGl="$printOpts"
if [[ $GLUCOSE != "" ]]
then
printOptsGl="glucose$printOpts"
fi
if [ -n "$OPTS" ] || [[ $GLUCOSE != "" ]]
then
printOpts=`echo -e "$printOptsGl" | sed 's/\s\(.*\)--/\1 and /' | sed 's/--/, /g'`
PRINT_OPTS=`echo -e "$printOpts" | sed -e 's/and/,/g' | sed 's/[[:space:]]*,/,/g'`
printOpts=`echo -e "$printOpts" | sed 's/./\U&/g' | sed 's/ AND / and /g'`
OPT_OUT=" with the option"$cntOpts" "$printOpts
else
OPT_OUT=''
fi
if [ -n "$OPTS" ] || [[ $GLUCOSE != "" ]]
then
OPTIONS='\n'"# Further Options: "$PRINT_OPTS
else
OPTIONS=''
fi
if [[ $FILE == "" ]]
then
echo -e "No file specified. Now terminating."
exit
fi
if [[ $RULES == "" ]]
then
echo -e "No voting rules specified. Now terminating."
exit
fi
if [[ $PROPS == "" ]]
then
echo -e "No properties specified. Now terminating."
exit
fi
if [[ $c == "" ]] || (( "$c" <= "0" ))
then
echo -e "No valid candidate number specified. Now terminating."
exit
fi
if [[ $v == "" ]] || (( "$v" <= "0" ))
then
echo -e "No valid voter number specified. Now terminating."
exit
fi
if [ ${FILE: -2} == ".c" ]
then
FILE="${FILE%%.*}"
fi
F=$FILE.c
if [ ! -f $F ]
then
echo -e $F" is not a valid file. Now terminating."
exit
fi
OUTFILE="$FILE.out"
DOM=`./scripts/printPropertyNumber.sh $PROPS "DOM"`
ANON=`./scripts/printPropertyNumber.sh $PROPS "ANON"`
COND=`./scripts/printPropertyNumber.sh $PROPS "COND"`
SYMCANC=`./scripts/printPropertyNumber.sh $PROPS "SYMCANC"`
FVSC=`./scripts/printPropertyNumber.sh $PROPS "FVSC"`
ELEM=`./scripts/printPropertyNumber.sh $PROPS "ELEM"`
CYCL=`./scripts/printPropertyNumber.sh $PROPS "CYCL"`
CANC=`./scripts/printPropertyNumber.sh $PROPS "CANC"`
REINF=`./scripts/printPropertyNumber.sh $PROPS "REINF"`
REINF_SUB=`./scripts/printPropertyNumber.sh $PROPS "REINF_SUB"`
SIMP=`./scripts/printPropertyNumber.sh $PROPS "SIMP"`
MAJ=`./scripts/printPropertyNumber.sh $PROPS "MAJ"`
WEAK_MAJO=`./scripts/printPropertyNumber.sh $PROPS "WEAK_MAJO"`
NO_BLOCKING=`./scripts/printPropertyNumber.sh $PROPS "NO_BLOCKING"`
BLOCK_STRING="-D NO_BLOCKING="$NO_BLOCKING
PROP_STRING="-D DOM="$DOM" -D ANON="$ANON" -D COND="$COND" -D SYMCANC="$SYMCANC" -D FVSC="$FVSC" -D ELEM="$ELEM" -D CYCL="$CYCL" -D CANC="$CANC" -D REINF="$REINF" -D REINF_SUB="$REINF_SUB" -D SIMP="$SIMP" -D MAJ="$MAJ" -D WEAK_MAJO="$WEAK_MAJO
unw=$(( $c < $v ? $v : $c ))
unw=$(( $unw * $unw ))
BOUNDS="-D C="$c" -D V="$v" --unwind "$(( $unw + 2 ))
rule=""
if [[ $RULES == "borda.h" ]]
then
rule="BORDA"
fi
if [[ $RULES == "black.h" ]]
then
rule="BLACK"
fi
if [[ $RULES == "copeland.h" ]]
then
rule="COPELAND"
fi
RULES='"'"$RULES"'"'
RULES="-D RULES="$RULES
p=`./scripts/printProperties.sh "$PROP_STRING" | sed 's/^[ \t]*//;s/[ \t]*$//' | sed 's/ /, /g'`
echo -e "Starting verification for "$c" candidates and "$v" voters"'\n'"for the property/-ies "$p$OPT_OUT"."'\n''\n'"This might take a while ..."
start=$(date +%s.%3N)
timeout 30m $CBMC --trace $RULES $BOUNDS $PROP_STRING $BLOCK_STRING $OPTS $FILE.c &> $OUTFILE
end=$(date +%s.%3N)
echo -e "... VERIFICATION FINISHED!"
if [[ $rule == "" ]]
then
rule=`tac $OUTFILE | grep " RULE\[" | head -n 1 | sed 's/" ([0-9]*)//' | sed 's/ RULE\[0l\]="//'`
fi
var=`cat $OUTFILE | grep " variables" | head -n 1 | sed -r 's/([0-9]*) variables, ([0-9]*) clauses/\1/'`
cla=`cat $OUTFILE | grep " clauses" | head -n 1 | sed -r 's/([0-9]*) variables, ([0-9]*) clauses/\2/'`
variables=''
if [ "$var" != "" ]
then
variables=", Variables: "$var
else
variables=""
fi
clauses=''
if [ "$cla" != "" ]
then
clauses=", Clauses: "$cla
else
clauses=""
fi
sec=`cat $OUTFILE | grep 'Runtime decision procedure:' | tail -n 1 | sed -r 's/^.* ([0-9]*.[0-9]*)s*$/\1/' | sed -r 's/s//'`
sec2=$(echo "$end - $start" | bc)
if [[ $sec2 == .* ]]
then
sec2="0"$sec2
fi
succ=`cat $OUTFILE | grep "VERIFICATION SUCCESSFUL" | sed -r 's/UCCESSFUL//' | sed -r 's/VERIFICATION //'`
err=`cat $OUTFILE | grep "VERIFICATION FAILED" | sed -r 's/RIFICATION FAILED//' | sed -r 's/V//'`
echo -e '\n'"############################################################"
echo -e $TIMESTAMP'\n'$VERSION$OPTIONS
echo -e "############################################################"
echo -e '\n'"############################################################"
echo -e "Candidates: "$c", Voters: "$v
echo -e "Time: "$sec2" seconds"$variables$clauses'\n'
if [ "$err" == "" ]
then
if [ "$succ" == "" ]
then
echo -e "VERIFICATION TIMED OUT."
else
echo -e "PROPERTIES FOUND TO BE INCONSISTENT FOR GIVEN BOUNDS."
fi
if [ "$rule" != "" ]
then
echo -e '\n'"Voting Rule: "$rule
fi
./scripts/printProperties.sh '\n'"Checked Properties: $PROP_STRING "
echo -e ""
else
echo -e "PROPERTIES SATISFIABLE FOR GIVEN BOUNDS."
if [ "$rule" != "" ]
then
echo -e '\n'"Voting Rule: "$rule
fi
./scripts/printProperties.sh '\n'"Satisfied Properties: $PROP_STRING "
echo -e '\n'"EXAMPLE:"'\n'"Input is given as ranked ballots and output as a set of"
echo -e "all elected candidates (here denoted as YES). Candidates"
echo -e "and voters have small or capital letters respectively."'\n'
echo -e "==========================================="
echo -e "===================VOTES==================="
echo -e "==========================================="
./scripts/printVotes.sh $OUTFILE $c $v
if [[ $ANON == "1" ]] || [[ $ANON == "-1" ]]
then
echo -e ''
echo -e "============VOTES FOR ANONYMITY============"
v_prop=`./scripts/printVoteNumber.sh $OUTFILE '_ANON'`
./scripts/printVotes.sh $OUTFILE $c $v_prop 'ANON_'
fi
if [[ $REINF == "1" ]] || [[ $REINF == "-1" ]]
then
echo -e ''
echo -e "==========VOTES FOR REINFORCEMENT=========="
echo -e "-----FIRST PROFILE-----"
v_prop=`./scripts/printVoteNumber.sh $OUTFILE '_REINF_A'`
./scripts/printVotes.sh $OUTFILE $c $v_prop 'REINF_A_'
echo -e "----SECOND PROFILE----"
v_prop=`./scripts/printVoteNumber.sh $OUTFILE '_REINF_B'`
./scripts/printVotes.sh $OUTFILE $c $v_prop 'REINF_B_'
fi
if [[ $REINF_SUB == "1" ]] || [[ $REINF_SUB == "-1" ]]
then
echo -e ''
echo -e "====VOTES FOR REINFORCEMENT SUBTRACTION===="
echo -e "-----FIRST PROFILE-----"
v_prop=`./scripts/printVoteNumber.sh $OUTFILE '_REINF_SUB_A'`
./scripts/printVotes.sh $OUTFILE $c $v_prop 'REINF_SUB_A_'
echo -e "----SECOND PROFILE----"
v_prop=`./scripts/printVoteNumber.sh $OUTFILE '_REINF_SUB_B'`
./scripts/printVotes.sh $OUTFILE $c $v_prop 'REINF_SUB_B_'
fi
if [[ $SIMP == "1" ]] || [[ $SIMP == "-1" ]]
then
echo -e ''
echo -e "=============VOTES FOR SIMPLIFY============="
v_prop=`./scripts/printVoteNumber.sh $OUTFILE '_SIMP'`
if [ "$v_prop" != "" ]
then
./scripts/printVotes.sh $OUTFILE $c $v_prop 'SIMP_'
fi
fi
echo -e ''
echo -e "==========================================="
echo -e "==============ELECTION RESULT=============="
echo -e "==========================================="
./scripts/printResult.sh $OUTFILE $c
if [[ $ANON == "1" ]] || [[ $ANON == "-1" ]]
then
echo -e ''
echo -e "============RESULT FOR ANONYMITY============"
./scripts/printResult.sh $OUTFILE $c "ANON_"
fi
if [[ $REINF == "1" ]] || [[ $REINF == "-1" ]]
then
echo -e ''
echo -e "=========RESULTS FOR REINFORCEMENT========="
echo -e "------FIRST RESULT------"
./scripts/printResult.sh $OUTFILE $c "REINF_A_"
echo -e ''
echo -e "-----SECOND RESULT-----"
./scripts/printResult.sh $OUTFILE $c "REINF_B_"
fi
if [[ $REINF_SUB == "1" ]] || [[ $REINF_SUB == "-1" ]]
then
echo -e ''
echo -e "=RESULTS FOR REINFORCEMENT SUBTRACTION="
echo -e "------FIRST RESULT------"
./scripts/printResult.sh $OUTFILE $c "REINF_SUB_A_"
echo -e ''
echo -e "-----SECOND RESULT-----"
./scripts/printResult.sh $OUTFILE $c "REINF_SUB_B_"
fi
if [[ $SIMP == "1" ]] || [[ $SIMP == "-1" ]]
then
echo -e ''
echo -e "============RESULT FOR SIMPLIFY============"
./scripts/printResult.sh $OUTFILE $c "SIMP_"
fi
echo -e ''
fi
echo -e "############################################################"
#cat $OUTFILE
rm $OUTFILE