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 { "direct", 'd', 0, 0,
13 "don't apply generalized basis reduction first" },
18 struct barvinok_options
*barvinok
;
22 error_t
parse_opt(int key
, char *arg
, struct argp_state
*state
)
24 struct options
*options
= state
->input
;
28 state
->child_inputs
[0] = options
->barvinok
;
35 printf(barvinok_version());
38 return ARGP_ERR_UNKNOWN
;
43 static void scan_poly(Polyhedron
*S
, int pos
, Value
*z
, Matrix
*T
)
49 v
= Vector_Alloc(T
->NbRows
);
50 Matrix_Vector_Product(T
, z
+1, v
->p
);
51 value_print(stdout
, VALUE_FMT
, v
->p
[0]);
52 for (k
=1; k
< pos
; ++k
) {
54 value_print(stdout
,VALUE_FMT
, v
->p
[k
]);
64 ok
= !(lower_upper_bounds(1+pos
, S
, z
, &LB
, &UB
));
66 for (value_assign(tmp
,LB
); value_le(tmp
,UB
); value_increment(tmp
,tmp
)) {
67 value_assign(z
[pos
+1], tmp
);
68 scan_poly(S
->next
, pos
+1, z
, T
);
70 value_set_si(z
[pos
+1], 0);
77 int main(int argc
, char **argv
)
79 Polyhedron
*A
, *P
, *U
, *S
;
82 Matrix
*basis
, *T
, *inv
;
84 struct barvinok_options
*bv_options
= barvinok_options_new_with_defaults();
85 static struct argp_child argp_children
[] = {
86 { &barvinok_argp
, 0, 0, 0 },
89 static struct argp argp
= { argp_options
, parse_opt
, 0, 0, argp_children
};
90 struct options options
;
92 options
.barvinok
= bv_options
;
94 set_program_name(argv
[0]);
95 argp_parse(&argp
, argc
, argv
, 0, 0, &options
);
97 A
= Polyhedron_Read(bv_options
->MaxRays
);
100 inv
= Identity(A
->Dimension
+1);
103 basis
= Polyhedron_Reduced_Basis(A
, bv_options
);
105 T
= Matrix_Alloc(A
->Dimension
+1, A
->Dimension
+1);
106 inv
= Matrix_Alloc(A
->Dimension
+1, A
->Dimension
+1);
107 for (i
= 0; i
< A
->Dimension
; ++i
)
108 for (j
= 0; j
< A
->Dimension
; ++j
)
109 value_assign(T
->p
[i
][j
], basis
->p
[i
][j
]);
110 value_set_si(T
->p
[A
->Dimension
][A
->Dimension
], 1);
113 ok
= Matrix_Inverse(T
, inv
);
117 P
= Polyhedron_Preimage(A
, inv
, bv_options
->MaxRays
);
121 U
= Universe_Polyhedron(0);
122 S
= Polyhedron_Scan(P
, U
, bv_options
->MaxRays
);
124 p
= ALLOCN(Value
, P
->Dimension
+2);
125 for(i
=0;i
<=P
->Dimension
;i
++) {
127 value_set_si(p
[i
],0);
130 value_set_si(p
[i
],1);
132 scan_poly(S
, 0, p
, inv
);
135 for(i
=0;i
<=(P
->Dimension
+1);i
++)
141 barvinok_options_free(bv_options
);