1 #include <polylib/polylibgmp.h>
2 #include <barvinok/util.h>
5 #ifdef HAVE_GROWING_CHERNIKOVA
6 #define MAXRAYS POL_NO_DUAL
13 #define getopt_long(a,b,c,d,e) getopt(a,b,c)
16 struct option options
[] = {
17 { "continue", no_argument
, 0, 'k' },
18 { "max", no_argument
, 0, 'M' },
19 { "live", no_argument
, 0, 'l' },
20 { "verbose", no_argument
, 0, 'v' },
21 { "version", no_argument
, 0, 'V' },
27 static int print_max
= 0;
28 static int verbose
= 0;
29 static int keep_going
= 0;
33 #define LS_P 2 /* continue searching P */
34 #define LS_D 4 /* continue searching D */
36 static int check_lexsmaller(Polyhedron
*SP
, Polyhedron
*SD
, Enumeration
*en
,
37 int pos
, int nvar
, Value
*zP
, Value
*zD
, Value
*zE
,
42 Value PLB
, PUB
, DLB
, DUB
, LB
, UB
, tmp
, c
;
45 return LS_OK
| LS_P
| LS_D
;
47 value_init(PLB
); value_init(PUB
);
48 value_init(DLB
); value_init(DUB
);
49 value_init(LB
); value_init(UB
);
53 ok
= !(lower_upper_bounds(1+pos
, SP
, zP
, &PLB
, &PUB
));
57 ok
= !(lower_upper_bounds(1+pos
, SD
, zD
, &DLB
, &DUB
));
60 if (!SD
|| (SP
&& value_lt(PLB
, DLB
)))
61 value_assign(LB
, PLB
);
63 value_assign(LB
, DLB
);
64 if (!SD
|| (SP
&& value_gt(PUB
, DUB
)))
65 value_assign(UB
, PUB
);
67 value_assign(UB
, DUB
);
72 ok
= LS_OK
| LS_P
| LS_D
;
74 for(value_assign(tmp
,LB
); value_le(tmp
,UB
); value_increment(tmp
,tmp
)) {
75 int inP
= SP
&& value_ge(tmp
, PLB
) && value_le(tmp
, PUB
);
76 int inD
= SD
&& value_ge(tmp
, DLB
) && value_le(tmp
, DUB
);
81 value_assign(zP
[pos
+1], tmp
);
83 value_assign(zD
[pos
+1], tmp
);
84 if (inD
&& pos
< nvar
)
85 value_assign(zE
[pos
], tmp
);
87 if (inD
&& !SD
->next
) {
90 value_assign(c
,*(ctmp
=compute_poly(en
, zE
)));
96 value_print(stdout
, VALUE_FMT
, zE
[0]);
97 for (i
= 1; i
< nvar
; ++i
) {
99 value_print(stdout
, VALUE_FMT
, zE
[i
]);
102 value_print(stdout
, VALUE_FMT
, c
);
103 printf("; count = ");
104 value_print(stdout
, VALUE_FMT
, *count
);
108 if (value_ne(c
, *count
)) {
111 fprintf(stderr
,"Error !\n");
112 fprintf(stderr
, "EP( ");
113 value_print(stderr
, VALUE_FMT
, zE
[0]);
114 for (i
= 1; i
< nvar
; ++i
) {
115 fprintf(stderr
, ", ");
116 value_print(stderr
, VALUE_FMT
, zE
[i
]);
118 fprintf(stderr
, " ) = ");
119 value_print(stderr
, VALUE_FMT
, c
);
120 fprintf(stderr
, " but count = ");
121 value_print(stderr
, VALUE_FMT
, *count
);
127 value_decrement(*count
, *count
);
133 ok
&= check_lexsmaller(inP
? SP
->next
: NULL
,
134 inD
? SD
->next
: NULL
,
135 en
, pos
+1, nvar
, zP
, zD
, zE
, count
);
137 ok
&= check_lexsmaller(NULL
, inD
? SD
->next
: NULL
,
138 en
, pos
+1, nvar
, zP
, zD
, zE
, count
)
139 & check_lexsmaller(inP
? SP
->next
: NULL
, NULL
,
140 en
, pos
+1, nvar
, zP
, zD
, zE
, count
);
141 if (pos
>= nvar
&& !(ok
& LS_D
))
143 if (pos
>= nvar
&& !(ok
& LS_P
))
147 if (!ok
&& !keep_going
)
150 if (inP
&& !SP
->next
) {
151 value_increment(*count
, *count
);
152 if (value_gt(*count
, max
))
153 value_assign(max
, *count
);
158 value_set_si(zP
[pos
+1], 0);
160 value_set_si(zD
[pos
+1], 0);
166 value_clear(PLB
); value_clear(PUB
);
167 value_clear(DLB
); value_clear(DUB
);
168 value_clear(LB
); value_clear(UB
);
174 int main(int argc
,char *argv
[])
177 Polyhedron
*P
, *D
, *C
;
180 char **param_name
= NULL
;
183 Vector
*zP
, *zD
, *zE
;
189 while ((c
= getopt_long(argc
, argv
, "klMvV", options
, &ind
)) != -1) {
203 printf(barvinok_version());
210 P
= Constraints2Polyhedron(M
, MAXRAYS
);
214 D
= Constraints2Polyhedron(M
, MAXRAYS
);
218 fgets(s
, 128, stdin
);
219 while ((*s
=='#') || (sscanf(s
, "D %u", &dim
)<1))
220 fgets(s
, 128, stdin
);
223 C
= Constraints2Polyhedron(M
, MAXRAYS
);
227 nb_parms
= D
->Dimension
;
228 param_name
= Read_ParamNames(stdin
, nb_parms
);
230 EP
= barvinok_lexsmaller_ev(P
, D
, dim
, C
, MAXRAYS
);
233 evalue
*EC
= barvinok_lexsmaller_ev(D
, D
, dim
, C
, MAXRAYS
);
236 print_evalue(stdout
, EP
, param_name
);
238 print_evalue(stdout
, EC
, param_name
);
241 evalue_set_si(&mone
, -1, 1);
244 free_evalue_refs(&mone
);
245 free_evalue_refs(EC
);
251 print_evalue(stdout
, EP
, param_name
);
253 en
= partition2enumeration(EP
);
255 assert(C
->Dimension
== 0); /* for now */
257 /* S = scanning list of polyhedra */
258 SP
= Polyhedron_Scan(P
, C
, MAXRAYS
);
259 SD
= Polyhedron_Scan(D
, C
, MAXRAYS
);
261 zP
= Vector_Alloc(1+P
->Dimension
+1);
262 value_set_si(zP
->p
[1+P
->Dimension
], 1);
263 zD
= Vector_Alloc(1+D
->Dimension
+1);
264 value_set_si(zD
->p
[1+D
->Dimension
], 1);
265 zE
= Vector_Alloc(dim
+C
->Dimension
);
270 check_lexsmaller(SP
, SD
, en
, 0, dim
, zP
->p
, zD
->p
, zE
->p
, &count
);
275 value_print(stdout
, VALUE_FMT
, max
);
280 Enumeration_Free(en
);
281 Free_ParamNames(param_name
, nb_parms
);