2 #include <barvinok/util.h>
5 #define MAXRAYS POL_NO_DUAL
9 #define getopt_long(a,b,c,d,e) getopt(a,b,c)
12 struct option options
[] = {
13 { "continue", no_argument
, 0, 'k' },
14 { "max", no_argument
, 0, 'M' },
15 { "live", no_argument
, 0, 'l' },
16 { "verbose", no_argument
, 0, 'v' },
17 { "version", no_argument
, 0, 'V' },
23 static int print_max
= 0;
24 static int verbose
= 0;
25 static int keep_going
= 0;
29 #define LS_P 2 /* continue searching P */
30 #define LS_D 4 /* continue searching D */
32 static int check_lexsmaller(Polyhedron
*SP
, Polyhedron
*SD
, Enumeration
*en
,
33 int pos
, int nvar
, Value
*zP
, Value
*zD
, Value
*zE
,
38 Value PLB
, PUB
, DLB
, DUB
, LB
, UB
, tmp
, c
;
41 return LS_OK
| LS_P
| LS_D
;
43 value_init(PLB
); value_init(PUB
);
44 value_init(DLB
); value_init(DUB
);
45 value_init(LB
); value_init(UB
);
49 ok
= !(lower_upper_bounds(1+pos
, SP
, zP
, &PLB
, &PUB
));
53 ok
= !(lower_upper_bounds(1+pos
, SD
, zD
, &DLB
, &DUB
));
56 if (!SD
|| (SP
&& value_lt(PLB
, DLB
)))
57 value_assign(LB
, PLB
);
59 value_assign(LB
, DLB
);
60 if (!SD
|| (SP
&& value_gt(PUB
, DUB
)))
61 value_assign(UB
, PUB
);
63 value_assign(UB
, DUB
);
68 ok
= LS_OK
| LS_P
| LS_D
;
70 for(value_assign(tmp
,LB
); value_le(tmp
,UB
); value_increment(tmp
,tmp
)) {
71 int inP
= SP
&& value_ge(tmp
, PLB
) && value_le(tmp
, PUB
);
72 int inD
= SD
&& value_ge(tmp
, DLB
) && value_le(tmp
, DUB
);
77 value_assign(zP
[pos
+1], tmp
);
79 value_assign(zD
[pos
+1], tmp
);
80 if (inD
&& pos
< nvar
)
81 value_assign(zE
[pos
], tmp
);
83 if (inD
&& !SD
->next
) {
86 value_assign(c
,*(ctmp
=compute_poly(en
, zE
)));
92 value_print(stdout
, VALUE_FMT
, zE
[0]);
93 for (i
= 1; i
< nvar
; ++i
) {
95 value_print(stdout
, VALUE_FMT
, zE
[i
]);
98 value_print(stdout
, VALUE_FMT
, c
);
100 value_print(stdout
, VALUE_FMT
, *count
);
104 if (value_ne(c
, *count
)) {
107 fprintf(stderr
,"Error !\n");
108 fprintf(stderr
, "EP( ");
109 value_print(stderr
, VALUE_FMT
, zE
[0]);
110 for (i
= 1; i
< nvar
; ++i
) {
111 fprintf(stderr
, ", ");
112 value_print(stderr
, VALUE_FMT
, zE
[i
]);
114 fprintf(stderr
, " ) = ");
115 value_print(stderr
, VALUE_FMT
, c
);
116 fprintf(stderr
, " but count = ");
117 value_print(stderr
, VALUE_FMT
, *count
);
123 value_decrement(*count
, *count
);
129 ok
&= check_lexsmaller(inP
? SP
->next
: NULL
,
130 inD
? SD
->next
: NULL
,
131 en
, pos
+1, nvar
, zP
, zD
, zE
, count
);
133 ok
&= check_lexsmaller(NULL
, inD
? SD
->next
: NULL
,
134 en
, pos
+1, nvar
, zP
, zD
, zE
, count
)
135 & check_lexsmaller(inP
? SP
->next
: NULL
, NULL
,
136 en
, pos
+1, nvar
, zP
, zD
, zE
, count
);
137 if (pos
>= nvar
&& !(ok
& LS_D
))
139 if (pos
>= nvar
&& !(ok
& LS_P
))
143 if (!ok
&& !keep_going
)
146 if (inP
&& !SP
->next
) {
147 value_increment(*count
, *count
);
148 if (value_gt(*count
, max
))
149 value_assign(max
, *count
);
154 value_set_si(zP
[pos
+1], 0);
156 value_set_si(zD
[pos
+1], 0);
162 value_clear(PLB
); value_clear(PUB
);
163 value_clear(DLB
); value_clear(DUB
);
164 value_clear(LB
); value_clear(UB
);
170 int main(int argc
,char *argv
[])
173 Polyhedron
*P
, *D
, *C
;
176 char **param_name
= NULL
;
179 Vector
*zP
, *zD
, *zE
;
185 while ((c
= getopt_long(argc
, argv
, "klMvV", options
, &ind
)) != -1) {
199 printf(barvinok_version());
206 P
= Constraints2Polyhedron(M
, MAXRAYS
);
210 D
= Constraints2Polyhedron(M
, MAXRAYS
);
214 fgets(s
, 128, stdin
);
215 while ((*s
=='#') || (sscanf(s
, "D %u", &dim
)<1))
216 fgets(s
, 128, stdin
);
219 C
= Constraints2Polyhedron(M
, MAXRAYS
);
223 nb_parms
= D
->Dimension
;
224 param_name
= Read_ParamNames(stdin
, nb_parms
);
226 EP
= barvinok_lexsmaller_ev(P
, D
, dim
, C
, MAXRAYS
);
229 evalue
*EC
= barvinok_lexsmaller_ev(D
, D
, dim
, C
, MAXRAYS
);
232 print_evalue(stdout
, EP
, (const char **)param_name
);
234 print_evalue(stdout
, EC
, (const char **)param_name
);
237 evalue_set_si(&mone
, -1, 1);
240 free_evalue_refs(&mone
);
246 print_evalue(stdout
, EP
, (const char **)param_name
);
248 en
= partition2enumeration(EP
);
250 assert(C
->Dimension
== 0); /* for now */
252 /* S = scanning list of polyhedra */
253 SP
= Polyhedron_Scan(P
, C
, MAXRAYS
);
254 SD
= Polyhedron_Scan(D
, C
, MAXRAYS
);
256 zP
= Vector_Alloc(1+P
->Dimension
+1);
257 value_set_si(zP
->p
[1+P
->Dimension
], 1);
258 zD
= Vector_Alloc(1+D
->Dimension
+1);
259 value_set_si(zD
->p
[1+D
->Dimension
], 1);
260 zE
= Vector_Alloc(dim
+C
->Dimension
);
265 check_lexsmaller(SP
, SD
, en
, 0, dim
, zP
->p
, zD
->p
, zE
->p
, &count
);
270 value_print(stdout
, VALUE_FMT
, max
);
275 Enumeration_Free(en
);
276 Free_ParamNames(param_name
, nb_parms
);