From 9d6f0267f9c4d085adcde63dda462a3456766c27 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Wed, 24 Dec 2008 22:56:12 +0100 Subject: [PATCH] vector_partition_chambers: computes chambers of vector partition function Requested by Elke Eisenschmidt. --- Makefile.am | 2 +- vector_partition_chambers.c | 109 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 vector_partition_chambers.c diff --git a/Makefile.am b/Makefile.am index d3c77d6..76ad746 100644 --- a/Makefile.am +++ b/Makefile.am @@ -52,7 +52,7 @@ noinst_PROGRAMS = test testlib randomtest \ polyhedron_sample 4coins lexmin @bv_barvinok_bound@ \ @bv_cone_hilbert_basis@ cone_integer_hull \ polytope_lattice_width polytope_minimize \ - polyhedron_integer_hull + polyhedron_integer_hull vector_partition_chambers EXTRA_PROGRAMS = barvinok_bound test_bound cone_hilbert_basis pkginclude_HEADERS = \ barvinok/NTL_QQ.h \ diff --git a/vector_partition_chambers.c b/vector_partition_chambers.c new file mode 100644 index 0000000..f55bcd9 --- /dev/null +++ b/vector_partition_chambers.c @@ -0,0 +1,109 @@ +#include +#include "argp.h" +#include "progname.h" +#include "param_util.h" + +/* This program computes the full-dimensional chambers of the vector + * partition function + * + * A \lambda = u + * + * The input is the matrix A in PolyLib notation. + * The output consists of the number of chambers, followed by + * a constraint description of each chamber in PolyLib notation. + * + * Example run: + * + * $ cat elke + * 2 4 + * + * 1 1 1 1 + * 0 1 2 3 + * + * $ ./vector_partition_chambers < elke + * 3 + * + * 3 4 + * 1 1 -1 0 + * 1 0 1 0 + * 1 0 0 1 + * + * 3 4 + * 1 -1 1 0 + * 1 2 -1 0 + * 1 0 0 1 + * + * 3 4 + * 1 3 -1 0 + * 1 -2 1 0 + * 1 0 0 1 + */ + +static Polyhedron *partition2polyhedron(Matrix *A, + struct barvinok_options *options) +{ + int i; + unsigned nvar, nparam; + Matrix *M; + Polyhedron *P; + + nvar = A->NbColumns; + nparam = A->NbRows; + + M = Matrix_Alloc(nvar + nparam, 1 + nvar + nparam + 1); + assert(M); + + for (i = 0; i < nparam; ++i) { + Vector_Copy(A->p[i], M->p[i] + 1, nvar); + value_set_si(M->p[i][1 + nvar + i], -1); + } + for (i = 0; i < nvar; ++i) { + value_set_si(M->p[nparam + i][0], 1); + value_set_si(M->p[nparam + i][1 + i], 1); + } + + P = Constraints2Polyhedron(M, options->MaxRays); + Matrix_Free(M); + + return P; +} + +int main(int argc, char **argv) +{ + int nchamber; + unsigned nparam; + Matrix *A; + Polyhedron *P, *C; + Param_Polyhedron *PP; + Param_Domain *PD; + struct barvinok_options *options = barvinok_options_new_with_defaults(); + + set_program_name(argv[0]); + argp_parse(&barvinok_argp, argc, argv, 0, 0, options); + + A = Matrix_Read(); + assert(A); + + nparam = A->NbRows; + C = Universe_Polyhedron(nparam); + P = partition2polyhedron(A, options); + Matrix_Free(A); + + PP = Polyhedron2Param_Polyhedron(P, C, options); + Polyhedron_Free(P); + Polyhedron_Free(C); + + nchamber = 0; + for (PD = PP->D; PD; PD = PD->next) + nchamber++; + + printf("%d\n", nchamber); + for (PD = PP->D; PD; PD = PD->next) { + printf("\n"); + Polyhedron_PrintConstraints(stdout, P_VALUE_FMT, PD->Domain); + } + Param_Polyhedron_Free(PP); + + barvinok_options_free(options); + return 0; +} -- 2.11.4.GIT