965dadaa
Salvador Abreu
initial commit fr...
|
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
|
static int N1 = 11, N2 = 11; // actual number of queens
void init_queens(fd_int *queens, int N)
{
#define queens (queens + BASE)
static int BASE = 0;
int i, j;
/*
FORWARD_CHECKING REBENTA(VA) (N == 6)
queens[0] = fd_new(2, 5);
_fd_val_del_val(5, queens[0]->domain);
queens[N - 1] = fd_new(6, 6);
*/
//queens[0] = fd_new(2, 2);
//queens[1] = fd_new(5, 5);
//queens[2] = fd_new(3, 3);
// N == 20
//queens[0] = fd_new(3, 3);
//queens[1] = fd_new(12, 12);
//queens[2] = fd_new(9, 9);
//queens[3] = fd_new(17, 17);
//queens[4] = fd_new(14, 14);
//queens[5] = fd_new(5, 5);
//queens[6] = fd_new(15, 15);
for (i = 0; i < N; ++i)
#if 0
if (i == 0)
queens[i] = fd_new(1, 1);
else if (i == 99)
queens[i] = fd_new(2, 2);
else
#endif
queens[i] = fd_new(1, N);
//queens[N - 1] = fd_new(6, 6);
#if 01
fd_fake_all_different(queens, N);
#elif 01
fd_all_different(queens, N);
#else
for (i = 0; i < N; ++i)
fd_exactly_one(queens, N, i + 1);
#endif
for (i = 0; i < N; ++i)
for (j = i + 1; j < N; ++j)
fd_minus_ne(queens[i], queens[j], i - j);
for (i = 0; i < N; ++i)
for (j = i + 1; j < N; ++j)
fd_minus_ne(queens[i], queens[j], j - i);
BASE += N;
#undef queens
}
int main(int argc, char *argv[])
{
fd_int queens[2 * NMAX];
int solutions = 0, one_solution = 1;
int i, j;
int seed;
int dev_random;
|
965dadaa
Salvador Abreu
initial commit fr...
|
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
fd_init(&argc, &argv);
for (i = 1; i < argc; ++i)
if (!strcmp(argv[i], "--all"))
one_solution = 0;
else
{
N1 = atoi(argv[i]);
if (i + 1 < argc)
N2 = atoi(argv[++i]);
}
#ifdef LOCAL_SEARCH
|
965dadaa
Salvador Abreu
initial commit fr...
|
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
init_queens(queens, N2);
while (fd_solve() == FD_OK)
{
printf("solution %d:\n", ++solutions);
printf("problem 1\n");
#if 01
for (i = 0; i < N1; ++i)
if (!fd_var_single(queens[i], NULL))
_fd_fatal("solution contains non-singleton variable");
#endif
|
965dadaa
Salvador Abreu
initial commit fr...
|
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
{
fd_print(queens[i]);
putchar(' ');
}
putchar('\n');
#if !(defined(LOCAL_SEARCH) || defined(DISTRIBUTED_SOLVER))
if (one_solution)
#endif
break;
}
if (solutions)
printf("%d solutions found\n", solutions);
else
printf("inconsistent CSP\n");
fd_end();
return !solutions;
}
|