-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
59 lines (52 loc) · 1.24 KB
/
main.cpp
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
#include <cstdio>
#include <cstring>
#include "solver.hpp"
static const char kHelpStr[]{
"AdamYuan's 3-SAT solver\n"\
"\t-in [CNF FILE NAME]\n"
"\t-max_tries [MAX TRIES]\n"\
"\t-max_temp [MAX TEMPERATURE]\n"\
"\t-min_temp [MIN TEMPERATURE]\n"\
"\t-seed [RANDOM SEED]\n"\
"\t-mthread\n"};
#define PRINT_HELP_AND_EXIT { printf("%s\n", kHelpStr); return 1; }
CnfFile file;
SatSolver solver;
int main(int argc, char **argv)
{
argc--; argv++;
char filename[512] = {};
if(argc == 0)
PRINT_HELP_AND_EXIT;
for(int i = 0; i < argc; )
{
char *(&cmd){argv[i]};
if(strcmp("-mthread", cmd) == 0)
{
solver.multi_thread = true;
++ i;
}
else if(i < argc - 1)
{
char *(&arg){argv[i + 1]};
if(strcmp("-in", cmd) == 0)
strcpy(filename, arg);
else if(strcmp("-max_tries", cmd) == 0)
sscanf(arg, "%d", &solver.max_tries);
else if(strcmp("-max_temp", cmd) == 0)
sscanf(arg, "%f", &solver.max_temperature);
else if(strcmp("-min_temp", cmd) == 0)
sscanf(arg, "%f", &solver.min_temperature);
else if(strcmp("-seed", cmd) == 0)
sscanf(arg, "%lu", &solver.seed);
else
PRINT_HELP_AND_EXIT;
i += 2;
}
else
PRINT_HELP_AND_EXIT;
}
file.Parse(filename);
solver.OutputArgs();
solver.Run(file);
}