-
Notifications
You must be signed in to change notification settings - Fork 0
/
ksat.c
74 lines (53 loc) · 2.58 KB
/
ksat.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
67
68
69
70
71
72
/** ******************************************************* **/
/** ** SatisfyMe! ** **/
/** **/
/** 05/05/2012 **/
/** **/
/** Written by: Pedro Brandimarte ([email protected]) **/
/** **/
/** ******************************************************* **/
/** **/
/** For implementation details refer to the documentation **/
/** docs folder. **/
/** **/
/** ******************************************************* **/
#include <stdio.h>
#include <stdlib.h>
#include "CP.h"
int main (int argc, char *argv[])
{
int opt, k, n, m, cont = 0;
column root; /* root from column list */
column *clmn = NULL; /* pointer to the column being covered */
node **partial = NULL; /* array of pointers to store the partial solutions */
line *row; /* array of pointers to the rows */
solution sol; /* store the solutions */
/* Initialization. */
sol.next = NULL;
/* Get command line options. */
getOptions (argc, argv, &opt);
if (opt == 3) { /* exact cover problem */
/* Read fist line 'n m', where 'n' = # columns and 'm' = # rows. */
scanf ("%d%d", &n, &m);
row = checkMalloc (m * sizeof (*row)); /* row array */
readECP (&root, row, n, m); /* read and create structure from stdin */
partial = checkMalloc (m * sizeof (*partial)); /* partial solutions array */
searchECP (0, &root, clmn, partial, row, &cont, &sol); /* search and store solutions */
writeSol (cont, sol, opt); /* print solutions if any */
}
else { /* k-sat problem */
/* Read fist line 'k n m', where 'k' = # literals, 'n' = # variables */
/* (primary columns) and 'm' = # clauses (secondary columns). */
scanf ("%d%d%d", &k, &n, &m);
row = checkMalloc (2 * n * sizeof (*row)); /* row array */
readGCP (&root, row, k, n, m); /* read and create structure from stdin */
partial = checkMalloc (n * sizeof (*partial)); /* partial solutions array */
searchGCP (0, k, &root, clmn, partial, row, &cont, &sol); /* search and store solutions */
writeSol (cont, sol, opt); /* print solutions if any */
}
/* Free memory. */
free (partial);
free (row);
freeSol (&sol);
return (0);
} /* main */