-
Notifications
You must be signed in to change notification settings - Fork 0
/
complement_design.c
85 lines (71 loc) · 2.02 KB
/
complement_design.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
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "covering_array.h"
Design *finite_field_based_design(int);
Design *complement_design(int number, int *ranges)
{
// values[] must be an descending ordered array of values of length number
int i, j;
int v1, v2;
Design *new_design;
Design *base;
int *tuple;
int l, r, q;
if (number < 2)
exit(1);
new_design = (Design *)malloc(sizeof(Design));
new_design->no_pars = number;
new_design->size = 0;
new_design->range = (int *)calloc(number, sizeof(int));
memcpy(new_design->range, ranges, number*sizeof(int));
tuple = (int *)calloc(number, sizeof(int));
r = greatest_prime_power(*(ranges+1));
// Case 1
if (number <= r+1)
{
base = finite_field_based_design(r);
truncate_design(base, new_design->no_pars);
new_design->size = base->size;
new_design->value = base->value;
free(base->range); free(base);
// determine l
for(l = 1; l < number; l++) {
if (l + 1 == number)
break;
if (r > *(ranges + l + 1))
break;
}
for (v1 = r ; v1 < *(ranges + l); v1++) {
for(v2 = 0; v2 < r; v2++) {
for(j = 0; j < number; j++)
*(tuple + j) = v2;
*(tuple + l) = v1;
add_tuple(new_design, tuple);
}
}
//
for (i = l-1; i >= 0; i--) { // l-1, l-2, ..., 0
for (v1 = r ; v1 < *(ranges + i); v1++) {
for(v2 = 0; v2 < *(ranges + i + 1); v2++) {
for(j = 0; j < number; j++)
*(tuple + j) = v2;
*(tuple + i) = v1;
add_tuple(new_design, tuple);
}
}
}
}
else // Case 2
{
q = smallest_prime_power(*ranges);
base = finite_field_based_design(q);
truncate_design(base, new_design->no_pars);
new_design->size = base->size;
new_design->value = base->value;
free(base->range); free(base);
}
set_dontcare_value(new_design);
free(tuple);
return new_design;
}