2 This file is part of PolyLib.
4 PolyLib is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 PolyLib is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with PolyLib. If not, see <http://www.gnu.org/licenses/>.
23 #include <polylib/polylib.h>
26 void Union_Read(Polyhedron
**P
, Polyhedron
**C
, const char ***param_name
)
30 unsigned NbRows
, NbColumns
;
31 char s
[1025], param
[1025];
41 if( fgets(s
, 1024, stdin
) == 0 )
44 while ( (*s
=='#' || *s
=='\n') && f
);
46 if( f
&& sscanf(s
, "%d %d", &NbRows
, &NbColumns
)==2 )
48 /* gets old pm and add it to the union */
50 if( pm
->NbColumns
!= ((*P
)->Dimension
)+2 )
53 "Polyhedra must be in the same dimension space !\n");
56 ptmp
= Constraints2Polyhedron(pm
, 200);
61 /* reads the new pm */
62 pm
= Matrix_Alloc(NbRows
, NbColumns
);
63 Matrix_Read_Input( pm
);
69 /* Context : last read pm */
70 *C
= Constraints2Polyhedron(pm
, 200);
76 char **pp
= (char **)malloc((*C
)->Dimension
*sizeof(char *));
77 *param_name
= (const char **)pp
;
78 /* read the parameter names */
80 for( i
=0 ; i
<(*C
)->Dimension
; ++i
)
85 if( s
[c
]==' ' || s
[c
]=='\n' || s
[c
]==0 ) {
94 /* else, no parameters (use default) */
98 pp
[i
] = (char *)malloc(j
);
101 if( i
!= (*C
)->Dimension
)
104 *param_name
= Read_ParamNames(NULL
,(*C
)->Dimension
);
108 *param_name
= Read_ParamNames(NULL
,(*C
)->Dimension
);
112 void recurse(Polyhedron
*C
, const char **param_name
, Enumeration
*e
,
113 Value
*pmin
, Value
*pmax
, Value
*p
, int l
)
115 Value z
, *tmp
; int k
;
117 if( l
== C
->Dimension
)
119 fprintf(stdout
,"EP( ");
120 value_print(stdout
,VALUE_FMT
,p
[0]);
121 for(k
=1;k
<C
->Dimension
;++k
) {
123 value_print(stdout
,VALUE_FMT
,p
[k
]);
125 fprintf(stdout
," ) = ");
126 value_print(stdout
,VALUE_FMT
,*(tmp
=compute_poly(e
,p
)));
129 fprintf(stdout
,"\n");
133 for( value_assign( z
, pmin
[l
]) ; value_le(z
,pmax
[l
]) ; value_increment(z
,z
) )
135 value_assign( p
[l
], z
);
136 recurse ( C
, param_name
, e
, pmin
, pmax
, p
, l
+1 );
144 int main( int argc
, char **argv
)
147 const char **param_name
;
149 Value
*pmin
, *pmax
, *p
; int i
, k
; char str
[256], *s
;
153 fprintf( stderr
, " Usage : %s [< file]\n", argv
[0] );
157 Union_Read( &P
, &C
, ¶m_name
);
159 e
= Domain_Enumerate( P
, C
, 200, param_name
);
161 for( en
=e
; en
; en
=en
->next
)
163 Print_Domain(stdout
,en
->ValidityDomain
, param_name
);
164 print_evalue(stdout
,&en
->EP
, param_name
);
165 printf( "\n-----------------------------------\n" );
168 if( isatty(0) && C
->Dimension
!= 0)
169 { /* no tty input or no polyhedron -> no evaluation. */
170 printf("Evaluation of the Ehrhart polynomial :\n");
171 pmin
= (Value
*)malloc(sizeof(Value
) * (C
->Dimension
));
172 pmax
= (Value
*)malloc(sizeof(Value
) * (C
->Dimension
));
173 p
= (Value
*)malloc(sizeof(Value
) * (C
->Dimension
));
174 for(i
=0;i
<C
->Dimension
;i
++)
182 printf("Enter %d parameters (or intervals, comma separated) : ",C
->Dimension
);
183 for(k
=0;k
<C
->Dimension
;++k
)
186 if( (s
=strpbrk(str
,",")) )
188 value_read(pmin
[k
],str
);
189 value_read(pmax
[k
],(s
+1));
192 { value_read(pmin
[k
],str
);
193 value_assign(pmax
[k
],pmin
[k
]);
197 recurse( C
, param_name
, e
, pmin
, pmax
, p
, 0 );