94b2b13d
Pedro Roque
PHACT source
|
1
2
3
4
|
/*
* all_diff.c
*
* Created on: 15/10/2015
|
4d26a735
Pedro Roque
Increased recogni...
|
5
|
* Author: pedro
|
94b2b13d
Pedro Roque
PHACT source
|
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
*
* All_diff constraint:
* Solve a CSP with 1 all_different constraint with N variables with N values each.
*/
#include "all_diff.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "../config.h"
#include "../constraints/all_different.h"
#include "../split.h"
#include "../variables.h"
|
4d26a735
Pedro Roque
Increased recogni...
|
25
|
void run_all_diff(int* csp_dims) {
|
94b2b13d
Pedro Roque
PHACT source
|
26
27
28
29
30
|
int n = csp_dims[0];
unsigned long result;
int i;
// vector with the IDs of the variables constrained by the all_diff constraint
|
4d26a735
Pedro Roque
Increased recogni...
|
31
|
unsigned int* c_vs = malloc((unsigned long)n * sizeof(unsigned int));
|
94b2b13d
Pedro Roque
PHACT source
|
32
33
34
|
for {
|
4d26a735
Pedro Roque
Increased recogni...
|
35
|
c_vs[i] = v_new_range(0, (unsigned int)n - 1, true);
|
94b2b13d
Pedro Roque
PHACT source
|
36
37
38
|
}
|
4d26a735
Pedro Roque
Increased recogni...
|
39
|
c_all_different(c_vs, (unsigned int)n);
|
94b2b13d
Pedro Roque
PHACT source
|
40
41
42
43
44
45
46
47
48
49
50
51
|
if (FINDING_ONE_SOLUTION) {
printf("\nFinding one solution for the all-different constraint with %u variables.\n", n);
} else {
printf("\nCounting all the solutions for the all-different constraint with %u variables.\n", n);
}
// Solve the CSP
result = solve_CSP();
if (FINDING_ONE_SOLUTION && result == 1) {
printf("Solution:\n");
|
4d26a735
Pedro Roque
Increased recogni...
|
52
|
vs_print_single_val(c_vs, (unsigned int)n, 1);
|
94b2b13d
Pedro Roque
PHACT source
|
53
54
55
56
57
58
59
|
printf("\n");
} else {
printf("%lu solution(s) found\n", result);
}
free(c_vs);
}
|