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)
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"},
35 struct convert_options convert
;
36 struct verify_options verify
;
43 static error_t
parse_opt(int key
, char *arg
, struct argp_state
*state
)
45 struct options
*options
= (struct options
*) state
->input
;
49 state
->child_inputs
[0] = &options
->convert
;
50 state
->child_inputs
[1] = &options
->verify
;
51 state
->child_inputs
[2] = options
->verify
.barvinok
;
52 options
->var_list
= NULL
;
55 options
->minimize
= 0;
61 options
->var_list
= strdup(arg
);
64 options
->split
= atoi(arg
);
67 options
->minimize
= 1;
70 return ARGP_ERR_UNKNOWN
;
76 #define ALLOC(type) (type*)malloc(sizeof(type))
77 #define ALLOCN(type,n) (type*)malloc((n) * sizeof(type))
79 enum token_type
{ TOKEN_UNKNOWN
= 256, TOKEN_VALUE
, TOKEN_IDENT
, TOKEN_GE
,
80 TOKEN_UNION
, TOKEN_VARS
};
94 static struct token
*token_new(int line
, int col
)
96 struct token
*tok
= ALLOC(struct token
);
102 void token_free(struct token
*tok
)
104 if (tok
->type
== TOKEN_VALUE
)
105 value_clear(tok
->u
.v
);
106 else if (tok
->type
== TOKEN_IDENT
)
122 struct token
*tokens
[5];
126 static struct stream
* stream_new(FILE *file
)
129 struct stream
*s
= ALLOC(struct stream
);
132 s
->buffer
= (char*)malloc(s
->size
);
138 for (i
= 0; i
< 5; ++i
)
144 static void stream_free(struct stream
*s
)
147 assert(s
->n_token
== 0);
151 static int stream_getc(struct stream
*s
)
170 static void stream_ungetc(struct stream
*s
, int c
)
176 static void stream_push_char(struct stream
*s
, int c
)
178 if (s
->len
>= s
->size
) {
179 s
->size
= (3*s
->size
)/2;
180 s
->buffer
= (char*)realloc(s
->buffer
, s
->size
);
182 s
->buffer
[s
->len
++] = c
;
185 static struct token
*stream_push_token(struct stream
*s
, struct token
*tok
)
187 assert(s
->n_token
< 5);
188 s
->tokens
[s
->n_token
++] = tok
;
191 static struct token
*stream_next_token(struct stream
*s
)
198 return s
->tokens
[--s
->n_token
];
203 while ((c
= stream_getc(s
)) != -1 && isspace(c
))
225 tok
= token_new(line
, col
);
226 tok
->type
= (token_type
)c
;
229 if (c
== '-' || isdigit(c
)) {
230 tok
= token_new(line
, col
);
231 tok
->type
= TOKEN_VALUE
;
232 value_init(tok
->u
.v
);
233 stream_push_char(s
, c
);
234 while ((c
= stream_getc(s
)) != -1 && isdigit(c
))
235 stream_push_char(s
, c
);
238 if (s
->len
== 1 && s
->buffer
[0] == '-')
239 value_set_si(tok
->u
.v
, -1);
241 stream_push_char(s
, '\0');
242 mpz_set_str(tok
->u
.v
, s
->buffer
, 0);
246 if (c
== '#' || isalpha(c
)) {
247 tok
= token_new(line
, col
);
248 stream_push_char(s
, c
);
249 while ((c
= stream_getc(s
)) != -1 && isalpha(c
))
250 stream_push_char(s
, c
);
253 stream_push_char(s
, '\0');
254 if (!strcmp(s
->buffer
, "#variables")) {
255 tok
->type
= TOKEN_VARS
;
256 } else if (s
->buffer
[0] == '#') {
257 tok
->type
= TOKEN_UNKNOWN
;
258 } else if (!strcmp(s
->buffer
, "UNION")) {
259 tok
->type
= TOKEN_UNION
;
261 tok
->type
= TOKEN_IDENT
;
262 tok
->u
.s
= strdup(s
->buffer
);
267 if ((c
= stream_getc(s
)) == '=') {
268 tok
= token_new(line
, col
);
269 tok
->type
= TOKEN_GE
;
276 tok
= token_new(line
, col
);
277 tok
->type
= TOKEN_UNKNOWN
;
281 void stream_error(struct stream
*s
, struct token
*tok
, char *msg
)
283 int line
= tok
? tok
->line
: s
->line
;
284 int col
= tok
? tok
->col
: s
->col
;
285 fprintf(stderr
, "syntax error (%d, %d): %s\n", line
, col
, msg
);
288 fprintf(stderr
, "got '%c'\n", tok
->type
);
295 struct parameter
*next
;
298 struct parameter
*parameter_new(char *name
, int pos
, struct parameter
*next
)
300 struct parameter
*p
= ALLOC(struct parameter
);
301 p
->name
= strdup(name
);
307 static int parameter_pos(struct parameter
**p
, char *s
)
309 int pos
= *p
? (*p
)->pos
+1 : 0;
312 for (q
= *p
; q
; q
= q
->next
) {
313 if (strcmp(q
->name
, s
) == 0)
319 *p
= parameter_new(s
, pos
, *p
);
323 static int optional_power(struct stream
*s
)
327 tok
= stream_next_token(s
);
330 if (tok
->type
!= '^') {
331 stream_push_token(s
, tok
);
335 tok
= stream_next_token(s
);
336 if (!tok
|| tok
->type
!= TOKEN_VALUE
) {
337 stream_error(s
, tok
, "expecting exponent");
339 stream_push_token(s
, tok
);
342 pow
= VALUE_TO_INT(tok
->u
.v
);
347 static evalue
*evalue_read_factor(struct stream
*s
, struct parameter
**p
);
348 static evalue
*evalue_read_term(struct stream
*s
, struct parameter
**p
);
350 static evalue
*create_fract_like(struct stream
*s
, evalue
*arg
, enode_type type
,
351 struct parameter
**p
)
355 pow
= optional_power(s
);
359 e
->x
.p
= new_enode(type
, pow
+2, -1);
360 value_clear(e
->x
.p
->arr
[0].d
);
361 e
->x
.p
->arr
[0] = *arg
;
363 evalue_set_si(&e
->x
.p
->arr
[1+pow
], 1, 1);
365 evalue_set_si(&e
->x
.p
->arr
[1+pow
], 0, 1);
370 static evalue
*read_fract(struct stream
*s
, struct token
*tok
, struct parameter
**p
)
374 tok
= stream_next_token(s
);
376 assert(tok
->type
== '{');
379 arg
= evalue_read_term(s
, p
);
380 tok
= stream_next_token(s
);
381 if (!tok
|| tok
->type
!= '}') {
382 stream_error(s
, tok
, "expecting \"}\"");
384 stream_push_token(s
, tok
);
388 return create_fract_like(s
, arg
, fractional
, p
);
391 static evalue
*read_periodic(struct stream
*s
, struct parameter
**p
)
399 tok
= stream_next_token(s
);
400 assert(tok
&& tok
->type
== '[');
404 list
= (evalue
**)malloc(len
* sizeof(evalue
*));
408 evalue
*e
= evalue_read_term(s
, p
);
410 stream_error(s
, NULL
, "missing argument or list element");
415 list
= (evalue
**)realloc(list
, len
* sizeof(evalue
*));
419 tok
= stream_next_token(s
);
421 stream_error(s
, NULL
, "unexpected EOF");
424 if (tok
->type
!= ',')
429 if (tok
->type
!= ']') {
430 stream_error(s
, tok
, "expecting \"]\"");
431 stream_push_token(s
, tok
);
437 tok
= stream_next_token(s
);
438 if (tok
->type
== '_') {
441 tok
= stream_next_token(s
);
442 if (!tok
|| tok
->type
!= TOKEN_IDENT
) {
443 stream_error(s
, tok
, "expecting identifier");
445 stream_push_token(s
, tok
);
450 pos
= parameter_pos(p
, tok
->u
.s
);
452 e
->x
.p
= new_enode(periodic
, n
, pos
+1);
454 value_clear(e
->x
.p
->arr
[n
].d
);
455 e
->x
.p
->arr
[n
] = *list
[n
];
459 stream_push_token(s
, tok
);
460 e
= create_fract_like(s
, list
[0], flooring
, p
);
463 stream_error(s
, tok
, "unexpected token");
464 stream_push_token(s
, tok
);
469 free_evalue_refs(list
[n
]);
476 static evalue
*evalue_read_factor(struct stream
*s
, struct parameter
**p
)
481 tok
= stream_next_token(s
);
485 if (tok
->type
== '(') {
487 e
= evalue_read_term(s
, p
);
488 tok
= stream_next_token(s
);
489 if (!tok
|| tok
->type
!= ')') {
490 stream_error(s
, tok
, "expecting \")\"");
492 stream_push_token(s
, tok
);
495 } else if (tok
->type
== TOKEN_VALUE
) {
498 value_set_si(e
->d
, 1);
500 value_assign(e
->x
.n
, tok
->u
.v
);
502 tok
= stream_next_token(s
);
503 if (tok
&& tok
->type
== '/') {
505 tok
= stream_next_token(s
);
506 if (!tok
|| tok
->type
!= TOKEN_VALUE
) {
507 stream_error(s
, tok
, "expecting denominator");
509 stream_push_token(s
, tok
);
512 value_assign(e
->d
, tok
->u
.v
);
515 stream_push_token(s
, tok
);
516 } else if (tok
->type
== TOKEN_IDENT
) {
517 int pos
= parameter_pos(p
, tok
->u
.s
);
518 int pow
= optional_power(s
);
522 e
->x
.p
= new_enode(polynomial
, pow
+1, pos
+1);
523 evalue_set_si(&e
->x
.p
->arr
[pow
], 1, 1);
525 evalue_set_si(&e
->x
.p
->arr
[pow
], 0, 1);
526 } else if (tok
->type
== '[') {
527 stream_push_token(s
, tok
);
528 e
= read_periodic(s
, p
);
529 } else if (tok
->type
== '{') {
530 stream_push_token(s
, tok
);
531 e
= read_fract(s
, tok
, p
);
534 tok
= stream_next_token(s
);
535 if (tok
&& tok
->type
== '*') {
538 e2
= evalue_read_factor(s
, p
);
540 stream_error(s
, NULL
, "unexpected EOF");
544 free_evalue_refs(e2
);
547 stream_push_token(s
, tok
);
552 static evalue
*evalue_read_term(struct stream
*s
, struct parameter
**p
)
557 e
= evalue_read_factor(s
, p
);
561 tok
= stream_next_token(s
);
565 if (tok
->type
== '+') {
568 e2
= evalue_read_term(s
, p
);
570 stream_error(s
, NULL
, "unexpected EOF");
574 free_evalue_refs(e2
);
577 stream_push_token(s
, tok
);
585 struct constraint
*next
;
586 struct constraint
*union_next
;
589 static struct constraint
*constraint_new()
591 struct constraint
*c
= ALLOC(struct constraint
);
593 c
->v
= Vector_Alloc(16);
595 c
->union_next
= NULL
;
599 static void constraint_free(struct constraint
*c
)
602 struct constraint
*next
= c
->next
? c
->next
: c
->union_next
;
609 static void constraint_extend(struct constraint
*c
, int pos
)
612 if (pos
< c
->v
->Size
)
615 v
= Vector_Alloc((3*c
->v
->Size
)/2);
616 Vector_Copy(c
->v
->p
, v
->p
, c
->v
->Size
);
621 static int evalue_read_constraint(struct stream
*s
, struct parameter
**p
,
622 struct constraint
**constraints
,
623 struct constraint
*union_next
)
626 struct constraint
*c
= NULL
;
628 while ((tok
= stream_next_token(s
))) {
631 if (tok
->type
== '+')
633 else if (tok
->type
== TOKEN_IDENT
) {
635 c
= constraint_new();
636 pos
= parameter_pos(p
, tok
->u
.s
);
637 constraint_extend(c
, 1+pos
);
638 value_set_si(c
->v
->p
[1+pos
], 1);
640 } else if (tok
->type
== TOKEN_VALUE
) {
642 c
= constraint_new();
643 tok2
= stream_next_token(s
);
644 if (tok2
&& tok2
->type
== TOKEN_IDENT
) {
645 pos
= parameter_pos(p
, tok2
->u
.s
);
646 constraint_extend(c
, 1+pos
);
647 value_assign(c
->v
->p
[1+pos
], tok
->u
.v
);
652 stream_push_token(s
, tok2
);
653 value_assign(c
->v
->p
[0], tok
->u
.v
);
656 } else if (tok
->type
== TOKEN_GE
|| tok
->type
== '=') {
657 int type
= tok
->type
== TOKEN_GE
;
659 tok
= stream_next_token(s
);
660 if (!tok
|| tok
->type
!= TOKEN_VALUE
|| value_notzero_p(tok
->u
.v
)) {
661 stream_error(s
, tok
, "expecting \"0\"");
663 stream_push_token(s
, tok
);
667 c
->next
= *constraints
;
668 c
->union_next
= union_next
;
675 stream_push_token(s
, tok
);
677 stream_error(s
, tok
, "unexpected token");
686 static struct constraint
*evalue_read_domain(struct stream
*s
, struct parameter
**p
,
689 struct constraint
*constraints
= NULL
;
690 struct constraint
*union_next
= NULL
;
694 tok
= stream_next_token(s
);
697 stream_push_token(s
, tok
);
700 while (evalue_read_constraint(s
, p
, &constraints
, union_next
)) {
701 tok
= stream_next_token(s
);
703 if (tok
->type
== TOKEN_UNION
) {
705 tok
= stream_next_token(s
);
707 stream_error(s
, NULL
, "unexpected EOF");
710 stream_push_token(s
, tok
);
711 union_next
= constraints
;
715 stream_push_token(s
, tok
);
716 /* empty line separates domain from evalue */
717 if (tok
->line
> line
+1)
727 struct constraint
*constraints
;
729 struct section
*next
;
732 static char **extract_parameters(struct parameter
*p
, unsigned *nparam
)
737 *nparam
= p
? p
->pos
+1 : 0;
738 params
= ALLOCN(char *, *nparam
);
739 for (i
= 0; i
< *nparam
; ++i
) {
740 struct parameter
*next
= p
->next
;
741 params
[p
->pos
] = p
->name
;
748 static Polyhedron
*constraints2domain(struct constraint
*constraints
,
749 unsigned nparam
, unsigned MaxRays
)
754 struct constraint
*c
;
755 struct constraint
*union_next
= NULL
;
757 for (n
= 0, c
= constraints
; c
; ++n
, c
= c
->next
)
759 M
= Matrix_Alloc(n
, 1+nparam
+1);
761 struct constraint
*next
= constraints
->next
;
762 union_next
= constraints
->union_next
;
763 Vector_Copy(constraints
->v
->p
+1, M
->p
[n
]+1, nparam
);
764 if (constraints
->type
)
765 value_set_si(M
->p
[n
][0], 1);
766 value_assign(M
->p
[n
][1+nparam
], constraints
->v
->p
[0]);
767 constraints
->next
= NULL
;
768 constraints
->union_next
= NULL
;
769 constraint_free(constraints
);
772 D
= Constraints2Polyhedron(M
, MaxRays
);
776 D
= DomainConcat(D
, constraints2domain(union_next
, nparam
, MaxRays
));
780 static evalue
*evalue_read_partition(struct stream
*s
, struct parameter
*p
,
782 unsigned *nparam
, unsigned MaxRays
)
784 struct section
*part
= NULL
;
785 struct constraint
*constraints
;
789 while ((constraints
= evalue_read_domain(s
, &p
, MaxRays
))) {
790 evalue
*e
= evalue_read_term(s
, &p
);
792 stream_error(s
, NULL
, "missing evalue");
795 struct section
*sect
= ALLOC(struct section
);
796 sect
->constraints
= constraints
;
807 *ppp
= extract_parameters(p
, nparam
);
810 e
->x
.p
= new_enode(partition
, 2*m
, *nparam
);
812 for (j
= 0; j
< m
; ++j
) {
814 struct section
*next
= part
->next
;
815 constraints
= part
->constraints
;
816 D
= constraints2domain(part
->constraints
, *nparam
, MaxRays
);
817 EVALUE_SET_DOMAIN(e
->x
.p
->arr
[2*j
], D
);
818 value_clear(e
->x
.p
->arr
[2*j
+1].d
);
819 e
->x
.p
->arr
[2*j
+1] = *part
->e
;
828 static evalue
*evalue_read(FILE *in
, char *var_list
, char ***ppp
, unsigned *nvar
,
829 unsigned *nparam
, unsigned MaxRays
)
831 struct stream
*s
= stream_new(in
);
834 struct parameter
*p
= NULL
;
839 while ((next
= strchr(var_list
, ','))) {
842 parameter_pos(&p
, var_list
);
846 if (strlen(var_list
) > 0)
847 parameter_pos(&p
, var_list
);
848 nv
= p
? p
->pos
+1 : 0;
852 if (!(tok
= stream_next_token(s
)))
855 if (tok
->type
== TOKEN_VARS
) {
858 tok
= stream_next_token(s
);
859 if (!tok
|| tok
->type
!= TOKEN_IDENT
) {
860 stream_error(s
, tok
, "expecting identifier");
864 parameter_pos(&p
, tok
->u
.s
);
866 tok
= stream_next_token(s
);
867 if (!tok
|| tok
->type
!= ',')
874 nv
= p
? p
->pos
+1 : 0;
877 if (tok
->type
== TOKEN_VALUE
) {
878 struct token
*tok2
= stream_next_token(s
);
880 stream_push_token(s
, tok2
);
881 stream_push_token(s
, tok
);
882 if (tok2
&& (tok2
->type
== TOKEN_IDENT
|| tok2
->type
== TOKEN_GE
))
883 e
= evalue_read_partition(s
, p
, ppp
, nparam
, MaxRays
);
885 e
= evalue_read_term(s
, &p
);
886 *ppp
= extract_parameters(p
, nparam
);
888 } else if (tok
->type
== TOKEN_IDENT
) {
889 stream_push_token(s
, tok
);
890 e
= evalue_read_partition(s
, p
, ppp
, nparam
, MaxRays
);
892 stream_error(s
, tok
, "unexpected token");
893 *nparam
= nv
== -1 ? 0 : nv
;
905 static int check_poly_max(const struct check_poly_data
*data
,
906 int nparam
, Value
*z
,
907 const struct verify_options
*options
);
909 struct check_poly_max_data
: public check_poly_data
{
914 check_poly_max_data(Value
*z
, evalue
*EP
, piecewise_lst
*pl
) :
917 this->check
= check_poly_max
;
921 static void optimum(Polyhedron
*S
, int pos
, const check_poly_max_data
*data
,
922 Value
*opt
, bool& found
,
923 const struct verify_options
*options
)
928 value_set_double(c
, compute_evalue(data
->EP
, data
->z
+1)+.25);
930 value_assign(*opt
, c
);
933 if (options
->barvinok
->bernstein_optimize
== BV_BERNSTEIN_MAX
) {
934 if (value_gt(c
, *opt
))
935 value_assign(*opt
, c
);
937 if (value_lt(c
, *opt
))
938 value_assign(*opt
, c
);
947 ok
= !(lower_upper_bounds(1+pos
, S
, data
->z
, &LB
, &UB
));
949 for (; value_le(LB
, UB
); value_increment(LB
, LB
)) {
950 value_assign(data
->z
[1+pos
], LB
);
951 optimum(S
->next
, pos
+1, data
, opt
, found
, options
);
953 value_set_si(data
->z
[1+pos
], 0);
959 static void optimum(const check_poly_max_data
*data
, Value
*opt
,
960 const struct verify_options
*options
)
963 for (int i
= 0; i
< data
->EP
->x
.p
->size
/2; ++i
)
964 if (!emptyQ2(data
->S
[i
]))
965 optimum(data
->S
[i
], 0, data
, opt
, found
, options
);
969 static int check_poly_max(const struct check_poly_data
*data
,
970 int nparam
, Value
*z
,
971 const struct verify_options
*options
)
975 const check_poly_max_data
*max_data
;
976 max_data
= static_cast<const check_poly_max_data
*>(data
);
983 if (options
->barvinok
->bernstein_optimize
== BV_BERNSTEIN_MAX
)
988 max_data
->pl
->evaluate(nparam
, z
, &n
, &d
);
989 if (options
->barvinok
->bernstein_optimize
== BV_BERNSTEIN_MAX
)
994 if (options
->print_all
) {
995 printf("%s(", minmax
);
996 value_print(stdout
, VALUE_FMT
, z
[0]);
997 for (k
= 1; k
< nparam
; ++k
) {
999 value_print(stdout
, VALUE_FMT
, z
[k
]);
1002 value_print(stdout
, VALUE_FMT
, n
);
1003 if (value_notone_p(d
)) {
1005 value_print(stdout
, VALUE_FMT
, d
);
1008 value_print(stdout
, VALUE_FMT
, m
);
1012 optimum(max_data
, &n
, options
);
1014 if (options
->barvinok
->bernstein_optimize
== BV_BERNSTEIN_MAX
)
1015 ok
= value_ge(m
, n
);
1017 ok
= value_le(m
, n
);
1019 if (options
->print_all
) {
1020 printf(", %s(EP) = ", minmax
);
1021 value_print(stdout
, VALUE_FMT
, n
);
1028 fprintf(stderr
, "Error !\n");
1029 fprintf(stderr
, "%s(", minmax
);
1030 value_print(stderr
, VALUE_FMT
, z
[0]);
1031 for (k
= 1; k
< nparam
; ++k
) {
1032 fprintf(stderr
,", ");
1033 value_print(stderr
, VALUE_FMT
, z
[k
]);
1035 fprintf(stderr
, ") should be ");
1036 if (options
->barvinok
->bernstein_optimize
== BV_BERNSTEIN_MAX
)
1037 fprintf(stderr
, "greater");
1039 fprintf(stderr
, "smaller");
1040 fprintf(stderr
, " than or equal to ");
1041 value_print(stderr
, VALUE_FMT
, n
);
1042 fprintf(stderr
, ", while pl eval gives ");
1043 value_print(stderr
, VALUE_FMT
, m
);
1044 fprintf(stderr
, ".\n");
1045 cerr
<< *max_data
->pl
<< endl
;
1046 } else if (options
->print_all
)
1056 static int verify(Polyhedron
*D
, piecewise_lst
*pl
, evalue
*EP
,
1057 unsigned nvar
, unsigned nparam
, Vector
*p
,
1058 struct verify_options
*options
)
1061 unsigned MaxRays
= options
->barvinok
->MaxRays
;
1062 assert(value_zero_p(EP
->d
));
1063 assert(EP
->x
.p
->type
== partition
);
1066 CS
= check_poly_context_scan(NULL
, &D
, D
->Dimension
, options
);
1068 check_poly_init(D
, options
);
1070 if (!(CS
&& emptyQ2(CS
))) {
1071 check_poly_max_data
data(p
->p
, EP
, pl
);
1072 data
.S
= ALLOCN(Polyhedron
*, EP
->x
.p
->size
/2);
1073 for (int i
= 0; i
< EP
->x
.p
->size
/2; ++i
) {
1074 Polyhedron
*A
= EVALUE_DOMAIN(EP
->x
.p
->arr
[2*i
]);
1075 data
.S
[i
] = Polyhedron_Scan(A
, D
, MaxRays
& POL_NO_DUAL
? 0 : MaxRays
);
1077 ok
= check_poly(CS
, &data
, nparam
, 0, p
->p
+1+nvar
, options
);
1078 for (int i
= 0; i
< EP
->x
.p
->size
/2; ++i
)
1079 Domain_Free(data
.S
[i
]);
1083 if (!options
->print_all
)
1094 static int verify(piecewise_lst
*pl
, evalue
*EP
, unsigned nvar
, unsigned nparam
,
1095 struct verify_options
*options
)
1099 p
= Vector_Alloc(nvar
+nparam
+2);
1100 value_set_si(p
->p
[nvar
+nparam
+1], 1);
1102 for (int i
= 0; i
< pl
->list
.size(); ++i
) {
1103 int ok
= verify(pl
->list
[i
].first
, pl
, EP
, nvar
, nparam
, p
, options
);
1104 if (!ok
&& !options
->continue_on_error
)
1113 static int optimize(evalue
*EP
, char **all_vars
, unsigned nvar
, unsigned nparam
,
1114 struct options
*options
)
1117 piecewise_lst
*pl
= NULL
;
1118 U
= Universe_Polyhedron(nparam
);
1119 int print_solution
= 1;
1123 params
= constructParameterVector(all_vars
+nvar
, nparam
);
1125 if (options
->verify
.verify
) {
1126 verify_options_set_range(&options
->verify
, nvar
+nparam
);
1127 if (!options
->verbose
)
1131 if (options
->minimize
)
1132 options
->verify
.barvinok
->bernstein_optimize
= BV_BERNSTEIN_MIN
;
1134 options
->verify
.barvinok
->bernstein_optimize
= BV_BERNSTEIN_MAX
;
1135 pl
= evalue_bernstein_coefficients(NULL
, EP
, U
, params
,
1136 options
->verify
.barvinok
);
1138 if (options
->minimize
)
1143 cout
<< *pl
<< endl
;
1144 if (options
->verify
.verify
)
1145 result
= verify(pl
, EP
, nvar
, nparam
, &options
->verify
);
1153 int main(int argc
, char **argv
)
1156 char **all_vars
= NULL
;
1159 struct options options
;
1160 struct barvinok_options
*bv_options
= barvinok_options_new_with_defaults();
1161 static struct argp_child argp_children
[] = {
1162 { &convert_argp
, 0, "input conversion", 1 },
1163 { &verify_argp
, 0, "verification", 2 },
1164 { &barvinok_argp
, 0, "barvinok options", 3 },
1167 static struct argp argp
= { argp_options
, parse_opt
, 0, 0, argp_children
};
1170 options
.verify
.barvinok
= bv_options
;
1171 set_program_name(argv
[0]);
1172 argp_parse(&argp
, argc
, argv
, 0, 0, &options
);
1174 EP
= evalue_read(stdin
, options
.var_list
, &all_vars
, &nvar
, &nparam
,
1175 bv_options
->MaxRays
);
1179 evalue_split_periods(EP
, options
.split
, bv_options
->MaxRays
);
1181 evalue_convert(EP
, &options
.convert
, options
.verbose
, nparam
, all_vars
);
1183 if (EVALUE_IS_ZERO(*EP
))
1184 print_evalue(stdout
, EP
, all_vars
);
1186 result
= optimize(EP
, all_vars
, nvar
, nparam
, &options
);
1188 free_evalue_refs(EP
);
1191 if (options
.var_list
)
1192 free(options
.var_list
);
1193 Free_ParamNames(all_vars
, nvar
+nparam
);
1194 barvinok_options_free(bv_options
);