bernstein: add piecewise_lst::is_equal
[barvinok.git] / polytope_lattice_width.c
blobbfc3716187f0d3c5513f388ead85d57e461b1ebb
1 #include <barvinok/polylib.h>
2 #include <barvinok/evalue.h>
3 #include <barvinok/options.h>
4 #include "lattice_width.h"
5 #include "argp.h"
6 #include "progname.h"
8 struct argp_option argp_options[] = {
9 { "direction", 'd', 0, 0, "print width directions" },
10 { 0 }
13 struct arguments {
14 struct barvinok_options *options;
15 int direction;
18 error_t parse_opt(int key, char *arg, struct argp_state *state)
20 struct arguments *arguments = state->input;
22 switch (key) {
23 case ARGP_KEY_INIT:
24 state->child_inputs[0] = arguments->options;
25 arguments->direction = 0;
26 break;
27 case 'd':
28 arguments->direction = 1;
29 break;
30 default:
31 return ARGP_ERR_UNKNOWN;
33 return 0;
36 int main(int argc, char **argv)
38 Polyhedron *P, *C;
39 Matrix *M;
40 char **param_name;
41 struct arguments arguments;
42 static struct argp_child argp_children[] = {
43 { &barvinok_argp, 0, 0, 0 },
44 { 0 }
46 static struct argp argp = { argp_options, parse_opt, 0, 0, argp_children };
47 struct barvinok_options *options = barvinok_options_new_with_defaults();
48 struct width_direction_array *dirs;
49 int i;
51 arguments.options = options;
53 set_program_name(argv[0]);
54 argp_parse(&argp, argc, argv, 0, 0, &arguments);
56 M = Matrix_Read();
57 assert(M);
58 P = Constraints2Polyhedron(M, options->MaxRays);
59 Matrix_Free(M);
60 M = Matrix_Read();
61 assert(M);
62 C = Constraints2Polyhedron(M, options->MaxRays);
63 Matrix_Free(M);
64 param_name = Read_ParamNames(stdin, C->Dimension);
66 dirs = Polyhedron_Lattice_Width_Directions(P, C, options);
67 for (i = 0; i < dirs->n; ++i) {
68 evalue *E;
70 Print_Domain(stdout, dirs->wd[i].domain, param_name);
71 if (arguments.direction)
72 Vector_Print(stdout, P_VALUE_FMT, dirs->wd[i].dir);
73 E = affine2evalue(dirs->wd[i].width->p,
74 dirs->wd[i].width->p[C->Dimension+1],
75 C->Dimension);
76 print_evalue(stdout, E, param_name);
77 evalue_free(E);
79 free_width_direction_array(dirs);
81 Free_ParamNames(param_name, C->Dimension);
82 Polyhedron_Free(P);
83 Polyhedron_Free(C);
84 barvinok_options_free(options);
86 return 0;