-
Notifications
You must be signed in to change notification settings - Fork 1
/
kidney-exchange.sh
executable file
·105 lines (99 loc) · 3.45 KB
/
kidney-exchange.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
#!/bin/bash
function usage
{
echo "Usage: kidney-exchange.sh [-a <algorithm>] [-h] [-i] [-m <max surgeries>] [-n <number hospitals>] [-p <number pairs>] [-q] [-r <number rounds>] [-s <RNG seed>] [-t]"
echo
echo "Driver for Kidney Exchange program on PowerShell or PowerShell Core. Requires at least JRE 1.8."
echo
echo " -a <algorithm> Matching algorithm to use for kidney exchange. Choose either ILP, Local_ILP, or Greedy."
echo " -h Show this usage and exit."
echo " -i Disable incremental setting."
echo " -m <max surgeries> Max surgeries that can be performed per hospital per time step."
echo " -n <number hospitals> Number of hospitals participating in the exchange."
echo " -p <number pairs> Initial number of pairs per hospital."
echo " -q Enable quiet mode."
echo " -r <number rounds> Number of time steps to run the kidney exchange for."
echo " -s <RNG seed> Set the RNG seed for the kidney exchange."
echo " -t Enable test output."
echo
}
SEED=
HOSPITALS=
PAIRS=
SURGERIES=
ROUNDS=
ALGORITHM=
QUIET=
TEST=
DISABLE_INCREMENTAL=
while getopts "s:n:p:m:r:a:qtih" OPTION; do
case "$OPTION" in
a)
ALGORITHM_VALUE=`echo "$OPTARG" | tr a-z A-Z`
if [ "$ALGORITHM_VALUE" != "GREEDY" ] && [ "$ALGORITHM_VALUE" != "ILP" ] && [ "$ALGORITHM_VALUE" != "LOCAL_ILP" ]; then
echo "Invalid algorithm $OPTARG given. Must be Greedy or ILP."
exit 1
fi
ALGORITHM="-a $ALGORITHM_VALUE"
;;
h)
usage
exit 0
;;
i)
DISABLE_INCREMENTAL="-i"
;;
m)
if [ "$OPTARG" -eq 0 ] || ! [[ "$OPTARG" =~ ^[0-9]+$ ]]; then
echo "Invalid max number of surgeries: $OPTARG"
exit 1
fi
SURGERIES="-m $OPTARG"
;;
n)
if [ "$OPTARG" -eq 0 ] || ! [[ "$OPTARG" =~ ^[0-9]+$ ]]; then
echo "Invalid number of hospitals: $OPTARG"
exit 1
fi
HOSPITALS="-n $OPTARG"
;;
p)
if [ "$OPTARG" -eq 0 ] || ! [[ "$OPTARG" =~ ^[0-9]+$ ]]; then
echo "Invalid number of pairs: $OPTARG"
exit 1
fi
PAIRS="-p $OPTARG"
;;
q)
QUIET="-q"
;;
r)
if [ "$OPTARG" -eq 0 ] || ! [[ "$OPTARG" =~ ^[0-9]+$ ]]; then
echo "Invalid number of rounds $OPTARG"
exit 1
fi
ROUNDS="-r $OPTARG"
;;
s)
if ! [[ $OPTARG =~ '^[0-9]+$' ]] ; then
echo "Invalid seed $OPTARG"
exit 1
fi
SEED="-s $OPTARG"
;;
t)
TEST="-t"
;;
*)
usage
exit 1
;;
esac
done
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
KIDNEY_JAR="$SCRIPT_DIR/out/artifacts/KidneyExchange_jar/KidneyExchange.jar"
if [ ! -f "$KIDNEY_JAR" ]; then
echo "Missing Kidney Exchange JAR file $KIDNEY_JAR. Please build the artifact with the IntelliJ project first."
exit 1
fi
java -jar $KIDNEY_JAR $ALGORITHM $DISABLE_INCREMENTAL $SURGERIES $HOSPITALS $PAIRS $QUIET $ROUNDS $SEED $TEST