-
Notifications
You must be signed in to change notification settings - Fork 7
/
sat.sh
executable file
·110 lines (93 loc) · 2.59 KB
/
sat.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
#! /bin/bash
pushd `dirname $0` > /dev/null
SCRIPTPATH=`pwd`
popd > /dev/null
# make variables
BIN_DIR=$(cd "$SCRIPTPATH/bin"; pwd)
BIN_NAME="sat"
BIN_FILE="$BIN_DIR/$BIN_NAME"
TIME_FORMAT="%e"
function usage {
echo ""
echo "Usage: `basename $0` [compile | profile PROBLEM_FILE [OUT_FILE] | run PROBLEM_FILE [OUT_FILE]]"
echo ""
echo "Targets:"
echo " compile: compiles the SAT solver project, producing an executable file at $BIN_DIR, and exits"
echo " profile: runs the compiled SAT solver with the given input and output files. If no executable"
echo " is found, the project is compiled as if the 'compile' target was called. The execution"
echo " is timed by the 'time' command."
echo " run: runs the compiled SAT solver with the given input and output files. If no executable"
echo " is found, the project is compiled as if the 'compile' target was called."
echo ""
echo "Run options:"
echo " PROBLEM_FILE: the file with the SAT problem to be solved"
echo " OUT_FILE: the file where the output solution will be printed"
echo ""
exit
}
function compile {
pushd $SCRIPTPATH > /dev/null
echo "compiling SAT..."
make BIN_DIR=$BIN_DIR BIN_NAME=$BIN_NAME
echo ""
popd > /dev/null
}
function run_sat {
# check if enough arguments are passed in
if [ "$#" -lt 2 ]; then
echo "ERROR: not enough parameters"
usage
fi
# check if the input problem file exists
if [ ! -f $2 ]; then
echo "ERROR: file '$2' not found or not a regular file"
usage
fi
# check if the executable file exists
if [ ! -x $BIN_FILE ]; then
compile
fi
echo "running SAT with the problem definition at '$2'..."
if [ "$#" -eq 3 ]; then
$BIN_FILE < $2 > $3
else
$BIN_FILE < $2
fi
}
function profile_sat {
# check if enough arguments are passed in
if [ "$#" -lt 2 ]; then
echo "ERROR: not enough parameters"
usage
fi
# check if the input problem file exists
if [ ! -f $2 ]; then
echo "ERROR: file '$2' not found or not a regular file"
usage
fi
# check if the executable file exists
if [ ! -x $BIN_FILE ]; then
compile
fi
echo "running SAT with the problem definition at '$2'..."
if [ "$#" -eq 3 ]; then
(/usr/bin/time -f $TIME_FORMAT $BIN_FILE < $2) &> $3
else
(/usr/bin/time -f $TIME_FORMAT $BIN_FILE) < $2
fi
}
# make sure that executables will work in the current directory, without
# having to prepend './'
export PATH=$PATH:.
# MAIN SCRIPT PROCEDURE:
if [ "$1" = "compile" ]; then
compile
exit
elif [ "$1" = "profile" ]; then
profile_sat $@
elif [ "$1" = "run" ]; then
run_sat $@
else
echo "ERROR: invalid target execution"
usage
fi