6 #include <polylib/polylib.h>
9 void Union_Read(Polyhedron
**P
, Polyhedron
**C
, const char ***param_name
)
13 unsigned NbRows
, NbColumns
;
14 char s
[1025], param
[1025];
24 if( fgets(s
, 1024, stdin
) == 0 )
27 while ( (*s
=='#' || *s
=='\n') && f
);
29 if( f
&& sscanf(s
, "%d %d", &NbRows
, &NbColumns
)==2 )
31 /* gets old pm and add it to the union */
33 if( pm
->NbColumns
!= ((*P
)->Dimension
)+2 )
36 "Polyhedra must be in the same dimension space !\n");
39 ptmp
= Constraints2Polyhedron(pm
, 200);
44 /* reads the new pm */
45 pm
= Matrix_Alloc(NbRows
, NbColumns
);
46 Matrix_Read_Input( pm
);
52 /* Context : last read pm */
53 *C
= Constraints2Polyhedron(pm
, 200);
59 char **pp
= (char **)malloc((*C
)->Dimension
*sizeof(char *));
60 *param_name
= (const char **)pp
;
61 /* read the parameter names */
63 for( i
=0 ; i
<(*C
)->Dimension
; ++i
)
68 if( s
[c
]==' ' || s
[c
]=='\n' || s
[c
]==0 ) {
77 /* else, no parameters (use default) */
81 pp
[i
] = (char *)malloc(j
);
84 if( i
!= (*C
)->Dimension
)
87 *param_name
= Read_ParamNames(NULL
,(*C
)->Dimension
);
91 *param_name
= Read_ParamNames(NULL
,(*C
)->Dimension
);
95 void recurse(Polyhedron
*C
, const char **param_name
, Enumeration
*e
,
96 Value
*pmin
, Value
*pmax
, Value
*p
, int l
)
100 if( l
== C
->Dimension
)
102 fprintf(stdout
,"EP( ");
103 value_print(stdout
,VALUE_FMT
,p
[0]);
104 for(k
=1;k
<C
->Dimension
;++k
) {
106 value_print(stdout
,VALUE_FMT
,p
[k
]);
108 fprintf(stdout
," ) = ");
109 value_print(stdout
,VALUE_FMT
,*(tmp
=compute_poly(e
,p
)));
112 fprintf(stdout
,"\n");
116 for( value_assign( z
, pmin
[l
]) ; value_le(z
,pmax
[l
]) ; value_increment(z
,z
) )
118 value_assign( p
[l
], z
);
119 recurse ( C
, param_name
, e
, pmin
, pmax
, p
, l
+1 );
127 int main( int argc
, char **argv
)
130 const char **param_name
;
132 Value
*pmin
, *pmax
, *p
; int i
, k
; char str
[256], *s
;
136 fprintf( stderr
, " Usage : %s [< file]\n", argv
[0] );
140 Union_Read( &P
, &C
, ¶m_name
);
142 e
= Domain_Enumerate( P
, C
, 200, param_name
);
144 for( en
=e
; en
; en
=en
->next
)
146 Print_Domain(stdout
,en
->ValidityDomain
, param_name
);
147 print_evalue(stdout
,&en
->EP
, param_name
);
148 printf( "\n-----------------------------------\n" );
151 if( isatty(0) && C
->Dimension
!= 0)
152 { /* no tty input or no polyhedron -> no evaluation. */
153 printf("Evaluation of the Ehrhart polynomial :\n");
154 pmin
= (Value
*)malloc(sizeof(Value
) * (C
->Dimension
));
155 pmax
= (Value
*)malloc(sizeof(Value
) * (C
->Dimension
));
156 p
= (Value
*)malloc(sizeof(Value
) * (C
->Dimension
));
157 for(i
=0;i
<C
->Dimension
;i
++)
165 printf("Enter %d parameters (or intervals, comma separated) : ",C
->Dimension
);
166 for(k
=0;k
<C
->Dimension
;++k
)
169 if( (s
=strpbrk(str
,",")) )
171 value_read(pmin
[k
],str
);
172 value_read(pmax
[k
],(s
+1));
175 { value_read(pmin
[k
],str
);
176 value_assign(pmax
[k
],pmin
[k
]);
180 recurse( C
, param_name
, e
, pmin
, pmax
, p
, 0 );