-
Notifications
You must be signed in to change notification settings - Fork 3
/
generator.sh
executable file
·150 lines (117 loc) · 3.64 KB
/
generator.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
#!/bin/bash
# LOAD OPTIONS
while getopts o:a:n:N:m:W:C:k:d:- opt
do
case "$opt" in
o)
optimized="$OPTARG" # -a (algorithm name)
;;
a)
algo="$OPTARG" # -a (algorithm name)
;;
n)
num_items="$OPTARG" # -n (number of items)
;;
N)
num_instances="$OPTARG" # -N (number of instances)
;;
m)
capacity_weights_ratio="$OPTARG" # -m (ratio between knapsack capacity and sum of weights)
;;
W)
max_weight="$OPTARG" # -W (max weight)
;;
C)
max_price="$OPTARG" # -C (max price)
;;
k)
exponent="$OPTARG" # -k (exponent k)
;;
d)
type="$OPTARG" # -d (-1 = more small items, 0 = equlibrium, 1 = more big items)
;;
esac
done
shift "$(( OPTIND - 1 ))"
echo "__________________________________"
echo "optimized: $optimized"
echo "algorithm: $algo"
echo "num items: $num_items"
echo "num instances: $num_instances"
echo "ratio: $capacity_weights_ratio"
echo "max weight: $max_weight"
echo "max price: $max_price"
echo "exponent: $exponent"
echo "type: $type"
echo "__________________________________"
rm -rf input/input-*
rm -rf instance_data.csv
if [ $optimized = "weight" ]
then
counter=0
printf -- "________WEIGHT________"
if [ $algo == "heuristic" ]
then
printf -- "weight,duration,error\n" >> instance_data.csv
else
printf -- "weight,duration\n" >> instance_data.csv
fi
for i in `seq 1000 1000 30000`; do
./knapgen/knapgen -n $num_items -N $num_instances -m $capacity_weights_ratio -W $i -C $max_price -k $exponent -d $type > "input/input-${i}"
#./knapgen/knapgen -n 23 -N 15 -m 0.2 -W $i -C 500 -k 1 -d 0 > "input/input-${i}"
echo "Running Knapsack on input/input-${i}"
printf -- "${i},$(./main -algorithm ${algo} < input/input-${i})\n" >> instance_data.csv
$(( counter++ ))
done
fi
if [ $optimized = "price" ]
then
counter=0
printf -- "________PRICE________"
if [ $algo == "heuristic" ]
then
printf -- "price,duration,error\n" >> instance_data.csv
else
printf -- "price,duration\n" >> instance_data.csv
fi
for i in `seq 1000 1000 30000`; do
./knapgen/knapgen -n $num_items -N $num_instances -m $capacity_weights_ratio -W $max_weight -C $i -k $exponent -d $type > "input/input-${i}"
echo "Running Knapsack on input/input-${i}"
printf -- "${i},$(./main -algorithm ${algo} < input/input-${i})\n" >> instance_data.csv
$(( counter++ ))
done
fi
if [ $optimized = "ratio" ]
then
counter=0
printf -- "________RATIO________"
if [ $algo == "heuristic" ]
then
printf -- "ratio,duration,error\n" >> instance_data.csv
else
printf -- "ratio,duration\n" >> instance_data.csv
fi
for i in `seq 0.1 0.1 1`; do
./knapgen/knapgen -n $num_items -N $num_instances -m $i -W $max_weight -C $max_price -k $exponent -d $type > "input/input-${i}"
echo "Running Knapsack on input/input-${i}"
printf -- "${i},$(./main -algorithm ${algo} < input/input-${i})\n" >> instance_data.csv
$(( counter++ ))
done
fi
if [ $optimized = "exponent" ]
then
counter=0
printf -- "________EXPONENT________"
if [ $algo == "heuristic" ]
then
printf -- "exponent,duration,error\n" >> instance_data.csv
else
printf -- "exponent,duration\n" >> instance_data.csv
fi
for i in `seq 0 0.1 3.1`; do
./knapgen/knapgen -n $num_items -N $num_instances -m $capacity_weights_ratio -W $max_weight -C $max_price -k $i -d $type > "input/input-${i}"
echo "Running Knapsack on input/input-${i}"
printf -- "${i},$(./main -algorithm ${algo} < input/input-${i})\n" >> instance_data.csv
$(( counter++ ))
done
fi