2 #include <bernstein/bernstein.h>
3 #include <barvinok/evalue.h>
4 #include <barvinok/options.h>
5 #include <barvinok/util.h>
6 #include <barvinok/bernstein.h>
8 #include "evalue_convert.h"
14 using namespace GiNaC
;
15 using namespace bernstein
;
16 using namespace barvinok
;
18 #define ALLOCN(type,n) (type*)malloc((n) * sizeof(type))
20 #define OPT_VARS (BV_OPT_LAST+1)
21 #define OPT_SPLIT (BV_OPT_LAST+2)
22 #define OPT_MIN (BV_OPT_LAST+3)
23 #define OPT_RECURSE (BV_OPT_LAST+4)
25 struct argp_option argp_options
[] = {
26 { "split", OPT_SPLIT
, "int" },
27 { "variables", OPT_VARS
, "list", 0,
28 "comma separated list of variables over which to maximize" },
29 { "verbose", 'V', 0, 0, },
30 { "minimize", OPT_MIN
, 0, 0, "minimize instead of maximize"},
31 { "recurse", OPT_RECURSE
, "none|factors|intervals|full", 0,
32 "[default: factors]" },
37 struct convert_options convert
;
38 struct verify_options verify
;
46 static error_t
parse_opt(int key
, char *arg
, struct argp_state
*state
)
48 struct options
*options
= (struct options
*) state
->input
;
52 state
->child_inputs
[0] = &options
->convert
;
53 state
->child_inputs
[1] = &options
->verify
;
54 options
->var_list
= NULL
;
57 options
->minimize
= 0;
58 options
->recurse
= BV_BERNSTEIN_FACTORS
;
64 options
->var_list
= strdup(arg
);
67 options
->split
= atoi(arg
);
70 options
->minimize
= 1;
73 if (!strcmp(arg
, "none"))
75 else if (!strcmp(arg
, "factors"))
76 options
->recurse
= BV_BERNSTEIN_FACTORS
;
77 else if (!strcmp(arg
, "intervals"))
78 options
->recurse
= BV_BERNSTEIN_INTERVALS
;
79 else if (!strcmp(arg
, "full"))
80 options
->recurse
= BV_BERNSTEIN_FACTORS
| BV_BERNSTEIN_INTERVALS
;
83 return ARGP_ERR_UNKNOWN
;
89 #define ALLOC(type) (type*)malloc(sizeof(type))
90 #define ALLOCN(type,n) (type*)malloc((n) * sizeof(type))
92 enum token_type
{ TOKEN_UNKNOWN
= 256, TOKEN_VALUE
, TOKEN_IDENT
, TOKEN_GE
,
107 static struct token
*token_new(int line
, int col
)
109 struct token
*tok
= ALLOC(struct token
);
115 void token_free(struct token
*tok
)
117 if (tok
->type
== TOKEN_VALUE
)
118 value_clear(tok
->u
.v
);
119 else if (tok
->type
== TOKEN_IDENT
)
135 struct token
*tokens
[5];
139 static struct stream
* stream_new(FILE *file
)
142 struct stream
*s
= ALLOC(struct stream
);
145 s
->buffer
= (char*)malloc(s
->size
);
151 for (i
= 0; i
< 5; ++i
)
157 static void stream_free(struct stream
*s
)
160 assert(s
->n_token
== 0);
164 static int stream_getc(struct stream
*s
)
183 static void stream_ungetc(struct stream
*s
, int c
)
189 static void stream_push_char(struct stream
*s
, int c
)
191 if (s
->len
>= s
->size
) {
192 s
->size
= (3*s
->size
)/2;
193 s
->buffer
= (char*)realloc(s
->buffer
, s
->size
);
195 s
->buffer
[s
->len
++] = c
;
198 static struct token
*stream_push_token(struct stream
*s
, struct token
*tok
)
200 assert(s
->n_token
< 5);
201 s
->tokens
[s
->n_token
++] = tok
;
204 static struct token
*stream_next_token(struct stream
*s
)
211 return s
->tokens
[--s
->n_token
];
216 while ((c
= stream_getc(s
)) != -1 && isspace(c
))
238 tok
= token_new(line
, col
);
239 tok
->type
= (token_type
)c
;
242 if (c
== '-' || isdigit(c
)) {
243 tok
= token_new(line
, col
);
244 tok
->type
= TOKEN_VALUE
;
245 value_init(tok
->u
.v
);
246 stream_push_char(s
, c
);
247 while ((c
= stream_getc(s
)) != -1 && isdigit(c
))
248 stream_push_char(s
, c
);
251 if (s
->len
== 1 && s
->buffer
[0] == '-')
252 value_set_si(tok
->u
.v
, -1);
254 stream_push_char(s
, '\0');
255 mpz_set_str(tok
->u
.v
, s
->buffer
, 0);
260 tok
= token_new(line
, col
);
261 stream_push_char(s
, c
);
262 while ((c
= stream_getc(s
)) != -1 && isalpha(c
))
263 stream_push_char(s
, c
);
266 stream_push_char(s
, '\0');
267 if (!strcmp(s
->buffer
, "UNION")) {
268 tok
->type
= TOKEN_UNION
;
270 tok
->type
= TOKEN_IDENT
;
271 tok
->u
.s
= strdup(s
->buffer
);
276 if ((c
= stream_getc(s
)) == '=') {
277 tok
= token_new(line
, col
);
278 tok
->type
= TOKEN_GE
;
285 tok
= token_new(line
, col
);
286 tok
->type
= TOKEN_UNKNOWN
;
290 void stream_error(struct stream
*s
, struct token
*tok
, char *msg
)
292 int line
= tok
? tok
->line
: s
->line
;
293 int col
= tok
? tok
->col
: s
->col
;
294 fprintf(stderr
, "syntax error (%d, %d): %s\n", line
, col
, msg
);
297 fprintf(stderr
, "got '%c'\n", tok
->type
);
304 struct parameter
*next
;
307 struct parameter
*parameter_new(char *name
, int pos
, struct parameter
*next
)
309 struct parameter
*p
= ALLOC(struct parameter
);
310 p
->name
= strdup(name
);
316 static int parameter_pos(struct parameter
**p
, char *s
)
318 int pos
= *p
? (*p
)->pos
+1 : 0;
321 for (q
= *p
; q
; q
= q
->next
) {
322 if (strcmp(q
->name
, s
) == 0)
328 *p
= parameter_new(s
, pos
, *p
);
332 static int optional_power(struct stream
*s
)
336 tok
= stream_next_token(s
);
339 if (tok
->type
!= '^') {
340 stream_push_token(s
, tok
);
344 tok
= stream_next_token(s
);
345 if (!tok
|| tok
->type
!= TOKEN_VALUE
) {
346 stream_error(s
, tok
, "expecting exponent");
348 stream_push_token(s
, tok
);
351 pow
= VALUE_TO_INT(tok
->u
.v
);
356 static evalue
*evalue_read_factor(struct stream
*s
, struct parameter
**p
);
357 static evalue
*evalue_read_term(struct stream
*s
, struct parameter
**p
);
359 static evalue
*create_fract_like(struct stream
*s
, evalue
*arg
, enode_type type
,
360 struct parameter
**p
)
364 pow
= optional_power(s
);
368 e
->x
.p
= new_enode(type
, pow
+2, -1);
369 value_clear(e
->x
.p
->arr
[0].d
);
370 e
->x
.p
->arr
[0] = *arg
;
372 evalue_set_si(&e
->x
.p
->arr
[1+pow
], 1, 1);
374 evalue_set_si(&e
->x
.p
->arr
[1+pow
], 0, 1);
379 static evalue
*read_fract(struct stream
*s
, struct token
*tok
, struct parameter
**p
)
383 tok
= stream_next_token(s
);
385 assert(tok
->type
== '{');
388 arg
= evalue_read_term(s
, p
);
389 tok
= stream_next_token(s
);
390 if (!tok
|| tok
->type
!= '}') {
391 stream_error(s
, tok
, "expecting \"}\"");
393 stream_push_token(s
, tok
);
397 return create_fract_like(s
, arg
, fractional
, p
);
400 static evalue
*read_periodic(struct stream
*s
, struct parameter
**p
)
408 tok
= stream_next_token(s
);
409 assert(tok
&& tok
->type
== '[');
413 list
= (evalue
**)malloc(len
* sizeof(evalue
*));
417 evalue
*e
= evalue_read_term(s
, p
);
419 stream_error(s
, NULL
, "missing argument or list element");
424 list
= (evalue
**)realloc(list
, len
* sizeof(evalue
*));
428 tok
= stream_next_token(s
);
430 stream_error(s
, NULL
, "unexpected EOF");
433 if (tok
->type
!= ',')
438 if (tok
->type
!= ']') {
439 stream_error(s
, tok
, "expecting \"]\"");
440 stream_push_token(s
, tok
);
446 tok
= stream_next_token(s
);
447 if (tok
->type
== '_') {
450 tok
= stream_next_token(s
);
451 if (!tok
|| tok
->type
!= TOKEN_IDENT
) {
452 stream_error(s
, tok
, "expecting identifier");
454 stream_push_token(s
, tok
);
459 pos
= parameter_pos(p
, tok
->u
.s
);
461 e
->x
.p
= new_enode(periodic
, n
, pos
+1);
463 value_clear(e
->x
.p
->arr
[n
].d
);
464 e
->x
.p
->arr
[n
] = *list
[n
];
468 stream_push_token(s
, tok
);
469 e
= create_fract_like(s
, list
[0], flooring
, p
);
472 stream_error(s
, tok
, "unexpected token");
473 stream_push_token(s
, tok
);
478 free_evalue_refs(list
[n
]);
485 static evalue
*evalue_read_factor(struct stream
*s
, struct parameter
**p
)
490 tok
= stream_next_token(s
);
494 if (tok
->type
== '(') {
496 e
= evalue_read_term(s
, p
);
497 tok
= stream_next_token(s
);
498 if (!tok
|| tok
->type
!= ')') {
499 stream_error(s
, tok
, "expecting \")\"");
501 stream_push_token(s
, tok
);
504 } else if (tok
->type
== TOKEN_VALUE
) {
507 value_set_si(e
->d
, 1);
509 value_assign(e
->x
.n
, tok
->u
.v
);
511 tok
= stream_next_token(s
);
512 if (tok
&& tok
->type
== '/') {
514 tok
= stream_next_token(s
);
515 if (!tok
|| tok
->type
!= TOKEN_VALUE
) {
516 stream_error(s
, tok
, "expecting denominator");
518 stream_push_token(s
, tok
);
521 value_assign(e
->d
, tok
->u
.v
);
524 stream_push_token(s
, tok
);
525 } else if (tok
->type
== TOKEN_IDENT
) {
526 int pos
= parameter_pos(p
, tok
->u
.s
);
527 int pow
= optional_power(s
);
531 e
->x
.p
= new_enode(polynomial
, pow
+1, pos
+1);
532 evalue_set_si(&e
->x
.p
->arr
[pow
], 1, 1);
534 evalue_set_si(&e
->x
.p
->arr
[pow
], 0, 1);
535 } else if (tok
->type
== '[') {
536 stream_push_token(s
, tok
);
537 e
= read_periodic(s
, p
);
538 } else if (tok
->type
== '{') {
539 stream_push_token(s
, tok
);
540 e
= read_fract(s
, tok
, p
);
543 tok
= stream_next_token(s
);
544 if (tok
&& tok
->type
== '*') {
547 e2
= evalue_read_factor(s
, p
);
549 stream_error(s
, NULL
, "unexpected EOF");
553 free_evalue_refs(e2
);
556 stream_push_token(s
, tok
);
561 static evalue
*evalue_read_term(struct stream
*s
, struct parameter
**p
)
566 e
= evalue_read_factor(s
, p
);
570 tok
= stream_next_token(s
);
574 if (tok
->type
== '+') {
577 e2
= evalue_read_term(s
, p
);
579 stream_error(s
, NULL
, "unexpected EOF");
583 free_evalue_refs(e2
);
586 stream_push_token(s
, tok
);
594 struct constraint
*next
;
595 struct constraint
*union_next
;
598 static struct constraint
*constraint_new()
600 struct constraint
*c
= ALLOC(struct constraint
);
602 c
->v
= Vector_Alloc(16);
604 c
->union_next
= NULL
;
608 static void constraint_free(struct constraint
*c
)
611 struct constraint
*next
= c
->next
? c
->next
: c
->union_next
;
618 static void constraint_extend(struct constraint
*c
, int pos
)
621 if (pos
< c
->v
->Size
)
624 v
= Vector_Alloc((3*c
->v
->Size
)/2);
625 Vector_Copy(c
->v
->p
, v
->p
, c
->v
->Size
);
630 static int evalue_read_constraint(struct stream
*s
, struct parameter
**p
,
631 struct constraint
**constraints
,
632 struct constraint
*union_next
)
635 struct constraint
*c
= NULL
;
637 while ((tok
= stream_next_token(s
))) {
640 if (tok
->type
== '+')
642 else if (tok
->type
== TOKEN_IDENT
) {
644 c
= constraint_new();
645 pos
= parameter_pos(p
, tok
->u
.s
);
646 constraint_extend(c
, 1+pos
);
647 value_set_si(c
->v
->p
[1+pos
], 1);
649 } else if (tok
->type
== TOKEN_VALUE
) {
651 c
= constraint_new();
652 tok2
= stream_next_token(s
);
653 if (tok2
&& tok2
->type
== TOKEN_IDENT
) {
654 pos
= parameter_pos(p
, tok2
->u
.s
);
655 constraint_extend(c
, 1+pos
);
656 value_assign(c
->v
->p
[1+pos
], tok
->u
.v
);
661 stream_push_token(s
, tok2
);
662 value_assign(c
->v
->p
[0], tok
->u
.v
);
665 } else if (tok
->type
== TOKEN_GE
|| tok
->type
== '=') {
666 int type
= tok
->type
== TOKEN_GE
;
668 tok
= stream_next_token(s
);
669 if (!tok
|| tok
->type
!= TOKEN_VALUE
|| value_notzero_p(tok
->u
.v
)) {
670 stream_error(s
, tok
, "expecting \"0\"");
672 stream_push_token(s
, tok
);
676 c
->next
= *constraints
;
677 c
->union_next
= union_next
;
684 stream_push_token(s
, tok
);
686 stream_error(s
, tok
, "unexpected token");
695 static struct constraint
*evalue_read_domain(struct stream
*s
, struct parameter
**p
,
698 struct constraint
*constraints
= NULL
;
699 struct constraint
*union_next
= NULL
;
703 tok
= stream_next_token(s
);
706 stream_push_token(s
, tok
);
709 while (evalue_read_constraint(s
, p
, &constraints
, union_next
)) {
710 tok
= stream_next_token(s
);
712 if (tok
->type
== TOKEN_UNION
) {
714 tok
= stream_next_token(s
);
716 stream_error(s
, NULL
, "unexpected EOF");
719 stream_push_token(s
, tok
);
720 union_next
= constraints
;
724 stream_push_token(s
, tok
);
725 /* empty line separates domain from evalue */
726 if (tok
->line
> line
+1)
736 struct constraint
*constraints
;
738 struct section
*next
;
741 static char **extract_parameters(struct parameter
*p
, unsigned *nparam
)
746 *nparam
= p
? p
->pos
+1 : 0;
747 params
= ALLOCN(char *, *nparam
);
748 for (i
= 0; i
< *nparam
; ++i
) {
749 struct parameter
*next
= p
->next
;
750 params
[p
->pos
] = p
->name
;
757 static Polyhedron
*constraints2domain(struct constraint
*constraints
,
758 unsigned nparam
, unsigned MaxRays
)
763 struct constraint
*c
;
764 struct constraint
*union_next
= NULL
;
766 for (n
= 0, c
= constraints
; c
; ++n
, c
= c
->next
)
768 M
= Matrix_Alloc(n
, 1+nparam
+1);
770 struct constraint
*next
= constraints
->next
;
771 union_next
= constraints
->union_next
;
772 Vector_Copy(constraints
->v
->p
+1, M
->p
[n
]+1, nparam
);
773 if (constraints
->type
)
774 value_set_si(M
->p
[n
][0], 1);
775 value_assign(M
->p
[n
][1+nparam
], constraints
->v
->p
[0]);
776 constraints
->next
= NULL
;
777 constraints
->union_next
= NULL
;
778 constraint_free(constraints
);
781 D
= Constraints2Polyhedron(M
, MaxRays
);
785 D
= DomainConcat(D
, constraints2domain(union_next
, nparam
, MaxRays
));
789 static evalue
*evalue_read_partition(struct stream
*s
, struct parameter
*p
,
791 unsigned *nparam
, unsigned MaxRays
)
793 struct section
*part
= NULL
;
794 struct constraint
*constraints
;
798 while ((constraints
= evalue_read_domain(s
, &p
, MaxRays
))) {
799 evalue
*e
= evalue_read_term(s
, &p
);
801 stream_error(s
, NULL
, "missing evalue");
804 struct section
*sect
= ALLOC(struct section
);
805 sect
->constraints
= constraints
;
816 *ppp
= extract_parameters(p
, nparam
);
819 e
->x
.p
= new_enode(partition
, 2*m
, *nparam
);
821 for (j
= 0; j
< m
; ++j
) {
823 struct section
*next
= part
->next
;
824 constraints
= part
->constraints
;
825 D
= constraints2domain(part
->constraints
, *nparam
, MaxRays
);
826 EVALUE_SET_DOMAIN(e
->x
.p
->arr
[2*j
], D
);
827 value_clear(e
->x
.p
->arr
[2*j
+1].d
);
828 e
->x
.p
->arr
[2*j
+1] = *part
->e
;
837 static evalue
*evalue_read(FILE *in
, char *var_list
, char ***ppp
, unsigned *nvar
,
838 unsigned *nparam
, unsigned MaxRays
)
840 struct stream
*s
= stream_new(in
);
843 struct parameter
*p
= NULL
;
848 while ((next
= strchr(var_list
, ','))) {
851 parameter_pos(&p
, var_list
);
855 if (strlen(var_list
) > 0)
856 parameter_pos(&p
, var_list
);
857 nv
= p
? p
->pos
+1 : 0;
861 if (!(tok
= stream_next_token(s
)))
864 if (tok
->type
== TOKEN_VALUE
) {
865 struct token
*tok2
= stream_next_token(s
);
867 stream_push_token(s
, tok2
);
868 stream_push_token(s
, tok
);
869 if (tok2
&& (tok2
->type
== TOKEN_IDENT
|| tok2
->type
== TOKEN_GE
))
870 e
= evalue_read_partition(s
, p
, ppp
, nparam
, MaxRays
);
872 e
= evalue_read_term(s
, &p
);
873 *ppp
= extract_parameters(p
, nparam
);
875 } else if (tok
->type
== TOKEN_IDENT
) {
876 stream_push_token(s
, tok
);
877 e
= evalue_read_partition(s
, p
, ppp
, nparam
, MaxRays
);
888 static int check_poly_max(const struct check_poly_data
*data
,
889 int nparam
, Value
*z
,
890 const struct verify_options
*options
);
892 struct check_poly_max_data
: public check_poly_data
{
897 check_poly_max_data(Value
*z
, evalue
*EP
, piecewise_lst
*pl
) :
900 this->check
= check_poly_max
;
904 static void optimum(Polyhedron
*S
, int pos
, const check_poly_max_data
*data
,
905 Value
*opt
, bool& found
,
906 const struct verify_options
*options
)
911 value_set_double(c
, compute_evalue(data
->EP
, data
->z
+1)+.25);
913 value_assign(*opt
, c
);
916 if (options
->barvinok
->bernstein_optimize
== BV_BERNSTEIN_MAX
) {
917 if (value_gt(c
, *opt
))
918 value_assign(*opt
, c
);
920 if (value_lt(c
, *opt
))
921 value_assign(*opt
, c
);
930 ok
= !(lower_upper_bounds(1+pos
, S
, data
->z
, &LB
, &UB
));
932 for (; value_le(LB
, UB
); value_increment(LB
, LB
)) {
933 value_assign(data
->z
[1+pos
], LB
);
934 optimum(S
->next
, pos
+1, data
, opt
, found
, options
);
936 value_set_si(data
->z
[1+pos
], 0);
942 static void optimum(const check_poly_max_data
*data
, Value
*opt
,
943 const struct verify_options
*options
)
946 for (int i
= 0; i
< data
->EP
->x
.p
->size
/2; ++i
)
947 if (!emptyQ2(data
->S
[i
]))
948 optimum(data
->S
[i
], 0, data
, opt
, found
, options
);
952 static int check_poly_max(const struct check_poly_data
*data
,
953 int nparam
, Value
*z
,
954 const struct verify_options
*options
)
958 const check_poly_max_data
*max_data
;
959 max_data
= static_cast<const check_poly_max_data
*>(data
);
966 if (options
->barvinok
->bernstein_optimize
== BV_BERNSTEIN_MAX
)
971 max_data
->pl
->evaluate(nparam
, z
, &n
, &d
);
972 if (options
->barvinok
->bernstein_optimize
== BV_BERNSTEIN_MAX
)
977 if (options
->print_all
) {
978 printf("%s(", minmax
);
979 value_print(stdout
, VALUE_FMT
, z
[0]);
980 for (k
= 1; k
< nparam
; ++k
) {
982 value_print(stdout
, VALUE_FMT
, z
[k
]);
985 value_print(stdout
, VALUE_FMT
, n
);
986 if (value_notone_p(d
)) {
988 value_print(stdout
, VALUE_FMT
, d
);
991 value_print(stdout
, VALUE_FMT
, m
);
995 optimum(max_data
, &n
, options
);
997 if (options
->barvinok
->bernstein_optimize
== BV_BERNSTEIN_MAX
)
1000 ok
= value_le(m
, n
);
1002 if (options
->print_all
) {
1003 printf(", %s(EP) = ", minmax
);
1004 value_print(stdout
, VALUE_FMT
, n
);
1011 fprintf(stderr
, "Error !\n");
1012 fprintf(stderr
, "%s(", minmax
);
1013 value_print(stderr
, VALUE_FMT
, z
[0]);
1014 for (k
= 1; k
< nparam
; ++k
) {
1015 fprintf(stderr
,", ");
1016 value_print(stderr
, VALUE_FMT
, z
[k
]);
1018 fprintf(stderr
, ") should be ");
1019 if (options
->barvinok
->bernstein_optimize
== BV_BERNSTEIN_MAX
)
1020 fprintf(stderr
, "greater");
1022 fprintf(stderr
, "smaller");
1023 fprintf(stderr
, " than or equal to ");
1024 value_print(stderr
, VALUE_FMT
, n
);
1025 fprintf(stderr
, ", while pl eval gives ");
1026 value_print(stderr
, VALUE_FMT
, m
);
1027 fprintf(stderr
, ".\n");
1028 cerr
<< *max_data
->pl
<< endl
;
1029 } else if (options
->print_all
)
1039 static int verify(Polyhedron
*D
, piecewise_lst
*pl
, evalue
*EP
,
1040 unsigned nvar
, unsigned nparam
, Vector
*p
,
1041 struct verify_options
*options
)
1044 unsigned MaxRays
= options
->barvinok
->MaxRays
;
1045 assert(value_zero_p(EP
->d
));
1046 assert(EP
->x
.p
->type
== partition
);
1049 CS
= check_poly_context_scan(D
, options
);
1051 check_poly_init(D
, options
);
1053 if (!(CS
&& emptyQ2(CS
))) {
1054 check_poly_max_data
data(p
->p
, EP
, pl
);
1055 data
.S
= ALLOCN(Polyhedron
*, EP
->x
.p
->size
/2);
1056 for (int i
= 0; i
< EP
->x
.p
->size
/2; ++i
) {
1057 Polyhedron
*A
= EVALUE_DOMAIN(EP
->x
.p
->arr
[2*i
]);
1058 data
.S
[i
] = Polyhedron_Scan(A
, D
, MaxRays
& POL_NO_DUAL
? 0 : MaxRays
);
1060 ok
= check_poly(CS
, &data
, nparam
, 0, p
->p
+1+nvar
, options
);
1061 for (int i
= 0; i
< EP
->x
.p
->size
/2; ++i
)
1062 Domain_Free(data
.S
[i
]);
1066 if (!options
->print_all
)
1075 static int verify(piecewise_lst
*pl
, evalue
*EP
, unsigned nvar
, unsigned nparam
,
1076 struct verify_options
*options
)
1080 p
= Vector_Alloc(nvar
+nparam
+2);
1081 value_set_si(p
->p
[nvar
+nparam
+1], 1);
1083 for (int i
= 0; i
< pl
->list
.size(); ++i
) {
1084 int ok
= verify(pl
->list
[i
].first
, pl
, EP
, nvar
, nparam
, p
, options
);
1085 if (!ok
&& !options
->continue_on_error
)
1094 static int optimize(evalue
*EP
, char **all_vars
, unsigned nvar
, unsigned nparam
,
1095 struct options
*options
)
1098 piecewise_lst
*pl
= NULL
;
1099 U
= Universe_Polyhedron(nparam
);
1100 int print_solution
= 1;
1104 params
= constructParameterVector(all_vars
+nvar
, nparam
);
1106 if (options
->verify
.verify
) {
1107 verify_options_set_range(&options
->verify
, nvar
+nparam
);
1108 if (!options
->verbose
)
1112 options
->verify
.barvinok
->bernstein_recurse
= options
->recurse
;
1113 if (options
->minimize
)
1114 options
->verify
.barvinok
->bernstein_optimize
= BV_BERNSTEIN_MIN
;
1116 options
->verify
.barvinok
->bernstein_optimize
= BV_BERNSTEIN_MAX
;
1117 pl
= evalue_bernstein_coefficients(NULL
, EP
, U
, params
,
1118 options
->verify
.barvinok
);
1120 if (options
->minimize
)
1125 cout
<< *pl
<< endl
;
1126 if (options
->verify
.verify
)
1127 result
= verify(pl
, EP
, nvar
, nparam
, &options
->verify
);
1135 int main(int argc
, char **argv
)
1138 char **all_vars
= NULL
;
1141 struct options options
;
1142 struct barvinok_options
*bv_options
= barvinok_options_new_with_defaults();
1143 static struct argp_child argp_children
[] = {
1144 { &convert_argp
, 0, "input conversion", 1 },
1145 { &verify_argp
, 0, "verification", 2 },
1148 static struct argp argp
= { argp_options
, parse_opt
, 0, 0, argp_children
};
1151 options
.verify
.barvinok
= bv_options
;
1152 argp_parse(&argp
, argc
, argv
, 0, 0, &options
);
1154 EP
= evalue_read(stdin
, options
.var_list
, &all_vars
, &nvar
, &nparam
,
1155 bv_options
->MaxRays
);
1159 evalue_split_periods(EP
, options
.split
, bv_options
->MaxRays
);
1161 evalue_convert(EP
, &options
.convert
, nparam
, options
.verbose
? all_vars
: NULL
);
1163 if (EVALUE_IS_ZERO(*EP
))
1164 print_evalue(stdout
, EP
, all_vars
);
1166 result
= optimize(EP
, all_vars
, nvar
, nparam
, &options
);
1168 free_evalue_refs(EP
);
1171 if (options
.var_list
)
1172 free(options
.var_list
);
1173 Free_ParamNames(all_vars
, nvar
+nparam
);
1174 barvinok_options_free(bv_options
);