fixed a small bug in eval ehrhart
[polylib.git] / applications / ehrhart_union.c
blob8e3c6962549b232f83a3ce0d46937c11c8c0f1d5
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
5 #include <polylib/polylib.h>
8 void Union_Read( Polyhedron **P, Polyhedron **C, char ***param_name )
10 Matrix *pm;
11 Polyhedron *ptmp;
12 unsigned NbRows, NbColumns;
13 char s[1025], param[1025];
14 int i, j, c, f;
16 *P = NULL;
17 pm = Matrix_Read();
18 f=1;
19 while( f )
23 if( fgets(s, 1024, stdin) == 0 )
24 f=0;
26 while ( (*s=='#' || *s=='\n') && f );
28 if( f && sscanf(s, "%d %d", &NbRows, &NbColumns)==2 )
30 /* gets old pm and add it to the union */
31 if( *P )
32 if( pm->NbColumns != ((*P)->Dimension)+2 )
34 fprintf( stderr,
35 "Polyhedra must be in the same dimension space !\n");
36 exit(0);
38 ptmp = Constraints2Polyhedron(pm, 200);
39 ptmp->next = *P;
40 *P = ptmp;
41 Matrix_Free(pm);
43 /* reads the new pm */
44 pm = Matrix_Alloc(NbRows, NbColumns);
45 Matrix_Read_Input( pm );
47 else
48 break;
51 /* Context : last read pm */
52 *C = Constraints2Polyhedron(pm, 200);
53 Matrix_Free(pm);
56 if( f )
58 /* read the parameter names */
59 *param_name = (char **)malloc( (*C)->Dimension*sizeof(char *) );
60 c = 0;
61 for( i=0 ; i<(*C)->Dimension ; ++i )
63 j=0;
64 for( ; ; ++c )
66 if( s[c]==' ' || s[c]=='\n' || s[c]==0 ) {
67 if( j==0 )
68 continue;
69 else
70 break;
72 param[j++] = s[c];
75 /* else, no parameters (use default) */
76 if( j==0 )
77 break;
78 param[j] = 0;
79 (*param_name)[i] = (char *)malloc( j );
80 strcpy( (*param_name)[i], param );
82 if( i != (*C)->Dimension )
84 free( *param_name );
85 *param_name = Read_ParamNames(NULL,(*C)->Dimension);
88 else
89 *param_name = Read_ParamNames(NULL,(*C)->Dimension);
95 int main( int argc, char **argv)
97 Polyhedron *P, *C;
98 char **param_name;
99 Enumeration *e, *en;
101 if( argc != 1 )
103 fprintf( stderr, " Usage : %s [< file]\n", argv[0] );
104 return( -1 );
107 Union_Read( &P, &C, &param_name );
109 e = Domain_Enumerate( P, C, 200, param_name );
111 for( en=e ; en ; en=en->next )
113 Print_Domain(stdout,en->ValidityDomain, param_name);
114 print_evalue(stdout,&en->EP, param_name);
115 printf( "\n-----------------------------------\n" );
118 return( 0 );