2 #include <barvinok/options.h>
3 #include <barvinok/util.h>
10 struct barvinok_options
*barvinok
;
13 ISL_ARGS_START(struct arguments
, arguments_args
)
14 ISL_ARG_CHILD(struct arguments
, barvinok
, NULL
, &barvinok_options_args
, NULL
)
15 ISL_ARG_BOOL(struct arguments
, live
, 'l', "live", 0, NULL
)
16 ISL_ARG_BOOL(struct arguments
, print_max
, 'M', "max", 0, NULL
)
17 ISL_ARG_BOOL(struct arguments
, keep_going
, 'k', "continue", 0, NULL
)
20 ISL_ARG_DEF(arguments
, struct arguments
, arguments_args
)
23 #define LS_P 2 /* continue searching P */
24 #define LS_D 4 /* continue searching D */
26 static int check_lexsmaller(Polyhedron
*SP
, Polyhedron
*SD
, Enumeration
*en
,
27 int pos
, int nvar
, Value
*zP
, Value
*zD
, Value
*zE
,
28 Value
*count
, struct arguments
*options
)
32 Value PLB
, PUB
, DLB
, DUB
, LB
, UB
, tmp
, c
;
35 return LS_OK
| LS_P
| LS_D
;
37 value_init(PLB
); value_init(PUB
);
38 value_init(DLB
); value_init(DUB
);
39 value_init(LB
); value_init(UB
);
43 ok
= !(lower_upper_bounds(1+pos
, SP
, zP
, &PLB
, &PUB
));
47 ok
= !(lower_upper_bounds(1+pos
, SD
, zD
, &DLB
, &DUB
));
50 if (!SD
|| (SP
&& value_lt(PLB
, DLB
)))
51 value_assign(LB
, PLB
);
53 value_assign(LB
, DLB
);
54 if (!SD
|| (SP
&& value_gt(PUB
, DUB
)))
55 value_assign(UB
, PUB
);
57 value_assign(UB
, DUB
);
62 ok
= LS_OK
| LS_P
| LS_D
;
64 for(value_assign(tmp
,LB
); value_le(tmp
,UB
); value_increment(tmp
,tmp
)) {
65 int inP
= SP
&& value_ge(tmp
, PLB
) && value_le(tmp
, PUB
);
66 int inD
= SD
&& value_ge(tmp
, DLB
) && value_le(tmp
, DUB
);
71 value_assign(zP
[pos
+1], tmp
);
73 value_assign(zD
[pos
+1], tmp
);
74 if (inD
&& pos
< nvar
)
75 value_assign(zE
[pos
], tmp
);
77 if (inD
&& !SD
->next
) {
80 value_assign(c
,*(ctmp
=compute_poly(en
, zE
)));
84 if (options
->barvinok
->verbose
>= 2) {
86 value_print(stdout
, VALUE_FMT
, zE
[0]);
87 for (i
= 1; i
< nvar
; ++i
) {
89 value_print(stdout
, VALUE_FMT
, zE
[i
]);
92 value_print(stdout
, VALUE_FMT
, c
);
94 value_print(stdout
, VALUE_FMT
, *count
);
98 if (value_ne(c
, *count
)) {
101 fprintf(stderr
,"Error !\n");
102 fprintf(stderr
, "EP( ");
103 value_print(stderr
, VALUE_FMT
, zE
[0]);
104 for (i
= 1; i
< nvar
; ++i
) {
105 fprintf(stderr
, ", ");
106 value_print(stderr
, VALUE_FMT
, zE
[i
]);
108 fprintf(stderr
, " ) = ");
109 value_print(stderr
, VALUE_FMT
, c
);
110 fprintf(stderr
, " but count = ");
111 value_print(stderr
, VALUE_FMT
, *count
);
117 value_decrement(*count
, *count
);
123 ok
&= check_lexsmaller(inP
? SP
->next
: NULL
,
124 inD
? SD
->next
: NULL
,
125 en
, pos
+1, nvar
, zP
, zD
, zE
, count
,
128 ok
&= check_lexsmaller(NULL
, inD
? SD
->next
: NULL
,
129 en
, pos
+1, nvar
, zP
, zD
, zE
, count
,
131 & check_lexsmaller(inP
? SP
->next
: NULL
, NULL
,
132 en
, pos
+1, nvar
, zP
, zD
, zE
, count
,
134 if (pos
>= nvar
&& !(ok
& LS_D
))
136 if (pos
>= nvar
&& !(ok
& LS_P
))
140 if (!ok
&& !options
->keep_going
)
143 if (inP
&& !SP
->next
) {
144 value_increment(*count
, *count
);
145 if (value_gt(*count
, options
->max
))
146 value_assign(options
->max
, *count
);
151 value_set_si(zP
[pos
+1], 0);
153 value_set_si(zD
[pos
+1], 0);
159 value_clear(PLB
); value_clear(PUB
);
160 value_clear(DLB
); value_clear(DUB
);
161 value_clear(LB
); value_clear(UB
);
167 int main(int argc
,char *argv
[])
170 Polyhedron
*P
, *D
, *C
;
173 const char **param_name
= NULL
;
176 Vector
*zP
, *zD
, *zE
;
180 struct arguments
*options
= arguments_new_with_defaults();
182 argc
= arguments_parse(options
, argc
, argv
, ISL_ARG_ALL
);
185 P
= Constraints2Polyhedron(M
, options
->barvinok
->MaxRays
);
189 D
= Constraints2Polyhedron(M
, options
->barvinok
->MaxRays
);
193 fgets(s
, 128, stdin
);
194 while ((*s
=='#') || (sscanf(s
, "D %u", &dim
)<1))
195 fgets(s
, 128, stdin
);
198 C
= Constraints2Polyhedron(M
, options
->barvinok
->MaxRays
);
202 nb_parms
= D
->Dimension
;
203 param_name
= Read_ParamNames(stdin
, nb_parms
);
205 EP
= barvinok_lexsmaller_ev(P
, D
, dim
, C
, options
->barvinok
->MaxRays
);
208 evalue
*EC
= barvinok_lexsmaller_ev(D
, D
, dim
, C
, options
->barvinok
->MaxRays
);
209 if (options
->barvinok
->verbose
>= 2) {
211 print_evalue(stdout
, EP
, (const char **)param_name
);
213 print_evalue(stdout
, EC
, (const char **)param_name
);
216 evalue_set_si(&mone
, -1, 1);
219 free_evalue_refs(&mone
);
223 if (options
->barvinok
->verbose
>= 1) {
225 print_evalue(stdout
, EP
, (const char **)param_name
);
227 en
= partition2enumeration(EP
);
229 assert(C
->Dimension
== 0); /* for now */
231 /* S = scanning list of polyhedra */
232 SP
= Polyhedron_Scan(P
, C
, options
->barvinok
->MaxRays
);
233 SD
= Polyhedron_Scan(D
, C
, options
->barvinok
->MaxRays
);
235 zP
= Vector_Alloc(1+P
->Dimension
+1);
236 value_set_si(zP
->p
[1+P
->Dimension
], 1);
237 zD
= Vector_Alloc(1+D
->Dimension
+1);
238 value_set_si(zD
->p
[1+D
->Dimension
], 1);
239 zE
= Vector_Alloc(dim
+C
->Dimension
);
241 if (options
->print_max
)
242 value_init(options
->max
);
244 check_lexsmaller(SP
, SD
, en
, 0, dim
, zP
->p
, zD
->p
, zE
->p
, &count
, options
);
247 if (options
->print_max
) {
249 value_print(stdout
, VALUE_FMT
, options
->max
);
251 value_clear(options
->max
);
254 Enumeration_Free(en
);
255 Free_ParamNames(param_name
, nb_parms
);
264 arguments_free(options
);