1 #include <barvinok/util.h>
4 #ifdef HAVE_GROWING_CHERNIKOVA
5 #define MAXRAYS POL_NO_DUAL
12 #define getopt_long(a,b,c,d,e) getopt(a,b,c)
15 struct option options
[] = {
16 { "continue", no_argument
, 0, 'k' },
17 { "max", no_argument
, 0, 'M' },
18 { "live", no_argument
, 0, 'l' },
19 { "verbose", no_argument
, 0, 'v' },
20 { "version", no_argument
, 0, 'V' },
26 static int print_max
= 0;
27 static int verbose
= 0;
28 static int keep_going
= 0;
32 #define LS_P 2 /* continue searching P */
33 #define LS_D 4 /* continue searching D */
35 static int check_lexsmaller(Polyhedron
*SP
, Polyhedron
*SD
, Enumeration
*en
,
36 int pos
, int nvar
, Value
*zP
, Value
*zD
, Value
*zE
,
41 Value PLB
, PUB
, DLB
, DUB
, LB
, UB
, tmp
, c
;
44 return LS_OK
| LS_P
| LS_D
;
46 value_init(PLB
); value_init(PUB
);
47 value_init(DLB
); value_init(DUB
);
48 value_init(LB
); value_init(UB
);
52 ok
= !(lower_upper_bounds(1+pos
, SP
, zP
, &PLB
, &PUB
));
56 ok
= !(lower_upper_bounds(1+pos
, SD
, zD
, &DLB
, &DUB
));
59 if (!SD
|| (SP
&& value_lt(PLB
, DLB
)))
60 value_assign(LB
, PLB
);
62 value_assign(LB
, DLB
);
63 if (!SD
|| (SP
&& value_gt(PUB
, DUB
)))
64 value_assign(UB
, PUB
);
66 value_assign(UB
, DUB
);
71 ok
= LS_OK
| LS_P
| LS_D
;
73 for(value_assign(tmp
,LB
); value_le(tmp
,UB
); value_increment(tmp
,tmp
)) {
74 int inP
= SP
&& value_ge(tmp
, PLB
) && value_le(tmp
, PUB
);
75 int inD
= SD
&& value_ge(tmp
, DLB
) && value_le(tmp
, DUB
);
80 value_assign(zP
[pos
+1], tmp
);
82 value_assign(zD
[pos
+1], tmp
);
83 if (inD
&& pos
< nvar
)
84 value_assign(zE
[pos
], tmp
);
86 if (inD
&& !SD
->next
) {
89 value_assign(c
,*(ctmp
=compute_poly(en
, zE
)));
95 value_print(stdout
, VALUE_FMT
, zE
[0]);
96 for (i
= 1; i
< nvar
; ++i
) {
98 value_print(stdout
, VALUE_FMT
, zE
[i
]);
101 value_print(stdout
, VALUE_FMT
, c
);
102 printf("; count = ");
103 value_print(stdout
, VALUE_FMT
, *count
);
107 if (value_ne(c
, *count
)) {
110 fprintf(stderr
,"Error !\n");
111 fprintf(stderr
, "EP( ");
112 value_print(stderr
, VALUE_FMT
, zE
[0]);
113 for (i
= 1; i
< nvar
; ++i
) {
114 fprintf(stderr
, ", ");
115 value_print(stderr
, VALUE_FMT
, zE
[i
]);
117 fprintf(stderr
, " ) = ");
118 value_print(stderr
, VALUE_FMT
, c
);
119 fprintf(stderr
, " but count = ");
120 value_print(stderr
, VALUE_FMT
, *count
);
126 value_decrement(*count
, *count
);
132 ok
&= check_lexsmaller(inP
? SP
->next
: NULL
,
133 inD
? SD
->next
: NULL
,
134 en
, pos
+1, nvar
, zP
, zD
, zE
, count
);
136 ok
&= check_lexsmaller(NULL
, inD
? SD
->next
: NULL
,
137 en
, pos
+1, nvar
, zP
, zD
, zE
, count
)
138 & check_lexsmaller(inP
? SP
->next
: NULL
, NULL
,
139 en
, pos
+1, nvar
, zP
, zD
, zE
, count
);
140 if (pos
>= nvar
&& !(ok
& LS_D
))
142 if (pos
>= nvar
&& !(ok
& LS_P
))
146 if (!ok
&& !keep_going
)
149 if (inP
&& !SP
->next
) {
150 value_increment(*count
, *count
);
151 if (value_gt(*count
, max
))
152 value_assign(max
, *count
);
157 value_set_si(zP
[pos
+1], 0);
159 value_set_si(zD
[pos
+1], 0);
165 value_clear(PLB
); value_clear(PUB
);
166 value_clear(DLB
); value_clear(DUB
);
167 value_clear(LB
); value_clear(UB
);
173 int main(int argc
,char *argv
[])
176 Polyhedron
*P
, *D
, *C
;
179 char **param_name
= NULL
;
182 Vector
*zP
, *zD
, *zE
;
188 while ((c
= getopt_long(argc
, argv
, "klMvV", options
, &ind
)) != -1) {
202 printf(barvinok_version());
209 P
= Constraints2Polyhedron(M
, MAXRAYS
);
213 D
= Constraints2Polyhedron(M
, MAXRAYS
);
217 fgets(s
, 128, stdin
);
218 while ((*s
=='#') || (sscanf(s
, "D %u", &dim
)<1))
219 fgets(s
, 128, stdin
);
222 C
= Constraints2Polyhedron(M
, MAXRAYS
);
226 nb_parms
= D
->Dimension
;
227 param_name
= Read_ParamNames(stdin
, nb_parms
);
229 EP
= barvinok_lexsmaller_ev(P
, D
, dim
, C
, MAXRAYS
);
232 evalue
*EC
= barvinok_lexsmaller_ev(D
, D
, dim
, C
, MAXRAYS
);
235 print_evalue(stdout
, EP
, param_name
);
237 print_evalue(stdout
, EC
, param_name
);
240 evalue_set_si(&mone
, -1, 1);
243 free_evalue_refs(&mone
);
244 free_evalue_refs(EC
);
250 print_evalue(stdout
, EP
, param_name
);
252 en
= partition2enumeration(EP
);
254 assert(C
->Dimension
== 0); /* for now */
256 /* S = scanning list of polyhedra */
257 SP
= Polyhedron_Scan(P
, C
, MAXRAYS
);
258 SD
= Polyhedron_Scan(D
, C
, MAXRAYS
);
260 zP
= Vector_Alloc(1+P
->Dimension
+1);
261 value_set_si(zP
->p
[1+P
->Dimension
], 1);
262 zD
= Vector_Alloc(1+D
->Dimension
+1);
263 value_set_si(zD
->p
[1+D
->Dimension
], 1);
264 zE
= Vector_Alloc(dim
+C
->Dimension
);
269 check_lexsmaller(SP
, SD
, en
, 0, dim
, zP
->p
, zD
->p
, zE
->p
, &count
);
274 value_print(stdout
, VALUE_FMT
, max
);
279 Enumeration_Free(en
);
280 Free_ParamNames(param_name
, nb_parms
);