-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabm.sh
More file actions
executable file
·173 lines (148 loc) · 4.46 KB
/
abm.sh
File metadata and controls
executable file
·173 lines (148 loc) · 4.46 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
#!/bin/bash
: '
FLAMEGPU2 Agent-Based Model
abm.sh
Generate the configuration file, build and run the ABM.
Inputs:
-expdir or --experiment_dir: directory with the scenario to simulate
-ob or --only_build: build the model without execute it
-v or --visualisation: activate the visualisation
-cps or --checkpoint_simulation: run the model in a simplified version with the aim to obtain a checkpoint
-g or --debug: execute the simulation with debug prints
-c or --clean: clean old files and directories
Authors: Daniele Baccega, Irene Terrone, Simone Pernice
'
bash drivers_check.sh
if [ $? -eq 1 ];
then
exit 1
fi
# Default values for input parameters
EXPERIMENT_DIR="None"
RESULTS_DIR="results"
ONLY_BUILD="OFF"
VISUALISATION="OFF"
CHECKPOINT_SIMULATION="OFF"
DEBUG="OFF"
CLEAN="OFF"
SUBSTITUTE_DIR="OFF"
while [[ $# -gt 0 ]]; do
case $1 in
-expdir|--experiment_dir)
EXPERIMENT_DIR="$2"
shift
shift
;;
-resdir|--results_dir)
RESULTS_DIR="$2"
shift
shift
;;
-ob|--only_build)
ONLY_BUILD="$2"
shift
shift
;;
-v|--visualisation)
VISUALISATION="$2"
shift
shift
;;
-g|--debug)
DEBUG="$2"
shift
shift
;;
-c|--clean)
CLEAN="$2"
shift
shift
;;
-subdir|--substitute_dir)
SUBSTITUTE_DIR="$2"
shift
shift
;;
-h|--help)
printf "./run.sh - run the ABM\n\n"
printf "Arguments:\n"
printf " -expdir or --experiment_dir: directory with the scenario to simulate\n"
printf " -ob or --only_build: build the model without execute it (default: OFF; possible values: ON, OFF)\n"
printf " -v or --visualisation: activate the visualisation (default: OFF; possible values: ON, OFF)\n"
printf " -g or --debug: execute the simulation with debug prints (default: OFF; possible values: ON, OFF)\n"
printf " -c or --clean: clean old files and directories (default: OFF; possible values: ON, OFF)\n"
exit 1
;;
-*|--*)
echo "Unknown option $1"
exit 1
;;
*)
POSITIONAL_ARGS+=("$1") # Save positional arg
shift # Past argument
;;
esac
done
set -- "${POSITIONAL_ARGS[@]}" # Restore positional parameters
DIR="resources/f4f/$EXPERIMENT_DIR"
# Check if the directory exists
if [ ! -d "$DIR" ]; then
echo "❌ Error: Directory $DIR does not exist."
exit 1
fi
DIR_PATH="results/$EXPERIMENT_DIR"
if [ -d "$DIR_PATH" ]; then
read -p "The directory '$DIR_PATH' already exists. Do you want to replace it? (y/n): " response
if [ "$response" == "y" ] || [ $SUBSTITUTE_DIR == "ON" ]; then
rm -rf "$DIR_PATH" # Remove the directory and its contents
mkdir -p "$DIR_PATH" # Recreate the directory
echo "The directory '$DIR_PATH' has been replaced."
else
echo "Operation canceled. The existing directory was not replaced."
exit 1
fi
else
mkdir -p "$DIR_PATH" # Create the directory if it doesn't exist
echo "The directory '$DIR_PATH' has been created."
fi
if [ ! -d flamegpu2 ];
then
python3 -m venv flamegpu2
source flamegpu2/bin/activate
pip install -r flamegpu2-python.txt
else
source flamegpu2/bin/activate
fi
if [ $CLEAN == "ON" ];
then
bash clean.sh
fi
# Generate the configuration file to give in input to the ABM model
WHOLE_OUTPUT="$(bash generate_configuration.sh -e OFF -expdir $EXPERIMENT_DIR 2>&1)"
# Count the number of words in WHOLE_OUTPUT
WORD_COUNT=$(echo "$WHOLE_OUTPUT" | wc -w)
# Check if exactly two values are present
if [ "$WORD_COUNT" -ne 2 ]; then
echo "Error: Expected 2 values in WHOLE_OUTPUT, but got $WORD_COUNT."
echo "Output: $WHOLE_OUTPUT"
exit 1
fi
SEED="$(echo "$WHOLE_OUTPUT" | cut -d' ' -f1)"
echo $SEED > results/$EXPERIMENT_DIR/seed.txt
# Build the model
bash build.sh -cps $CHECKPOINT_SIMULATION -g $DEBUG -v $VISUALISATION
if [ $ONLY_BUILD == "OFF" ];
then
# Run the model
bash run.sh -expdir $EXPERIMENT_DIR -v $VISUALISATION -e OFF
fi
if [ -f /.dockerenv ]; then
cp -r results flamegpu2_results
chmod -R 777 flamegpu2_results/results
else
if [ "$RESULTS_DIR" != "results" ]; then
cp -r results $RESULTS_DIR
chmod -R 777 $RESULTS_DIR/results
fi
fi
deactivate