PIPS
integrer.c
Go to the documentation of this file.
1 /*
2 
3  $Id: integrer.c 23065 2016-03-02 09:05:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 #include <stdio.h>
28 #include "pip__type.h"
29 #include "pip__tab.h"
30 
32 Entier x, y;
33 {Entier r;
34  r = x % y;
35  if(r<0) r += y;
36  return(r);
37 }
38 
39 int non_borne(tp, nvar, D, bigparm)
40 Tableau *tp;
41 int nvar, bigparm;
42 Entier D;
43 {int i, ff;
44  for(i = 0; i<nvar; i++)
45  {ff = Flag(tp, i);
46  if(bigparm > 0)
47  {if(ff & Unit)return(True);
48  if(Index(tp, i, bigparm) != D) return(True);
49  }
50  }
51  return(False);
52 }
53 
55 
56 int integrer(ptp, pcontext, D, pnvar, pnparm, pni, pnc)
57 Tableau **ptp, **pcontext;
58 int *pnvar, *pnparm, *pni, *pnc;
59 int D;
60 {int ncol = *pnvar+*pnparm+1;
61  int nligne = *pnvar + *pni;
62  Entier coupure[MAXCOL];
63  int i, j, k, ff;
64  Entier x, d;
65  int ok_var, ok_const, ok_parm;
66  if(D == 1) return(-1); /* attention, en cas de succes, nligne augmente
67  l'echec ne peut donc etre marque par une valeur
68  superieure a nligne */
69  if(ncol >= MAXCOL) {
70  fprintf(stderr, "Trop de colonnes : %d\n", ncol);
71  exit(3);
72  }
73  for(i = 0; i<*pnvar; i++)
74  {
75  ff = Flag(*ptp, i);
76  if(ff & Unit)continue;
77  ok_var = False;
78  for(j = 0; j<*pnvar; j++)
79  {x = coupure[j] = sol_mod(Index(*ptp, i, j), D);
80  if(x > 0) ok_var = True;
81  }
82  if(! ok_var) continue;
83  x = coupure[*pnvar] = - sol_mod(-Index(*ptp, i, *pnvar), D);
84  ok_const = (x != 0);
85  d = x;
86  ok_parm = False;
87  for(j = (*pnvar)+1; j<ncol; j++)
88  {
89  x = coupure[j] = - sol_mod(- Index(*ptp, i, j), D);
90  d = sol_pgcd(d, x);
91  if(x != 0) ok_parm = True;
92  }
93 #if (DEBUG > 2)
94  Q{printf("%ld/cut : %d %d #[", cross_product, *pnvar, *pnparm);
95  for(j = 0; j<ncol; j++)printf(" %d",coupure[j]);
96  printf("]/ %d\n", D);
97  }
98 #endif
99  if(ok_parm)
100  {
101  Entier discrp[MAXPARM], discrm[MAXPARM];
102  if(*pnparm >= MAXPARM) {
103  fprintf(stderr, "Trop de parametres : %d\n", *pnparm);
104  exit(4);
105  }
106  d = sol_pgcd(d, D);
107  sol_new(*pnparm);
108  sol_div();
109  sol_forme(*pnparm+1);
110  for(j = 0; j<*pnparm; j++)sol_val(-coupure[j+*pnvar+1]/d, 1);
111  sol_val(-coupure[*pnvar]/d, 1);
112  sol_val(D/d, 1);
113  for(j = 0; j<*pnparm; j++)
114  {x = coupure[j+*pnvar+1];
115  discrp[j] = -x;
116  discrm[j] = x;
117  }
118  discrp[*pnparm] = -D;
119  discrm[*pnparm] = D;
120  x = coupure[*pnvar];
121  discrp[(*pnparm)+1] = -x;
122  discrm[(*pnparm)+1] = -x + D -1;
123  if((*pnc) +2 > (*pcontext)->height ||
124  (*pnparm) + 2 > (*pcontext)->width)
125  {int dcw, dch;
126  dcw = llog(D);
127  dch = 2 * dcw + *pni;
128  Flag(*pcontext, *pnc) = 0;
129  *pcontext = expanser(*pcontext, 0, *pnc, *pnparm+1, 0,
130  dch, dcw);
131  }
132  (*pnparm)++;
133  for(k = 0; k < *pnc; k++)
134  {Index(*pcontext, k, *pnparm) =
135  Index(*pcontext, k, (*pnparm)-1);
136  Index(*pcontext, k, (*pnparm)-1) = 0;
137  }
138  for(j = 0; j <= *pnparm; j++)
139  {Index(*pcontext, *pnc, j) = discrp[j];
140  Index(*pcontext, *pnc + 1, j) = discrm[j];
141  }
142  Flag(*pcontext, *pnc) = Unknown;
143  Flag(*pcontext, *pnc+1) = Unknown;
144  (*pnc) += 2;
145  coupure[ncol] = D;
146  break;
147  }
148  else if(ok_const)break;
149  }
150  if(i >= *pnvar)return(-1);
151  if(i < *pnvar)
152  {/* y a t'il de la place ? */
153  if(nligne >= (*ptp)->height || ncol >= (*ptp)->width)
154  {int d, dth, dtw;
155  int llog();
156  d = llog(D);
157  dth = d + (*pnparm? *pni : 0);
158  dtw = (*pnparm ? d : 0);
159  *ptp = expanser(*ptp, *pnvar, *pni, ncol, 0, dth, dtw);
160  }
161  ncol = *pnvar + *pnparm + 1;
162  Flag(*ptp, nligne) = Minus;
163  for(j = 0; j<ncol; j++) Index(*ptp, nligne, j) = coupure[j];
164  for(j = ncol; j < (*ptp)->width; j++) Index(*ptp, nligne, j) =0;
165  (*pni)++;
166  }
167  return(nligne);
168 }
169 
#define D(A)
Definition: iabrev.h:56
Entier sol_mod(Entier x, Entier y)
Definition: integrer.c:31
Tableau * expanser()
int integrer(Tableau **ptp, Tableau **pcontext, int D, int *pnvar, int *pnparm, int *pni, int *pnc)
Definition: integrer.c:56
int non_borne(Tableau *tp, int nvar, Entier D, int bigparm)
Definition: integrer.c:39
long int cross_product
Definition: pip.c:91
#define exit(code)
Definition: misc-local.h:54
void sol_new()
int sol_pgcd()
void sol_div()
Definition: sol.c:151
void sol_val()
#define Index(p, i, j)
Definition: pip__tab.h:45
#define Unknown
Definition: pip__tab.h:41
#define Flag(p, i)
Definition: pip__tab.h:46
#define Unit
Definition: pip__tab.h:36
#define Minus
Definition: pip__tab.h:38
#define Entier
Definition: pip__type.h:24
#define MAXPARM
Definition: pip__type.h:42
#define False
Definition: pip__type.h:33
#define Q
Definition: pip__type.h:39
#define True
Definition: pip__type.h:32
#define MAXCOL
Definition: pip__type.h:41
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
int printf()
void sol_forme(int l)
Definition: sol.c:133
static char * x
Definition: split_file.c:159
Definition: pip__tab.h:48
int llog(Entier x)
Definition: traiter.c:39