File: count.c

package info (click to toggle)
polylib 5.22.5-4.2%2Bdfsg
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 14,464 kB
  • sloc: ansic: 16,346; sh: 10,134; makefile: 506
file content (120 lines) | stat: -rw-r--r-- 3,411 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
    This file is part of PolyLib.

    PolyLib is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    PolyLib is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with PolyLib.  If not, see <http://www.gnu.org/licenses/>.
*/

/*************************************************/
/*     count.c                                   */
/* program to count the number of points         */
/* in a parameterized polytope                   */
/*                                               */
/* input : polytope                              */
/*         context                               */
/*                                               */
/* written by Vincent Loechner, aug. 2000.       */
/*  loechner@icps.u-strasbg.fr                   */
/*************************************************/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include <polylib/polylib.h>
#define MAXRAYS 1024

/****************************************************************/
int main(int argc,char *argv[]) {
	
  Matrix *C1, *P1;
  Polyhedron *C, *P, *S;
  Polyhedron *CC, *PP;
  Enumeration *en;
  Value *p;
  int i,j,k;
  int m,M;
  char str[1024];
  Value c;

  /******* Read the input *********/
  P1 = Matrix_Read();
  C1 = Matrix_Read();
  if(C1->NbColumns < 2) {
    fprintf(stderr,"Not enough parameters !\n");
    exit(0);
  }
  P = Constraints2Polyhedron(P1, MAXRAYS);
  C = Constraints2Polyhedron(C1, MAXRAYS);
  Matrix_Free(C1);
  Matrix_Free(P1);
  
  
  /******* Compute the true context *******/
  CC = align_context(C,P->Dimension,MAXRAYS);
  PP = DomainIntersection(P,CC,MAXRAYS);
  Domain_Free(CC);
  C1 = Matrix_Alloc(C->Dimension+1,P->Dimension+1);
  for(i=0;i<C1->NbRows;i++)
    for(j=0;j<C1->NbColumns;j++)
      if(i==j-P->Dimension+C->Dimension)
	value_set_si(C1->p[i][j],1);
      else
	value_set_si(C1->p[i][j],0);
  CC = Polyhedron_Image(PP,C1,MAXRAYS);
  Domain_Free(C);
  Domain_Free(PP);
  Matrix_Free(C1);
  C = CC;
  
  /******* Initialize parameters *********/
  p = (Value *)malloc(sizeof(Value) * (P->Dimension+2));
  for(i=0;i<=P->Dimension;i++) {
    value_init(p[i]);
    value_set_si(p[i],0);
  }
  value_init(p[i]);
  value_set_si(p[i],1);
  
  /*** S = scanning list of polyhedra ***/
  S = Polyhedron_Scan(P,C,MAXRAYS);

  value_init(c);
  
  /******* Count now *********/
  FOREVER {
    fflush(stdin);
    printf("Enter %d parameters : ",C->Dimension);
    for(k=S->Dimension-C->Dimension+1;k<=S->Dimension;++k) {
      scanf(" %s", str);
      value_read(p[k],str);
    }      
    printf("EP( ");
    value_print(stdout,VALUE_FMT,p[S->Dimension-C->Dimension+1]);
    for(k=S->Dimension-C->Dimension+2;k<=S->Dimension;++k) {
      printf(", ");
      value_print(stdout,VALUE_FMT,p[k]);
    }  
    printf(" ) = "); 
    count_points(1,S,p,&c);
    value_print(stdout,VALUE_FMT,c);
    printf("\n"); 
  }
  for(i=0;i<=(P->Dimension+1);i++)
    value_clear(p[i]);
  value_clear(c);
  return(0);
} /* main */