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>
9 #include "evalue_convert.h"
15 using namespace GiNaC
;
16 using namespace bernstein
;
17 using namespace barvinok
;
19 #define ALLOCN(type,n) (type*)malloc((n) * sizeof(type))
21 #define OPT_VARS (BV_OPT_LAST+1)
22 #define OPT_SPLIT (BV_OPT_LAST+2)
23 #define OPT_MIN (BV_OPT_LAST+3)
24 #define OPT_RECURSE (BV_OPT_LAST+4)
26 struct argp_option argp_options
[] = {
27 { "split", OPT_SPLIT
, "int" },
28 { "variables", OPT_VARS
, "list", 0,
29 "comma separated list of variables over which to maximize" },
30 { "verbose", 'V', 0, 0, },
31 { "minimize", OPT_MIN
, 0, 0, "minimize instead of maximize"},
32 { "recurse", OPT_RECURSE
, "none|factors|intervals|full", 0,
33 "[default: factors]" },
38 struct convert_options convert
;
39 struct verify_options verify
;
47 static error_t
parse_opt(int key
, char *arg
, struct argp_state
*state
)
49 struct options
*options
= (struct options
*) state
->input
;
53 state
->child_inputs
[0] = &options
->convert
;
54 state
->child_inputs
[1] = &options
->verify
;
55 options
->var_list
= NULL
;
58 options
->minimize
= 0;
59 options
->recurse
= BV_BERNSTEIN_FACTORS
;
65 options
->var_list
= strdup(arg
);
68 options
->split
= atoi(arg
);
71 options
->minimize
= 1;
74 if (!strcmp(arg
, "none"))
76 else if (!strcmp(arg
, "factors"))
77 options
->recurse
= BV_BERNSTEIN_FACTORS
;
78 else if (!strcmp(arg
, "intervals"))
79 options
->recurse
= BV_BERNSTEIN_INTERVALS
;
80 else if (!strcmp(arg
, "full"))
81 options
->recurse
= BV_BERNSTEIN_FACTORS
| BV_BERNSTEIN_INTERVALS
;
84 return ARGP_ERR_UNKNOWN
;
90 #define ALLOC(type) (type*)malloc(sizeof(type))
91 #define ALLOCN(type,n) (type*)malloc((n) * sizeof(type))
93 enum token_type
{ TOKEN_UNKNOWN
= 256, TOKEN_VALUE
, TOKEN_IDENT
, TOKEN_GE
,
108 static struct token
*token_new(int line
, int col
)
110 struct token
*tok
= ALLOC(struct token
);
116 void token_free(struct token
*tok
)
118 if (tok
->type
== TOKEN_VALUE
)
119 value_clear(tok
->u
.v
);
120 else if (tok
->type
== TOKEN_IDENT
)
136 struct token
*tokens
[5];
140 static struct stream
* stream_new(FILE *file
)
143 struct stream
*s
= ALLOC(struct stream
);
146 s
->buffer
= (char*)malloc(s
->size
);
152 for (i
= 0; i
< 5; ++i
)
158 static void stream_free(struct stream
*s
)
161 assert(s
->n_token
== 0);
165 static int stream_getc(struct stream
*s
)
184 static void stream_ungetc(struct stream
*s
, int c
)
190 static void stream_push_char(struct stream
*s
, int c
)
192 if (s
->len
>= s
->size
) {
193 s
->size
= (3*s
->size
)/2;
194 s
->buffer
= (char*)realloc(s
->buffer
, s
->size
);
196 s
->buffer
[s
->len
++] = c
;
199 static struct token
*stream_push_token(struct stream
*s
, struct token
*tok
)
201 assert(s
->n_token
< 5);
202 s
->tokens
[s
->n_token
++] = tok
;
205 static struct token
*stream_next_token(struct stream
*s
)
212 return s
->tokens
[--s
->n_token
];
217 while ((c
= stream_getc(s
)) != -1 && isspace(c
))
239 tok
= token_new(line
, col
);
240 tok
->type
= (token_type
)c
;
243 if (c
== '-' || isdigit(c
)) {
244 tok
= token_new(line
, col
);
245 tok
->type
= TOKEN_VALUE
;
246 value_init(tok
->u
.v
);
247 stream_push_char(s
, c
);
248 while ((c
= stream_getc(s
)) != -1 && isdigit(c
))
249 stream_push_char(s
, c
);
252 if (s
->len
== 1 && s
->buffer
[0] == '-')
253 value_set_si(tok
->u
.v
, -1);
255 stream_push_char(s
, '\0');
256 mpz_set_str(tok
->u
.v
, s
->buffer
, 0);
261 tok
= token_new(line
, col
);
262 stream_push_char(s
, c
);
263 while ((c
= stream_getc(s
)) != -1 && isalpha(c
))
264 stream_push_char(s
, c
);
267 stream_push_char(s
, '\0');
268 if (!strcmp(s
->buffer
, "UNION")) {
269 tok
->type
= TOKEN_UNION
;
271 tok
->type
= TOKEN_IDENT
;
272 tok
->u
.s
= strdup(s
->buffer
);
277 if ((c
= stream_getc(s
)) == '=') {
278 tok
= token_new(line
, col
);
279 tok
->type
= TOKEN_GE
;
286 tok
= token_new(line
, col
);
287 tok
->type
= TOKEN_UNKNOWN
;
291 void stream_error(struct stream
*s
, struct token
*tok
, char *msg
)
293 int line
= tok
? tok
->line
: s
->line
;
294 int col
= tok
? tok
->col
: s
->col
;
295 fprintf(stderr
, "syntax error (%d, %d): %s\n", line
, col
, msg
);
298 fprintf(stderr
, "got '%c'\n", tok
->type
);
305 struct parameter
*next
;
308 struct parameter
*parameter_new(char *name
, int pos
, struct parameter
*next
)
310 struct parameter
*p
= ALLOC(struct parameter
);
311 p
->name
= strdup(name
);
317 static int parameter_pos(struct parameter
**p
, char *s
)
319 int pos
= *p
? (*p
)->pos
+1 : 0;
322 for (q
= *p
; q
; q
= q
->next
) {
323 if (strcmp(q
->name
, s
) == 0)
329 *p
= parameter_new(s
, pos
, *p
);
333 static int optional_power(struct stream
*s
)
337 tok
= stream_next_token(s
);
340 if (tok
->type
!= '^') {
341 stream_push_token(s
, tok
);
345 tok
= stream_next_token(s
);
346 if (!tok
|| tok
->type
!= TOKEN_VALUE
) {
347 stream_error(s
, tok
, "expecting exponent");
349 stream_push_token(s
, tok
);
352 pow
= VALUE_TO_INT(tok
->u
.v
);
357 static evalue
*evalue_read_factor(struct stream
*s
, struct parameter
**p
);
358 static evalue
*evalue_read_term(struct stream
*s
, struct parameter
**p
);
360 static evalue
*create_fract_like(struct stream
*s
, evalue
*arg
, enode_type type
,
361 struct parameter
**p
)
365 pow
= optional_power(s
);
369 e
->x
.p
= new_enode(type
, pow
+2, -1);
370 value_clear(e
->x
.p
->arr
[0].d
);
371 e
->x
.p
->arr
[0] = *arg
;
373 evalue_set_si(&e
->x
.p
->arr
[1+pow
], 1, 1);
375 evalue_set_si(&e
->x
.p
->arr
[1+pow
], 0, 1);
380 static evalue
*read_fract(struct stream
*s
, struct token
*tok
, struct parameter
**p
)
384 tok
= stream_next_token(s
);
386 assert(tok
->type
== '{');
389 arg
= evalue_read_term(s
, p
);
390 tok
= stream_next_token(s
);
391 if (!tok
|| tok
->type
!= '}') {
392 stream_error(s
, tok
, "expecting \"}\"");
394 stream_push_token(s
, tok
);
398 return create_fract_like(s
, arg
, fractional
, p
);
401 static evalue
*read_periodic(struct stream
*s
, struct parameter
**p
)
409 tok
= stream_next_token(s
);
410 assert(tok
&& tok
->type
== '[');
414 list
= (evalue
**)malloc(len
* sizeof(evalue
*));
418 evalue
*e
= evalue_read_term(s
, p
);
420 stream_error(s
, NULL
, "missing argument or list element");
425 list
= (evalue
**)realloc(list
, len
* sizeof(evalue
*));
429 tok
= stream_next_token(s
);
431 stream_error(s
, NULL
, "unexpected EOF");
434 if (tok
->type
!= ',')
439 if (tok
->type
!= ']') {
440 stream_error(s
, tok
, "expecting \"]\"");
441 stream_push_token(s
, tok
);
447 tok
= stream_next_token(s
);
448 if (tok
->type
== '_') {
451 tok
= stream_next_token(s
);
452 if (!tok
|| tok
->type
!= TOKEN_IDENT
) {
453 stream_error(s
, tok
, "expecting identifier");
455 stream_push_token(s
, tok
);
460 pos
= parameter_pos(p
, tok
->u
.s
);
462 e
->x
.p
= new_enode(periodic
, n
, pos
+1);
464 value_clear(e
->x
.p
->arr
[n
].d
);
465 e
->x
.p
->arr
[n
] = *list
[n
];
469 stream_push_token(s
, tok
);
470 e
= create_fract_like(s
, list
[0], flooring
, p
);
473 stream_error(s
, tok
, "unexpected token");
474 stream_push_token(s
, tok
);
479 free_evalue_refs(list
[n
]);
486 static evalue
*evalue_read_factor(struct stream
*s
, struct parameter
**p
)
491 tok
= stream_next_token(s
);
495 if (tok
->type
== '(') {
497 e
= evalue_read_term(s
, p
);
498 tok
= stream_next_token(s
);
499 if (!tok
|| tok
->type
!= ')') {
500 stream_error(s
, tok
, "expecting \")\"");
502 stream_push_token(s
, tok
);
505 } else if (tok
->type
== TOKEN_VALUE
) {
508 value_set_si(e
->d
, 1);
510 value_assign(e
->x
.n
, tok
->u
.v
);
512 tok
= stream_next_token(s
);
513 if (tok
&& tok
->type
== '/') {
515 tok
= stream_next_token(s
);
516 if (!tok
|| tok
->type
!= TOKEN_VALUE
) {
517 stream_error(s
, tok
, "expecting denominator");
519 stream_push_token(s
, tok
);
522 value_assign(e
->d
, tok
->u
.v
);
525 stream_push_token(s
, tok
);
526 } else if (tok
->type
== TOKEN_IDENT
) {
527 int pos
= parameter_pos(p
, tok
->u
.s
);
528 int pow
= optional_power(s
);
532 e
->x
.p
= new_enode(polynomial
, pow
+1, pos
+1);
533 evalue_set_si(&e
->x
.p
->arr
[pow
], 1, 1);
535 evalue_set_si(&e
->x
.p
->arr
[pow
], 0, 1);
536 } else if (tok
->type
== '[') {
537 stream_push_token(s
, tok
);
538 e
= read_periodic(s
, p
);
539 } else if (tok
->type
== '{') {
540 stream_push_token(s
, tok
);
541 e
= read_fract(s
, tok
, p
);
544 tok
= stream_next_token(s
);
545 if (tok
&& tok
->type
== '*') {
548 e2
= evalue_read_factor(s
, p
);
550 stream_error(s
, NULL
, "unexpected EOF");
554 free_evalue_refs(e2
);
557 stream_push_token(s
, tok
);
562 static evalue
*evalue_read_term(struct stream
*s
, struct parameter
**p
)
567 e
= evalue_read_factor(s
, p
);
571 tok
= stream_next_token(s
);
575 if (tok
->type
== '+') {
578 e2
= evalue_read_term(s
, p
);
580 stream_error(s
, NULL
, "unexpected EOF");
584 free_evalue_refs(e2
);
587 stream_push_token(s
, tok
);
595 struct constraint
*next
;
596 struct constraint
*union_next
;
599 static struct constraint
*constraint_new()
601 struct constraint
*c
= ALLOC(struct constraint
);
603 c
->v
= Vector_Alloc(16);
605 c
->union_next
= NULL
;
609 static void constraint_free(struct constraint
*c
)
612 struct constraint
*next
= c
->next
? c
->next
: c
->union_next
;
619 static void constraint_extend(struct constraint
*c
, int pos
)
622 if (pos
< c
->v
->Size
)
625 v
= Vector_Alloc((3*c
->v
->Size
)/2);
626 Vector_Copy(c
->v
->p
, v
->p
, c
->v
->Size
);
631 static int evalue_read_constraint(struct stream
*s
, struct parameter
**p
,
632 struct constraint
**constraints
,
633 struct constraint
*union_next
)
636 struct constraint
*c
= NULL
;
638 while ((tok
= stream_next_token(s
))) {
641 if (tok
->type
== '+')
643 else if (tok
->type
== TOKEN_IDENT
) {
645 c
= constraint_new();
646 pos
= parameter_pos(p
, tok
->u
.s
);
647 constraint_extend(c
, 1+pos
);
648 value_set_si(c
->v
->p
[1+pos
], 1);
650 } else if (tok
->type
== TOKEN_VALUE
) {
652 c
= constraint_new();
653 tok2
= stream_next_token(s
);
654 if (tok2
&& tok2
->type
== TOKEN_IDENT
) {
655 pos
= parameter_pos(p
, tok2
->u
.s
);
656 constraint_extend(c
, 1+pos
);
657 value_assign(c
->v
->p
[1+pos
], tok
->u
.v
);
662 stream_push_token(s
, tok2
);
663 value_assign(c
->v
->p
[0], tok
->u
.v
);
666 } else if (tok
->type
== TOKEN_GE
|| tok
->type
== '=') {
667 int type
= tok
->type
== TOKEN_GE
;
669 tok
= stream_next_token(s
);
670 if (!tok
|| tok
->type
!= TOKEN_VALUE
|| value_notzero_p(tok
->u
.v
)) {
671 stream_error(s
, tok
, "expecting \"0\"");
673 stream_push_token(s
, tok
);
677 c
->next
= *constraints
;
678 c
->union_next
= union_next
;
685 stream_push_token(s
, tok
);
687 stream_error(s
, tok
, "unexpected token");
696 static struct constraint
*evalue_read_domain(struct stream
*s
, struct parameter
**p
,
699 struct constraint
*constraints
= NULL
;
700 struct constraint
*union_next
= NULL
;
704 tok
= stream_next_token(s
);
707 stream_push_token(s
, tok
);
710 while (evalue_read_constraint(s
, p
, &constraints
, union_next
)) {
711 tok
= stream_next_token(s
);
713 if (tok
->type
== TOKEN_UNION
) {
715 tok
= stream_next_token(s
);
717 stream_error(s
, NULL
, "unexpected EOF");
720 stream_push_token(s
, tok
);
721 union_next
= constraints
;
725 stream_push_token(s
, tok
);
726 /* empty line separates domain from evalue */
727 if (tok
->line
> line
+1)
737 struct constraint
*constraints
;
739 struct section
*next
;
742 static char **extract_parameters(struct parameter
*p
, unsigned *nparam
)
747 *nparam
= p
? p
->pos
+1 : 0;
748 params
= ALLOCN(char *, *nparam
);
749 for (i
= 0; i
< *nparam
; ++i
) {
750 struct parameter
*next
= p
->next
;
751 params
[p
->pos
] = p
->name
;
758 static Polyhedron
*constraints2domain(struct constraint
*constraints
,
759 unsigned nparam
, unsigned MaxRays
)
764 struct constraint
*c
;
765 struct constraint
*union_next
= NULL
;
767 for (n
= 0, c
= constraints
; c
; ++n
, c
= c
->next
)
769 M
= Matrix_Alloc(n
, 1+nparam
+1);
771 struct constraint
*next
= constraints
->next
;
772 union_next
= constraints
->union_next
;
773 Vector_Copy(constraints
->v
->p
+1, M
->p
[n
]+1, nparam
);
774 if (constraints
->type
)
775 value_set_si(M
->p
[n
][0], 1);
776 value_assign(M
->p
[n
][1+nparam
], constraints
->v
->p
[0]);
777 constraints
->next
= NULL
;
778 constraints
->union_next
= NULL
;
779 constraint_free(constraints
);
782 D
= Constraints2Polyhedron(M
, MaxRays
);
786 D
= DomainConcat(D
, constraints2domain(union_next
, nparam
, MaxRays
));
790 static evalue
*evalue_read_partition(struct stream
*s
, struct parameter
*p
,
792 unsigned *nparam
, unsigned MaxRays
)
794 struct section
*part
= NULL
;
795 struct constraint
*constraints
;
799 while ((constraints
= evalue_read_domain(s
, &p
, MaxRays
))) {
800 evalue
*e
= evalue_read_term(s
, &p
);
802 stream_error(s
, NULL
, "missing evalue");
805 struct section
*sect
= ALLOC(struct section
);
806 sect
->constraints
= constraints
;
817 *ppp
= extract_parameters(p
, nparam
);
820 e
->x
.p
= new_enode(partition
, 2*m
, *nparam
);
822 for (j
= 0; j
< m
; ++j
) {
824 struct section
*next
= part
->next
;
825 constraints
= part
->constraints
;
826 D
= constraints2domain(part
->constraints
, *nparam
, MaxRays
);
827 EVALUE_SET_DOMAIN(e
->x
.p
->arr
[2*j
], D
);
828 value_clear(e
->x
.p
->arr
[2*j
+1].d
);
829 e
->x
.p
->arr
[2*j
+1] = *part
->e
;
838 static evalue
*evalue_read(FILE *in
, char *var_list
, char ***ppp
, unsigned *nvar
,
839 unsigned *nparam
, unsigned MaxRays
)
841 struct stream
*s
= stream_new(in
);
844 struct parameter
*p
= NULL
;
849 while ((next
= strchr(var_list
, ','))) {
852 parameter_pos(&p
, var_list
);
856 if (strlen(var_list
) > 0)
857 parameter_pos(&p
, var_list
);
858 nv
= p
? p
->pos
+1 : 0;
862 if (!(tok
= stream_next_token(s
)))
865 if (tok
->type
== TOKEN_VALUE
) {
866 struct token
*tok2
= stream_next_token(s
);
868 stream_push_token(s
, tok2
);
869 stream_push_token(s
, tok
);
870 if (tok2
&& (tok2
->type
== TOKEN_IDENT
|| tok2
->type
== TOKEN_GE
))
871 e
= evalue_read_partition(s
, p
, ppp
, nparam
, MaxRays
);
873 e
= evalue_read_term(s
, &p
);
874 *ppp
= extract_parameters(p
, nparam
);
876 } else if (tok
->type
== TOKEN_IDENT
) {
877 stream_push_token(s
, tok
);
878 e
= evalue_read_partition(s
, p
, ppp
, nparam
, MaxRays
);
889 static int check_poly_max(const struct check_poly_data
*data
,
890 int nparam
, Value
*z
,
891 const struct verify_options
*options
);
893 struct check_poly_max_data
: public check_poly_data
{
898 check_poly_max_data(Value
*z
, evalue
*EP
, piecewise_lst
*pl
) :
901 this->check
= check_poly_max
;
905 static void optimum(Polyhedron
*S
, int pos
, const check_poly_max_data
*data
,
906 Value
*opt
, bool& found
,
907 const struct verify_options
*options
)
912 value_set_double(c
, compute_evalue(data
->EP
, data
->z
+1)+.25);
914 value_assign(*opt
, c
);
917 if (options
->barvinok
->bernstein_optimize
== BV_BERNSTEIN_MAX
) {
918 if (value_gt(c
, *opt
))
919 value_assign(*opt
, c
);
921 if (value_lt(c
, *opt
))
922 value_assign(*opt
, c
);
931 ok
= !(lower_upper_bounds(1+pos
, S
, data
->z
, &LB
, &UB
));
933 for (; value_le(LB
, UB
); value_increment(LB
, LB
)) {
934 value_assign(data
->z
[1+pos
], LB
);
935 optimum(S
->next
, pos
+1, data
, opt
, found
, options
);
937 value_set_si(data
->z
[1+pos
], 0);
943 static void optimum(const check_poly_max_data
*data
, Value
*opt
,
944 const struct verify_options
*options
)
947 for (int i
= 0; i
< data
->EP
->x
.p
->size
/2; ++i
)
948 if (!emptyQ2(data
->S
[i
]))
949 optimum(data
->S
[i
], 0, data
, opt
, found
, options
);
953 static int check_poly_max(const struct check_poly_data
*data
,
954 int nparam
, Value
*z
,
955 const struct verify_options
*options
)
959 const check_poly_max_data
*max_data
;
960 max_data
= static_cast<const check_poly_max_data
*>(data
);
967 if (options
->barvinok
->bernstein_optimize
== BV_BERNSTEIN_MAX
)
972 max_data
->pl
->evaluate(nparam
, z
, &n
, &d
);
973 if (options
->barvinok
->bernstein_optimize
== BV_BERNSTEIN_MAX
)
978 if (options
->print_all
) {
979 printf("%s(", minmax
);
980 value_print(stdout
, VALUE_FMT
, z
[0]);
981 for (k
= 1; k
< nparam
; ++k
) {
983 value_print(stdout
, VALUE_FMT
, z
[k
]);
986 value_print(stdout
, VALUE_FMT
, n
);
987 if (value_notone_p(d
)) {
989 value_print(stdout
, VALUE_FMT
, d
);
992 value_print(stdout
, VALUE_FMT
, m
);
996 optimum(max_data
, &n
, options
);
998 if (options
->barvinok
->bernstein_optimize
== BV_BERNSTEIN_MAX
)
1001 ok
= value_le(m
, n
);
1003 if (options
->print_all
) {
1004 printf(", %s(EP) = ", minmax
);
1005 value_print(stdout
, VALUE_FMT
, n
);
1012 fprintf(stderr
, "Error !\n");
1013 fprintf(stderr
, "%s(", minmax
);
1014 value_print(stderr
, VALUE_FMT
, z
[0]);
1015 for (k
= 1; k
< nparam
; ++k
) {
1016 fprintf(stderr
,", ");
1017 value_print(stderr
, VALUE_FMT
, z
[k
]);
1019 fprintf(stderr
, ") should be ");
1020 if (options
->barvinok
->bernstein_optimize
== BV_BERNSTEIN_MAX
)
1021 fprintf(stderr
, "greater");
1023 fprintf(stderr
, "smaller");
1024 fprintf(stderr
, " than or equal to ");
1025 value_print(stderr
, VALUE_FMT
, n
);
1026 fprintf(stderr
, ", while pl eval gives ");
1027 value_print(stderr
, VALUE_FMT
, m
);
1028 fprintf(stderr
, ".\n");
1029 cerr
<< *max_data
->pl
<< endl
;
1030 } else if (options
->print_all
)
1040 static int verify(Polyhedron
*D
, piecewise_lst
*pl
, evalue
*EP
,
1041 unsigned nvar
, unsigned nparam
, Vector
*p
,
1042 struct verify_options
*options
)
1045 unsigned MaxRays
= options
->barvinok
->MaxRays
;
1046 assert(value_zero_p(EP
->d
));
1047 assert(EP
->x
.p
->type
== partition
);
1050 CS
= check_poly_context_scan(NULL
, &D
, D
->Dimension
, options
);
1052 check_poly_init(D
, options
);
1054 if (!(CS
&& emptyQ2(CS
))) {
1055 check_poly_max_data
data(p
->p
, EP
, pl
);
1056 data
.S
= ALLOCN(Polyhedron
*, EP
->x
.p
->size
/2);
1057 for (int i
= 0; i
< EP
->x
.p
->size
/2; ++i
) {
1058 Polyhedron
*A
= EVALUE_DOMAIN(EP
->x
.p
->arr
[2*i
]);
1059 data
.S
[i
] = Polyhedron_Scan(A
, D
, MaxRays
& POL_NO_DUAL
? 0 : MaxRays
);
1061 ok
= check_poly(CS
, &data
, nparam
, 0, p
->p
+1+nvar
, options
);
1062 for (int i
= 0; i
< EP
->x
.p
->size
/2; ++i
)
1063 Domain_Free(data
.S
[i
]);
1067 if (!options
->print_all
)
1078 static int verify(piecewise_lst
*pl
, evalue
*EP
, unsigned nvar
, unsigned nparam
,
1079 struct verify_options
*options
)
1083 p
= Vector_Alloc(nvar
+nparam
+2);
1084 value_set_si(p
->p
[nvar
+nparam
+1], 1);
1086 for (int i
= 0; i
< pl
->list
.size(); ++i
) {
1087 int ok
= verify(pl
->list
[i
].first
, pl
, EP
, nvar
, nparam
, p
, options
);
1088 if (!ok
&& !options
->continue_on_error
)
1097 static int optimize(evalue
*EP
, char **all_vars
, unsigned nvar
, unsigned nparam
,
1098 struct options
*options
)
1101 piecewise_lst
*pl
= NULL
;
1102 U
= Universe_Polyhedron(nparam
);
1103 int print_solution
= 1;
1107 params
= constructParameterVector(all_vars
+nvar
, nparam
);
1109 if (options
->verify
.verify
) {
1110 verify_options_set_range(&options
->verify
, nvar
+nparam
);
1111 if (!options
->verbose
)
1115 options
->verify
.barvinok
->bernstein_recurse
= options
->recurse
;
1116 if (options
->minimize
)
1117 options
->verify
.barvinok
->bernstein_optimize
= BV_BERNSTEIN_MIN
;
1119 options
->verify
.barvinok
->bernstein_optimize
= BV_BERNSTEIN_MAX
;
1120 pl
= evalue_bernstein_coefficients(NULL
, EP
, U
, params
,
1121 options
->verify
.barvinok
);
1123 if (options
->minimize
)
1128 cout
<< *pl
<< endl
;
1129 if (options
->verify
.verify
)
1130 result
= verify(pl
, EP
, nvar
, nparam
, &options
->verify
);
1138 int main(int argc
, char **argv
)
1141 char **all_vars
= NULL
;
1144 struct options options
;
1145 struct barvinok_options
*bv_options
= barvinok_options_new_with_defaults();
1146 static struct argp_child argp_children
[] = {
1147 { &convert_argp
, 0, "input conversion", 1 },
1148 { &verify_argp
, 0, "verification", 2 },
1151 static struct argp argp
= { argp_options
, parse_opt
, 0, 0, argp_children
};
1154 options
.verify
.barvinok
= bv_options
;
1155 set_program_name(argv
[0]);
1156 argp_parse(&argp
, argc
, argv
, 0, 0, &options
);
1158 EP
= evalue_read(stdin
, options
.var_list
, &all_vars
, &nvar
, &nparam
,
1159 bv_options
->MaxRays
);
1163 evalue_split_periods(EP
, options
.split
, bv_options
->MaxRays
);
1165 evalue_convert(EP
, &options
.convert
, options
.verbose
, nparam
, all_vars
);
1167 if (EVALUE_IS_ZERO(*EP
))
1168 print_evalue(stdout
, EP
, all_vars
);
1170 result
= optimize(EP
, all_vars
, nvar
, nparam
, &options
);
1172 free_evalue_refs(EP
);
1175 if (options
.var_list
)
1176 free(options
.var_list
);
1177 Free_ParamNames(all_vars
, nvar
+nparam
);
1178 barvinok_options_free(bv_options
);