-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_batch.sh
More file actions
executable file
·97 lines (76 loc) · 2.67 KB
/
run_batch.sh
File metadata and controls
executable file
·97 lines (76 loc) · 2.67 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
#!/bin/bash
# Default paths if not provided
INPUT_DIR="${1:-data/input}"
OUTPUT_DIR="${2:-data/output}"
# Check if input directory exists
if [ ! -d "$INPUT_DIR" ]; then
echo "Error: Input directory '$INPUT_DIR' does not exist."
echo "Usage: $0 [input_directory] [output_directory]"
echo "Example: $0 data/input data/output"
exit 1
fi
# Load environment configuration and dependencies.
echo "Setting up environment..."
source ./setup.sh
if [ $? -ne 0 ]; then
echo "Error: Failed to set up environment."
exit 1
fi
# Ensure the output directory exists before processing.
echo "Creating output directory: $OUTPUT_DIR"
mkdir -p "$OUTPUT_DIR"
# Count total files
total_files=$(ls -1 "$INPUT_DIR"/*.txt 2>/dev/null | wc -l)
if [ "$total_files" -eq 0 ]; then
echo "Error: No .txt files found in $INPUT_DIR"
deactivate 2>/dev/null
exit 1
fi
echo "Found $total_files input file(s) in $INPUT_DIR"
echo "Results will be saved to $OUTPUT_DIR"
echo "----------------------------------------"
file_count=0
# Iterate over input files in natural sort order (handles numerical suffixes correctly).
# Example: file2.txt comes before file10.txt.
for input_file in $(ls "$INPUT_DIR"/*.txt 2>/dev/null | sort -V); do
file_count=$((file_count + 1))
filename=$(basename "$input_file")
echo ""
echo "[$file_count/$total_files] Processing: $filename"
# Run BASIC mode processing on the current file.
echo " → Running BASIC algorithm..."
python3 src/main.py basic "$input_file" "$OUTPUT_DIR/basic_$filename"
if [ $? -ne 0 ]; then
echo " ✗ BASIC algorithm failed for $filename"
else
echo " ✓ BASIC algorithm completed"
fi
# Run EFFICIENT mode processing on the current file.
echo " → Running EFFICIENT algorithm..."
python3 src/main.py efficient "$input_file" "$OUTPUT_DIR/efficient_$filename"
if [ $? -ne 0 ]; then
echo " ✗ EFFICIENT algorithm failed for $filename"
else
echo " ✓ EFFICIENT algorithm completed"
fi
done
echo ""
echo "----------------------------------------"
echo "All files processed successfully!"
# Once all files have been processed, generate a consolidated plot.
if [ -f "src/plot_results.py" ]; then
echo "Generating performance comparison plots..."
python3 src/plot_results.py
if [ $? -eq 0 ]; then
echo "✓ Plots generated successfully"
else
echo "✗ Plot generation failed"
fi
else
echo "Note: plot_results.py not found. Skipping plot generation."
fi
# Deactivate virtual environment to restore clean shell state.
if [[ "$VIRTUAL_ENV" != "" ]]; then
deactivate
fi
echo "✓ Batch processing complete!"