2 #include <barvinok/options.h>
3 #include <barvinok/util.h>
10 struct barvinok_options
*barvinok
;
13 struct isl_arg arguments_arg
[] = {
14 ISL_ARG_CHILD(struct arguments
, barvinok
, NULL
, barvinok_options_arg
, 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
)
21 ISL_ARG_DEF(arguments
, struct arguments
, arguments_arg
)
24 #define LS_P 2 /* continue searching P */
25 #define LS_D 4 /* continue searching D */
27 static int check_lexsmaller(Polyhedron
*SP
, Polyhedron
*SD
, Enumeration
*en
,
28 int pos
, int nvar
, Value
*zP
, Value
*zD
, Value
*zE
,
29 Value
*count
, struct arguments
*options
)
33 Value PLB
, PUB
, DLB
, DUB
, LB
, UB
, tmp
, c
;
36 return LS_OK
| LS_P
| LS_D
;
38 value_init(PLB
); value_init(PUB
);
39 value_init(DLB
); value_init(DUB
);
40 value_init(LB
); value_init(UB
);
44 ok
= !(lower_upper_bounds(1+pos
, SP
, zP
, &PLB
, &PUB
));
48 ok
= !(lower_upper_bounds(1+pos
, SD
, zD
, &DLB
, &DUB
));
51 if (!SD
|| (SP
&& value_lt(PLB
, DLB
)))
52 value_assign(LB
, PLB
);
54 value_assign(LB
, DLB
);
55 if (!SD
|| (SP
&& value_gt(PUB
, DUB
)))
56 value_assign(UB
, PUB
);
58 value_assign(UB
, DUB
);
63 ok
= LS_OK
| LS_P
| LS_D
;
65 for(value_assign(tmp
,LB
); value_le(tmp
,UB
); value_increment(tmp
,tmp
)) {
66 int inP
= SP
&& value_ge(tmp
, PLB
) && value_le(tmp
, PUB
);
67 int inD
= SD
&& value_ge(tmp
, DLB
) && value_le(tmp
, DUB
);
72 value_assign(zP
[pos
+1], tmp
);
74 value_assign(zD
[pos
+1], tmp
);
75 if (inD
&& pos
< nvar
)
76 value_assign(zE
[pos
], tmp
);
78 if (inD
&& !SD
->next
) {
81 value_assign(c
,*(ctmp
=compute_poly(en
, zE
)));
85 if (options
->barvinok
->verbose
>= 2) {
87 value_print(stdout
, VALUE_FMT
, zE
[0]);
88 for (i
= 1; i
< nvar
; ++i
) {
90 value_print(stdout
, VALUE_FMT
, zE
[i
]);
93 value_print(stdout
, VALUE_FMT
, c
);
95 value_print(stdout
, VALUE_FMT
, *count
);
99 if (value_ne(c
, *count
)) {
102 fprintf(stderr
,"Error !\n");
103 fprintf(stderr
, "EP( ");
104 value_print(stderr
, VALUE_FMT
, zE
[0]);
105 for (i
= 1; i
< nvar
; ++i
) {
106 fprintf(stderr
, ", ");
107 value_print(stderr
, VALUE_FMT
, zE
[i
]);
109 fprintf(stderr
, " ) = ");
110 value_print(stderr
, VALUE_FMT
, c
);
111 fprintf(stderr
, " but count = ");
112 value_print(stderr
, VALUE_FMT
, *count
);
118 value_decrement(*count
, *count
);
124 ok
&= check_lexsmaller(inP
? SP
->next
: NULL
,
125 inD
? SD
->next
: NULL
,
126 en
, pos
+1, nvar
, zP
, zD
, zE
, count
,
129 ok
&= check_lexsmaller(NULL
, inD
? SD
->next
: NULL
,
130 en
, pos
+1, nvar
, zP
, zD
, zE
, count
,
132 & check_lexsmaller(inP
? SP
->next
: NULL
, NULL
,
133 en
, pos
+1, nvar
, zP
, zD
, zE
, count
,
135 if (pos
>= nvar
&& !(ok
& LS_D
))
137 if (pos
>= nvar
&& !(ok
& LS_P
))
141 if (!ok
&& !options
->keep_going
)
144 if (inP
&& !SP
->next
) {
145 value_increment(*count
, *count
);
146 if (value_gt(*count
, options
->max
))
147 value_assign(options
->max
, *count
);
152 value_set_si(zP
[pos
+1], 0);
154 value_set_si(zD
[pos
+1], 0);
160 value_clear(PLB
); value_clear(PUB
);
161 value_clear(DLB
); value_clear(DUB
);
162 value_clear(LB
); value_clear(UB
);
168 int main(int argc
,char *argv
[])
171 Polyhedron
*P
, *D
, *C
;
174 const char **param_name
= NULL
;
177 Vector
*zP
, *zD
, *zE
;
181 struct arguments
*options
= arguments_new_with_defaults();
183 argc
= arguments_parse(options
, argc
, argv
, ISL_ARG_ALL
);
186 P
= Constraints2Polyhedron(M
, options
->barvinok
->MaxRays
);
190 D
= Constraints2Polyhedron(M
, options
->barvinok
->MaxRays
);
194 fgets(s
, 128, stdin
);
195 while ((*s
=='#') || (sscanf(s
, "D %u", &dim
)<1))
196 fgets(s
, 128, stdin
);
199 C
= Constraints2Polyhedron(M
, options
->barvinok
->MaxRays
);
203 nb_parms
= D
->Dimension
;
204 param_name
= Read_ParamNames(stdin
, nb_parms
);
206 EP
= barvinok_lexsmaller_ev(P
, D
, dim
, C
, options
->barvinok
->MaxRays
);
209 evalue
*EC
= barvinok_lexsmaller_ev(D
, D
, dim
, C
, options
->barvinok
->MaxRays
);
210 if (options
->barvinok
->verbose
>= 2) {
212 print_evalue(stdout
, EP
, (const char **)param_name
);
214 print_evalue(stdout
, EC
, (const char **)param_name
);
217 evalue_set_si(&mone
, -1, 1);
220 free_evalue_refs(&mone
);
224 if (options
->barvinok
->verbose
>= 1) {
226 print_evalue(stdout
, EP
, (const char **)param_name
);
228 en
= partition2enumeration(EP
);
230 assert(C
->Dimension
== 0); /* for now */
232 /* S = scanning list of polyhedra */
233 SP
= Polyhedron_Scan(P
, C
, options
->barvinok
->MaxRays
);
234 SD
= Polyhedron_Scan(D
, C
, options
->barvinok
->MaxRays
);
236 zP
= Vector_Alloc(1+P
->Dimension
+1);
237 value_set_si(zP
->p
[1+P
->Dimension
], 1);
238 zD
= Vector_Alloc(1+D
->Dimension
+1);
239 value_set_si(zD
->p
[1+D
->Dimension
], 1);
240 zE
= Vector_Alloc(dim
+C
->Dimension
);
242 if (options
->print_max
)
243 value_init(options
->max
);
245 check_lexsmaller(SP
, SD
, en
, 0, dim
, zP
->p
, zD
->p
, zE
->p
, &count
, options
);
248 if (options
->print_max
) {
250 value_print(stdout
, VALUE_FMT
, options
->max
);
252 value_clear(options
->max
);
255 Enumeration_Free(en
);
256 Free_ParamNames(param_name
, nb_parms
);
265 arguments_free(options
);