1 /******************************************************************************
2 * PIP : Parametric Integer Programming *
3 ******************************************************************************
5 ******************************************************************************
7 * Copyright Paul Feautrier, 1988-2005 *
9 * This library is free software; you can redistribute it and/or modify it *
10 * under the terms of the GNU Lesser General Public License as published by *
11 * the Free Software Foundation; either version 2.1 of the License, or (at *
12 * your option) any later version. *
14 * This software is distributed in the hope that it will be useful, but *
15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
19 * You should have received a copy of the GNU Lesser General Public License *
20 * along with this library; if not, write to the Free Software Foundation, *
21 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
23 * Written by Paul Feautrier *
25 ******************************************************************************/
30 #include <sys/types.h>
35 #define min(x,y) ((x) < (y)? (x) : (y))
41 #include <sys/times.h>
45 static char version
[] = "Version "PIPLIB_HEAD
"\n";
48 extern long int cross_product
, limit
;
49 extern int allocation
, comptage
, verbose
;
51 extern int compa_count
;
52 extern int deepest_cut
;
54 void balance(FILE *foo
, FILE *bar
)
58 while((c
= dgetc(foo
)) != EOF
)
61 {case '(' : level
++; break;
62 case ')' : if(--level
== 0) return;
68 void escape(FILE *foo
, FILE *bar
, int level
)
70 while((c
= dgetc(foo
)) != EOF
)
72 {case '(' : level
++; break;
73 case ')' : if(--level
== 0)
74 { fprintf(bar
, "\nSyntax error\n)\n");
82 int main(int argc
, char *argv
[])
85 Tableau
*ineq
, *context
, *ctxt
;
86 int nvar
, nparm
, ni
, nc
, bigparm
;
89 struct high_water_mark hq
;
95 #if defined(LINEAR_VALUE_IS_MP)
101 #if defined(LINEAR_VALUE_IS_MP)
102 mpz_init_set_si(UN
, 1);
103 mpz_init_set_si(ZERO
, 0);
109 in
= stdin
; out
= stdout
;
112 { if(strcmp(argv
[1], "-s") == 0)
116 /* the number of 'v' in the verbose option control the amount of debug
117 * information generated by Pip.
120 if(strncmp(argv
[1], "-v", 2) == 0)
123 while(*g
++ == 'v') verbose
++;
126 dump
= pip_create_dump_file();
130 if(argc
>p
&& strcmp(argv
[p
], "-d") == 0)
136 if(verbose
>= 0) fprintf(stderr
, version
);
138 { if(strcmp(argv
[p
], "-z") == 0)
143 in
= fopen(argv
[p
], "r");
145 { fprintf(stderr
, "%s unaccessible\n", argv
[p
]);
151 { out
= fopen(argv
[p
], "w");
153 { fprintf(stderr
, "%s unaccessible\n", argv
[p
]);
160 if(argc
> p
) limit
= atol(argv
[p
]);
163 while((c
= dgetc(in
)) != EOF
)
164 {if(c
!= '(') continue;
167 #if defined(LINEAR_VALUE_IS_MP)
168 if(dscanf(in
, x
) < 0){escape(in
, out
, 1); continue;}
170 nvar
= mpz_get_si(x
);
171 if(dscanf(in
, x
) < 0){escape(in
, out
, 1); continue;}
173 nparm
= mpz_get_si(x
);
174 if(dscanf(in
, x
) < 0){escape(in
, out
, 1); continue;}
177 if(dscanf(in
, x
) < 0){escape(in
, out
, 1); continue;}
180 if(dscanf(in
, x
) < 0){escape(in
, out
, 1); continue;}
182 bigparm
= mpz_get_si(x
);
183 if(dscanf(in
, x
) < 0){escape(in
, out
, 1); continue;}
187 if(dscanf(in
, &x
) < 0){escape(in
, out
, 1); continue;}
190 if(dscanf(in
, &x
) < 0){escape(in
, out
, 1); continue;}
193 if(dscanf(in
, &x
) < 0){escape(in
, out
, 1); continue;}
196 if(dscanf(in
, &x
) < 0){escape(in
, out
, 1); continue;}
199 if(dscanf(in
, &x
) < 0){escape(in
, out
, 1); continue;}
202 if(dscanf(in
, &x
) < 0){escape(in
, out
, 1); continue;}
207 if(verbose
> 0) {fprintf(dump
, "%d %d %d %d %d %d\n",nvar
, nparm
, ni
, nc
,
213 if(verbose
> 0) {fprintf(dump
, "hwm %x\n", g
);
216 ineq
= tab_get(in
, ni
, nvar
+nparm
+1, nvar
);
218 tab_simplify(ineq
, nvar
);
219 if(ineq
== NULL
){escape(in
, out
, 2); continue;}
220 context
= tab_get(in
, nc
, nparm
+1, 0);
222 tab_simplify(context
, nparm
);
223 if(context
== NULL
){escape(in
, out
, 2); continue;}
225 /* verification de la non-vacuite' du contexte */
227 {ctxt
= expanser(context
, nparm
, nc
, nparm
+1, nparm
, 0, 0);
228 traiter(ctxt
, NULL
, nparm
, 0, nc
, 0, -1, TRAITER_INT
);
229 non_vide
= is_not_Nil(p
);
232 else non_vide
= Pip_True
;
235 traiter(ineq
, context
, nvar
, nparm
, ni
, nc
, bigparm
, nq
? TRAITER_INT
: 0);
237 fprintf(dump
, "det: ");
238 #if defined(LINEAR_VALUE_IS_MP)
239 mpz_out_str(dump
, 10, ineq
->determinant
);
241 for (i
=0; i
<ineq
->l_determinant
; i
++) {
242 fprintf(dump
, FORMAT
, ineq
->determinant
[i
]);
249 if(simple
) sol_simplify(xq
);
251 while((xq
= sol_edit(out
, xq
)) != q
);
254 else fprintf(out
, "void\n");
256 if(verbose
> 0) fflush(dump
);
257 /* add a right parenthesis in order to keep the output in balance */
261 fprintf(stderr
,"cross : %ld, alloc : %d, compa : %d\n\r",
262 cross_product
, allocation
, compa_count
);
267 fprintf(stderr
, "n %d u %d''' s %d'''\r\n",
268 comptage
, chrono
.tms_utime
, chrono
.tms_stime
);
271 #if defined(LINEAR_VALUE_IS_MP)