4 #include <barvinok/util.h>
5 #include <barvinok/options.h>
6 #include <barvinok/basis_reduction.h>
9 #define ALLOCN(type,n) (type*)malloc((n) * sizeof(type))
11 struct argp_option argp_options
[] = {
12 #if defined(HAVE_LIBCDDGMP) || defined(HAVE_LIBGLPK)
13 { "direct", 'd', 0, 0,
14 "don't apply generalized basis reduction first" },
20 struct barvinok_options
*barvinok
;
24 error_t
parse_opt(int key
, char *arg
, struct argp_state
*state
)
26 struct options
*options
= state
->input
;
30 state
->child_inputs
[0] = options
->barvinok
;
31 #if defined(HAVE_LIBCDDGMP) || defined(HAVE_LIBGLPK)
41 printf(barvinok_version());
44 return ARGP_ERR_UNKNOWN
;
49 static void scan_poly(Polyhedron
*S
, int pos
, Value
*z
, Matrix
*T
)
55 v
= Vector_Alloc(T
->NbRows
);
56 Matrix_Vector_Product(T
, z
+1, v
->p
);
57 value_print(stdout
, VALUE_FMT
, v
->p
[0]);
58 for (k
=1; k
< pos
; ++k
) {
60 value_print(stdout
,VALUE_FMT
, v
->p
[k
]);
70 ok
= !(lower_upper_bounds(1+pos
, S
, z
, &LB
, &UB
));
72 for (value_assign(tmp
,LB
); value_le(tmp
,UB
); value_increment(tmp
,tmp
)) {
73 value_assign(z
[pos
+1], tmp
);
74 scan_poly(S
->next
, pos
+1, z
, T
);
76 value_set_si(z
[pos
+1], 0);
83 int main(int argc
, char **argv
)
85 Polyhedron
*A
, *P
, *U
, *S
;
88 Matrix
*basis
, *T
, *inv
;
90 struct barvinok_options
*bv_options
= barvinok_options_new_with_defaults();
91 static struct argp_child argp_children
[] = {
92 { &barvinok_argp
, 0, 0, 0 },
95 static struct argp argp
= { argp_options
, parse_opt
, 0, 0, argp_children
};
96 struct options options
;
98 options
.barvinok
= bv_options
;
100 set_program_name(argv
[0]);
101 argp_parse(&argp
, argc
, argv
, 0, 0, &options
);
103 A
= Polyhedron_Read(bv_options
->MaxRays
);
105 if (options
.direct
) {
106 inv
= Identity(A
->Dimension
+1);
109 basis
= Polyhedron_Reduced_Basis(A
, bv_options
);
111 T
= Matrix_Alloc(A
->Dimension
+1, A
->Dimension
+1);
112 inv
= Matrix_Alloc(A
->Dimension
+1, A
->Dimension
+1);
113 for (i
= 0; i
< A
->Dimension
; ++i
)
114 for (j
= 0; j
< A
->Dimension
; ++j
)
115 value_assign(T
->p
[i
][j
], basis
->p
[i
][j
]);
116 value_set_si(T
->p
[A
->Dimension
][A
->Dimension
], 1);
119 ok
= Matrix_Inverse(T
, inv
);
123 P
= Polyhedron_Preimage(A
, inv
, bv_options
->MaxRays
);
127 U
= Universe_Polyhedron(0);
128 S
= Polyhedron_Scan(P
, U
, bv_options
->MaxRays
);
130 p
= ALLOCN(Value
, P
->Dimension
+2);
131 for(i
=0;i
<=P
->Dimension
;i
++) {
133 value_set_si(p
[i
],0);
136 value_set_si(p
[i
],1);
138 scan_poly(S
, 0, p
, inv
);
141 for(i
=0;i
<=(P
->Dimension
+1);i
++)
147 barvinok_options_free(bv_options
);