1 /******************************************************************************
2 * PIP : Parametric Integer Programming *
3 ******************************************************************************
5 ******************************************************************************
7 * Copyright Paul Feautrier, 1988-2005 *
9 * This is free software; you can redistribute it and/or modify it under the *
10 * terms of the GNU General Public License as published by the Free Software *
11 * Foundation; either version 2 of the License, or (at your option) any later *
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 General Public License along *
20 * with software; if not, write to the Free Software Foundation, Inc., *
21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
23 * Written by Paul Feautrier *
25 ******************************************************************************/
30 #include <sys/types.h>
35 #define min(x,y) ((x) < (y)? (x) : (y))
40 #include <sys/times.h>
44 char version
[]="Version E.2 $Revision: 1.3 $\n";
47 extern long int cross_product
, limit
;
48 extern int allocation
, comptage
, verbose
;
50 extern int compa_count
;
51 extern char dump_name
[] ;
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
++;
128 { dump
= fopen(g
, "w");
130 { fprintf(stderr
, "%s unaccessible\n", g
);
135 { mkstemp(dump_name
);
136 dump
= fopen(dump_name
, "w");
139 if(argc
>p
&& strcmp(argv
[p
], "-d") == 0)
145 if(verbose
>= 0) fprintf(stderr
, version
);
147 { if(strcmp(argv
[p
], "-z") == 0)
152 in
= fopen(argv
[p
], "r");
154 { fprintf(stderr
, "%s unaccessible\n", argv
[p
]);
160 { out
= fopen(argv
[p
], "w");
162 { fprintf(stderr
, "%s unaccessible\n", argv
[p
]);
169 if(argc
> p
) limit
= atol(argv
[p
]);
172 while((c
= dgetc(in
)) != EOF
)
173 {if(c
!= '(') continue;
176 #if defined(LINEAR_VALUE_IS_MP)
177 if(dscanf(in
, x
) < 0){escape(in
, out
, 1); continue;}
179 nvar
= mpz_get_si(x
);
180 if(dscanf(in
, x
) < 0){escape(in
, out
, 1); continue;}
182 nparm
= mpz_get_si(x
);
183 if(dscanf(in
, x
) < 0){escape(in
, out
, 1); continue;}
186 if(dscanf(in
, x
) < 0){escape(in
, out
, 1); continue;}
189 if(dscanf(in
, x
) < 0){escape(in
, out
, 1); continue;}
191 bigparm
= mpz_get_si(x
);
192 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;}
205 if(dscanf(in
, &x
) < 0){escape(in
, out
, 1); continue;}
208 if(dscanf(in
, &x
) < 0){escape(in
, out
, 1); continue;}
211 if(dscanf(in
, &x
) < 0){escape(in
, out
, 1); continue;}
216 if(verbose
> 0) {fprintf(dump
, "%d %d %d %d %d %d\n",nvar
, nparm
, ni
, nc
,
222 if(verbose
> 0) {fprintf(dump
, "hwm %x\n", g
);
225 ineq
= tab_get(in
, ni
, nvar
+nparm
+1, nvar
);
226 if(ineq
== NULL
){escape(in
, out
, 2); continue;}
227 context
= tab_get(in
, nc
, nparm
+1, 0);
228 if(context
== NULL
){escape(in
, out
, 2); continue;}
230 /* verification de la non-vacuite' du contexte */
232 {ctxt
= expanser(context
, nparm
, nc
, nparm
+1, nparm
, 0, 0);
233 traiter(ctxt
, NULL
, Pip_True
, nparm
, 0, nc
, 0, -1);
234 non_vide
= is_not_Nil(p
);
237 else non_vide
= Pip_True
;
240 traiter(ineq
, context
, nq
, nvar
, nparm
, ni
, nc
, bigparm
);
242 #if defined(LINEAR_VALUE_IS_MP)
243 mpz_out_str(out
, 10, ineq
->determinant
);
245 for(i
=0; i
<ineq
->l_determinant
; i
++) {
246 fprintf(out
, FORMAT
, ineq
->determinant
[i
]);
251 if(simple
) sol_simplify(xq
);
253 while((xq
= sol_edit(out
, xq
)) != q
);
256 else fprintf(out
, "void\n");
258 if(verbose
> 0) fflush(dump
);
259 /* add a right parenthesis in order to keep the output in balance */
263 fprintf(stderr
,"cross : %ld, alloc : %d, compa : %d\n\r",
264 cross_product
, allocation
, compa_count
);
269 fprintf(stderr
, "n %d u %d''' s %d'''\r\n",
270 comptage
, chrono
.tms_utime
, chrono
.tms_stime
);
273 #if defined(LINEAR_VALUE_IS_MP)