5 #include <barvinok/util.h>
6 #include <barvinok/options.h>
7 #include <barvinok/basis_reduction.h>
10 #define ALLOCN(type,n) (type*)malloc((n) * sizeof(type))
12 struct argp_option argp_options
[] = {
13 { "direct", 'd', 0, 0,
14 "don't apply generalized basis reduction first" },
19 struct barvinok_options
*barvinok
;
23 error_t
parse_opt(int key
, char *arg
, struct argp_state
*state
)
25 struct options
*options
= state
->input
;
29 state
->child_inputs
[0] = options
->barvinok
;
36 printf(barvinok_version());
39 return ARGP_ERR_UNKNOWN
;
44 static void scan_poly(Polyhedron
*S
, int pos
, Value
*z
, Matrix
*T
)
50 v
= Vector_Alloc(T
->NbRows
);
51 Matrix_Vector_Product(T
, z
+1, v
->p
);
52 value_print(stdout
, VALUE_FMT
, v
->p
[0]);
53 for (k
=1; k
< pos
; ++k
) {
55 value_print(stdout
,VALUE_FMT
, v
->p
[k
]);
65 ok
= !(lower_upper_bounds(1+pos
, S
, z
, &LB
, &UB
));
67 for (value_assign(tmp
,LB
); value_le(tmp
,UB
); value_increment(tmp
,tmp
)) {
68 value_assign(z
[pos
+1], tmp
);
69 scan_poly(S
->next
, pos
+1, z
, T
);
71 value_set_si(z
[pos
+1], 0);
78 int main(int argc
, char **argv
)
80 Polyhedron
*A
, *P
, *U
, *S
;
83 Matrix
*basis
, *T
, *inv
;
85 struct barvinok_options
*bv_options
= barvinok_options_new_with_defaults();
86 static struct argp_child argp_children
[] = {
87 { &barvinok_argp
, 0, 0, 0 },
90 static struct argp argp
= { argp_options
, parse_opt
, 0, 0, argp_children
};
91 struct options options
;
93 options
.barvinok
= bv_options
;
95 set_program_name(argv
[0]);
96 argp_parse(&argp
, argc
, argv
, 0, 0, &options
);
98 A
= Polyhedron_Read(bv_options
->MaxRays
);
100 if (options
.direct
) {
101 inv
= Identity(A
->Dimension
+1);
104 basis
= Polyhedron_Reduced_Basis(A
, bv_options
);
106 T
= Matrix_Alloc(A
->Dimension
+1, A
->Dimension
+1);
107 inv
= Matrix_Alloc(A
->Dimension
+1, A
->Dimension
+1);
108 for (i
= 0; i
< A
->Dimension
; ++i
)
109 for (j
= 0; j
< A
->Dimension
; ++j
)
110 value_assign(T
->p
[i
][j
], basis
->p
[i
][j
]);
111 value_set_si(T
->p
[A
->Dimension
][A
->Dimension
], 1);
114 ok
= Matrix_Inverse(T
, inv
);
118 P
= Polyhedron_Preimage(A
, inv
, bv_options
->MaxRays
);
122 U
= Universe_Polyhedron(0);
123 S
= Polyhedron_Scan(P
, U
, bv_options
->MaxRays
);
125 p
= ALLOCN(Value
, P
->Dimension
+2);
126 for(i
=0;i
<=P
->Dimension
;i
++) {
128 value_set_si(p
[i
],0);
131 value_set_si(p
[i
],1);
133 scan_poly(S
, 0, p
, inv
);
136 for(i
=0;i
<=(P
->Dimension
+1);i
++)
142 barvinok_options_free(bv_options
);