summaryrefslogtreecommitdiff
path: root/start
blob: d3b71e11a484f342bf6dff90aa55b23866d54a0f (plain)
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
#!/bin/bash

#  SETUP

TIME_LIMIT=300  # In seconds, per query
NUM_PROBLEMS=1350  # First n problems from models path (e.g. MCC2022/)

STRATEGIES=(
    "RDFS --seed-offset 5760351"
    "BestFS"
    "DFS"
    "BFS"
)

# DO NOT CHANGE THIS BELOW THIS POINT

PIPELINE_PATH=$(dirname "$0")

main() {
    if [ $# -eq 0 ]; then
        help; exit 1
    fi

    case "$1" in
        -h|--help)
            help
            exit
            ;;
        *) 
            BINARY="$1"
            MODELS_PATH="$2" 
            OUTPUT_PATH="$3"
            ;;
    esac

    if [[ ! -d "$MODELS_PATH" ]]; then
        echo "error: invalid models path"
        exit 1
    fi

    OUTPUT_PATH="$OUTPUT_PATH/$(date -u +"%d-%m-%YT%H.%M.%S")"
    mkdir -p "$OUTPUT_PATH/pipeline"
    cp -r "$PIPELINE_PATH" "$OUTPUT_PATH"
    start_jobs
}

start_jobs() {
    STRAT_LEN=${#STRATEGIES[@]}
    serialize_array STRATEGIES STRAT_STR "|"

    TOTAL_TIME_LIMIT=$(echo "($TIME_LIMIT * $STRAT_LEN * 16) / 60 + 1" | bc)

    for MODEL in $(ls "$MODELS_PATH" | head -n "$NUM_PROBLEMS"); do
	sbatch --time "$TOTAL_TIME_LIMIT" "$PIPELINE_PATH/run-model" "$BINARY" "$TIME_LIMIT" "$STRAT_STR" "$MODELS_PATH/$MODEL" "$OUTPUT_PATH/$MODEL.csv"
	# timeout "${TOTAL_TIME_LIMIT}m" "$PIPELINE_PATH/run-model" "$BINARY" "$TIME_LIMIT" "$STRAT_STR" "$MODELS_PATH/$MODEL" "$OUTPUT_PATH/$MODEL.csv"
    done
}

serialize_array() {
    declare -n _array="${1}" _str="${2}" # _array, _str => local reference vars
    local IFS="${3:-$'\x01'}"
    # shellcheck disable=SC2034 # Reference vars assumed used by caller
    _str="${_array[*]}" # * => join on IFS
}

help() {
cat << EOF
Usage: $0 BINARY MODELS-PATH OUTPUT-PATH 

Run TAPAAL heuristic search experiment.

Number of models to run, time limit and search strategies can be 
configured in the top of this script.

EOF
}

main "$@"