-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.c
66 lines (62 loc) · 1.51 KB
/
main.c
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
/*H*
*
* FILENAME: main.c
* DESCRIPTION: Boolean satisfiability problem in CNF
* AUTHORS: José Antonio Riaza Valverde
* UPDATED: 25.11.2018
* COMPILING: gcc -I/usr/include -L/usr/lib main.c io.h io.c structures.c structures.h cdcl.h cdcl.c 2sat.h 2sat.c sat.h sat.c -o sat
*
*H*/
#include <stdio.h>
#include <string.h>
#include "io.h"
#include "structures.h"
#include "sat.h"
int main(int argc, char **argv) {
FILE *stream;
double time_spent;
int i, sat, op_stats = 0, op_algorithm = AUTO;
Formula *F;
// Check minimum number of arguments
if(argc < 2) {
printf("Error: input file was not specified.\n");
return 1;
}
// Check options
for(i = 1; i < argc-1; i++) {
if(strcmp(argv[i], "-st") == 0)
op_stats = 1;
else if(strcmp(argv[i], "-cdcl") == 0)
op_algorithm = CDCL;
else if(strcmp(argv[i], "-apsvall") == 0)
op_algorithm = APSVALL;
}
// Read formula
stream = fopen(argv[argc-1], "r");
// File is ok
if(stream != NULL) {
F = formula_fread_dimacs(stream);
fclose(stream);
// Formula is ok
if(F != NULL) {
// Check satisfiability
sat = formula_check_sat(F, op_algorithm);
// Show SAT result
printf(sat ? "sat\n" : "unsat\n");
if(sat)
formula_printf_interpretation(F);
// Show statistics
if(op_stats)
formula_printf_statistics(F);
// Free formula
formula_free(F);
// Error reading formula
} else {
printf("Error: file must be in DIMACS format.\n");
}
// Error opening file
} else {
printf("Error: failed to open file.\n");
}
return 0;
}