fixed a small bug in eval ehrhart
[polylib.git] / doc / codeDoc / html / polyhedron_8c-source.html
blobda40da80b6aaffd307c0c87720a311e17bc7da0f
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
3 <title>polyhedron.c Source File</title>
4 <link href="doxygen.css" rel="stylesheet" type="text/css">
5 </head><body>
6 <!-- Generated by Doxygen 1.2.15 -->
7 <center>
8 <a class="qindex" href="main.html">Main Page</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; </center>
9 <hr><h1>polyhedron.c</h1><a href="polyhedron_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">/* polyhedron.c</font>
10 00002 <font class="comment"> COPYRIGHT</font>
11 00003 <font class="comment"> Both this software and its documentation are</font>
12 00004 <font class="comment"></font>
13 00005 <font class="comment"> Copyright 1993 by IRISA /Universite de Rennes I - France,</font>
14 00006 <font class="comment"> Copyright 1995,1996 by BYU, Provo, Utah</font>
15 00007 <font class="comment"> all rights reserved.</font>
16 00008 <font class="comment"></font>
17 00009 <font class="comment"> Permission is granted to copy, use, and distribute</font>
18 00010 <font class="comment"> for any commercial or noncommercial purpose under the terms</font>
19 00011 <font class="comment"> of the GNU General Public license, version 2, June 1991</font>
20 00012 <font class="comment"> (see file : LICENSING).</font>
21 00013 <font class="comment">*/</font>
22 00014
23 00015 <font class="comment">/*</font>
24 00016 <font class="comment"></font>
25 00017 <font class="comment">1997/12/02 - Olivier Albiez</font>
26 00018 <font class="comment"> Ce fichier contient les fonctions de la polylib de l'IRISA,</font>
27 00019 <font class="comment"> passees en 64bits.</font>
28 00020 <font class="comment"> La structure de la polylib a donc ete modifie pour permettre </font>
29 00021 <font class="comment"> le passage aux Value. La fonction Chernikova a ete reecrite.</font>
30 00022 <font class="comment"></font>
31 00023 <font class="comment">*/</font>
32 00024
33 00025 <font class="comment">/*</font>
34 00026 <font class="comment"></font>
35 00027 <font class="comment">1998/26/02 - Vincent Loechner</font>
36 00028 <font class="comment"> Ajout de nombreuses fonctions, a la fin de ce fichier,</font>
37 00029 <font class="comment"> pour les polyedres parametres 64 bits.</font>
38 00030 <font class="comment">1998/16/03</font>
39 00031 <font class="comment"> #define DEBUG printf</font>
40 00032 <font class="comment"> tests out of memory</font>
41 00033 <font class="comment"> compatibilite avec la version de doran</font>
42 00034 <font class="comment"></font>
43 00035 <font class="comment">*/</font>
44 00036
45 00037 <font class="preprocessor">#undef POLY_DEBUG </font><font class="comment">/* debug printf: general functions */</font>
46 00038 <font class="preprocessor">#undef POLY_RR_DEBUG </font><font class="comment">/* debug printf: Remove Redundants */</font>
47 00039 <font class="preprocessor">#undef POLY_CH_DEBUG </font><font class="comment">/* debug printf: Chernikova */</font>
48 00040
49 00041 <font class="preprocessor">#include &lt;stdio.h&gt;</font>
50 00042 <font class="preprocessor">#include &lt;stdlib.h&gt;</font>
51 00043 <font class="preprocessor">#include &lt;string.h&gt;</font>
52 00044 <font class="preprocessor">#include &lt;<a class="code" href="assert_8h.html">assert.h</a>&gt;</font>
53 00045 <font class="preprocessor">#include &lt;polylib/polylib.h&gt;</font>
54 00046
55 00047 <font class="preprocessor">#ifdef MAC_OS</font>
56 00048 <font class="preprocessor"></font><font class="preprocessor"> #define abs __abs</font>
57 00049 <font class="preprocessor"></font><font class="preprocessor">#endif</font>
58 00050 <font class="preprocessor"></font>
59 00051 <font class="comment">/* WSIZE is the number of bits in a word or int type */</font>
60 <a name="l00052"></a><a class="code" href="polyhedron_8c.html#a0">00052</a> <font class="preprocessor">#define WSIZE (8*sizeof(int)) </font>
61 00053 <font class="preprocessor"></font>
62 <a name="l00054"></a><a class="code" href="polyhedron_8c.html#a1">00054</a> <font class="preprocessor">#define bexchange(a, b, l)\</font>
63 00055 <font class="preprocessor">{\</font>
64 00056 <font class="preprocessor"> char *t = (char *)malloc(l*sizeof(char));\</font>
65 00057 <font class="preprocessor"> memcpy((t), (char *)(a), (int)(l));\</font>
66 00058 <font class="preprocessor"> memcpy((char *)(a), (char *)(b), (int)(l));\</font>
67 00059 <font class="preprocessor"> memcpy((char *)(b), (t), (int)(l));\</font>
68 00060 <font class="preprocessor"> free(t); \</font>
69 00061 <font class="preprocessor">}</font>
70 00062 <font class="preprocessor"></font>
71 <a name="l00063"></a><a class="code" href="polyhedron_8c.html#a2">00063</a> <font class="preprocessor">#define exchange(a, b, t)\</font>
72 00064 <font class="preprocessor">{ (t)=(a); (a)=(b); (b)=(t); }</font>
73 00065 <font class="preprocessor"></font>
74 00066 <font class="comment">/* errormsg1 is an external function which is usually supplied by the</font>
75 00067 <font class="comment"> calling program (e.g. Domlib.c, ReadAlpha, etc...).</font>
76 00068 <font class="comment"> See errormsg.c for an example of such a function. */</font>
77 00069
78 00070 <font class="keywordtype">void</font> <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="keywordtype">char</font> *f , <font class="keywordtype">char</font> *msgname, <font class="keywordtype">char</font> *msg);
79 00071
80 <a name="l00072"></a><a class="code" href="polyhedron_8c.html#a5">00072</a> <font class="keywordtype">int</font> <a class="code" href="polyhedron_8c.html#a5">Pol_status</a>; <font class="comment">/* error status after operations */</font>
81 00073
82 00074 <font class="comment">/*</font>
83 00075 <font class="comment"> * The Saturation matrix is defined to be an integer (int type) matrix.</font>
84 00076 <font class="comment"> * It is a boolean matrix which has a row for every constraint and a column</font>
85 00077 <font class="comment"> * for every line or ray. The bits in the binary format of each integer in </font>
86 00078 <font class="comment"> * the stauration matrix stores the information whether the corresponding</font>
87 00079 <font class="comment"> * constraint is saturated by ray(line) or not. </font>
88 00080 <font class="comment"> */</font>
89 00081
90 <a name="l00082"></a><a class="code" href="structSatMatrix.html">00082</a> <font class="keyword">typedef</font> <font class="keyword">struct </font>{
91 00083 <font class="keywordtype">unsigned</font> <font class="keywordtype">int</font> NbRows;
92 00084 <font class="keywordtype">unsigned</font> <font class="keywordtype">int</font> NbColumns;
93 <a name="l00085"></a><a class="code" href="structSatMatrix.html#m2">00085</a> <font class="keywordtype">int</font> **p;
94 <a name="l00086"></a><a class="code" href="structSatMatrix.html#m3">00086</a> <font class="keywordtype">int</font> *p_init;
95 00087 } <a class="code" href="structSatMatrix.html">SatMatrix</a>;
96 00088
97 00089 <font class="comment">/*</font>
98 00090 <font class="comment"> * Allocate memory space for a saturation matrix. </font>
99 00091 <font class="comment"> */</font>
100 <a name="l00092"></a><a class="code" href="polyhedron_8c.html#a7">00092</a> <font class="keyword">static</font> <a class="code" href="structSatMatrix.html">SatMatrix</a> *<a class="code" href="polyparam_8c.html#a23">SMAlloc</a>(<font class="keywordtype">int</font> rows,<font class="keywordtype">int</font> cols) {
101 00093
102 00094 <font class="keywordtype">int</font> **q, *p, i;
103 00095 <a class="code" href="structSatMatrix.html">SatMatrix</a> *result;
104 00096
105 00097 result = (<a class="code" href="structSatMatrix.html">SatMatrix</a> *) malloc (<font class="keyword">sizeof</font>(<a class="code" href="structSatMatrix.html">SatMatrix</a>));
106 00098 <font class="keywordflow">if</font>(!result) {
107 00099 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"SMAlloc"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
108 00100 <font class="keywordflow">return</font> 0;
109 00101 }
110 00102 result-&gt;<a class="code" href="structSatMatrix.html#m0">NbRows</a> = rows;
111 00103 result-&gt;<a class="code" href="structSatMatrix.html#m1">NbColumns</a> = cols;
112 00104 <font class="keywordflow">if</font>(rows == 0 || cols == 0) {
113 00105 result-&gt;<a class="code" href="structSatMatrix.html#m2">p</a> = NULL;
114 00106 <font class="keywordflow">return</font> result;
115 00107 }
116 00108 result-&gt;<a class="code" href="structSatMatrix.html#m2">p</a> = q = (<font class="keywordtype">int</font> **)malloc(rows * <font class="keyword">sizeof</font>(<font class="keywordtype">int</font> *));
117 00109 <font class="keywordflow">if</font>(!result-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>) {
118 00110 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"SMAlloc"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
119 00111 <font class="keywordflow">return</font> 0;
120 00112 }
121 00113 result-&gt;<a class="code" href="structSatMatrix.html#m3">p_init</a> = p = (<font class="keywordtype">int</font> *)malloc (rows * cols * <font class="keyword">sizeof</font> (<font class="keywordtype">int</font>));
122 00114 <font class="keywordflow">if</font>(!result-&gt;<a class="code" href="structSatMatrix.html#m3">p_init</a>) {
123 00115 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"SMAlloc"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
124 00116 <font class="keywordflow">return</font> 0;
125 00117 }
126 00118 <font class="keywordflow">for</font> (i=0; i&lt;rows; i++) {
127 00119 *q++ = p;
128 00120 p += cols;
129 00121 }
130 00122 <font class="keywordflow">return</font> result;
131 00123 } <font class="comment">/* SMAlloc */</font>
132 00124
133 00125 <font class="comment">/* </font>
134 00126 <font class="comment"> * Free the memory space occupied by saturation matrix. </font>
135 00127 <font class="comment"> */</font>
136 <a name="l00128"></a><a class="code" href="polyhedron_8c.html#a8">00128</a> <font class="keyword">static</font> <font class="keywordtype">void</font> <a class="code" href="polyparam_8c.html#a24">SMFree</a> (<a class="code" href="structSatMatrix.html">SatMatrix</a> **matrix) {
137 00129
138 00130 <font class="keywordflow">if</font> (matrix[0]){
139 00131 free ((<font class="keywordtype">char</font> *) matrix[0]-&gt;p_init);
140 00132 free ((<font class="keywordtype">char</font> *) matrix[0]-&gt;p);
141 00133 free ((<font class="keywordtype">char</font> *) matrix[0]);
142 00134 matrix[0]=NULL;}
143 00135 } <font class="comment">/* SMFree */</font>
144 00136
145 00137 <font class="comment">/*</font>
146 00138 <font class="comment"> * Print the contents of a saturation matrix.</font>
147 00139 <font class="comment"> * This function is defined only for debugging purpose. </font>
148 00140 <font class="comment"> */</font>
149 <a name="l00141"></a><a class="code" href="polyhedron_8c.html#a9">00141</a> <font class="keyword">static</font> <font class="keywordtype">void</font> <a class="code" href="polyhedron_8c.html#a9">SMPrint</a> (<a class="code" href="structSatMatrix.html">SatMatrix</a> *matrix) {
150 00142
151 00143 <font class="keywordtype">int</font> *p;
152 00144 <font class="keywordtype">int</font> i, j;
153 00145 <font class="keywordtype">unsigned</font> NbRows, NbColumns;
154 00146
155 00147 fprintf(stderr,<font class="stringliteral">"%d %d\n"</font>,NbRows=matrix-&gt;<a class="code" href="structSatMatrix.html#m0">NbRows</a>, NbColumns=matrix-&gt;<a class="code" href="structSatMatrix.html#m1">NbColumns</a>);
156 00148 <font class="keywordflow">for</font> (i=0;i&lt;NbRows;i++) {
157 00149 p = *(matrix-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>+i);
158 00150 <font class="keywordflow">for</font> (j=0;j&lt;NbColumns;j++)
159 00151 fprintf(stderr, <font class="stringliteral">" %10X "</font>, *p++);
160 00152 fprintf(stderr, <font class="stringliteral">"\n"</font>);
161 00153 }
162 00154 } <font class="comment">/* SMPrint */</font>
163 00155
164 00156 <font class="comment">/* </font>
165 00157 <font class="comment"> * Compute the bitwise OR of two saturation matrices.</font>
166 00158 <font class="comment"> */</font>
167 <a name="l00159"></a><a class="code" href="polyhedron_8c.html#a10">00159</a> <font class="keyword">static</font> <font class="keywordtype">void</font> <a class="code" href="polyhedron_8c.html#a10">SatVector_OR</a>(<font class="keywordtype">int</font> *p1,<font class="keywordtype">int</font> *p2,<font class="keywordtype">int</font> *p3,<font class="keywordtype">unsigned</font> length) {
168 00160
169 00161 <font class="keywordtype">int</font> *cp1, *cp2, *cp3;
170 00162 <font class="keywordtype">int</font> i;
171 00163
172 00164 cp1=p1;
173 00165 cp2=p2;
174 00166 cp3=p3;
175 00167 <font class="keywordflow">for</font> (i=0;i&lt;length;i++) {
176 00168 *cp3 = *cp1 | *cp2;
177 00169 cp3++;
178 00170 cp1++;
179 00171 cp2++;
180 00172 }
181 00173 } <font class="comment">/* SatVector_OR */</font>
182 00174
183 00175 <font class="comment">/* </font>
184 00176 <font class="comment"> * Copy a saturation matrix to another (macro definition). </font>
185 00177 <font class="comment"> */</font>
186 <a name="l00178"></a><a class="code" href="polyhedron_8c.html#a3">00178</a> <font class="preprocessor">#define SMVector_Copy(p1, p2, length) \</font>
187 00179 <font class="preprocessor"> memcpy((char *)(p2), (char *)(p1), (int)((length)*sizeof(int)))</font>
188 00180 <font class="preprocessor"></font>
189 00181 <font class="comment">/*</font>
190 00182 <font class="comment"> * Initialize a saturation matrix with zeros (macro definition) </font>
191 00183 <font class="comment"> */</font>
192 <a name="l00184"></a><a class="code" href="polyhedron_8c.html#a4">00184</a> <font class="preprocessor">#define SMVector_Init(p1, length) \</font>
193 00185 <font class="preprocessor"> memset((char *)(p1), 0, (int)((length)*sizeof(int)))</font>
194 00186 <font class="preprocessor"></font>
195 00187 <font class="comment">/*</font>
196 00188 <font class="comment"> * Defining operations on polyhedron --</font>
197 00189 <font class="comment"> */</font>
198 00190
199 00191 <font class="comment">/* </font>
200 00192 <font class="comment"> * Vector p3 is a linear combination of two vectors (p1 and p2) such that </font>
201 00193 <font class="comment"> * p3[pos] is zero. First element of each vector (p1,p2,p3) is a status </font>
202 00194 <font class="comment"> * element and is not changed in p3. The value of 'pos' may be 0 however.</font>
203 00195 <font class="comment"> * The parameter 'length' does not include status element one. </font>
204 00196 <font class="comment"> */</font>
205 <a name="l00197"></a><a class="code" href="polyhedron_8c.html#a11">00197</a> <font class="keyword">static</font> <font class="keywordtype">void</font> <a class="code" href="polyhedron_8c.html#a11">Combine</a>(<a class="code" href="arithmetique_8h.html#a93">Value</a> *p1, <a class="code" href="arithmetique_8h.html#a93">Value</a> *p2, <a class="code" href="arithmetique_8h.html#a93">Value</a> *p3, <font class="keywordtype">int</font> pos, <font class="keywordtype">unsigned</font> length) {
206 00198
207 00199 <a class="code" href="arithmetique_8h.html#a93">Value</a> a1, a2, gcd;
208 00200 <a class="code" href="arithmetique_8h.html#a93">Value</a> abs_a1,abs_a2,neg_a1;
209 00201
210 00202 <font class="comment">/* Initialize all the 'Value' variables */</font>
211 00203 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(a1); <a class="code" href="arithmetique_8h.html#a10">value_init</a>(a2); <a class="code" href="arithmetique_8h.html#a10">value_init</a>(gcd);
212 00204 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(abs_a1); <a class="code" href="arithmetique_8h.html#a10">value_init</a>(abs_a2); <a class="code" href="arithmetique_8h.html#a10">value_init</a>(neg_a1);
213 00205
214 00206 <font class="comment">/* a1 = p1[pos] */</font>
215 00207 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(a1,p1[pos]);
216 00208
217 00209 <font class="comment">/* a2 = p2[pos] */</font>
218 00210 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(a2,p2[pos]);
219 00211
220 00212 <font class="comment">/* a1_abs = |a1| */</font>
221 00213 <a class="code" href="arithmetique_8h.html#a55">value_absolute</a>(abs_a1,a1);
222 00214
223 00215 <font class="comment">/* a2_abs = |a2| */</font>
224 00216 <a class="code" href="arithmetique_8h.html#a55">value_absolute</a>(abs_a2,a2);
225 00217
226 00218 <font class="comment">/* gcd = Gcd(abs(a1), abs(a2)) */</font>
227 00219 <a class="code" href="vector_8c.html#a3">Gcd</a>(abs_a1,abs_a2,&amp;gcd);
228 00220
229 00221 <font class="comment">/* a1 = a1/gcd */</font>
230 00222 <a class="code" href="arithmetique_8h.html#a51">value_division</a> (a1,a1,gcd);
231 00223
232 00224 <font class="comment">/* a2 = a2/gcd */</font>
233 00225 <a class="code" href="arithmetique_8h.html#a51">value_division</a> (a2,a2,gcd);
234 00226
235 00227 <font class="comment">/* neg_a1 = -(a1) */</font>
236 00228 <a class="code" href="arithmetique_8h.html#a54">value_oppose</a>(neg_a1,a1);
237 00229
238 00230 <a class="code" href="vector_8c.html#a20">Vector_Combine</a>(p1+1,p2+1,p3+1,a2,neg_a1,length);
239 00231 <a class="code" href="vector_8c.html#a25">Vector_Normalize</a>(p3+1,length);
240 00232
241 00233 <font class="comment">/* Clear all the 'Value' variables */</font>
242 00234 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(a1); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(a2); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(gcd);
243 00235 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(abs_a1); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(abs_a2); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(neg_a1);
244 00236
245 00237 <font class="keywordflow">return</font>;
246 00238 } <font class="comment">/* Combine */</font>
247 00239
248 00240 <font class="comment">/* </font>
249 00241 <font class="comment"> * Return the transpose of the saturation matrix 'Sat'. 'Mat' is a matrix</font>
250 00242 <font class="comment"> * of constraints and 'Ray' is a matrix of ray vectors and 'Sat' is the </font>
251 00243 <font class="comment"> * corresponding saturation matrix. </font>
252 00244 <font class="comment"> */</font>
253 <a name="l00245"></a><a class="code" href="polyhedron_8c.html#a12">00245</a> <font class="keyword">static</font> <a class="code" href="structSatMatrix.html">SatMatrix</a> *<a class="code" href="polyhedron_8c.html#a12">TransformSat</a>(Matrix *Mat, Matrix *Ray, <a class="code" href="structSatMatrix.html">SatMatrix</a> *Sat) {
254 00246
255 00247 <font class="keywordtype">int</font> i, j, sat_nbcolumns;
256 00248 <font class="keywordtype">unsigned</font> jx1, jx2, bx1, bx2;
257 00249 <a class="code" href="structSatMatrix.html">SatMatrix</a> *result;
258 00250
259 00251 <font class="keywordflow">if</font> (Mat-&gt;NbRows != 0)
260 00252 sat_nbcolumns = (Mat-&gt;NbRows-1) /(<font class="keyword">sizeof</font>(int)*8) + 1;
261 00253 <font class="keywordflow">else</font>
262 00254 sat_nbcolumns = 0;
263 00255
264 00256 result = <a class="code" href="polyparam_8c.html#a23">SMAlloc</a>(Ray-&gt;NbRows, sat_nbcolumns);
265 00257 <a class="code" href="polyhedron_8c.html#a4">SMVector_Init</a>(result-&gt;<a class="code" href="structSatMatrix.html#m3">p_init</a>, Ray-&gt;NbRows * sat_nbcolumns);
266 00258
267 00259 <font class="keywordflow">for</font>(i=0,jx1=0,bx1=MSB; i&lt;Ray-&gt;NbRows; i++) {
268 00260 <font class="keywordflow">for</font>(j=0,jx2=0,bx2=MSB; j&lt;Mat-&gt;NbRows; j++) {
269 00261 <font class="keywordflow">if</font> (Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[j][jx1] &amp; bx1)
270 00262 result-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[i][jx2] |= bx2;
271 00263 NEXT(jx2,bx2);
272 00264 }
273 00265 NEXT(jx1, bx1);
274 00266 }
275 00267 <font class="keywordflow">return</font> result;
276 00268 } <font class="comment">/* TransformSat */</font>
277 00269
278 00270 <font class="comment">/* </font>
279 00271 <font class="comment"> * Sort the rays (Ray, Sat) into three tiers as used in 'Chernikova' function:</font>
280 00272 <font class="comment"> * NbBid &lt;= i &lt; equal_bound : saturates the constraint</font>
281 00273 <font class="comment"> * equal_bound &lt;= i &lt; sup_bound : verifies the constraint</font>
282 00274 <font class="comment"> * sup_bound &lt;= i &lt; NbRay : does not verify </font>
283 00275 <font class="comment"> *</font>
284 00276 <font class="comment"> * 'Ray' is the matrix of rays and 'Sat' is the corresponding saturation </font>
285 00277 <font class="comment"> * matrix. (jx,bx) pair specify the constraint in the saturation matrix. The</font>
286 00278 <font class="comment"> * status element of the 'Ray' matrix holds the saturation value w.r.t the </font>
287 00279 <font class="comment"> * constraint specified by (jx,bx). Thus</font>
288 00280 <font class="comment"> * Ray-&gt;p[i][0] = 0 -&gt; ray(i) saturates the constraint</font>
289 00281 <font class="comment"> * Ray-&gt;p[i][0] &gt; 0 -&gt; ray(i) verifies the constraint</font>
290 00282 <font class="comment"> * Ray-&gt;p[i][0] &lt; 0 -&gt; ray(i) doesn't verify the constraint </font>
291 00283 <font class="comment"> */</font>
292 <a name="l00284"></a><a class="code" href="polyhedron_8c.html#a13">00284</a> <font class="keyword">static</font> <font class="keywordtype">void</font> <a class="code" href="polyhedron_8c.html#a13">RaySort</a>(Matrix *Ray,<a class="code" href="structSatMatrix.html">SatMatrix</a> *Sat,<font class="keywordtype">int</font> NbBid,<font class="keywordtype">int</font> NbRay,<font class="keywordtype">int</font> *equal_bound,<font class="keywordtype">int</font> *sup_bound,<font class="keywordtype">unsigned</font> RowSize1, <font class="keywordtype">unsigned</font> RowSize2, <font class="keywordtype">unsigned</font> bx, <font class="keywordtype">unsigned</font> jx) {
293 00285
294 00286 <font class="keywordtype">int</font> inf_bound;
295 00287 <a class="code" href="arithmetique_8h.html#a93">Value</a> **uni_eq, **uni_sup, **uni_inf;
296 00288 <font class="keywordtype">int</font> **inc_eq, **inc_sup, **inc_inf;
297 00289
298 00290 <font class="comment">/* 'uni_eq' points to the first ray in the ray matrix which verifies a</font>
299 00291 <font class="comment"> * constraint, 'inc_eq' is the corresponding pointer in saturation </font>
300 00292 <font class="comment"> * matrix. 'uni_inf' points to the first ray (from top) which doesn't </font>
301 00293 <font class="comment"> * verify a constraint, 'inc_inf' is the corresponding pointer in </font>
302 00294 <font class="comment"> * saturation matrix. 'uni_sup' scans the ray matrix and 'inc_sup' is </font>
303 00295 <font class="comment"> * the corresponding pointer in saturation matrix. 'inf_bound' holds the </font>
304 00296 <font class="comment"> * number of the first ray which does not verify the constraints. </font>
305 00297 <font class="comment"> */</font>
306 00298
307 00299 *sup_bound = *equal_bound = NbBid;
308 00300 uni_sup = uni_eq = Ray-&gt;p+NbBid;
309 00301 inc_sup = inc_eq = Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>+NbBid;
310 00302 inf_bound = NbRay;
311 00303 uni_inf = Ray-&gt;p+NbRay;
312 00304 inc_inf = Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>+NbRay;
313 00305
314 00306 <font class="keywordflow">while</font> (inf_bound&gt;*sup_bound) {
315 00307 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a67">value_zero_p</a>(**uni_sup)) { <font class="comment">/* status = satisfy */</font>
316 00308 <a class="code" href="vector_8c.html#a10">Vector_Exchange</a>(*uni_eq,*uni_sup,RowSize1);
317 00309 <a class="code" href="polyhedron_8c.html#a1">bexchange</a>(*inc_eq,*inc_sup,RowSize2);
318 00310 (*equal_bound)++; uni_eq++; inc_eq++;
319 00311 (*sup_bound)++; uni_sup++; inc_sup++;
320 00312 }
321 00313 <font class="keywordflow">else</font> {
322 00314 *((*inc_sup)+jx)|=bx;
323 00315
324 00316 <font class="comment">/* if (**uni_sup&lt;0) */</font>
325 00317 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a64">value_neg_p</a>(**uni_sup)) { <font class="comment">/* Status != verify */</font>
326 00318 inf_bound--; uni_inf--; inc_inf--;
327 00319 <a class="code" href="vector_8c.html#a10">Vector_Exchange</a>(*uni_inf,*uni_sup,RowSize1);
328 00320 <a class="code" href="polyhedron_8c.html#a1">bexchange</a>(*inc_inf,*inc_sup,RowSize2);
329 00321 }
330 00322 <font class="keywordflow">else</font> { <font class="comment">/* status == verify */</font>
331 00323 (*sup_bound)++; uni_sup++; inc_sup++;
332 00324 }
333 00325 }
334 00326 }
335 00327 } <font class="comment">/* RaySort */</font>
336 00328
337 00329 <font class="comment">/* </font>
338 00330 <font class="comment"> * Compute the dual of matrix 'Mat' and place it in matrix 'Ray'.'Mat' </font>
339 00331 <font class="comment"> * contains the constraints (equalities and inequalities) in rows and 'Ray' </font>
340 00332 <font class="comment"> * contains the ray space (lines and rays) in its rows. 'Sat' is a boolean </font>
341 00333 <font class="comment"> * saturation matrix defined as Sat(i,j)=0 if ray(i) saturates constraint(j),</font>
342 00334 <font class="comment"> * otherwise 1. The constraints in the 'Mat' matrix are processed starting at</font>
343 00335 <font class="comment"> * 'FirstConstraint', 'Ray' and 'Sat' matrices are changed accordingly.'NbBid'</font>
344 00336 <font class="comment"> * is the number of lines in the ray matrix and 'NbMaxRays' is the maximum </font>
345 00337 <font class="comment"> * number of rows (rays) permissible in the 'Ray' and 'Sat' matrix. Return 0 </font>
346 00338 <font class="comment"> * if successful, otherwise return 1. </font>
347 00339 <font class="comment"> */</font>
348 <a name="l00340"></a><a class="code" href="polyhedron_8c.html#a14">00340</a> <font class="keyword">static</font> <font class="keywordtype">int</font> <a class="code" href="polyhedron_8c.html#a14">Chernikova</a> (Matrix *Mat,Matrix *Ray,<a class="code" href="structSatMatrix.html">SatMatrix</a> *Sat, <font class="keywordtype">unsigned</font> NbBid, <font class="keywordtype">unsigned</font> NbMaxRays, <font class="keywordtype">unsigned</font> FirstConstraint,<font class="keywordtype">unsigned</font> dual) {
349 00341
350 00342 <font class="keywordtype">unsigned</font> NbRay, Dimension, NbConstraints, RowSize1, RowSize2, sat_nbcolumns;
351 00343 <font class="keywordtype">int</font> sup_bound, equal_bound, index_non_zero, bound;
352 00344 <font class="keywordtype">int</font> i, j, k, l, redundant, rayonly, nbcommonconstraints;
353 00345 <font class="keywordtype">int</font> *Temp, aux;
354 00346 <font class="keywordtype">int</font> *ip1, *ip2;
355 00347 <font class="keywordtype">unsigned</font> bx, m, jx;
356 00348 <a class="code" href="arithmetique_8h.html#a93">Value</a> tmp;
357 00349 <a class="code" href="arithmetique_8h.html#a93">Value</a> *p1, *p2, *p3;
358 00350
359 00351 <font class="preprocessor">#ifdef POLY_CH_DEBUG</font>
360 00352 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"[Chernikova: Input]\nRay = "</font>);
361 00353 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Ray);
362 00354 fprintf(stderr, <font class="stringliteral">"\nConstraints = "</font>);
363 00355 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Mat);
364 00356 fprintf(stderr, <font class="stringliteral">"\nSat = "</font>);
365 00357 <a class="code" href="polyhedron_8c.html#a9">SMPrint</a>(Sat);
366 00358 <font class="preprocessor">#endif</font>
367 00359 <font class="preprocessor"></font>
368 00360 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(tmp);
369 00361 NbConstraints=Mat-&gt;NbRows;
370 00362 NbRay = Ray-&gt;NbRows;
371 00363 Dimension = Mat-&gt;NbColumns-1; <font class="comment">/* Homogeneous Dimension */</font>
372 00364 sat_nbcolumns=Sat-&gt;<a class="code" href="structSatMatrix.html#m1">NbColumns</a>;
373 00365
374 00366 RowSize1=(Dimension+1);
375 00367 RowSize2=sat_nbcolumns * <font class="keyword">sizeof</font>(int);
376 00368
377 00369 Temp=(<font class="keywordtype">int</font> *)malloc(RowSize2);
378 00370 <font class="keywordflow">if</font>(!Temp) {
379 00371 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"Chernikova"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
380 00372 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
381 00373 <font class="keywordflow">return</font> 0;
382 00374 }
383 00375 <a class="code" href="arithmetic__errors_8h.html#a4">CATCH</a>(any_exception_error) {
384 00376
385 00377 <font class="comment">/* </font>
386 00378 <font class="comment"> * In case of overflow, free the allocated memory!</font>
387 00379 <font class="comment"> * Rethrow upwards the stack to forward the exception.</font>
388 00380 <font class="comment"> */</font>
389 00381 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
390 00382 free(Temp);
391 00383 <a class="code" href="arithmetic__errors_8h.html#a7">RETHROW</a>();
392 00384 }
393 00385 <a class="code" href="arithmetic__errors_8h.html#a6">TRY</a> {
394 00386 jx = FirstConstraint/<a class="code" href="polyhedron_8c.html#a0">WSIZE</a>;
395 00387 bx = MSB; bx &gt;&gt;= FirstConstraint%<a class="code" href="polyhedron_8c.html#a0">WSIZE</a>;
396 00388 <font class="keywordflow">for</font> (k=FirstConstraint; k&lt;NbConstraints; k++) {
397 00389
398 00390 <font class="comment">/* Set the status word of each ray[i] to ray[i] dot constraint[k] */</font>
399 00391 <font class="comment">/* This is equivalent to evaluating each ray by the constraint[k] */</font>
400 00392 <font class="comment">/* 'index_non_zero' is assigned the smallest ray index which does */</font>
401 00393 <font class="comment">/* not saturate the constraint. */</font>
402 00394
403 00395 index_non_zero = NbRay;
404 00396 <font class="keywordflow">for</font> (i=0; i&lt;NbRay; i++) {
405 00397 p1 = Ray-&gt;p[i]+1;
406 00398 p2 = Mat-&gt;p[k]+1;
407 00399 p3 = Ray-&gt;p[i];
408 00400
409 00401 <font class="comment">/* *p3 = *p1 * *p2 */</font>
410 00402 <a class="code" href="arithmetique_8h.html#a47">value_multiply</a>(*p3,*p1,*p2);
411 00403 p1++; p2++;
412 00404 <font class="keywordflow">for</font> (j=1; j&lt;Dimension; j++) {
413 00405
414 00406 <font class="comment">/* *p3 += *p1 * *p2 */</font>
415 00407 <a class="code" href="arithmetique_8h.html#a47">value_multiply</a>(tmp,*p1,*p2);
416 00408 <a class="code" href="arithmetique_8h.html#a43">value_addto</a>(*p3,*p3,tmp);
417 00409 p1++; p2++;
418 00410 }
419 00411 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(*p3) &amp;&amp; (i&lt;index_non_zero))
420 00412 index_non_zero=i;
421 00413 }
422 00414
423 00415 <font class="preprocessor">#ifdef POLY_CH_DEBUG</font>
424 00416 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"[Chernikova: A]\nRay = "</font>);
425 00417 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Ray);
426 00418 fprintf(stderr, <font class="stringliteral">"\nConstraints = "</font>);
427 00419 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Mat);
428 00420 fprintf(stderr, <font class="stringliteral">"\nSat = "</font>);
429 00421 <a class="code" href="polyhedron_8c.html#a9">SMPrint</a> (Sat);
430 00422 <font class="preprocessor">#endif</font>
431 00423 <font class="preprocessor"></font>
432 00424 <font class="comment">/* Find a bidirectional ray z such that cz &lt;&gt; 0 */</font>
433 00425 <font class="keywordflow">if</font> (index_non_zero&lt;NbBid) {
434 00426
435 00427 <font class="comment">/* Discard index_non_zero bidirectional ray */</font>
436 00428 NbBid--;
437 00429 <font class="keywordflow">if</font> (NbBid!=index_non_zero)
438 00430 <a class="code" href="vector_8c.html#a10">Vector_Exchange</a>(Ray-&gt;p[index_non_zero],Ray-&gt;p[NbBid],RowSize1);
439 00431
440 00432 <font class="preprocessor">#ifdef POLY_CH_DEBUG </font>
441 00433 <font class="preprocessor"></font> fprintf(stderr,<font class="stringliteral">"************\n"</font>);
442 00434 <font class="keywordflow">for</font>(i=0;i&lt;RowSize1;i++) {
443 00435 <a class="code" href="arithmetique_8h.html#a16">value_print</a>(stderr,P_VALUE_FMT,Ray-&gt;p[index_non_zero][i]);
444 00436 }
445 00437 fprintf(stderr,<font class="stringliteral">"\n******\n"</font>);
446 00438 <font class="keywordflow">for</font>(i=0;i&lt;RowSize1;i++) {
447 00439 <a class="code" href="arithmetique_8h.html#a16">value_print</a>(stderr,P_VALUE_FMT,Ray-&gt;p[NbBid][i]);
448 00440 }
449 00441 fprintf(stderr,<font class="stringliteral">"\n*******\n"</font>);
450 00442 <font class="preprocessor">#endif</font>
451 00443 <font class="preprocessor"></font>
452 00444 <font class="comment">/* Compute the new lineality space */</font>
453 00445 <font class="keywordflow">for</font> (i=0; i&lt;NbBid; i++)
454 00446 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(Ray-&gt;p[i][0]))
455 00447 <a class="code" href="polyhedron_8c.html#a11">Combine</a>(Ray-&gt;p[i],Ray-&gt;p[NbBid],Ray-&gt;p[i],0,Dimension);
456 00448
457 00449 <font class="comment">/* Add the positive part of index_non_zero bidirectional ray to */</font>
458 00450 <font class="comment">/* the set of unidirectional rays */</font>
459 00451
460 00452 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a64">value_neg_p</a>(Ray-&gt;p[NbBid][0])) {
461 00453 p1=Ray-&gt;p[NbBid];
462 00454 <font class="keywordflow">for</font> (j=0;j&lt;Dimension+1; j++) {
463 00455
464 00456 <font class="comment">/* *p1 = - *p1 */</font>
465 00457 <a class="code" href="arithmetique_8h.html#a54">value_oppose</a>(*p1,*p1);
466 00458 p1++;
467 00459 }
468 00460 }
469 00461
470 00462 <font class="preprocessor">#ifdef POLY_CH_DEBUG</font>
471 00463 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"[Chernikova: B]\nRay = "</font>);
472 00464 Ray-&gt;NbRows=NbRay;
473 00465 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Ray);
474 00466 fprintf(stderr, <font class="stringliteral">"\nConstraints = "</font>);
475 00467 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Mat);
476 00468 fprintf(stderr, <font class="stringliteral">"\nSat = "</font>);
477 00469 <a class="code" href="polyhedron_8c.html#a9">SMPrint</a>(Sat);
478 00470 <font class="preprocessor">#endif</font>
479 00471 <font class="preprocessor"></font>
480 00472 <font class="comment">/* Compute the new pointed cone */</font>
481 00473 <font class="keywordflow">for</font> (i=NbBid+1; i&lt;NbRay; i++)
482 00474 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(Ray-&gt;p[i][0]))
483 00475 <a class="code" href="polyhedron_8c.html#a11">Combine</a>(Ray-&gt;p[i],Ray-&gt;p[NbBid],Ray-&gt;p[i],0,Dimension);
484 00476
485 00477 <font class="comment">/* Add the new ray */</font>
486 00478 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(Mat-&gt;p[k][0])) { <font class="comment">/* Constraint is an inequality */</font>
487 00479 <font class="keywordflow">for</font> (j=0;j&lt;sat_nbcolumns;j++) {
488 00480 Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[NbBid][j] = 0; <font class="comment">/* Saturation vec for new ray */</font>
489 00481 }
490 00482 <font class="comment">/* The new ray saturates everything except last inequality */</font>
491 00483 Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[NbBid][jx] |= bx;
492 00484 }
493 00485 <font class="keywordflow">else</font> { <font class="comment">/* Constraint is an equality */</font>
494 00486 NbRay--;
495 00487 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(Ray-&gt;p[NbRay],Ray-&gt;p[NbBid],Dimension+1);
496 00488 <a class="code" href="polyhedron_8c.html#a3">SMVector_Copy</a>(Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[NbRay],Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[NbBid],sat_nbcolumns);
497 00489 }
498 00490
499 00491 <font class="preprocessor">#ifdef POLY_CH_DEBUG</font>
500 00492 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"[Chernikova: C]\nRay = "</font>);
501 00493 Ray-&gt;NbRows=NbRay;
502 00494 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Ray);
503 00495 fprintf(stderr, <font class="stringliteral">"\nConstraints = "</font>);
504 00496 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Mat);
505 00497 fprintf(stderr, <font class="stringliteral">"\nSat = "</font>);
506 00498 <a class="code" href="polyhedron_8c.html#a9">SMPrint</a> (Sat);
507 00499 <font class="preprocessor">#endif</font>
508 00500 <font class="preprocessor"></font>
509 00501 }
510 00502 <font class="keywordflow">else</font> { <font class="comment">/* If the new constraint satisfies all the rays */</font>
511 00503 <a class="code" href="polyhedron_8c.html#a13">RaySort</a>(Ray, Sat, NbBid, NbRay, &amp;equal_bound, &amp;sup_bound,
512 00504 RowSize1, RowSize2,bx,jx);
513 00505
514 00506 <font class="comment">/* Sort the unidirectional rays into R0, R+, R- */</font>
515 00507 <font class="comment">/* Ray </font>
516 00508 <font class="comment"> NbRay-&gt; bound-&gt; ________</font>
517 00509 <font class="comment"> | R- | R- ==&gt; ray.eq &lt; 0 (outside domain)</font>
518 00510 <font class="comment"> sup-&gt; |------|</font>
519 00511 <font class="comment"> | R+ | R+ ==&gt; ray.eq &gt; 0 (inside domain)</font>
520 00512 <font class="comment"> equal-&gt; |------|</font>
521 00513 <font class="comment"> | R0 | R0 ==&gt; ray.eq = 0 (on face of domain)</font>
522 00514 <font class="comment"> NbBid-&gt; |______|</font>
523 00515 <font class="comment"> */</font>
524 00516
525 00517 <font class="preprocessor">#ifdef POLY_CH_DEBUG</font>
526 00518 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"[Chernikova: D]\nRay = "</font>);
527 00519 Ray-&gt;NbRows=NbRay;
528 00520 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Ray);
529 00521 fprintf(stderr, <font class="stringliteral">"\nConstraints = "</font>);
530 00522 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Mat);
531 00523 fprintf(stderr, <font class="stringliteral">"\nSat = "</font>);
532 00524 <a class="code" href="polyhedron_8c.html#a9">SMPrint</a> (Sat);
533 00525 <font class="preprocessor">#endif</font>
534 00526 <font class="preprocessor"></font>
535 00527 <font class="comment">/* Compute only the new pointed cone */</font>
536 00528 bound=NbRay;
537 00529 <font class="keywordflow">for</font> (i=equal_bound; i&lt;sup_bound; i++) <font class="comment">/* for all pairs of R- and R+ */</font>
538 00530 <font class="keywordflow">for</font>(j=sup_bound; j&lt;bound; j++) {
539 00531
540 00532 <font class="comment">/*--------------------------------------------------------------*/</font>
541 00533 <font class="comment">/* Count the set of constraints saturated by R+ and R- */</font>
542 00534 <font class="comment">/* Includes equalities, inequalities and the positivity constraint */</font>
543 00535 <font class="comment">/*-----------------------------------------------------------------*/</font>
544 00536
545 00537 nbcommonconstraints = 0;
546 00538 <font class="keywordflow">for</font> (l=0; l&lt;jx; l++) {
547 00539 aux = Temp[l] = Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[i][l] | Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[j][l];
548 00540 <font class="keywordflow">for</font> (m=MSB; m!=0; m&gt;&gt;=1)
549 00541 <font class="keywordflow">if</font> (!(aux&amp;m))
550 00542 nbcommonconstraints++;
551 00543 }
552 00544 aux = Temp[jx] = Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[i][jx] | Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[j][jx];
553 00545 <font class="keywordflow">for</font> (m=MSB; m!=bx; m&gt;&gt;=1)
554 00546 <font class="keywordflow">if</font> (!(aux&amp;m))
555 00547 nbcommonconstraints++;
556 00548 rayonly = (<a class="code" href="arithmetique_8h.html#a67">value_zero_p</a>(Ray-&gt;p[i][Dimension]) &amp;&amp;
557 00549 <a class="code" href="arithmetique_8h.html#a67">value_zero_p</a>(Ray-&gt;p[j][Dimension]) &amp;&amp;
558 00550 (dual == 0));
559 00551 <font class="keywordflow">if</font>(rayonly)
560 00552 nbcommonconstraints++; <font class="comment">/* account for pos constr */</font>
561 00553
562 00554 <font class="comment">/*-----------------------------------------------------------------*/</font>
563 00555 <font class="comment">/* Adjacency Test : is combination [R-,R+] a non redundant ray? */</font>
564 00556 <font class="comment">/*-----------------------------------------------------------------*/</font>
565 00557
566 00558 <font class="keywordflow">if</font> (nbcommonconstraints+NbBid&gt;=Dimension-2) { <font class="comment">/* Dimensionality check*/</font>
567 00559 <font class="comment">/* Check whether a ray m saturates the same set of constraints */</font>
568 00560 redundant=0;
569 00561 <font class="keywordflow">for</font> (m=NbBid; m&lt;bound; m++)
570 00562 <font class="keywordflow">if</font> ((m!=i)&amp;&amp;(m!=j)) {
571 00563
572 00564 <font class="comment">/* Two rays (r+ r-) are never made redundant by a vertex */</font>
573 00565 <font class="comment">/* because the positivity constraint saturates both rays */</font>
574 00566 <font class="comment">/* but not the vertex */</font>
575 00567
576 00568 <font class="keywordflow">if</font> (rayonly &amp;&amp; <a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(Ray-&gt;p[m][Dimension]))
577 00569 <font class="keywordflow">continue</font>;
578 00570
579 00571 <font class="comment">/* (r+ r-) is redundant if there doesn't exist an equation */</font>
580 00572 <font class="comment">/* which saturates both r+ and r- but not rm. */</font>
581 00573
582 00574 ip1 = Temp;
583 00575 ip2 = Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[m];
584 00576 <font class="keywordflow">for</font> (l=0; l&lt;=jx; l++,ip2++,ip1++)
585 00577 <font class="keywordflow">if</font> (*ip2 &amp; ~*ip1)
586 00578 <font class="keywordflow">break</font>;
587 00579 <font class="keywordflow">if</font> (l&gt;jx) {
588 00580 redundant=1;
589 00581 <font class="keywordflow">break</font>;
590 00582 }
591 00583 }
592 00584
593 00585 <font class="preprocessor">#ifdef POLY_CH_DEBUG</font>
594 00586 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"[Chernikova: E]\nRay = "</font>);
595 00587 Ray-&gt;NbRows=NbRay;
596 00588 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Ray);
597 00589 fprintf(stderr, <font class="stringliteral">"\nConstraints = "</font>);
598 00590 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Mat);
599 00591 fprintf(stderr, <font class="stringliteral">"\nSat = "</font>);
600 00592 <a class="code" href="polyhedron_8c.html#a9">SMPrint</a> (Sat);
601 00593 <font class="preprocessor">#endif</font>
602 00594 <font class="preprocessor"></font>
603 00595 <font class="comment">/*------------------------------------------------------------*/</font>
604 00596 <font class="comment">/* Add new ray generated by [R+,R-] */</font>
605 00597 <font class="comment">/*------------------------------------------------------------*/</font>
606 00598
607 00599 <font class="keywordflow">if</font> (!redundant) {
608 00600 <font class="keywordflow">if</font> (NbRay==NbMaxRays) {
609 00601 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"chernikova"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of table space"</font>);
610 00602 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
611 00603 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
612 00604 <font class="keywordflow">return</font> 1;
613 00605 }
614 00606
615 00607 <font class="comment">/* Compute the new ray */</font>
616 00608 <a class="code" href="polyhedron_8c.html#a11">Combine</a>(Ray-&gt;p[j],Ray-&gt;p[i],Ray-&gt;p[NbRay],0,Dimension);
617 00609 <a class="code" href="polyhedron_8c.html#a10">SatVector_OR</a>(Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[j],Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[i],Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[NbRay],sat_nbcolumns);
618 00610 Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[NbRay][jx] &amp;= ~bx;
619 00611 NbRay++;
620 00612 }
621 00613 }
622 00614 }
623 00615
624 00616 <font class="preprocessor">#ifdef POLY_CH_DEBUG</font>
625 00617 <font class="preprocessor"></font> fprintf(stderr,
626 00618 <font class="stringliteral">"[Chernikova: F]\n"</font>
627 00619 <font class="stringliteral">"sup_bound=%d\n"</font>
628 00620 <font class="stringliteral">"equal_bound=%d\n"</font>
629 00621 <font class="stringliteral">"bound=%d\n"</font>
630 00622 <font class="stringliteral">"NbRay=%d\n"</font>
631 00623 <font class="stringliteral">"Dimension = %d\n"</font>
632 00624 <font class="stringliteral">"Ray = "</font>,sup_bound,equal_bound,bound,NbRay,Dimension);
633 00625 <font class="preprocessor">#endif</font>
634 00626 <font class="preprocessor"></font><font class="preprocessor">#ifdef POLY_CH_DEBUG</font>
635 00627 <font class="preprocessor"></font> Ray-&gt;NbRows=NbRay;
636 00628 fprintf(stderr, <font class="stringliteral">"[Chernikova: F]:\nRay = "</font>);
637 00629 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Ray);
638 00630 <font class="preprocessor">#endif</font>
639 00631 <font class="preprocessor"></font>
640 00632 <font class="comment">/* Eliminates all non extremal rays */</font>
641 00633 <font class="comment">/* j = (Mat-&gt;p[k][0]) ? */</font>
642 00634
643 00635 j = (<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(Mat-&gt;p[k][0])) ?
644 00636 sup_bound : equal_bound;
645 00637
646 00638 i = NbRay;
647 00639 <font class="preprocessor">#ifdef POLY_CH_DEBUG</font>
648 00640 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"i = %d\nj = %d \n"</font>, i, j);
649 00641 <font class="preprocessor">#endif</font>
650 00642 <font class="preprocessor"></font> <font class="keywordflow">while</font> ((j&lt;bound)&amp;&amp;(i&gt;bound)) {
651 00643 i--;
652 00644 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(Ray-&gt;p[i],Ray-&gt;p[j],Dimension+1);
653 00645 <a class="code" href="polyhedron_8c.html#a3">SMVector_Copy</a>(Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[i],Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[j],sat_nbcolumns);
654 00646 j++;
655 00647 }
656 00648
657 00649 <font class="preprocessor">#ifdef POLY_CH_DEBUG</font>
658 00650 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"i = %d\nj = %d \n"</font>, i, j);
659 00651 fprintf(stderr,
660 00652 <font class="stringliteral">"[Chernikova: F]\n"</font>
661 00653 <font class="stringliteral">"sup_bound=%d\n"</font>
662 00654 <font class="stringliteral">"equal_bound=%d\n"</font>
663 00655 <font class="stringliteral">"bound=%d\n"</font>
664 00656 <font class="stringliteral">"NbRay=%d\n"</font>
665 00657 <font class="stringliteral">"Dimension = %d\n"</font>
666 00658 <font class="stringliteral">"Ray = "</font>,sup_bound,equal_bound,bound,NbRay, Dimension);
667 00659 <font class="preprocessor">#endif</font>
668 00660 <font class="preprocessor"></font><font class="preprocessor">#ifdef POLY_CH_DEBUG</font>
669 00661 <font class="preprocessor"></font> Ray-&gt;NbRows=NbRay;
670 00662 fprintf(stderr, <font class="stringliteral">"[Chernikova: G]\nRay = "</font>);
671 00663 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Ray);
672 00664 <font class="preprocessor">#endif </font>
673 00665 <font class="preprocessor"></font> <font class="keywordflow">if</font> (j==bound)
674 00666 NbRay=i;
675 00667 <font class="keywordflow">else</font>
676 00668 NbRay=j;
677 00669 }
678 00670 NEXT(jx,bx);
679 00671 }
680 00672 Ray-&gt;NbRows=NbRay;
681 00673 Sat-&gt;<a class="code" href="structSatMatrix.html#m0">NbRows</a>=NbRay;
682 00674
683 00675 } <font class="comment">/* End of TRY */</font>
684 00676
685 00677 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
686 00678 free(Temp);
687 00679
688 00680 <font class="preprocessor">#ifdef POLY_CH_DEBUG</font>
689 00681 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"[Chernikova: Output]\nRay = "</font>);
690 00682 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Ray);
691 00683 fprintf(stderr, <font class="stringliteral">"\nConstraints = "</font>);
692 00684 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Mat);
693 00685 fprintf(stderr, <font class="stringliteral">"\nSat = "</font>);
694 00686 <a class="code" href="polyhedron_8c.html#a9">SMPrint</a> (Sat);
695 00687 <font class="preprocessor">#endif</font>
696 00688 <font class="preprocessor"></font>
697 00689 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
698 00690 <font class="keywordflow">return</font> 0;
699 00691 } <font class="comment">/* Chernikova */</font>
700 00692
701 00693 <font class="comment">/* </font>
702 00694 <font class="comment"> * Compute a minimal system of equations using Gausian elimination method.</font>
703 00695 <font class="comment"> * 'Mat' is a matrix of constraints in which the first 'Nbeq' constraints</font>
704 00696 <font class="comment"> * are equations. The dimension of the homogenous system is 'Dimension'. </font>
705 00697 <font class="comment"> * The function returns the rank of the matrix 'Mat'. </font>
706 00698 <font class="comment"> */</font>
707 <a name="l00699"></a><a class="code" href="polyhedron_8c.html#a15">00699</a> <font class="keywordtype">int</font> <a class="code" href="polyhedron_8c.html#a15">Gauss</a>(Matrix *Mat,<font class="keywordtype">int</font> NbEq,<font class="keywordtype">int</font> Dimension) {
708 00700
709 00701 <font class="keywordtype">int</font> i, j, k, pivot, Rank;
710 00702 <font class="keywordtype">int</font> *column_index = NULL;
711 00703 <a class="code" href="arithmetique_8h.html#a93">Value</a> gcd,tmp,*cp;
712 00704
713 00705 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(gcd); <a class="code" href="arithmetique_8h.html#a10">value_init</a>(tmp);
714 00706 column_index=(<font class="keywordtype">int</font> *)malloc(Dimension * <font class="keyword">sizeof</font>(<font class="keywordtype">int</font>));
715 00707 <font class="keywordflow">if</font>(!column_index) {
716 00708 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"Gauss"</font>,<font class="stringliteral">"outofmem"</font>,<font class="stringliteral">"out of memory space"</font>);
717 00709 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(gcd); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
718 00710 <font class="keywordflow">return</font> 0;
719 00711 }
720 00712 Rank=0;
721 00713
722 00714 <font class="preprocessor">#ifdef POLY_DEBUG</font>
723 00715 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"[Gauss : Input]\nRay ="</font>);
724 00716 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Mat);
725 00717 <font class="preprocessor">#endif</font>
726 00718 <font class="preprocessor"></font>
727 00719 <a class="code" href="arithmetic__errors_8h.html#a4">CATCH</a>(any_exception_error) {
728 00720 <font class="keywordflow">if</font> (column_index)
729 00721 free(column_index);
730 00722 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(gcd); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
731 00723 <a class="code" href="arithmetic__errors_8h.html#a7">RETHROW</a>();
732 00724 }
733 00725 <a class="code" href="arithmetic__errors_8h.html#a6">TRY</a> {
734 00726
735 00727 <font class="keywordflow">for</font> (j=1; j&lt;=Dimension; j++) { <font class="comment">/* for each column (except status) */</font>
736 00728 <font class="keywordflow">for</font> (i=Rank; i&lt;NbEq; i++) <font class="comment">/* starting at diagonal, look down */</font>
737 00729
738 00730 <font class="comment">/* if (Mat-&gt;p[i][j] != 0) */</font>
739 00731 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(Mat-&gt;p[i][j]))
740 00732 <font class="keywordflow">break</font>; <font class="comment">/* Find the first non zero element */</font>
741 00733 <font class="keywordflow">if</font> (i!=NbEq) { <font class="comment">/* If a non-zero element is found? */</font>
742 00734 <font class="keywordflow">if</font> (i!=Rank) <font class="comment">/* If it is found below the diagonal*/</font>
743 00735 <a class="code" href="vector_8c.html#a10">Vector_Exchange</a>(Mat-&gt;p[Rank]+1,Mat-&gt;p[i]+1,Dimension);
744 00736
745 00737 <font class="comment">/* Normalize the pivot row by dividing it by the gcd */</font>
746 00738 <font class="comment">/* gcd = Vector_Gcd(Mat-&gt;p[Rank]+1,Dimension) */</font>
747 00739 <a class="code" href="vector_8c.html#a23">Vector_Gcd</a>(Mat-&gt;p[Rank]+1,Dimension,&amp;gcd);
748 00740
749 00741 <font class="comment">/* if (gcd &gt;= 2) */</font>
750 00742 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(tmp,2);
751 00743 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a25">value_ge</a>(gcd,tmp)) {
752 00744 cp = &amp;Mat-&gt;p[Rank][1];
753 00745 <font class="keywordflow">for</font> (k=0; k&lt;Dimension; k++) {
754 00746 <a class="code" href="arithmetique_8h.html#a51">value_division</a> (*cp,*cp,gcd); <font class="comment">/* *cp /= gcd */</font>
755 00747 cp++;
756 00748 }
757 00749 }
758 00750
759 00751 <font class="comment">/* if (Mat-&gt;p[Rank][j] &lt; 0) */</font>
760 00752 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a64">value_neg_p</a>(Mat-&gt;p[Rank][j])) {
761 00753 cp = Mat-&gt;p[Rank]+1;
762 00754 <font class="keywordflow">for</font> (k=0; k&lt;Dimension; k++) {
763 00755 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(tmp,-1);
764 00756 <a class="code" href="arithmetique_8h.html#a47">value_multiply</a> (*cp,*cp,tmp); <font class="comment">/* *cp *= -1 */</font>
765 00757 cp++;
766 00758 }
767 00759 }
768 00760 <font class="comment">/* End of normalize */</font>
769 00761
770 00762 pivot=i;
771 00763 <font class="keywordflow">for</font> (i=pivot+1; i&lt;NbEq; i++) { <font class="comment">/* Zero out the rest of the column */</font>
772 00764
773 00765 <font class="comment">/* if (Mat-&gt;p[i][j] != 0) */</font>
774 00766 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(Mat-&gt;p[i][j]))
775 00767 <a class="code" href="polyhedron_8c.html#a11">Combine</a>(Mat-&gt;p[i],Mat-&gt;p[Rank],Mat-&gt;p[i],j,Dimension);
776 00768 }
777 00769
778 00770 <font class="comment">/* For each row with non-zero entry Mat-&gt;p[Rank], store the column */</font>
779 00771 <font class="comment">/* number 'j' in 'column_index[Rank]'. This information will be */</font>
780 00772 <font class="comment">/* useful in performing Gaussian elimination backward step. */</font>
781 00773
782 00774 column_index[Rank]=j;
783 00775 Rank++;
784 00776 }
785 00777 } <font class="comment">/* end of Gaussian elimination forward step */</font>
786 00778
787 00779 <font class="comment">/* Back Substitution -- normalize the system of equations */</font>
788 00780 <font class="keywordflow">for</font> (k=Rank-1; k&gt;=0; k--) {
789 00781 j = column_index[k];
790 00782
791 00783 <font class="comment">/* Normalize the equations */</font>
792 00784 <font class="keywordflow">for</font> (i=0; i&lt;k; i++) {
793 00785
794 00786 <font class="comment">/* if (Mat-&gt;p[i][j] != 0) */</font>
795 00787 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(Mat-&gt;p[i][j]))
796 00788 <a class="code" href="polyhedron_8c.html#a11">Combine</a>(Mat-&gt;p[i],Mat-&gt;p[k],Mat-&gt;p[i],j,Dimension);
797 00789 }
798 00790
799 00791 <font class="comment">/* Normalize the inequalities */</font>
800 00792 <font class="keywordflow">for</font> (i=NbEq;i&lt;Mat-&gt;NbRows;i++) {
801 00793
802 00794 <font class="comment">/* if (Mat-&gt;p[i][j] != 0) */</font>
803 00795 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(Mat-&gt;p[i][j]))
804 00796 <a class="code" href="polyhedron_8c.html#a11">Combine</a>(Mat-&gt;p[i],Mat-&gt;p[k],Mat-&gt;p[i],j,Dimension);
805 00797 }
806 00798 }
807 00799 } <font class="comment">/* end of TRY */</font>
808 00800
809 00801 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
810 00802 free(column_index), column_index = NULL;
811 00803
812 00804 <font class="preprocessor">#ifdef POLY_DEBUG</font>
813 00805 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"[Gauss : Output]\nRay ="</font>);
814 00806 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Mat);
815 00807 <font class="preprocessor">#endif</font>
816 00808 <font class="preprocessor"></font>
817 00809 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(gcd); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
818 00810 <font class="keywordflow">return</font> Rank;
819 00811 } <font class="comment">/* Gauss */</font>
820 00812
821 00813 <font class="comment">/*</font>
822 00814 <font class="comment"> * Given 'Mat' - a matrix of equations and inequalities, 'Ray' - a matrix of </font>
823 00815 <font class="comment"> * lines and rays, 'Sat' - the corresponding saturation matrix, and 'Filter'</font>
824 00816 <font class="comment"> * - an array to mark (with 1) the non-redundant equalities and inequalities, </font>
825 00817 <font class="comment"> * compute a polyhedron composed of 'Mat' as constraint matrix and 'Ray' as </font>
826 00818 <font class="comment"> * ray matrix after reductions. This function is usually called as a follow</font>
827 00819 <font class="comment"> * up to 'Chernikova' to remove redundant constraints or rays.</font>
828 00820 <font class="comment"> * Note: (1) 'Chernikova' ensures that there are no redundant lines and rays. </font>
829 00821 <font class="comment"> * (2) The same function can be used with constraint and ray matrix used</font>
830 00822 <font class="comment"> interchangbly.</font>
831 00823 <font class="comment"> */</font>
832 <a name="l00824"></a><a class="code" href="polyhedron_8c.html#a16">00824</a> <font class="keyword">static</font> Polyhedron *<a class="code" href="polyhedron_8c.html#a16">Remove_Redundants</a>(Matrix *Mat,Matrix *Ray,<a class="code" href="structSatMatrix.html">SatMatrix</a> *Sat,<font class="keywordtype">unsigned</font> *Filter) {
833 00825
834 00826 <font class="keywordtype">int</font> i, j, k;
835 00827 <font class="keywordtype">unsigned</font> Dimension, sat_nbcolumns, NbRay, NbConstraints, RowSize1, RowSize2,
836 00828 *Trace = NULL, *bx = NULL, *jx = NULL, Dim_RaySpace, b;
837 00829 <font class="keywordtype">unsigned</font> NbBid, NbUni, NbEq, NbIneq;
838 00830 <font class="keywordtype">unsigned</font> NbBid2, NbUni2, NbEq2, NbIneq2;
839 00831 <font class="keywordtype">int</font> Redundant;
840 00832 <font class="keywordtype">int</font> aux, *temp2 = NULL;
841 00833 Polyhedron *Pol = NULL;
842 00834 <a class="code" href="arithmetique_8h.html#a93">Value</a> *temp1 = NULL;
843 00835 <a class="code" href="arithmetique_8h.html#a93">Value</a> *p, *q;
844 00836 <a class="code" href="arithmetique_8h.html#a93">Value</a> Status,tmp1,tmp2,tmp3;
845 00837
846 00838 Dimension = Mat-&gt;NbColumns-1; <font class="comment">/* Homogeneous Dimension */</font>
847 00839 NbRay = Ray-&gt;NbRows;
848 00840 sat_nbcolumns = Sat-&gt;<a class="code" href="structSatMatrix.html#m1">NbColumns</a>;
849 00841 NbConstraints = Mat-&gt;NbRows;
850 00842 RowSize1=(Dimension+1);
851 00843 RowSize2=sat_nbcolumns * <font class="keyword">sizeof</font>(int);
852 00844
853 00845 temp1=(<a class="code" href="arithmetique_8h.html#a93">Value</a> *)malloc(RowSize1*<font class="keyword">sizeof</font>(<a class="code" href="arithmetique_8h.html#a93">Value</a>));
854 00846 <font class="keywordflow">if</font>(!temp1) {
855 00847 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"Remove_Redundants"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
856 00848 <font class="keywordflow">return</font> 0;
857 00849 }
858 00850
859 00851 <font class="comment">/* Initialize all the 'Value' variables */</font>
860 00852 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(Status); <a class="code" href="arithmetique_8h.html#a10">value_init</a>(tmp1);
861 00853 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(tmp2); <a class="code" href="arithmetique_8h.html#a10">value_init</a>(tmp3);
862 00854
863 00855 <font class="keywordflow">for</font>(i=0;i&lt;RowSize1;i++)
864 00856 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(temp1[i]);
865 00857
866 00858 temp2=(<font class="keywordtype">int</font> *)malloc(RowSize2);
867 00859 <font class="keywordflow">if</font>(!temp2) {
868 00860 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"Remove_Redundants"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
869 00861
870 00862 <font class="comment">/* Clear all the 'Value' variables */</font>
871 00863 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(Status); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp1);
872 00864 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp2); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp3);
873 00865 <font class="keywordflow">for</font>(i=0;i&lt;RowSize1;i++)
874 00866 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(temp1[i]);
875 00867 free(temp1);
876 00868 <font class="keywordflow">return</font> 0;
877 00869 }
878 00870
879 00871 <font class="comment">/* Introduce indirections into saturation matrix 'Sat' to simplify */</font>
880 00872 <font class="comment">/* processing with 'Sat' and allow easy exchanges of columns. */</font>
881 00873 bx = (<font class="keywordtype">unsigned</font> *)malloc(NbConstraints * <font class="keyword">sizeof</font>(<font class="keywordtype">unsigned</font>));
882 00874 <font class="keywordflow">if</font>(!bx) {
883 00875 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"Remove_Redundants"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
884 00876
885 00877 <font class="comment">/* Clear all the 'Value' variables */</font>
886 00878 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(Status); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp1);
887 00879 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp2); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp3);
888 00880 <font class="keywordflow">for</font>(i=0;i&lt;RowSize1;i++)
889 00881 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(temp1[i]);
890 00882 free(temp1); free(temp2);
891 00883 <font class="keywordflow">return</font> 0;
892 00884 }
893 00885 jx = (<font class="keywordtype">unsigned</font> *)malloc(NbConstraints * <font class="keyword">sizeof</font>(<font class="keywordtype">unsigned</font>));
894 00886 <font class="keywordflow">if</font>(!jx) {
895 00887 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"Remove_Redundants"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
896 00888
897 00889 <font class="comment">/* Clear all the 'Value' variables */</font>
898 00890 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(Status); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp1);
899 00891 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp2); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp3);
900 00892 <font class="keywordflow">for</font>(i=0;i&lt;RowSize1;i++)
901 00893 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(temp1[i]);
902 00894 free(temp1); free(temp2); free(bx);
903 00895 <font class="keywordflow">return</font> 0;
904 00896 }
905 00897 <a class="code" href="arithmetic__errors_8h.html#a4">CATCH</a>(any_exception_error) {
906 00898
907 00899 <font class="keywordflow">if</font> (temp1) {
908 00900 <font class="keywordflow">for</font>(i=0;i&lt;RowSize1;i++)
909 00901 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(temp1[i]);
910 00902 free(temp1);
911 00903 }
912 00904 <font class="keywordflow">if</font> (temp2) free(temp2);
913 00905 <font class="keywordflow">if</font> (bx) free(bx);
914 00906 <font class="keywordflow">if</font> (jx) free(jx);
915 00907 <font class="keywordflow">if</font> (Trace) free(Trace);
916 00908 <font class="keywordflow">if</font> (Pol) <a class="code" href="polyhedron_8c.html#a18">Polyhedron_Free</a>(Pol);
917 00909
918 00910 <font class="comment">/* Clear all the 'Value' variables */</font>
919 00911 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(Status); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp1);
920 00912 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp2); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp3);
921 00913
922 00914 <a class="code" href="arithmetic__errors_8h.html#a7">RETHROW</a>();
923 00915 }
924 00916 <a class="code" href="arithmetic__errors_8h.html#a6">TRY</a> {
925 00917
926 00918 <font class="comment">/* For each constraint 'j' following mapping is defined to facilitate */</font>
927 00919 <font class="comment">/* data access from saturation matrix 'Sat' :- */</font>
928 00920 <font class="comment">/* (1) jx[j] -&gt; floor[j/(8*sizeof(int))] */</font>
929 00921 <font class="comment">/* (2) bx[j] -&gt; bin(00..10..0) where position of 1 = j%(8*sizeof(int)) */</font>
930 00922
931 00923 i = 0;
932 00924 b = MSB;
933 00925 <font class="keywordflow">for</font> (j=0; j&lt;NbConstraints; j++) {
934 00926 jx[j] = i;
935 00927 bx[j] = b;
936 00928 NEXT(i,b);
937 00929 }
938 00930
939 00931 <font class="comment">/* </font>
940 00932 <font class="comment"> * STEP(0): Count the number of vertices among the rays while initializing</font>
941 00933 <font class="comment"> * the ray status count to 0. If no vertices are found, quit the procedure</font>
942 00934 <font class="comment"> * and return an empty polyhedron as the result. </font>
943 00935 <font class="comment"> */</font>
944 00936
945 00937 <font class="comment">/* Reset the status element of each ray to zero. Store the number of */</font>
946 00938 <font class="comment">/* vertices in 'aux'. */</font>
947 00939 aux = 0;
948 00940 <font class="keywordflow">for</font> (i=0; i&lt;NbRay; i++) {
949 00941
950 00942 <font class="comment">/* Ray-&gt;p[i][0] = 0 */</font>
951 00943 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Ray-&gt;p[i][0],0);
952 00944
953 00945 <font class="comment">/* If ray(i) is a vertex of the Inhomogenous system */</font>
954 00946 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(Ray-&gt;p[i][Dimension]))
955 00947 aux++;
956 00948 }
957 00949
958 00950 <font class="comment">/* If no vertices, return an empty polyhedron. */</font>
959 00951 <font class="keywordflow">if</font> (!aux) {
960 00952
961 00953 <font class="comment">/* Clear all the 'Value' variables */</font>
962 00954 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(Status); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp1);
963 00955 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp2); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp3);
964 00956 <font class="keywordflow">for</font>(i=0;i&lt;RowSize1;i++)
965 00957 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(temp1[i]);
966 00958
967 00959 <font class="comment">/* Return an empty polyhedron */</font>
968 00960 free(temp1); free(temp2); free(jx); free(bx);
969 00961 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
970 00962 <font class="keywordflow">return</font> <a class="code" href="polyhedron_8c.html#a22">Empty_Polyhedron</a>(Dimension-1);
971 00963 }
972 00964
973 00965 <font class="preprocessor">#ifdef POLY_RR_DEBUG</font>
974 00966 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"[Remove_redundants : Init]\nConstraints ="</font>);
975 00967 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Mat);
976 00968 fprintf(stderr, <font class="stringliteral">"\nRays ="</font>);
977 00969 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Ray);
978 00970 <font class="preprocessor">#endif</font>
979 00971 <font class="preprocessor"></font>
980 00972 <font class="comment">/* </font>
981 00973 <font class="comment"> * STEP(1): Compute status counts for both rays and inequalities. For each</font>
982 00974 <font class="comment"> * constraint, count the number of vertices/rays saturated by that </font>
983 00975 <font class="comment"> * constraint, and put the result in the status words. At the same time, </font>
984 00976 <font class="comment"> * for each vertex/ray, count the number of constraints saturated by it.</font>
985 00977 <font class="comment"> * Delete any positivity constraints, but give rays credit in their status</font>
986 00978 <font class="comment"> * counts for saturating the positivity constraint.</font>
987 00979 <font class="comment"> */</font>
988 00980
989 00981 NbEq=0;
990 00982 <font class="preprocessor"> #ifdef JUNK</font>
991 00983 <font class="preprocessor"></font> <font class="comment">/* JUNK is a temporary flag, the code in the JUNK part, should probably</font>
992 00984 <font class="comment"> be removed (see with Fabien and Doran) */</font>
993 00985 memset((<font class="keywordtype">char</font> *)temp2, 0, RowSize2);
994 00986 <font class="preprocessor">#endif</font>
995 00987 <font class="preprocessor"></font>
996 00988 <font class="preprocessor">#ifdef POLY_RR_DEBUG</font>
997 00989 <font class="preprocessor"></font> fprintf (stderr, <font class="stringliteral">" j = "</font>);
998 00990 <font class="preprocessor">#endif</font>
999 00991 <font class="preprocessor"></font>
1000 00992 <font class="keywordflow">for</font> (j=0; j&lt;NbConstraints; j++) {
1001 00993
1002 00994 <font class="preprocessor">#ifdef POLY_RR_DEBUG</font>
1003 00995 <font class="preprocessor"></font> fprintf (stderr, <font class="stringliteral">" %i "</font>, j);
1004 00996 fflush (stderr);
1005 00997 <font class="preprocessor">#endif</font>
1006 00998 <font class="preprocessor"></font>
1007 00999 <font class="preprocessor">#ifdef JUNK</font>
1008 01000 <font class="preprocessor"></font> <font class="comment">/* If constraint(j) is an equality, mark '1' in array 'temp2' */</font>
1009 01001 <font class="keywordflow">if</font> (Filter &amp;&amp; <a class="code" href="arithmetique_8h.html#a67">value_zero_p</a>(Mat-&gt;p[j][0]))
1010 01002 temp2[jx[j]] |= bx[j];
1011 01003 <font class="preprocessor">#endif</font>
1012 01004 <font class="preprocessor"></font> <font class="comment">/* Reset the status element of each constraint to zero */</font>
1013 01005 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Mat-&gt;p[j][0],0);
1014 01006
1015 01007 <font class="comment">/* Identify and remove the positivity constraint 1&gt;=0 */</font>
1016 01008 <font class="keywordflow">for</font> (i=1, p = &amp;Mat-&gt;p[j][1]; i&lt;Dimension; i++) {
1017 01009
1018 01010 <font class="comment">/* if (*p) */</font>
1019 01011 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(*p)) {
1020 01012 p++;
1021 01013 <font class="keywordflow">break</font>;
1022 01014 }
1023 01015 <font class="keywordflow">else</font>
1024 01016 p++;
1025 01017 }
1026 01018
1027 01019 <font class="preprocessor">#ifdef POLY_RR_DEBUG</font>
1028 01020 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"[Remove_redundants : IntoStep1]\nConstraints ="</font>);
1029 01021 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Mat);
1030 01022 fprintf (stderr, <font class="stringliteral">" j = %i \n"</font>, j);
1031 01023 <font class="preprocessor">#endif</font>
1032 01024 <font class="preprocessor"></font>
1033 01025 <font class="comment">/* Check if constraint(j) is a positivity constraint, 1 &gt;= 0, or if it */</font>
1034 01026 <font class="comment">/* is 1==0. If constraint(j) saturates all the rays of the matrix 'Ray'*/</font>
1035 01027 <font class="comment">/* then it is an equality. in this case, return an empty polyhedron. */</font>
1036 01028
1037 01029 <font class="keywordflow">if</font> (i==Dimension) {
1038 01030 <font class="keywordflow">for</font> (i=0; i&lt;NbRay; i++)
1039 01031 <font class="keywordflow">if</font> (!(Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[i][jx[j]]&amp;bx[j])) {
1040 01032
1041 01033 <font class="comment">/* Mat-&gt;p[j][0]++ */</font>
1042 01034 <a class="code" href="arithmetique_8h.html#a45">value_increment</a>(Mat-&gt;p[j][0],Mat-&gt;p[j][0]);
1043 01035 }
1044 01036
1045 01037 <font class="comment">/* if ((Mat-&gt;p[j][0] == NbRay) &amp;&amp; : it is an equality</font>
1046 01038 <font class="comment"> (Mat-&gt;p[j][Dimension] != 0)) : and its not 0=0 */</font>
1047 01039 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(tmp1,NbRay);
1048 01040 <font class="keywordflow">if</font> ((<a class="code" href="arithmetique_8h.html#a22">value_eq</a>(Mat-&gt;p[j][0],tmp1)) &amp;&amp;
1049 01041 (<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(Mat-&gt;p[j][Dimension]))) {
1050 01042
1051 01043 <font class="comment">/* Clear all the 'Value' variables */</font>
1052 01044 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(Status); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp1);
1053 01045 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp2); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp3);
1054 01046 <font class="keywordflow">for</font>(i=0;i&lt;RowSize1;i++)
1055 01047 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(temp1[i]);
1056 01048
1057 01049 <font class="comment">/* Return an empty polyhedron */</font>
1058 01050 free(temp1); free(temp2); free(jx); free(bx);
1059 01051 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
1060 01052 <font class="keywordflow">return</font> <a class="code" href="polyhedron_8c.html#a22">Empty_Polyhedron</a>(Dimension-1);
1061 01053 }
1062 01054
1063 01055 <font class="comment">/* Delete the positivity constraint */</font>
1064 01056 NbConstraints--;
1065 01057 <font class="keywordflow">if</font> (j==NbConstraints) <font class="keywordflow">continue</font>;
1066 01058 <a class="code" href="vector_8c.html#a10">Vector_Exchange</a>(Mat-&gt;p[j], Mat-&gt;p[NbConstraints],RowSize1);
1067 01059 <a class="code" href="polyhedron_8c.html#a2">exchange</a>(jx[j], jx[NbConstraints], aux);
1068 01060 <a class="code" href="polyhedron_8c.html#a2">exchange</a>(bx[j], bx[NbConstraints], aux);
1069 01061 j--; <font class="keywordflow">continue</font>;
1070 01062 }
1071 01063
1072 01064 <font class="comment">/* Count the number of vertices/rays saturated by each constraint. At */</font>
1073 01065 <font class="comment">/* the same time, count the number of constraints saturated by each ray*/</font>
1074 01066 <font class="keywordflow">for</font> (i=0; i&lt;NbRay; i++)
1075 01067 <font class="keywordflow">if</font> (!(Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[i][jx[j]]&amp;bx[j])) {
1076 01068
1077 01069 <font class="comment">/* Mat-&gt;p[j][0]++ */</font>
1078 01070 <a class="code" href="arithmetique_8h.html#a45">value_increment</a>(Mat-&gt;p[j][0],Mat-&gt;p[j][0]);
1079 01071
1080 01072 <font class="comment">/* Ray-&gt;p[i][0]++ */</font>
1081 01073 <a class="code" href="arithmetique_8h.html#a45">value_increment</a> (Ray-&gt;p[i][0],Ray-&gt;p[i][0]);
1082 01074 }
1083 01075
1084 01076 <font class="comment">/* if (Mat-&gt;p[j][0]==NbRay) then increment the number of eq. count */</font>
1085 01077 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(tmp1,NbRay);
1086 01078 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a22">value_eq</a>(Mat-&gt;p[j][0],tmp1))
1087 01079 NbEq++; <font class="comment">/* all vertices/rays are saturated */</font>
1088 01080 }
1089 01081 Mat-&gt;NbRows = NbConstraints;
1090 01082
1091 01083 NbBid=0;
1092 01084 <font class="keywordflow">for</font> (i=0; i&lt;NbRay; i++) {
1093 01085
1094 01086 <font class="comment">/* Give rays credit for saturating the positivity constraint */</font>
1095 01087 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a67">value_zero_p</a>(Ray-&gt;p[i][Dimension]))
1096 01088
1097 01089 <font class="comment">/* Ray-&gt;p[i][0]++ */</font>
1098 01090 <a class="code" href="arithmetique_8h.html#a45">value_increment</a>(Ray-&gt;p[i][0],Ray-&gt;p[i][0]);
1099 01091
1100 01092 <font class="comment">/* If ray(i) saturates all the constraints including positivity */</font>
1101 01093 <font class="comment">/* constraint then it is a bi-directional ray or line. Increment */</font>
1102 01094 <font class="comment">/* 'NbBid' by one. */</font>
1103 01095
1104 01096 <font class="comment">/* if (Ray-&gt;p[i][0]==NbConstraints+1) */</font>
1105 01097 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(tmp1,(NbConstraints+1));
1106 01098 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a22">value_eq</a>(Ray-&gt;p[i][0],tmp1))
1107 01099 NbBid++;
1108 01100 }
1109 01101
1110 01102 <font class="preprocessor">#ifdef POLY_RR_DEBUG</font>
1111 01103 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"[Remove_redundants : Step1]\nConstraints ="</font>);
1112 01104 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Mat);
1113 01105 fprintf(stderr, <font class="stringliteral">"\nRay ="</font>);
1114 01106 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Ray);
1115 01107 <font class="preprocessor">#endif</font>
1116 01108 <font class="preprocessor"></font>
1117 01109 <font class="comment">/* </font>
1118 01110 <font class="comment"> * STEP(2): Sort equalities to the top of constraint matrix 'Mat'. Detect</font>
1119 01111 <font class="comment"> * implicit equations such as y&gt;=3; y&lt;=3. Keep Inequalities in same </font>
1120 01112 <font class="comment"> * relative order. (Note: Equalities are constraints which saturate all of</font>
1121 01113 <font class="comment"> * the rays) </font>
1122 01114 <font class="comment"> */</font>
1123 01115
1124 01116 <font class="keywordflow">for</font> (i=0; i&lt;NbEq; i++) {
1125 01117
1126 01118 <font class="comment">/* If constraint(i) doesn't saturate some ray, then it is an inequality*/</font>
1127 01119 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(tmp1,NbRay);
1128 01120 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a23">value_ne</a>(Mat-&gt;p[i][0],tmp1)) {
1129 01121
1130 01122 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(tmp1,NbRay);
1131 01123 <font class="comment">/* Skip over inequalities and find an equality */</font>
1132 01124 <font class="keywordflow">for</font> (k=i+1;<a class="code" href="arithmetique_8h.html#a23">value_ne</a>(Mat-&gt;p[k][0],tmp1) &amp;&amp; k&lt;NbConstraints;k++);
1133 01125 <font class="keywordflow">if</font> (k==NbConstraints) <font class="comment">/* If none found then error */</font> <font class="keywordflow">break</font>;
1134 01126
1135 01127 <font class="comment">/* Slide inequalities down the array 'Mat' and move equality up to */</font>
1136 01128 <font class="comment">/* position 'i'. */</font>
1137 01129 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(Mat-&gt;p[k], temp1,RowSize1);
1138 01130 aux = jx[k];
1139 01131 j = bx[k];
1140 01132 <font class="keywordflow">for</font> (;k&gt;i;k--) {
1141 01133 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(Mat-&gt;p[k-1],Mat-&gt;p[k],RowSize1);
1142 01134 jx[k] = jx[k-1];
1143 01135 bx[k] = bx[k-1];
1144 01136 }
1145 01137 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(temp1,Mat-&gt;p[i],RowSize1);
1146 01138 jx[i] = aux;
1147 01139 bx[i] = j;
1148 01140 }
1149 01141 }
1150 01142
1151 01143 <font class="preprocessor">#ifdef JUNK</font>
1152 01144 <font class="preprocessor"></font> <font class="keywordflow">if</font> (Filter) <font class="comment">/* for SIMPLIFY */</font>
1153 01145 <font class="keywordflow">for</font> (i=0; i&lt;NbEq; i++) {
1154 01146
1155 01147 <font class="comment">/* Detect implicit constraints such as y&gt;=3 and y&lt;=3 */</font>
1156 01148 Redundant = 0;
1157 01149 <font class="keywordflow">for</font> (j=i+1; j&lt;NbEq; j++) {
1158 01150 <font class="keywordflow">for</font> (k=0, p=&amp;Mat-&gt;p[i][1], q=&amp;Mat-&gt;p[j][1]; k&lt;Dimension; k++,p++,q++) {
1159 01151 <font class="comment">/* if (*p!=*q) */</font>
1160 01152 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a23">value_ne</a>(*p, *q))
1161 01153 <font class="keywordflow">break</font>;
1162 01154 }
1163 01155
1164 01156 <font class="comment">/* Redundant if both are same `and' constraint(j) was equality. */</font>
1165 01157 <font class="comment">/* That is, 'temp2' has entry 1 */</font>
1166 01158 <font class="keywordflow">if</font> (k==Dimension &amp;&amp; (temp2[jx[j]] &amp; bx[j])) {
1167 01159 Redundant=1;
1168 01160 <font class="keywordflow">break</font>;
1169 01161 }
1170 01162 }
1171 01163
1172 01164 <font class="comment">/* Set 'Filter' entry to 1 corresponding to the irredundant equality*/</font>
1173 01165 <font class="keywordflow">if</font> (!Redundant) Filter[jx[i]] |= bx[i]; <font class="comment">/* set flag */</font>
1174 01166 }
1175 01167
1176 01168 <font class="preprocessor">#endif</font>
1177 01169 <font class="preprocessor"></font><font class="preprocessor">#ifdef POLY_RR_DEBUG</font>
1178 01170 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"[Remove_redundants : Step2]\nConstraints ="</font>);
1179 01171 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Mat);
1180 01172 fprintf(stderr, <font class="stringliteral">"\nRay ="</font>);
1181 01173 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Ray);
1182 01174 <font class="preprocessor">#endif</font>
1183 01175 <font class="preprocessor"></font>
1184 01176 <font class="comment">/* </font>
1185 01177 <font class="comment"> * STEP(3): Perform Gaussian elimiation on the list of equalities. Obtain</font>
1186 01178 <font class="comment"> * a minimal basis by solving for as many variables as possible. Use this </font>
1187 01179 <font class="comment"> * solution to reduce the inequalities by eliminating as many variables as</font>
1188 01180 <font class="comment"> * possible. Set NbEq2 to the rank of the system of equalities.</font>
1189 01181 <font class="comment"> */</font>
1190 01182
1191 01183 NbEq2 = <a class="code" href="polyhedron_8c.html#a15">Gauss</a>(Mat,NbEq,Dimension);
1192 01184
1193 01185 <font class="comment">/* If number of equalities is not less then the homogenous dimension, */</font>
1194 01186 <font class="comment">/* return an empty polyhedron. */</font>
1195 01187
1196 01188 <font class="keywordflow">if</font> (NbEq2&gt;=Dimension) {
1197 01189
1198 01190 <font class="comment">/* Clear all the 'Value' variables */</font>
1199 01191 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(Status); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp1);
1200 01192 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp2); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp3);
1201 01193 <font class="keywordflow">for</font>(i=0;i&lt;RowSize1;i++)
1202 01194 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(temp1[i]);
1203 01195
1204 01196 free(temp1); free(temp2); free(jx); free(bx);
1205 01197 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
1206 01198 <font class="keywordflow">return</font> <a class="code" href="polyhedron_8c.html#a22">Empty_Polyhedron</a>(Dimension-1);
1207 01199 }
1208 01200
1209 01201 <font class="preprocessor">#ifdef POLY_RR_DEBUG</font>
1210 01202 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"[Remove_redundants : Step3]\nConstraints ="</font>);
1211 01203 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Mat);
1212 01204 fprintf(stderr, <font class="stringliteral">"\nRay ="</font>);
1213 01205 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Ray);
1214 01206 <font class="preprocessor">#endif</font>
1215 01207 <font class="preprocessor"></font>
1216 01208 <font class="comment">/*</font>
1217 01209 <font class="comment"> * STEP(4): Sort lines to the top of ray matrix 'Ray', leaving rays</font>
1218 01210 <font class="comment"> * afterwards. Detect implicit lines such as ray(1,2) and ray(-1,-2). </font>
1219 01211 <font class="comment"> * (Note: Lines are rays which saturate all of the constraints including</font>
1220 01212 <font class="comment"> * the positivity constraint 1&gt;=0. </font>
1221 01213 <font class="comment"> */</font>
1222 01214
1223 01215
1224 01216 <font class="keywordflow">for</font> (i=0, k=NbRay; i&lt;NbBid &amp;&amp; k&gt;i; i++) {
1225 01217 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(tmp1,(NbConstraints+1));
1226 01218
1227 01219 <font class="comment">/* If ray(i) doesn't saturate some constraint then it is not a line */</font>
1228 01220 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a23">value_ne</a>(Ray-&gt;p[i][0],tmp1)) {
1229 01221
1230 01222 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(tmp1,(NbConstraints+1));
1231 01223 <font class="comment">/* Skip over rays and vertices and find a line (bi-directional rays) */</font>
1232 01224 <font class="keywordflow">while</font> (--k &gt;i &amp;&amp; <a class="code" href="arithmetique_8h.html#a23">value_ne</a>(Ray-&gt;p[k][0],tmp1)) ;
1233 01225
1234 01226 <font class="comment">/* Exchange positions of ray(i) and line(k), thus sorting lines to */</font>
1235 01227 <font class="comment">/* the top of matrix 'Ray'. */</font>
1236 01228 <a class="code" href="vector_8c.html#a10">Vector_Exchange</a>(Ray-&gt;p[i], Ray-&gt;p[k], RowSize1);
1237 01229 <a class="code" href="polyhedron_8c.html#a1">bexchange</a>(Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[i], Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[k], RowSize2);
1238 01230 }
1239 01231 }
1240 01232
1241 01233 <font class="preprocessor">#ifdef POLY_RR_DEBUG</font>
1242 01234 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"[Remove_redundants : Step4]\nConstraints ="</font>);
1243 01235 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Mat);
1244 01236 fprintf(stderr, <font class="stringliteral">"\nRay ="</font>);
1245 01237 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Ray);
1246 01238 <font class="preprocessor">#endif</font>
1247 01239 <font class="preprocessor"></font>
1248 01240 <font class="comment">/* </font>
1249 01241 <font class="comment"> * STEP(5): Perform Gaussian elimination on the lineality space to obtain</font>
1250 01242 <font class="comment"> * a minimal basis of lines. Use this basis to reduce the represeentation</font>
1251 01243 <font class="comment"> * of the uniderectional rays. Set 'NbBid2' to the rank of the system of </font>
1252 01244 <font class="comment"> * lines. </font>
1253 01245 <font class="comment"> */</font>
1254 01246
1255 01247 NbBid2 = <a class="code" href="polyhedron_8c.html#a15">Gauss</a>(Ray, NbBid, Dimension);
1256 01248
1257 01249 <font class="preprocessor">#ifdef POLY_RR_DEBUG</font>
1258 01250 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"[Remove_redundants : After Gauss]\nRay ="</font>);
1259 01251 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Ray);
1260 01252 <font class="preprocessor">#endif</font>
1261 01253 <font class="preprocessor"></font>
1262 01254 <font class="comment">/* If number of lines is not less then the homogenous dimension, return */</font>
1263 01255 <font class="comment">/* an empty polyhedron. */</font>
1264 01256 <font class="keywordflow">if</font> (NbBid2&gt;=Dimension) {
1265 01257 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"RemoveRedundants"</font>, <font class="stringliteral">"rmrdt"</font>, <font class="stringliteral">"dimension error"</font>);
1266 01258
1267 01259 <font class="comment">/* Clear all the 'Value' variables */</font>
1268 01260 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(Status); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp1);
1269 01261 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp2); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp3);
1270 01262 <font class="keywordflow">for</font>(i=0;i&lt;RowSize1;i++)
1271 01263 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(temp1[i]);
1272 01264
1273 01265 free(temp1); free(temp2); free(jx); free(bx);
1274 01266 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
1275 01267 <font class="keywordflow">return</font> <a class="code" href="polyhedron_8c.html#a22">Empty_Polyhedron</a>(Dimension-1);
1276 01268 }
1277 01269
1278 01270 <font class="comment">/* Compute dimension of non-homogenous ray space */</font>
1279 01271 Dim_RaySpace = Dimension-1-NbEq2-NbBid2;
1280 01272
1281 01273 <font class="preprocessor">#ifdef POLY_RR_DEBUG</font>
1282 01274 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"[Remove_redundants : Step5]\nConstraints ="</font>);
1283 01275 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Mat);
1284 01276 fprintf(stderr, <font class="stringliteral">"\nRay ="</font>);
1285 01277 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Ray);
1286 01278 <font class="preprocessor">#endif</font>
1287 01279 <font class="preprocessor"></font>
1288 01280 <font class="comment">/* </font>
1289 01281 <font class="comment"> * STEP(6): Do a first pass filter of inequalities and equality identifi-</font>
1290 01282 <font class="comment"> * cation. New positivity constraints may have been created by step(3). </font>
1291 01283 <font class="comment"> * Check for and eliminate them. Count the irredundant inequalities and </font>
1292 01284 <font class="comment"> * store count in 'NbIneq'. </font>
1293 01285 <font class="comment"> */</font>
1294 01286
1295 01287 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(tmp2,Dim_RaySpace);
1296 01288 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(tmp3,NbRay);
1297 01289 NbIneq=0;
1298 01290 <font class="keywordflow">for</font> (j=0; j&lt;NbConstraints; j++) {
1299 01291
1300 01292 <font class="comment">/* Identify and remove the positivity constraint 1&gt;=0 */</font>
1301 01293 <font class="keywordflow">for</font> (i=1, p = &amp;Mat-&gt;p[j][1]; i&lt;Dimension; i++)
1302 01294 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a> (*p)) {
1303 01295 p++;
1304 01296 <font class="keywordflow">break</font>;
1305 01297 }
1306 01298 <font class="keywordflow">else</font>
1307 01299 p++;
1308 01300
1309 01301 <font class="comment">/* Check if constraint(j) is a positivity constraint, 1&gt;= 0, or if it */</font>
1310 01302 <font class="comment">/* is 1==0. */</font>
1311 01303 <font class="keywordflow">if</font> (i==Dimension) {
1312 01304
1313 01305 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(tmp1,NbRay);
1314 01306
1315 01307 <font class="comment">/* if ((Mat-&gt;p[j][0]==NbRay) &amp;&amp; : it is an equality </font>
1316 01308 <font class="comment"> (Mat-&gt;p[j][Dimension]!=0)) : and its not 0=0 */</font>
1317 01309 <font class="keywordflow">if</font> ((<a class="code" href="arithmetique_8h.html#a22">value_eq</a> (Mat-&gt;p[j][0],tmp1)) &amp;&amp;
1318 01310 (<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(Mat-&gt;p[j][Dimension]))) {
1319 01311
1320 01312 <font class="comment">/* Clear all the 'Value' variables */</font>
1321 01313 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(Status); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp1);
1322 01314 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp2); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp3);
1323 01315 <font class="keywordflow">for</font>(i=0;i&lt;RowSize1;i++)
1324 01316 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(temp1[i]);
1325 01317
1326 01318 <font class="comment">/* Return an empty polyhedron */</font>
1327 01319 free(temp1); free(temp2); free(jx); free(bx);
1328 01320 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
1329 01321 <font class="keywordflow">return</font> <a class="code" href="polyhedron_8c.html#a22">Empty_Polyhedron</a>(Dimension-1);
1330 01322 }
1331 01323
1332 01324 <font class="comment">/* Set the positivity constraint redundant by setting status element */</font>
1333 01325 <font class="comment">/* equal to 2. */</font>
1334 01326 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Mat-&gt;p[j][0],2);
1335 01327 <font class="keywordflow">continue</font>;
1336 01328 }
1337 01329
1338 01330 <font class="comment">/* Status = Mat-&gt;p[j][0] */</font>
1339 01331 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(Status, Mat-&gt;p[j][0]);
1340 01332
1341 01333 <font class="comment">/* if (Status == 0) then constraint is redundant */</font>
1342 01334 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a67">value_zero_p</a>(Status))
1343 01335
1344 01336 <font class="comment">/* Mat-&gt;p[j][0]=2 : redundant */</font>
1345 01337 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Mat-&gt;p[j][0],2);
1346 01338
1347 01339 <font class="comment">/* else if (Status&lt;Dim_RaySpace) then constraint is redundant */</font>
1348 01340 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a26">value_lt</a>(Status,tmp2))
1349 01341
1350 01342 <font class="comment">/* Mat-&gt;p[j][0]=2 : redundant */</font>
1351 01343 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Mat-&gt;p[j][0],2);
1352 01344
1353 01345 <font class="comment">/* else if (Status==NbRay) then constraint is an equality */</font>
1354 01346 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a22">value_eq</a>(Status,tmp3))
1355 01347
1356 01348 <font class="comment">/* Mat-&gt;p[j][0]=0 : equality */</font>
1357 01349 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Mat-&gt;p[j][0],0);
1358 01350
1359 01351 <font class="comment">/* else constraint is an irredundant inequality */</font>
1360 01352 <font class="keywordflow">else</font> {
1361 01353 NbIneq++;
1362 01354
1363 01355 <font class="comment">/* Mat-&gt;p[j][0]=1 : inequality */</font>
1364 01356 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Mat-&gt;p[j][0],1);
1365 01357 }
1366 01358 }
1367 01359
1368 01360 <font class="preprocessor">#ifdef POLY_RR_DEBUG</font>
1369 01361 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"[Remove_redundants : Step6]\nConstraints ="</font>);
1370 01362 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Mat);
1371 01363 fprintf(stderr, <font class="stringliteral">"\nRay ="</font>);
1372 01364 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Ray);
1373 01365 <font class="preprocessor">#endif</font>
1374 01366 <font class="preprocessor"></font>
1375 01367 <font class="comment">/* </font>
1376 01368 <font class="comment"> * STEP(7): Do a first pass filter of rays and identification of lines.</font>
1377 01369 <font class="comment"> * Count the irredundant Rays and store count in 'NbUni'. </font>
1378 01370 <font class="comment"> */</font>
1379 01371
1380 01372 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(tmp2,Dim_RaySpace);
1381 01373 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(tmp3,(NbConstraints+1));
1382 01374 NbUni=0;
1383 01375 <font class="keywordflow">for</font> (j=0; j&lt;NbRay; j++) {
1384 01376
1385 01377 <font class="comment">/* Status = Ray-&gt;p[j][0] */</font>
1386 01378 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(Status, Ray-&gt;p[j][0]);
1387 01379
1388 01380 <font class="comment">/* if (Status &lt; Dim_RaySpace) the ray is redundant */</font>
1389 01381 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a26">value_lt</a>(Status,tmp2))
1390 01382
1391 01383 <font class="comment">/* Ray-&gt;p[j][0]=2 : redundant */</font>
1392 01384 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Ray-&gt;p[j][0],2);
1393 01385
1394 01386 <font class="comment">/* else if (Status == (NbConstraints+1)) then ray is a line */</font>
1395 01387 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a22">value_eq</a>(Status,tmp3))
1396 01388
1397 01389 <font class="comment">/* Ray-&gt;p[j][0]=0 : line */</font>
1398 01390 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Ray-&gt;p[j][0],0);
1399 01391
1400 01392 <font class="comment">/* else ray is an irredundant unidirectional ray. */</font>
1401 01393 <font class="keywordflow">else</font> {
1402 01394 NbUni++;
1403 01395
1404 01396 <font class="comment">/* Ray-&gt;p[j][0]=1 : ray */</font>
1405 01397 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Ray-&gt;p[j][0],1);
1406 01398 }
1407 01399 }
1408 01400
1409 01401 <font class="comment">/*</font>
1410 01402 <font class="comment"> * STEP(8): Create the polyhedron (using approximate sizes).</font>
1411 01403 <font class="comment"> * Number of constraints = NbIneq + NbEq2 + 1</font>
1412 01404 <font class="comment"> * Number of rays = NbUni + NbBid2 </font>
1413 01405 <font class="comment"> * Partially fill the polyhedron structure with the lines computed in step</font>
1414 01406 <font class="comment"> * 3 and the equalities computed in step 5. </font>
1415 01407 <font class="comment"> */</font>
1416 01408
1417 01409 Pol = <a class="code" href="polyhedron_8c.html#a17">Polyhedron_Alloc</a>(Dimension-1, NbIneq+NbEq2+1, NbUni+NbBid2);
1418 01410 <font class="keywordflow">if</font> (!Pol) {
1419 01411 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"Remove_redundants"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
1420 01412
1421 01413 <font class="comment">/* Clear all the 'Value' variables */</font>
1422 01414 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(Status); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp1);
1423 01415 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp2); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp3);
1424 01416 <font class="keywordflow">for</font>(i=0;i&lt;RowSize1;i++)
1425 01417 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(temp1[i]);
1426 01418
1427 01419 free(temp1); free(temp2); free(jx); free(bx);
1428 01420 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
1429 01421 <font class="keywordflow">return</font> 0;
1430 01422 }
1431 01423 Pol-&gt;NbBid = NbBid2;
1432 01424 Pol-&gt;NbEq = NbEq2;
1433 01425
1434 01426 <font class="comment">/* Partially fill the polyhedron structure */</font>
1435 01427 <font class="keywordflow">if</font> (NbBid2) <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(Ray-&gt;p[0], Pol-&gt;Ray[0], (Dimension+1)*NbBid2);
1436 01428 <font class="keywordflow">if</font> (NbEq2) <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(Mat-&gt;p[0], Pol-&gt;Constraint[0], (Dimension+1)*NbEq2);
1437 01429
1438 01430 <font class="preprocessor">#ifdef POLY_RR_DEBUG</font>
1439 01431 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"[Remove_redundants : Step7]\nConstraints ="</font>);
1440 01432 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Mat);
1441 01433 fprintf(stderr, <font class="stringliteral">"\nRay ="</font>);
1442 01434 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Ray);
1443 01435 <font class="preprocessor">#endif</font>
1444 01436 <font class="preprocessor"></font>
1445 01437 <font class="comment">/* </font>
1446 01438 <font class="comment"> * STEP(9): Final Pass filter of inequalities and detection of redundant</font>
1447 01439 <font class="comment"> * inequaties. Redundant inequalities include: </font>
1448 01440 <font class="comment"> * (1) Inequalities which are always true, such as 1&gt;=0, </font>
1449 01441 <font class="comment"> * (2) Redundant inequalities such as y&gt;=4 given y&gt;=3, or x&gt;=1 given x=2. </font>
1450 01442 <font class="comment"> * (3) Redundant inequalities such as x+y&gt;=5 given x&gt;=3 and y&gt;=2.</font>
1451 01443 <font class="comment"> * Every 'good' inequality must saturate at least 'Dimension' rays and be </font>
1452 01444 <font class="comment"> * unique.</font>
1453 01445 <font class="comment"> */</font>
1454 01446
1455 01447 <font class="comment">/* 'Trace' is a (1 X sat_nbcolumns) row matrix to hold the union of all */</font>
1456 01448 <font class="comment">/* rows (corresponding to irredundant rays) of saturation matrix 'Sat' */</font>
1457 01449 <font class="comment">/* which saturate some constraint 'j'. See figure below:- */</font>
1458 01450 Trace=(<font class="keywordtype">unsigned</font> *)malloc(sat_nbcolumns * <font class="keyword">sizeof</font>(<font class="keywordtype">unsigned</font>));
1459 01451 <font class="keywordflow">if</font>(!Trace) {
1460 01452 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"Remove_Redundants"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
1461 01453
1462 01454 <font class="comment">/* Clear all the 'Value' variables */</font>
1463 01455 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(Status); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp1);
1464 01456 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp2); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp3);
1465 01457 <font class="keywordflow">for</font>(i=0;i&lt;RowSize1;i++)
1466 01458 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(temp1[i]);
1467 01459
1468 01460 free(temp1); free(temp2); free(jx); free(bx);
1469 01461 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
1470 01462 <font class="keywordflow">return</font> 0;
1471 01463 }
1472 01464
1473 01465 <font class="comment">/* NbEq NbConstraints</font>
1474 01466 <font class="comment"> |-----------&gt;</font>
1475 01467 <font class="comment"> ___________j____</font>
1476 01468 <font class="comment"> | | |</font>
1477 01469 <font class="comment"> | Mat | |</font>
1478 01470 <font class="comment"> |___________|___|</font>
1479 01471 <font class="comment"> | </font>
1480 01472 <font class="comment"> NbRay ^ ________ ____________|____</font>
1481 01473 <font class="comment"> | |-------|--------|-----------0---|t1</font>
1482 01474 <font class="comment"> |i|-------|--------|-----------0---|t2</font>
1483 01475 <font class="comment"> | | Ray | | Sat |</font>
1484 01476 <font class="comment"> NbBid - |-------|--------|-----------0---|tk</font>
1485 01477 <font class="comment"> |_______| |_______________|</font>
1486 01478 <font class="comment"> |</font>
1487 01479 <font class="comment"> |</font>
1488 01480 <font class="comment"> -OR- (of rows t1,t2,...,tk)</font>
1489 01481 <font class="comment"> ________|___|____</font>
1490 01482 <font class="comment"> |_____Trace_0___|</font>
1491 01483 <font class="comment"> </font>
1492 01484 <font class="comment"> */</font>
1493 01485
1494 01486 NbIneq2 = 0;
1495 01487 <font class="keywordflow">for</font> (j=NbEq; j&lt;NbConstraints; j++) {
1496 01488
1497 01489 <font class="comment">/* if (Mat-&gt;p[j][0]==1) : non-redundant inequality */</font>
1498 01490 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a69">value_one_p</a> (Mat-&gt;p[j][0])) {
1499 01491 <font class="keywordflow">for</font> (k=0; k&lt;sat_nbcolumns; k++) Trace[k]=0; <font class="comment">/* init Trace */</font>
1500 01492
1501 01493 <font class="comment">/* Compute Trace: the union of all rows of Sat where constraint(j) */</font>
1502 01494 <font class="comment">/* is saturated. */</font>
1503 01495 <font class="keywordflow">for</font> (i=NbBid; i&lt;NbRay; i++)
1504 01496
1505 01497 <font class="comment">/* if (Ray-&gt;p[i][0]==1) */</font>
1506 01498 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a69">value_one_p</a>(Ray-&gt;p[i][0])) {
1507 01499 <font class="keywordflow">if</font> (!(Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[i][jx[j]]&amp;bx[j]))
1508 01500 <font class="keywordflow">for</font> (k=0; k&lt;sat_nbcolumns; k++) Trace[k] |= Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[i][k];
1509 01501 }
1510 01502
1511 01503 <font class="comment">/* Only constraint(j) should saturate this set of vertices/rays. */</font>
1512 01504 <font class="comment">/* If another non-redundant constraint also saturates this set, */</font>
1513 01505 <font class="comment">/* then constraint(j) is redundant */</font>
1514 01506 Redundant=0;
1515 01507 <font class="keywordflow">for</font> (i=NbEq; i&lt;NbConstraints; i++) {
1516 01508
1517 01509 <font class="comment">/* if ((Mat-&gt;p[i][0] ==1) &amp;&amp; (i!=j) &amp;&amp; !(Trace[jx[i]] &amp; bx[i]) ) */</font>
1518 01510 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a69">value_one_p</a>(Mat-&gt;p[i][0]) &amp;&amp; (i!=j) &amp;&amp; !(Trace[jx[i]] &amp; bx[i])) {
1519 01511 Redundant=1;
1520 01512 <font class="keywordflow">break</font>;
1521 01513 }
1522 01514 }
1523 01515 <font class="keywordflow">if</font> (Redundant) {
1524 01516 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Mat-&gt;p[j][0],2);
1525 01517 }
1526 01518 <font class="keywordflow">else</font> {
1527 01519 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(Mat-&gt;p[j], Pol-&gt;Constraint[NbEq2+NbIneq2], Dimension+1);
1528 01520 <font class="keywordflow">if</font> (Filter) Filter[jx[j]] |= bx[j]; <font class="comment">/* for SIMPLIFY */</font>
1529 01521 NbIneq2++;
1530 01522 }
1531 01523 }
1532 01524 }
1533 01525 free(Trace), Trace = NULL;
1534 01526
1535 01527 <font class="preprocessor">#ifdef POLY_RR_DEBUG</font>
1536 01528 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"[Remove_redundants : Step8]\nConstraints ="</font>);
1537 01529 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Mat);
1538 01530 fprintf(stderr, <font class="stringliteral">"\nRay ="</font>);
1539 01531 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Ray);
1540 01532 <font class="preprocessor">#endif</font>
1541 01533 <font class="preprocessor"></font>
1542 01534 <font class="comment">/* </font>
1543 01535 <font class="comment"> * Step(10): Final pass filter of rays and detection of redundant rays.</font>
1544 01536 <font class="comment"> * The final list of rays is written to polyhedron. </font>
1545 01537 <font class="comment"> */</font>
1546 01538
1547 01539 <font class="comment">/* Trace is a (NbRay x 1) column matrix to hold the union of all columns */</font>
1548 01540 <font class="comment">/* (corresponding to irredundant inequalities) of saturation matrix 'Sat'*/</font>
1549 01541 <font class="comment">/* which saturate some ray 'i'. See figure below:- */</font>
1550 01542
1551 01543 Trace=(<font class="keywordtype">unsigned</font> *)malloc(NbRay * <font class="keyword">sizeof</font>(<font class="keywordtype">unsigned</font>));
1552 01544 <font class="keywordflow">if</font>(!Trace) {
1553 01545 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"Remove_Redundants"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
1554 01546
1555 01547 <font class="comment">/* Clear all the 'Value' variables */</font>
1556 01548 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(Status); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp1);
1557 01549 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp2); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp3);
1558 01550 <font class="keywordflow">for</font>(i=0;i&lt;RowSize1;i++)
1559 01551 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(temp1[i]);
1560 01552
1561 01553 free(bx); free(jx); free(temp2); free(temp1);
1562 01554 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
1563 01555 <font class="keywordflow">return</font> 0;
1564 01556 }
1565 01557
1566 01558 <font class="comment">/* NbEq NbConstraints</font>
1567 01559 <font class="comment"> |----------&gt;</font>
1568 01560 <font class="comment"> ___________j_____</font>
1569 01561 <font class="comment"> | | | | |</font>
1570 01562 <font class="comment"> | Mat | |</font>
1571 01563 <font class="comment"> |______|_|___|__|</font>
1572 01564 <font class="comment"> | | |</font>
1573 01565 <font class="comment">NbRay ^ _________ _______|_|___|__ ___</font>
1574 01566 <font class="comment"> | | | | | | | | |T|</font>
1575 01567 <font class="comment"> | | Ray | | Sat| | | | |r|</font>
1576 01568 <font class="comment"> | | | | | | | | |a| Trace = Union[col(t1,t2,..,tk)]</font>
1577 01569 <font class="comment"> |i|-------|------&gt;i 0 0 0 | |c|</font>
1578 01570 <font class="comment">NbBid - | | | | | | | |e|</font>
1579 01571 <font class="comment"> |_______| |______|_|___|__| |_|</font>
1580 01572 <font class="comment"> t1 t2 tk</font>
1581 01573 <font class="comment"> */</font>
1582 01574
1583 01575 NbUni2 = 0;
1584 01576
1585 01577 <font class="comment">/* Let 'aux' be the number of rays not vertices */</font>
1586 01578 aux = 0;
1587 01579 <font class="keywordflow">for</font> (i=NbBid; i&lt;NbRay; i++) {
1588 01580
1589 01581 <font class="comment">/* if (Ray-&gt;p[i][0]==1) */</font>
1590 01582 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a69">value_one_p</a> (Ray-&gt;p[i][0])) {
1591 01583
1592 01584 <font class="comment">/* if (Ray-&gt;p[i][Dimension]!=0) : vertex */</font>
1593 01585 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a> (Ray-&gt;p[i][Dimension]))
1594 01586 <font class="keywordflow">for</font> (k=NbBid; k&lt;NbRay; k++) Trace[k]=0; <font class="comment">/* init Trace */</font>
1595 01587 <font class="keywordflow">else</font> <font class="comment">/* for ray */</font>
1596 01588
1597 01589 <font class="comment">/* Include the positivity constraint incidences for rays. The */</font>
1598 01590 <font class="comment">/* positivity constraint saturates all rays and no vertices */</font>
1599 01591
1600 01592 <font class="keywordflow">for</font> (k=NbBid; k&lt;NbRay; k++)
1601 01593
1602 01594 <font class="comment">/* Trace[k]=(Ray-&gt;p[k][Dimension]!=0); */</font>
1603 01595 Trace[k] = (<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a> (Ray-&gt;p[k][Dimension]));
1604 01596
1605 01597 <font class="comment">/* Compute Trace: the union of all columns of Sat where ray(i) is */</font>
1606 01598 <font class="comment">/* saturated. */</font>
1607 01599 <font class="keywordflow">for</font> (j=NbEq; j&lt;NbConstraints; j++)
1608 01600
1609 01601 <font class="comment">/* if (Mat-&gt;p[j][0]==1) : inequality */</font>
1610 01602 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a69">value_one_p</a> (Mat-&gt;p[j][0])) {
1611 01603 <font class="keywordflow">if</font> (!(Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[i][jx[j]]&amp;bx[j]))
1612 01604 <font class="keywordflow">for</font> (k=NbBid; k&lt;NbRay; k++) Trace[k] |= Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[k][jx[j]]&amp;bx[j];
1613 01605 }
1614 01606
1615 01607 <font class="comment">/* If ray i does not saturate any inequalities (other than the */</font>
1616 01608 <font class="comment">/* the positivity constraint, then it is the case that there is */</font>
1617 01609 <font class="comment">/* only one inequality and that ray is its orthogonal */</font>
1618 01610
1619 01611 <font class="comment">/* only ray(i) should saturate this set of inequalities. If */</font>
1620 01612 <font class="comment">/* another non-redundant ray also saturates this set, then ray(i)*/</font>
1621 01613 <font class="comment">/* is redundant */</font>
1622 01614
1623 01615 Redundant = 0;
1624 01616 <font class="keywordflow">for</font> (j=NbBid; j&lt;NbRay; j++) {
1625 01617
1626 01618 <font class="comment">/* if ( (Ray-&gt;p[j][0]==1) &amp;&amp; (i!=j) &amp;&amp; !Trace[j] ) */</font>
1627 01619 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a69">value_one_p</a> (Ray-&gt;p[j][0]) &amp;&amp; (i!=j) &amp;&amp; !Trace[j]) {
1628 01620 Redundant=1;
1629 01621 <font class="keywordflow">break</font>;
1630 01622 }
1631 01623 }
1632 01624 <font class="keywordflow">if</font> (Redundant)
1633 01625 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Ray-&gt;p[i][0],2);
1634 01626 <font class="keywordflow">else</font> {
1635 01627 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(Ray-&gt;p[i], Pol-&gt;Ray[NbBid2+NbUni2], Dimension+1);
1636 01628 NbUni2++; <font class="comment">/* Increment number of uni-directional rays */</font>
1637 01629
1638 01630 <font class="comment">/* if (Ray-&gt;p[i][Dimension]==0) */</font>
1639 01631 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a67">value_zero_p</a> (Ray-&gt;p[i][Dimension]))
1640 01632 aux++; <font class="comment">/* Increment number of rays which are not vertices */</font>
1641 01633 }
1642 01634 }
1643 01635 }
1644 01636
1645 01637 <font class="comment">/* Include the positivity constraint */</font>
1646 01638 <font class="keywordflow">if</font> (aux&gt;=Dim_RaySpace) {
1647 01639 <a class="code" href="vector_8c.html#a9">Vector_Set</a>(Pol-&gt;Constraint[NbEq2+NbIneq2],0,Dimension+1);
1648 01640 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Pol-&gt;Constraint[NbEq2+NbIneq2][0],1);
1649 01641 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Pol-&gt;Constraint[NbEq2+NbIneq2][Dimension],1);
1650 01642 NbIneq2++;
1651 01643 }
1652 01644 } <font class="comment">/* end of TRY */</font>
1653 01645
1654 01646 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
1655 01647
1656 01648 <font class="preprocessor">#ifdef POLY_RR_DEBUG</font>
1657 01649 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"[Remove_redundants : Step9]\nConstraints ="</font>);
1658 01650 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Mat);
1659 01651 fprintf(stderr, <font class="stringliteral">"\nRay ="</font>);
1660 01652 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Ray);
1661 01653 <font class="preprocessor">#endif</font>
1662 01654 <font class="preprocessor"></font>
1663 01655 free(Trace);
1664 01656 free(bx);
1665 01657 free(jx);
1666 01658 free(temp2);
1667 01659
1668 01660 Pol-&gt;NbConstraints = NbEq2 + NbIneq2;
1669 01661 Pol-&gt;NbRays = NbBid2 + NbUni2;
1670 01662
1671 01663 <font class="comment">/* Clear all the 'Value' variables */</font>
1672 01664 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(Status); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp1);
1673 01665 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp2); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp3);
1674 01666 <font class="keywordflow">for</font>(i=0;i&lt;RowSize1;i++)
1675 01667 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(temp1[i]);
1676 01668 free(temp1);
1677 01669 <font class="keywordflow">return</font> Pol;
1678 01670 } <font class="comment">/* Remove_Redundants */</font>
1679 01671
1680 01672 <font class="comment">/*</font>
1681 01673 <font class="comment"> * Allocate memory space for polyhedron. </font>
1682 01674 <font class="comment"> */</font>
1683 <a name="l01675"></a><a class="code" href="polyhedron_8c.html#a17">01675</a> Polyhedron* <a class="code" href="polyhedron_8c.html#a17">Polyhedron_Alloc</a>(<font class="keywordtype">unsigned</font> Dimension,<font class="keywordtype">unsigned</font> NbConstraints,<font class="keywordtype">unsigned</font> NbRays) {
1684 01676
1685 01677 Polyhedron *Pol;
1686 01678 <font class="keywordtype">unsigned</font> NbRows,NbColumns;
1687 01679 <font class="keywordtype">int</font> i,j;
1688 01680 <a class="code" href="arithmetique_8h.html#a93">Value</a> *p, **q;
1689 01681
1690 01682 Pol=(Polyhedron *)malloc(<font class="keyword">sizeof</font>(Polyhedron));
1691 01683 <font class="keywordflow">if</font>(!Pol) {
1692 01684 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"Polyhedron_Alloc"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
1693 01685 <font class="keywordflow">return</font> 0;
1694 01686 }
1695 01687
1696 01688 Pol-&gt;next = (Polyhedron *)0;
1697 01689 Pol-&gt;Dimension = Dimension;
1698 01690 Pol-&gt;NbConstraints = NbConstraints;
1699 01691 Pol-&gt;NbRays = NbRays;
1700 01692 Pol-&gt;NbEq = 0;
1701 01693 Pol-&gt;NbBid = 0;
1702 01694 NbRows = NbConstraints + NbRays;
1703 01695 NbColumns = Dimension + 2;
1704 01696
1705 01697 q = (<a class="code" href="arithmetique_8h.html#a93">Value</a> **)malloc(NbRows * <font class="keyword">sizeof</font>(<a class="code" href="arithmetique_8h.html#a93">Value</a> *));
1706 01698 <font class="keywordflow">if</font>(!q) {
1707 01699 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"Polyhedron_Alloc"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
1708 01700 <font class="keywordflow">return</font> 0;
1709 01701 }
1710 01702 p = (<a class="code" href="arithmetique_8h.html#a93">Value</a> *)malloc(NbRows * NbColumns * <font class="keyword">sizeof</font>(<a class="code" href="arithmetique_8h.html#a93">Value</a>));
1711 01703 <font class="keywordflow">if</font>(!p) {
1712 01704 free(q);
1713 01705 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"Polyhedron_Alloc"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
1714 01706 <font class="keywordflow">return</font> 0;
1715 01707 }
1716 01708 Pol-&gt;Constraint = q;
1717 01709 Pol-&gt;Ray = q + NbConstraints;
1718 01710 Pol-&gt;p_Init = p;
1719 01711 <font class="keywordflow">for</font> (i=0;i&lt;NbRows;i++) {
1720 01712 *q++ = p;
1721 01713 <font class="keywordflow">for</font>(j=0;j&lt;NbColumns;j++)
1722 01714 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(*(p+j));
1723 01715 p += NbColumns;
1724 01716 }
1725 01717 Pol-&gt;p_Init_size = NbRows*NbColumns;
1726 01718 <font class="keywordflow">return</font> Pol;
1727 01719 } <font class="comment">/* Polyhedron_Alloc */</font>
1728 01720
1729 01721 <font class="comment">/* </font>
1730 01722 <font class="comment"> * Free the memory space occupied by the single polyhedron.</font>
1731 01723 <font class="comment"> */</font>
1732 <a name="l01724"></a><a class="code" href="polyhedron_8c.html#a18">01724</a> <font class="keywordtype">void</font> <a class="code" href="polyhedron_8c.html#a18">Polyhedron_Free</a>(Polyhedron *Pol) {
1733 01725
1734 01726 <font class="keywordtype">int</font> i,size;
1735 01727 <a class="code" href="arithmetique_8h.html#a93">Value</a> *p;
1736 01728
1737 01729 <font class="keywordflow">if</font>(!Pol)
1738 01730 <font class="keywordflow">return</font>;
1739 01731 size = Pol-&gt;p_Init_size;
1740 01732 p = Pol-&gt;p_Init;
1741 01733 <font class="keywordflow">for</font>(i=0;i&lt;size;i++)
1742 01734 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(p[i]);
1743 01735 free(Pol-&gt;p_Init);
1744 01736 free(Pol-&gt;Constraint);
1745 01737 free(Pol);
1746 01738 <font class="keywordflow">return</font>;
1747 01739 } <font class="comment">/* Polyhedron_Free */</font>
1748 01740
1749 01741 <font class="comment">/*</font>
1750 01742 <font class="comment"> * Free the memory space occupied by the domain. </font>
1751 01743 <font class="comment"> */</font>
1752 <a name="l01744"></a><a class="code" href="polyhedron_8c.html#a19">01744</a> <font class="keywordtype">void</font> <a class="code" href="polyhedron_8c.html#a19">Domain_Free</a>(Polyhedron *Pol) {
1753 01745
1754 01746 <font class="keywordtype">int</font> i,size;
1755 01747 <a class="code" href="arithmetique_8h.html#a93">Value</a> *p;
1756 01748
1757 01749 <font class="keywordflow">if</font>(!Pol)
1758 01750 <font class="keywordflow">return</font>;
1759 01751 <font class="keywordflow">if</font> (Pol-&gt;next)
1760 01752 <a class="code" href="polyhedron_8c.html#a19">Domain_Free</a>(Pol-&gt;next);
1761 01753
1762 01754 size = Pol-&gt;p_Init_size;
1763 01755 p = Pol-&gt;p_Init;
1764 01756 <font class="keywordflow">for</font>(i=0;i&lt;size;i++)
1765 01757 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(p[i]);
1766 01758 free(Pol-&gt;p_Init);
1767 01759 free(Pol-&gt;Constraint);
1768 01760 free(Pol);
1769 01761 <font class="keywordflow">return</font>;
1770 01762 } <font class="comment">/* Domain_Free */</font>
1771 01763
1772 01764 <font class="comment">/*</font>
1773 01765 <font class="comment"> * Print the contents of a polyhedron. </font>
1774 01766 <font class="comment"> */</font>
1775 <a name="l01767"></a><a class="code" href="polyhedron_8c.html#a20">01767</a> <font class="keywordtype">void</font> <a class="code" href="polyhedron_8c.html#a20">Polyhedron_Print</a>(FILE *Dst,<font class="keywordtype">char</font> *Format,Polyhedron *Pol) {
1776 01768
1777 01769 <font class="keywordtype">unsigned</font> Dimension, NbConstraints, NbRays;
1778 01770 <font class="keywordtype">int</font> i, j;
1779 01771 <a class="code" href="arithmetique_8h.html#a93">Value</a> *p;
1780 01772
1781 01773 <font class="keywordflow">if</font> (!Pol) {
1782 01774 fprintf(Dst, <font class="stringliteral">"&lt;null polyhedron&gt;\n"</font>);
1783 01775 <font class="keywordflow">return</font>;
1784 01776 }
1785 01777
1786 01778 Dimension = Pol-&gt;Dimension + 2; <font class="comment">/* Homogenous Dimension + status */</font>
1787 01779 NbConstraints = Pol-&gt;NbConstraints;
1788 01780 NbRays = Pol-&gt;NbRays;
1789 01781 fprintf(Dst, <font class="stringliteral">"POLYHEDRON Dimension:%d\n"</font>, Pol-&gt;Dimension);
1790 01782 fprintf(Dst,<font class="stringliteral">" Constraints:%d Equations:%d Rays:%d Lines:%d\n"</font>,
1791 01783 Pol-&gt;NbConstraints, Pol-&gt;NbEq, Pol-&gt;NbRays, Pol-&gt;NbBid);
1792 01784 fprintf(Dst,<font class="stringliteral">"Constraints %d %d\n"</font>, NbConstraints, Dimension);
1793 01785
1794 01786 <font class="keywordflow">for</font> (i=0;i&lt;NbConstraints;i++) {
1795 01787 p=Pol-&gt;Constraint[i];
1796 01788
1797 01789 <font class="comment">/* if (*p) */</font>
1798 01790 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a> (*p))
1799 01791 fprintf(Dst,<font class="stringliteral">"Inequality: ["</font>);
1800 01792 <font class="keywordflow">else</font>
1801 01793 fprintf(Dst,<font class="stringliteral">"Equality: ["</font>);
1802 01794 p++;
1803 01795 <font class="keywordflow">for</font> (j=1;j&lt;Dimension;j++) {
1804 01796 <a class="code" href="arithmetique_8h.html#a16">value_print</a>(Dst,Format,*p++);
1805 01797 }
1806 01798 (void)fprintf(Dst,<font class="stringliteral">" ]\n"</font>);
1807 01799 }
1808 01800
1809 01801 (void)fprintf(Dst, <font class="stringliteral">"Rays %d %d\n"</font>, NbRays, Dimension);
1810 01802 <font class="keywordflow">for</font> (i=0;i&lt;NbRays;i++) {
1811 01803 p=Pol-&gt;Ray[i];
1812 01804
1813 01805 <font class="comment">/* if (*p) */</font>
1814 01806 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a> (*p)) {
1815 01807 p++;
1816 01808
1817 01809 <font class="comment">/* if ( p[Dimension-2] ) */</font>
1818 01810 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a> (p[Dimension-2]))
1819 01811 fprintf(Dst, <font class="stringliteral">"Vertex: ["</font>);
1820 01812 <font class="keywordflow">else</font>
1821 01813 fprintf(Dst, <font class="stringliteral">"Ray: ["</font>);
1822 01814 }
1823 01815 <font class="keywordflow">else</font> {
1824 01816 p++;
1825 01817 fprintf(Dst, <font class="stringliteral">"Line: ["</font>);
1826 01818 }
1827 01819 <font class="keywordflow">for</font> (j=1; j &lt; Dimension-1; j++) {
1828 01820 <a class="code" href="arithmetique_8h.html#a16">value_print</a>(Dst,Format,*p++);
1829 01821 }
1830 01822
1831 01823 <font class="comment">/* if (*p) */</font>
1832 01824 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a> (*p)) {
1833 01825 fprintf( Dst, <font class="stringliteral">" ]/"</font> );
1834 01826 <a class="code" href="arithmetique_8h.html#a16">value_print</a>(Dst,<a class="code" href="arithmetique_8h.html#a5">VALUE_FMT</a>,*p);
1835 01827 fprintf( Dst, <font class="stringliteral">"\n"</font> );
1836 01828 }
1837 01829 <font class="keywordflow">else</font>
1838 01830 fprintf(Dst, <font class="stringliteral">" ]\n"</font>);
1839 01831 }
1840 01832 <font class="keywordflow">if</font> (Pol-&gt;next) {
1841 01833 fprintf(Dst, <font class="stringliteral">"UNION "</font>);
1842 01834 <a class="code" href="polyhedron_8c.html#a20">Polyhedron_Print</a>(Dst,Format,Pol-&gt;next);
1843 01835 }
1844 01836 } <font class="comment">/* Polyhedron_Print */</font>
1845 01837
1846 01838 <font class="comment">/* </font>
1847 01839 <font class="comment"> * Print the contents of a polyhedron 'Pol' (used for debugging purpose).</font>
1848 01840 <font class="comment"> */</font>
1849 <a name="l01841"></a><a class="code" href="polyhedron_8c.html#a21">01841</a> <font class="keywordtype">void</font> <a class="code" href="polyhedron_8c.html#a21">PolyPrint</a> (Polyhedron *Pol) {
1850 01842 <a class="code" href="polyhedron_8c.html#a20">Polyhedron_Print</a>(stderr,<font class="stringliteral">"%4d"</font>,Pol);
1851 01843 } <font class="comment">/* PolyPrint */</font>
1852 01844
1853 01845 <font class="comment">/* </font>
1854 01846 <font class="comment"> * Create and return an empty polyhedron of non-homogenous dimension </font>
1855 01847 <font class="comment"> * 'Dimension'. An empty polyhedron is characterized by :-</font>
1856 01848 <font class="comment"> * (a) The dimension of the ray-space is -1. </font>
1857 01849 <font class="comment"> * (b) There is an over-constrained system of equations given by:</font>
1858 01850 <font class="comment"> * x=0, y=0, ...... z=0, 1=0</font>
1859 01851 <font class="comment"> */</font>
1860 <a name="l01852"></a><a class="code" href="polyhedron_8c.html#a22">01852</a> Polyhedron *<a class="code" href="polyhedron_8c.html#a22">Empty_Polyhedron</a>(<font class="keywordtype">unsigned</font> Dimension) {
1861 01853
1862 01854 Polyhedron *Pol;
1863 01855 <font class="keywordtype">int</font> i;
1864 01856
1865 01857 Pol = <a class="code" href="polyhedron_8c.html#a17">Polyhedron_Alloc</a>(Dimension, Dimension+1, 0);
1866 01858 <font class="keywordflow">if</font> (!Pol) {
1867 01859 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"Empty_Polyhedron"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
1868 01860 <font class="keywordflow">return</font> 0;
1869 01861 }
1870 01862 <a class="code" href="vector_8c.html#a9">Vector_Set</a>(Pol-&gt;Constraint[0],0,(Dimension+1)*(Dimension+2));
1871 01863 <font class="keywordflow">for</font> (i=0; i&lt;=Dimension; i++) {
1872 01864
1873 01865 <font class="comment">/* Pol-&gt;Constraint[i][i+1]=1 */</font>
1874 01866 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Pol-&gt;Constraint[i][i+1],1);
1875 01867 }
1876 01868 Pol-&gt;NbEq = Dimension+1;
1877 01869 Pol-&gt;NbBid = 0;
1878 01870 <font class="keywordflow">return</font> Pol;
1879 01871 } <font class="comment">/* Empty_Polyhedron */</font>
1880 01872
1881 01873 <font class="comment">/* </font>
1882 01874 <font class="comment"> * Create and return a universe polyhedron of non-homogenous dimension</font>
1883 01875 <font class="comment"> * 'Dimension'. A universe polyhedron is characterized by :-</font>
1884 01876 <font class="comment"> * (a) The dimension of rayspace is zero. </font>
1885 01877 <font class="comment"> * (b) The dimension of lineality space is the dimension of the polyhedron.</font>
1886 01878 <font class="comment"> * (c) There is only one constraint (positivity constraint) in the constraint</font>
1887 01879 <font class="comment"> * set given by : 1 &gt;= 0. </font>
1888 01880 <font class="comment"> * (d) The bi-directional ray set is the canonical set of vectors. </font>
1889 01881 <font class="comment"> * (e) The only vertex is the origin (0,0,0,....0). </font>
1890 01882 <font class="comment"> */</font>
1891 <a name="l01883"></a><a class="code" href="polyhedron_8c.html#a23">01883</a> Polyhedron *<a class="code" href="polyhedron_8c.html#a23">Universe_Polyhedron</a>(<font class="keywordtype">unsigned</font> Dimension) {
1892 01884
1893 01885 Polyhedron *Pol;
1894 01886 <font class="keywordtype">int</font> i;
1895 01887
1896 01888 Pol = <a class="code" href="polyhedron_8c.html#a17">Polyhedron_Alloc</a>(Dimension,1,Dimension+1);
1897 01889 <font class="keywordflow">if</font> (!Pol) {
1898 01890 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"Universe_Polyhedron"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
1899 01891 <font class="keywordflow">return</font> 0;
1900 01892 }
1901 01893 <a class="code" href="vector_8c.html#a9">Vector_Set</a>(Pol-&gt;Constraint[0],0,(Dimension+2));
1902 01894
1903 01895 <font class="comment">/* Pol-&gt;Constraint[0][0] = 1 */</font>
1904 01896 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Pol-&gt;Constraint[0][0],1);
1905 01897
1906 01898 <font class="comment">/* Pol-&gt;Constraint[0][Dimension+1] = 1 */</font>
1907 01899 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Pol-&gt;Constraint[0][Dimension+1],1);
1908 01900 <a class="code" href="vector_8c.html#a9">Vector_Set</a>(Pol-&gt;Ray[0],0,(Dimension+1)*(Dimension+2));
1909 01901 <font class="keywordflow">for</font> (i=0;i&lt;=Dimension;i++) {
1910 01902
1911 01903 <font class="comment">/* Pol-&gt;Ray[i][i+1]=1 */</font>
1912 01904 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Pol-&gt;Ray[i][i+1],1);
1913 01905 }
1914 01906
1915 01907 <font class="comment">/* Pol-&gt;Ray[Dimension][0] = 1 : vertex status */</font>
1916 01908 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Pol-&gt;Ray[Dimension][0],1);
1917 01909 Pol-&gt;NbEq = 0;
1918 01910 Pol-&gt;NbBid = Dimension;
1919 01911 <font class="keywordflow">return</font> Pol;
1920 01912 } <font class="comment">/* Universe_Polyhedron */</font>
1921 01913
1922 01914 <font class="comment">/*</font>
1923 01915 <font class="comment"> * Given a matrix of constraints ('Constraints'), construct and return a </font>
1924 01916 <font class="comment"> * polyhedron. 'NbMaxRays' is the maximum allowed rays in the ray matrix</font>
1925 01917 <font class="comment"> * of the polyhedron. </font>
1926 01918 <font class="comment"> */</font>
1927 <a name="l01919"></a><a class="code" href="polyhedron_8c.html#a24">01919</a> Polyhedron *<a class="code" href="polyhedron_8c.html#a24">Constraints2Polyhedron</a>(Matrix *Constraints,<font class="keywordtype">unsigned</font> NbMaxRays) {
1928 01920
1929 01921 Polyhedron *Pol = NULL;
1930 01922 Matrix *Ray = NULL;
1931 01923 <a class="code" href="structSatMatrix.html">SatMatrix</a> *Sat = NULL;
1932 01924 <font class="keywordtype">unsigned</font> Dimension, nbcolumns;
1933 01925 <font class="keywordtype">int</font> i;
1934 01926
1935 01927 Dimension = Constraints-&gt;NbColumns - 1; <font class="comment">/* Homogeneous Dimension */</font>
1936 01928 <font class="keywordflow">if</font> (Dimension &lt; 1) {
1937 01929 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"Constraints2Polyhedron"</font>,<font class="stringliteral">"invalidpoly"</font>,<font class="stringliteral">"invalid polyhedron dimension"</font>);
1938 01930 <font class="keywordflow">return</font> 0;
1939 01931 }
1940 01932
1941 01933 <font class="comment">/* If there is no constraint in the constraint matrix, return universe */</font>
1942 01934 <font class="comment">/* polyhderon. */</font>
1943 01935 <font class="keywordflow">if</font> (Constraints-&gt;NbRows==0) {
1944 01936 Pol = <a class="code" href="polyhedron_8c.html#a23">Universe_Polyhedron</a>(Dimension-1);
1945 01937 <font class="keywordflow">return</font> Pol;
1946 01938 }
1947 01939
1948 01940 <font class="comment">/*</font>
1949 01941 <font class="comment"> * Rather than adding a 'positivity constraint', it is better to</font>
1950 01942 <font class="comment"> * initialize the lineality space with line in each of the index</font>
1951 01943 <font class="comment"> * dimensions, but no line in the lambda dimension. Then initialize</font>
1952 01944 <font class="comment"> * the ray space with an origin at 0. This is what you get anyway,</font>
1953 01945 <font class="comment"> * after the positivity constraint has been processed by Chernikova</font>
1954 01946 <font class="comment"> * function.</font>
1955 01947 <font class="comment"> */</font>
1956 01948
1957 01949 <font class="comment">/* Allocate and initialize the Ray Space */</font>
1958 01950 Ray = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(NbMaxRays, Dimension+1);
1959 01951 <font class="keywordflow">if</font>(!Ray) {
1960 01952 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"Constraints2Polyhedron"</font>,<font class="stringliteral">"outofmem"</font>,<font class="stringliteral">"out of memory space"</font>);
1961 01953 <font class="keywordflow">return</font> 0;
1962 01954 }
1963 01955 <a class="code" href="vector_8c.html#a9">Vector_Set</a>(Ray-&gt;p_Init,0, NbMaxRays * (Dimension+1));
1964 01956 <font class="keywordflow">for</font> (i=0; i&lt;Dimension; i++) {
1965 01957
1966 01958 <font class="comment">/* Ray-&gt;p[i][i+1] = 1 */</font>
1967 01959 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Ray-&gt;p[i][i+1],1);
1968 01960 }
1969 01961
1970 01962 <font class="comment">/* Ray-&gt;p[Dimension-1][0] = 1 : mark for ray */</font>
1971 01963 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Ray-&gt;p[Dimension-1][0],1);
1972 01964 Ray-&gt;NbRows = Dimension;
1973 01965
1974 01966 <font class="comment">/* Initialize the Sat Matrix */</font>
1975 01967 nbcolumns = (Constraints-&gt;NbRows - 1)/(<font class="keyword">sizeof</font>(int)*8) + 1;
1976 01968 Sat = <a class="code" href="polyparam_8c.html#a23">SMAlloc</a>(NbMaxRays, nbcolumns);
1977 01969 <a class="code" href="polyhedron_8c.html#a4">SMVector_Init</a>(Sat-&gt;<a class="code" href="structSatMatrix.html#m3">p_init</a>,Dimension*nbcolumns);
1978 01970 Sat-&gt;<a class="code" href="structSatMatrix.html#m0">NbRows</a> = Dimension;
1979 01971
1980 01972 <a class="code" href="arithmetic__errors_8h.html#a4">CATCH</a>(any_exception_error) {
1981 01973
1982 01974 <font class="comment">/* In case of overflow, free the allocated memory and forward. */</font>
1983 01975 <font class="keywordflow">if</font> (Sat) <a class="code" href="polyparam_8c.html#a24">SMFree</a>(&amp;Sat);
1984 01976 <font class="keywordflow">if</font> (Ray) <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Ray);
1985 01977 <font class="keywordflow">if</font> (Pol) <a class="code" href="polyhedron_8c.html#a18">Polyhedron_Free</a>(Pol);
1986 01978 <a class="code" href="arithmetic__errors_8h.html#a7">RETHROW</a>();
1987 01979 }
1988 01980 <a class="code" href="arithmetic__errors_8h.html#a6">TRY</a> {
1989 01981
1990 01982 <font class="comment">/* Create ray matrix 'Ray' from constraint matrix 'Constraints' */</font>
1991 01983 <a class="code" href="polyhedron_8c.html#a14">Chernikova</a>(Constraints,Ray,Sat,Dimension-1,NbMaxRays,0,0);
1992 01984
1993 01985 <font class="preprocessor">#ifdef POLY_DEBUG</font>
1994 01986 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"[constraints2polyhedron]\nConstraints = "</font>);
1995 01987 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Constraints);
1996 01988 fprintf(stderr, <font class="stringliteral">"\nRay = "</font>);
1997 01989 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Ray);
1998 01990 fprintf(stderr, <font class="stringliteral">"\nSat = "</font>);
1999 01991 <a class="code" href="polyhedron_8c.html#a9">SMPrint</a>(Sat);
2000 01992 <font class="preprocessor">#endif</font>
2001 01993 <font class="preprocessor"></font>
2002 01994 <font class="comment">/* Remove the redundant constraints and create the polyhedron */</font>
2003 01995 Pol = <a class="code" href="polyhedron_8c.html#a16">Remove_Redundants</a>(Constraints,Ray,Sat,0);
2004 01996 } <font class="comment">/* end of TRY */</font>
2005 01997
2006 01998 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
2007 01999
2008 02000 <font class="preprocessor">#ifdef POLY_DEBUG</font>
2009 02001 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"\nPol = "</font>);
2010 02002 <a class="code" href="polyhedron_8c.html#a20">Polyhedron_Print</a>(stderr,<font class="stringliteral">"%4d"</font>,Pol);
2011 02003 <font class="preprocessor">#endif</font>
2012 02004 <font class="preprocessor"></font>
2013 02005 <a class="code" href="polyparam_8c.html#a24">SMFree</a>(&amp;Sat), Sat = NULL;
2014 02006 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Ray), Ray = NULL;
2015 02007 <font class="keywordflow">return</font> Pol;
2016 02008 } <font class="comment">/* Constraints2Polyhedron */</font>
2017 02009
2018 02010 <font class="preprocessor">#undef POLY_DEBUG</font>
2019 02011 <font class="preprocessor"></font>
2020 02012 <font class="comment">/* </font>
2021 02013 <font class="comment"> * Given a polyhedron 'Pol', return a matrix of constraints. </font>
2022 02014 <font class="comment"> */</font>
2023 <a name="l02015"></a><a class="code" href="polyhedron_8c.html#a25">02015</a> Matrix *<a class="code" href="polyhedron_8c.html#a25">Polyhedron2Constraints</a>(Polyhedron *Pol) {
2024 02016
2025 02017 Matrix *Mat;
2026 02018 <font class="keywordtype">unsigned</font> NbConstraints,Dimension;
2027 02019
2028 02020 NbConstraints = Pol-&gt;NbConstraints;
2029 02021 Dimension = Pol-&gt;Dimension+2;
2030 02022 Mat = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(NbConstraints,Dimension);
2031 02023 <font class="keywordflow">if</font>(!Mat) {
2032 02024 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"Polyhedron2Constraints"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
2033 02025 <font class="keywordflow">return</font> 0;
2034 02026 }
2035 02027 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(Pol-&gt;Constraint[0],Mat-&gt;p_Init,NbConstraints * Dimension);
2036 02028 <font class="keywordflow">return</font> Mat;
2037 02029 } <font class="comment">/* Polyhedron2Constraints */</font>
2038 02030
2039 02031 <font class="comment">/* </font>
2040 02032 <font class="comment"> * Given a matrix of rays 'Ray', create and return a polyhedron. </font>
2041 02033 <font class="comment"> * 'NbMaxConstrs' is the maximum allowed constraints in the new </font>
2042 02034 <font class="comment"> * polyhedron. </font>
2043 02035 <font class="comment"> */</font>
2044 <a name="l02036"></a><a class="code" href="polyhedron_8c.html#a26">02036</a> Polyhedron *<a class="code" href="polyhedron_8c.html#a26">Rays2Polyhedron</a>(Matrix *Ray,<font class="keywordtype">unsigned</font> NbMaxConstrs) {
2045 02037
2046 02038 Polyhedron *Pol = NULL;
2047 02039 Matrix *Mat = NULL;
2048 02040 <a class="code" href="structSatMatrix.html">SatMatrix</a> *Sat = NULL, *SatTranspose = NULL;
2049 02041 <font class="keywordtype">unsigned</font> Dimension, nbcolumns;
2050 02042 <font class="keywordtype">int</font> i;
2051 02043
2052 02044 Dimension = Ray-&gt;<a class="code" href="structSatMatrix.html#m1">NbColumns</a>-1; <font class="comment">/* Homogeneous Dimension */</font>
2053 02045 Sat = NULL;
2054 02046 SatTranspose = NULL;
2055 02047 Mat = NULL;
2056 02048
2057 02049 <font class="keywordflow">if</font> (Ray-&gt;NbRows==0) {
2058 02050
2059 02051 <font class="comment">/* If there is no ray in the matrix 'Ray', return an empty polyhedron */</font>
2060 02052 Pol = <a class="code" href="polyhedron_8c.html#a22">Empty_Polyhedron</a>(Dimension-1);
2061 02053 <font class="keywordflow">return</font>(Pol);
2062 02054 }
2063 02055
2064 02056 <font class="comment">/* Allocate space for constraint matrix 'Mat' */</font>
2065 02057 Mat = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(NbMaxConstrs,Dimension+1);
2066 02058 <font class="keywordflow">if</font>(!Mat) {
2067 02059 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"Rays2Polyhedron"</font>,<font class="stringliteral">"outofmem"</font>,<font class="stringliteral">"out of memory space"</font>);
2068 02060 <font class="keywordflow">return</font> 0;
2069 02061 }
2070 02062
2071 02063 <font class="comment">/* Initialize the constraint matrix 'Mat' */</font>
2072 02064 <a class="code" href="vector_8c.html#a9">Vector_Set</a>(Mat-&gt;p_Init,0,NbMaxConstrs * (Dimension+1));
2073 02065 <font class="keywordflow">for</font> (i=0; i&lt;Dimension; i++) {
2074 02066
2075 02067 <font class="comment">/* Mat-&gt;p[i][i+1]=1 */</font>
2076 02068 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Mat-&gt;p[i][i+1],1);
2077 02069 }
2078 02070
2079 02071 <font class="comment">/* Allocate and assign the saturation matrix. Remember we are using a */</font>
2080 02072 <font class="comment">/* transposed saturation matrix referenced by (constraint,ray) pair. */</font>
2081 02073 Mat-&gt;NbRows = Dimension;
2082 02074 nbcolumns = (Ray-&gt;NbRows -1)/(<font class="keyword">sizeof</font>(int)*8) + 1;
2083 02075 SatTranspose = <a class="code" href="polyparam_8c.html#a23">SMAlloc</a>(NbMaxConstrs,nbcolumns);
2084 02076 <a class="code" href="polyhedron_8c.html#a4">SMVector_Init</a>(SatTranspose-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[0],Dimension * nbcolumns);
2085 02077 SatTranspose-&gt;<a class="code" href="structSatMatrix.html#m0">NbRows</a> = Dimension;
2086 02078
2087 02079 <font class="preprocessor">#ifdef POLY_DEBUG</font>
2088 02080 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"[ray2polyhedron: Before]\nRay = "</font>);
2089 02081 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Ray);
2090 02082 fprintf(stderr, <font class="stringliteral">"\nConstraints = "</font>);
2091 02083 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Mat);
2092 02084 fprintf(stderr, <font class="stringliteral">"\nSatTranspose = "</font>);
2093 02085 <a class="code" href="polyhedron_8c.html#a9">SMPrint</a> (SatTranspose);
2094 02086 <font class="preprocessor">#endif</font>
2095 02087 <font class="preprocessor"></font>
2096 02088 <a class="code" href="arithmetic__errors_8h.html#a4">CATCH</a>(any_exception_error) {
2097 02089
2098 02090 <font class="comment">/* In case of overflow, free the allocated memory before forwarding</font>
2099 02091 <font class="comment"> * the exception. </font>
2100 02092 <font class="comment"> */</font>
2101 02093 <font class="keywordflow">if</font> (SatTranspose) <a class="code" href="polyparam_8c.html#a24">SMFree</a>(&amp;SatTranspose);
2102 02094 <font class="keywordflow">if</font> (Sat) <a class="code" href="polyparam_8c.html#a24">SMFree</a>(&amp;Sat);
2103 02095 <font class="keywordflow">if</font> (Mat) <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Mat);
2104 02096 <font class="keywordflow">if</font> (Pol) <a class="code" href="polyhedron_8c.html#a18">Polyhedron_Free</a>(Pol);
2105 02097 <a class="code" href="arithmetic__errors_8h.html#a7">RETHROW</a>();
2106 02098 }
2107 02099 <a class="code" href="arithmetic__errors_8h.html#a6">TRY</a> {
2108 02100
2109 02101 <font class="comment">/* Create constraint matrix 'Mat' from ray matrix 'Ray' */</font>
2110 02102 <a class="code" href="polyhedron_8c.html#a14">Chernikova</a>(Ray,Mat,SatTranspose,Dimension,NbMaxConstrs,0,1);
2111 02103
2112 02104 <font class="preprocessor">#ifdef POLY_DEBUG</font>
2113 02105 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"[ray2polyhedron: After]\nRay = "</font>);
2114 02106 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Ray);
2115 02107 fprintf(stderr, <font class="stringliteral">"\nConstraints = "</font>);
2116 02108 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(stderr,0,Mat);
2117 02109 fprintf(stderr, <font class="stringliteral">"\nSatTranspose = "</font>);
2118 02110 <a class="code" href="polyhedron_8c.html#a9">SMPrint</a> (SatTranspose);
2119 02111 <font class="preprocessor">#endif</font>
2120 02112 <font class="preprocessor"></font>
2121 02113 <font class="comment">/* Transform the saturation matrix 'SatTranspose' in the standard */</font>
2122 02114 <font class="comment">/* format, that is, ray X constraint format. */</font>
2123 02115 Sat = <a class="code" href="polyhedron_8c.html#a12">TransformSat</a>(Mat,Ray,SatTranspose);
2124 02116
2125 02117 <font class="preprocessor">#ifdef POLY_DEBUG</font>
2126 02118 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"\nSat ="</font>);
2127 02119 <a class="code" href="polyhedron_8c.html#a9">SMPrint</a>(Sat);
2128 02120 <font class="preprocessor">#endif</font>
2129 02121 <font class="preprocessor"></font>
2130 02122 <a class="code" href="polyparam_8c.html#a24">SMFree</a>(&amp;SatTranspose), SatTranspose = NULL;
2131 02123
2132 02124 <font class="comment">/* Remove redundant rays from the ray matrix 'Ray' */</font>
2133 02125 Pol = <a class="code" href="polyhedron_8c.html#a16">Remove_Redundants</a>(Mat,Ray,Sat,0);
2134 02126 } <font class="comment">/* of TRY */</font>
2135 02127
2136 02128 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
2137 02129
2138 02130 <font class="preprocessor">#ifdef POLY_DEBUG</font>
2139 02131 <font class="preprocessor"></font> fprintf(stderr, <font class="stringliteral">"\nPol = "</font>);
2140 02132 <a class="code" href="polyhedron_8c.html#a20">Polyhedron_Print</a>(stderr,<font class="stringliteral">"%4d"</font>,Pol);
2141 02133 <font class="preprocessor">#endif</font>
2142 02134 <font class="preprocessor"></font>
2143 02135 <a class="code" href="polyparam_8c.html#a24">SMFree</a>(&amp;Sat);
2144 02136 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Mat);
2145 02137 <font class="keywordflow">return</font> Pol;
2146 02138 } <font class="comment">/* Rays2Polyhedron */</font>
2147 02139
2148 02140 <font class="comment">/* </font>
2149 02141 <font class="comment"> * Build a saturation matrix from constraint matrix 'Mat' and ray matrix </font>
2150 02142 <font class="comment"> * 'Ray'. Only 'NbConstraints' constraint of matrix 'Mat' are considered </font>
2151 02143 <font class="comment"> * in creating the saturation matrix. 'NbMaxRays' is the maximum number </font>
2152 02144 <font class="comment"> * of rows (rays) allowed in the saturation matrix.</font>
2153 02145 <font class="comment"> * Vin100's stuff, for the polyparam vertices to work.</font>
2154 02146 <font class="comment"> */</font>
2155 <a name="l02147"></a><a class="code" href="polyhedron_8c.html#a27">02147</a> <font class="keyword">static</font> <a class="code" href="structSatMatrix.html">SatMatrix</a> *<a class="code" href="polyhedron_8c.html#a27">BuildSat</a>(Matrix *Mat,Matrix *Ray,<font class="keywordtype">unsigned</font> NbConstraints,<font class="keywordtype">unsigned</font> NbMaxRays) {
2156 02148
2157 02149 <a class="code" href="structSatMatrix.html">SatMatrix</a> *Sat = NULL;
2158 02150 <font class="keywordtype">int</font> i, j, k, jx;
2159 02151 <a class="code" href="arithmetique_8h.html#a93">Value</a> *p1, *p2, *p3;
2160 02152 <a class="code" href="arithmetique_8h.html#a93">Value</a> tmp;
2161 02153 <font class="keywordtype">unsigned</font> Dimension, NbRay, bx, nbcolumns;
2162 02154
2163 02155 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(tmp);
2164 02156
2165 02157 <a class="code" href="arithmetic__errors_8h.html#a4">CATCH</a>(any_exception_error) {
2166 02158 <font class="keywordflow">if</font> (Sat)
2167 02159 <a class="code" href="polyparam_8c.html#a24">SMFree</a>(&amp;Sat);
2168 02160 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
2169 02161 <a class="code" href="arithmetic__errors_8h.html#a7">RETHROW</a>();
2170 02162 }
2171 02163 <a class="code" href="arithmetic__errors_8h.html#a6">TRY</a> {
2172 02164 NbRay = Ray-&gt;NbRows;
2173 02165 Dimension = Mat-&gt;NbColumns-1; <font class="comment">/* Homogeneous Dimension */</font>
2174 02166
2175 02167 <font class="comment">/* Build the Sat matrix */</font>
2176 02168 nbcolumns = (Mat-&gt;NbRows - 1)/(<font class="keyword">sizeof</font>(int)*8) + 1;
2177 02169 Sat = <a class="code" href="polyparam_8c.html#a23">SMAlloc</a>(NbMaxRays,nbcolumns);
2178 02170 Sat-&gt;<a class="code" href="structSatMatrix.html#m0">NbRows</a> = NbRay;
2179 02171 <a class="code" href="polyhedron_8c.html#a4">SMVector_Init</a>(Sat-&gt;<a class="code" href="structSatMatrix.html#m3">p_init</a>, nbcolumns * NbRay);
2180 02172 jx=0; bx=MSB;
2181 02173 <font class="keywordflow">for</font> (k=0; k&lt;NbConstraints; k++) {
2182 02174 <font class="keywordflow">for</font> (i=0; i&lt;NbRay; i++) {
2183 02175
2184 02176 <font class="comment">/* Compute the dot product of ray(i) and constraint(k) and */</font>
2185 02177 <font class="comment">/* store in the status element of ray(i). */</font>
2186 02178 p1 = Ray-&gt;p[i]+1;
2187 02179 p2 = Mat-&gt;p[k]+1;
2188 02180 p3 = Ray-&gt;p[i];
2189 02181 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(*p3,0);
2190 02182 <font class="keywordflow">for</font> (j=0; j&lt;Dimension; j++) {
2191 02183 <a class="code" href="arithmetique_8h.html#a47">value_multiply</a>(tmp,*p1,*p2);
2192 02184 <a class="code" href="arithmetique_8h.html#a43">value_addto</a>(*p3,*p3,tmp);
2193 02185 p1++; p2++;
2194 02186 }
2195 02187 }
2196 02188 <font class="keywordflow">for</font> (j=0; j&lt;NbRay; j++) {
2197 02189
2198 02190 <font class="comment">/* Set 1 in the saturation matrix if the ray doesn't saturate */</font>
2199 02191 <font class="comment">/* the constraint, otherwise the entry is 0. */</font>
2200 02192 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(Ray-&gt;p[j][0]))
2201 02193 Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[j][jx]|=bx;
2202 02194 }
2203 02195 NEXT(jx, bx);
2204 02196 }
2205 02197 } <font class="comment">/* end of TRY */</font>
2206 02198
2207 02199 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
2208 02200 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
2209 02201 <font class="keywordflow">return</font> Sat;
2210 02202 } <font class="comment">/* BuildSat */</font>
2211 02203
2212 02204 <font class="comment">/* </font>
2213 02205 <font class="comment"> * Add 'Nbconstraints' new constraints to polyhedron 'Pol'. Constraints are </font>
2214 02206 <font class="comment"> * pointed by 'Con' and the maximum allowed rays in the new polyhedron is</font>
2215 02207 <font class="comment"> * 'NbMaxRays'. </font>
2216 02208 <font class="comment"> */</font>
2217 <a name="l02209"></a><a class="code" href="polyhedron_8c.html#a28">02209</a> Polyhedron *<a class="code" href="polyhedron_8c.html#a28">AddConstraints</a>(<a class="code" href="arithmetique_8h.html#a93">Value</a> *Con,<font class="keywordtype">unsigned</font> NbConstraints,Polyhedron *Pol,<font class="keywordtype">unsigned</font> NbMaxRays) {
2218 02210
2219 02211 Polyhedron *NewPol = NULL;
2220 02212 Matrix *Mat = NULL, *Ray = NULL;
2221 02213 <a class="code" href="structSatMatrix.html">SatMatrix</a> *Sat = NULL;
2222 02214 <font class="keywordtype">unsigned</font> NbRay, NbCon, Dimension;
2223 02215
2224 02216 <a class="code" href="arithmetic__errors_8h.html#a4">CATCH</a>(any_exception_error) {
2225 02217 <font class="keywordflow">if</font> (NewPol) <a class="code" href="polyhedron_8c.html#a18">Polyhedron_Free</a>(NewPol);
2226 02218 <font class="keywordflow">if</font> (Mat) <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Mat);
2227 02219 <font class="keywordflow">if</font> (Ray) <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Ray);
2228 02220 <font class="keywordflow">if</font> (Sat) <a class="code" href="polyparam_8c.html#a24">SMFree</a>(&amp;Sat);
2229 02221 <a class="code" href="arithmetic__errors_8h.html#a7">RETHROW</a>();
2230 02222 }
2231 02223 <a class="code" href="arithmetic__errors_8h.html#a6">TRY</a> {
2232 02224 NbRay = Pol-&gt;NbRays;
2233 02225 NbCon = Pol-&gt;NbConstraints + NbConstraints;
2234 02226 Dimension = Pol-&gt;Dimension + 2; <font class="comment">/* Homogeneous Dimension + Status */</font>
2235 02227
2236 02228 Mat = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(NbCon, Dimension);
2237 02229 <font class="keywordflow">if</font>(!Mat) {
2238 02230 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"AddConstraints"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
2239 02231 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
2240 02232 <font class="keywordflow">return</font> 0;
2241 02233 }
2242 02234
2243 02235 <font class="comment">/* Copy constraints of polyhedron 'Pol' to matrix 'Mat' */</font>
2244 02236 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(Pol-&gt;Constraint[0], Mat-&gt;p[0], Pol-&gt;NbConstraints * Dimension);
2245 02237
2246 02238 <font class="comment">/* Add the new constraints pointed by 'Con' to matrix 'Mat' */</font>
2247 02239 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(Con, Mat-&gt;p[Pol-&gt;NbConstraints], NbConstraints * Dimension);
2248 02240
2249 02241 <font class="comment">/* Allocate space for ray matrix 'Ray' */</font>
2250 02242 Ray = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(NbMaxRays, Dimension);
2251 02243 <font class="keywordflow">if</font>(!Ray) {
2252 02244 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"AddConstraints"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
2253 02245 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
2254 02246 <font class="keywordflow">return</font> 0;
2255 02247 }
2256 02248 Ray-&gt;NbRows = NbRay;
2257 02249
2258 02250 <font class="comment">/* Copy rays of polyhedron 'Pol' to matrix 'Ray' */</font>
2259 02251 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(Pol-&gt;Ray[0], Ray-&gt;p[0], NbRay * Dimension);
2260 02252
2261 02253 <font class="comment">/* Create the saturation matrix 'Sat' from constraint matrix 'Mat' and */</font>
2262 02254 <font class="comment">/* ray matrix 'Ray' . */</font>
2263 02255 Sat = <a class="code" href="polyhedron_8c.html#a27">BuildSat</a>(Mat, Ray, Pol-&gt;NbConstraints, NbMaxRays);
2264 02256
2265 02257 <font class="comment">/* Create the ray matrix 'Ray' from the constraint matrix 'Mat' */</font>
2266 02258 <a class="code" href="polyhedron_8c.html#a5">Pol_status</a> = <a class="code" href="polyhedron_8c.html#a14">Chernikova</a>(Mat, Ray, Sat, Pol-&gt;NbBid, NbMaxRays, Pol-&gt;NbConstraints,0);
2267 02259
2268 02260 <font class="comment">/* Remove redundant constraints from matrix 'Mat' */</font>
2269 02261 NewPol = <a class="code" href="polyhedron_8c.html#a16">Remove_Redundants</a>(Mat, Ray, Sat, 0);
2270 02262
2271 02263 } <font class="comment">/* end of TRY */</font>
2272 02264
2273 02265 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
2274 02266 <a class="code" href="polyparam_8c.html#a24">SMFree</a>(&amp;Sat);
2275 02267 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Ray);
2276 02268 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Mat);
2277 02269 <font class="keywordflow">return</font> NewPol;
2278 02270 } <font class="comment">/* AddConstraints */</font>
2279 02271
2280 02272 <font class="comment">/* </font>
2281 02273 <font class="comment"> * Return 1 if 'Pol1' includes (covers) 'Pol2', 0 otherwise. </font>
2282 02274 <font class="comment"> * Polyhedron 'A' includes polyhedron 'B' if the rays of 'B' saturate</font>
2283 02275 <font class="comment"> * the equalities and verify the inequalities of 'A'. Both 'Pol1' and </font>
2284 02276 <font class="comment"> * 'Pol2' have same dimensions. </font>
2285 02277 <font class="comment"> */</font>
2286 <a name="l02278"></a><a class="code" href="polyhedron_8c.html#a29">02278</a> <font class="keywordtype">int</font> <a class="code" href="polyhedron_8c.html#a29">PolyhedronIncludes</a>(Polyhedron *Pol1,Polyhedron *Pol2) {
2287 02279
2288 02280 <font class="keywordtype">int</font> Dimension = Pol1-&gt;Dimension + 1; <font class="comment">/* Homogenous Dimension */</font>
2289 02281 <font class="keywordtype">int</font> i, j, k;
2290 02282 <a class="code" href="arithmetique_8h.html#a93">Value</a> *p1, *p2, p3, tmp;
2291 02283
2292 02284 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(p3); <a class="code" href="arithmetique_8h.html#a10">value_init</a>(tmp);
2293 02285 <font class="keywordflow">for</font> (k=0; k&lt;Pol1-&gt;NbConstraints; k++) {
2294 02286 <font class="keywordflow">for</font> (i=0;i&lt;Pol2-&gt;NbRays;i++) {
2295 02287
2296 02288 <font class="comment">/* Compute the dot product of ray(i) and constraint(k) and store in p3 */</font>
2297 02289 p1 = Pol2-&gt;Ray[i]+1;
2298 02290 p2 = Pol1-&gt;Constraint[k]+1;
2299 02291 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(p3,0);
2300 02292 <font class="keywordflow">for</font>(j=0;j&lt;Dimension;j++) {
2301 02293 <a class="code" href="arithmetique_8h.html#a47">value_multiply</a>(tmp,*p1,*p2);
2302 02294 <a class="code" href="arithmetique_8h.html#a43">value_addto</a>(p3,p3,tmp);
2303 02295 p1++; p2++;
2304 02296 }
2305 02297
2306 02298 <font class="comment">/* If (p3 &lt; 0) or (p3 &gt; 0 and (constraint(k) is equality</font>
2307 02299 <font class="comment"> or ray(i) is a line)), return 0 */</font>
2308 02300 <font class="keywordflow">if</font>(<a class="code" href="arithmetique_8h.html#a64">value_neg_p</a>(p3) ||
2309 02301 (<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(p3)
2310 02302 &amp;&amp; (<a class="code" href="arithmetique_8h.html#a67">value_zero_p</a>(Pol1-&gt;Constraint[k][0]) || (<a class="code" href="arithmetique_8h.html#a67">value_zero_p</a>(Pol2-&gt;Ray[i][0])) ) )) {
2311 02303 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(p3); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
2312 02304 <font class="keywordflow">return</font> 0;
2313 02305 }
2314 02306 }
2315 02307 }
2316 02308 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(p3); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
2317 02309 <font class="keywordflow">return</font> 1;
2318 02310 } <font class="comment">/* PolyhedronIncludes */</font>
2319 02311
2320 02312 <font class="comment">/*</font>
2321 02313 <font class="comment"> * Add Polyhedron 'Pol' to polhedral domain 'PolDomain'. If 'Pol' covers</font>
2322 02314 <font class="comment"> * some polyhedron in the domain 'PolDomain', it is removed from the list.</font>
2323 02315 <font class="comment"> * On the other hand if some polyhedron in the domain covers polyhedron </font>
2324 02316 <font class="comment"> * 'Pol' then 'Pol' is not included in the domain. </font>
2325 02317 <font class="comment"> */</font>
2326 <a name="l02318"></a><a class="code" href="polyhedron_8c.html#a30">02318</a> Polyhedron *<a class="code" href="polyhedron_8c.html#a30">AddPolyToDomain</a>(Polyhedron *Pol,Polyhedron *PolDomain) {
2327 02319
2328 02320 Polyhedron *p, *pnext, *p_domain_end = (Polyhedron *) 0;
2329 02321 <font class="keywordtype">int</font> Redundant;
2330 02322
2331 02323 <font class="keywordflow">if</font> (!Pol)
2332 02324 <font class="keywordflow">return</font> PolDomain;
2333 02325 <font class="keywordflow">if</font> (!PolDomain)
2334 02326 <font class="keywordflow">return</font> Pol;
2335 02327
2336 02328 <font class="comment">/* Check for emptiness of polyhedron 'Pol' */</font>
2337 02329 <font class="keywordflow">if</font> (emptyQ(Pol)) {
2338 02330 <a class="code" href="polyhedron_8c.html#a18">Polyhedron_Free</a>(Pol);
2339 02331 <font class="keywordflow">return</font> PolDomain;
2340 02332 }
2341 02333
2342 02334 <font class="comment">/* Check for emptiness of polyhedral domain 'PolDomain' */</font>
2343 02335 <font class="keywordflow">if</font> (emptyQ(PolDomain)) {
2344 02336 <a class="code" href="polyhedron_8c.html#a18">Polyhedron_Free</a>(PolDomain);
2345 02337 <font class="keywordflow">return</font> Pol;
2346 02338 }
2347 02339
2348 02340 <font class="comment">/* Test 'Pol' against the domain 'PolDomain' */</font>
2349 02341 Redundant = 0;
2350 02342 <font class="keywordflow">for</font> (p=PolDomain,PolDomain=(Polyhedron *)0; p; p=pnext) {
2351 02343
2352 02344 <font class="comment">/* If 'Pol' covers 'p' */</font>
2353 02345 <font class="keywordflow">if</font> (<a class="code" href="polyhedron_8c.html#a29">PolyhedronIncludes</a>(Pol, p))
2354 02346 {
2355 02347 <font class="comment">/* free p */</font>
2356 02348 pnext = p-&gt;next;
2357 02349 <a class="code" href="polyhedron_8c.html#a18">Polyhedron_Free</a>( p );
2358 02350 <font class="keywordflow">continue</font>;
2359 02351 }
2360 02352
2361 02353 <font class="comment">/* Add polyhedron p to the new domain list */</font>
2362 02354 <font class="keywordflow">if</font> (!PolDomain) PolDomain = p; <font class="keywordflow">else</font> p_domain_end-&gt;next = p;
2363 02355 p_domain_end = p;
2364 02356
2365 02357 <font class="comment">/* If p covers Pol */</font>
2366 02358 <font class="keywordflow">if</font> (<a class="code" href="polyhedron_8c.html#a29">PolyhedronIncludes</a>(p,Pol)) {
2367 02359 Redundant = 1;
2368 02360 <font class="keywordflow">break</font>;
2369 02361 }
2370 02362 pnext = p-&gt;next;
2371 02363 }
2372 02364 <font class="keywordflow">if</font> (!Redundant) {
2373 02365
2374 02366 <font class="comment">/* The whole list has been checked. Add new polyhedron 'Pol' to the */</font>
2375 02367 <font class="comment">/* new domain list. */</font>
2376 02368 <font class="keywordflow">if</font> (!PolDomain) PolDomain = Pol; <font class="keywordflow">else</font> p_domain_end-&gt;next = Pol;
2377 02369 }
2378 02370 <font class="keywordflow">else</font> {
2379 02371
2380 02372 <font class="comment">/* The rest of the list is just inherited from p */</font>
2381 02373 <a class="code" href="polyhedron_8c.html#a18">Polyhedron_Free</a>(Pol);
2382 02374 }
2383 02375 <font class="keywordflow">return</font> PolDomain;
2384 02376 } <font class="comment">/* AddPolyToDomain */</font>
2385 02377
2386 02378 <font class="comment">/* </font>
2387 02379 <font class="comment"> * Given a polyhedra 'Pol' and a single constraint 'Con' and an integer 'Pass' </font>
2388 02380 <font class="comment"> * whose value ranges from 0 to 3, add the inverse of constraint 'Con' to the </font>
2389 02381 <font class="comment"> * constraint set of 'Pol' and return the new polyhedron. 'NbMaxRays' is the </font>
2390 02382 <font class="comment"> * maximum allowed rays in the new generated polyhedron. </font>
2391 02383 <font class="comment"> * If Pass == 0, add ( -constraint -1) &gt;= 0</font>
2392 02384 <font class="comment"> * If Pass == 1, add ( +constraint -1) &gt;= 0</font>
2393 02385 <font class="comment"> * If Pass == 2, add ( -constraint ) &gt;= 0</font>
2394 02386 <font class="comment"> * If Pass == 3, add ( +constraint ) &gt;= 0</font>
2395 02387 <font class="comment"> */</font>
2396 <a name="l02388"></a><a class="code" href="polyhedron_8c.html#a31">02388</a> Polyhedron *<a class="code" href="polyhedron_8c.html#a31">SubConstraint</a>(<a class="code" href="arithmetique_8h.html#a93">Value</a> *Con,Polyhedron *Pol,<font class="keywordtype">unsigned</font> NbMaxRays,<font class="keywordtype">int</font> Pass) {
2397 02389
2398 02390 Polyhedron *NewPol = NULL;
2399 02391 Matrix *Mat = NULL, *Ray = NULL;
2400 02392 <a class="code" href="structSatMatrix.html">SatMatrix</a> *Sat = NULL;
2401 02393 <font class="keywordtype">unsigned</font> NbRay, NbCon, NbEle1, Dimension;
2402 02394 <font class="keywordtype">int</font> i;
2403 02395
2404 02396 <a class="code" href="arithmetic__errors_8h.html#a4">CATCH</a>(any_exception_error) {
2405 02397 <font class="keywordflow">if</font> (NewPol) <a class="code" href="polyhedron_8c.html#a18">Polyhedron_Free</a>(NewPol);
2406 02398 <font class="keywordflow">if</font> (Mat) <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Mat);
2407 02399 <font class="keywordflow">if</font> (Ray) <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Ray);
2408 02400 <font class="keywordflow">if</font> (Sat) <a class="code" href="polyparam_8c.html#a24">SMFree</a>(&amp;Sat);
2409 02401 <a class="code" href="arithmetic__errors_8h.html#a7">RETHROW</a>();
2410 02402 }
2411 02403 <a class="code" href="arithmetic__errors_8h.html#a6">TRY</a> {
2412 02404
2413 02405 <font class="comment">/* If 'Con' is the positivity constraint, return Null */</font>
2414 02406 Dimension = Pol-&gt;Dimension+1; <font class="comment">/* Homogeneous Dimension */</font>
2415 02407 <font class="keywordflow">for</font> (i=1; i&lt;Dimension; i++)
2416 02408 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(Con[i])) <font class="keywordflow">break</font>;
2417 02409 <font class="keywordflow">if</font> (i==Dimension) {
2418 02410 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
2419 02411 <font class="keywordflow">return</font> (Polyhedron *) 0;
2420 02412 }
2421 02413
2422 02414 NbRay = Pol-&gt;NbRays;
2423 02415 NbCon = Pol-&gt;NbConstraints;
2424 02416 Dimension = Pol-&gt;Dimension+2; <font class="comment">/* Homogeneous Dimension + Status */</font>
2425 02417 NbEle1 = NbCon * Dimension;
2426 02418
2427 02419 Mat = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(NbCon + 1, Dimension);
2428 02420 <font class="keywordflow">if</font>(!Mat) {
2429 02421 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"SubConstraint"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
2430 02422 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
2431 02423 <font class="keywordflow">return</font> 0;
2432 02424 }
2433 02425
2434 02426 <font class="comment">/* Set the constraints of Pol */</font>
2435 02427 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(Pol-&gt;Constraint[0], Mat-&gt;p[0], NbEle1);
2436 02428
2437 02429 <font class="comment">/* Add the new constraint */</font>
2438 02430 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Mat-&gt;p[NbCon][0],1);
2439 02431 <font class="keywordflow">if</font> (!(Pass&amp;1))
2440 02432 <font class="keywordflow">for</font>(i=1; i&lt;Dimension; i++)
2441 02433 <a class="code" href="arithmetique_8h.html#a54">value_oppose</a>(Mat-&gt;p[NbCon][i],Con[i]);
2442 02434 <font class="keywordflow">else</font>
2443 02435 <font class="keywordflow">for</font>(i=1; i&lt;Dimension; i++)
2444 02436 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(Mat-&gt;p[NbCon][i],Con[i]);
2445 02437 <font class="keywordflow">if</font> (!(Pass&amp;2))
2446 02438 <a class="code" href="arithmetique_8h.html#a50">value_decrement</a>(Mat-&gt;p[NbCon][Dimension-1],Mat-&gt;p[NbCon][Dimension-1]);
2447 02439
2448 02440 <font class="comment">/* Allocate the ray matrix. */</font>
2449 02441 Ray = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(NbMaxRays, Dimension);
2450 02442 <font class="keywordflow">if</font>(!Ray) {
2451 02443 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"SubConstraint"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
2452 02444 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
2453 02445 <font class="keywordflow">return</font> 0;
2454 02446 }
2455 02447
2456 02448 <font class="comment">/* Initialize the ray matrix with the rays of polyhedron 'Pol' */</font>
2457 02449 Ray-&gt;NbRows = NbRay;
2458 02450 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(Pol-&gt;Ray[0], Ray-&gt;p[0], NbRay * Dimension);
2459 02451
2460 02452 <font class="comment">/* Create the saturation matrix from the constraint matrix 'mat' and */</font>
2461 02453 <font class="comment">/* ray matrix 'Ray'. */</font>
2462 02454 Sat = <a class="code" href="polyhedron_8c.html#a27">BuildSat</a>(Mat, Ray, NbCon, NbMaxRays);
2463 02455
2464 02456 <font class="comment">/* Create the ray matrix 'Ray' from consraint matrix 'Mat' */</font>
2465 02457 <a class="code" href="polyhedron_8c.html#a5">Pol_status</a> = <a class="code" href="polyhedron_8c.html#a14">Chernikova</a>(Mat, Ray, Sat, Pol-&gt;NbBid, NbMaxRays, NbCon,0);
2466 02458
2467 02459 <font class="comment">/* Remove redundant constraints from matrix 'Mat' */</font>
2468 02460 NewPol = <a class="code" href="polyhedron_8c.html#a16">Remove_Redundants</a>(Mat, Ray, Sat, 0);
2469 02461
2470 02462 } <font class="comment">/* end of TRY */</font>
2471 02463
2472 02464 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
2473 02465
2474 02466 <a class="code" href="polyparam_8c.html#a24">SMFree</a>(&amp;Sat);
2475 02467 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Ray);
2476 02468 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Mat);
2477 02469 <font class="keywordflow">return</font> NewPol;
2478 02470 } <font class="comment">/* SubConstraint */</font>
2479 02471
2480 02472 <font class="comment">/*</font>
2481 02473 <font class="comment"> * Return the intersection of two polyhedral domains 'Pol1' and 'Pol2'. </font>
2482 02474 <font class="comment"> * The maximum allowed rays in the new polyhedron generated is 'NbMaxRays'. </font>
2483 02475 <font class="comment"> */</font>
2484 <a name="l02476"></a><a class="code" href="polyhedron_8c.html#a32">02476</a> Polyhedron *<a class="code" href="polyhedron_8c.html#a32">DomainIntersection</a>(Polyhedron *Pol1,Polyhedron *Pol2,<font class="keywordtype">unsigned</font> NbMaxRays) {
2485 02477
2486 02478 Polyhedron *p1, *p2, *p3, *d;
2487 02479
2488 02480 <font class="keywordflow">if</font> (!Pol1 || !Pol2) <font class="keywordflow">return</font> (Polyhedron*) 0;
2489 02481 <font class="keywordflow">if</font> (Pol1-&gt;Dimension != Pol2-&gt;Dimension) {
2490 02482 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>( <font class="stringliteral">"DomainIntersection"</font>, <font class="stringliteral">"diffdim"</font>,
2491 02483 <font class="stringliteral">"operation on different dimensions"</font>);
2492 02484 <font class="keywordflow">return</font> (Polyhedron*) 0;
2493 02485 }
2494 02486
2495 02487 <font class="comment">/* For every polyhedron pair (p1,p2) where p1 belongs to domain Pol1 and */</font>
2496 02488 <font class="comment">/* p2 belongs to domain Pol2, compute the intersection and add it to the */</font>
2497 02489 <font class="comment">/* new domain 'd'. */</font>
2498 02490 d = (Polyhedron *)0;
2499 02491 <font class="keywordflow">for</font> (p1=Pol1; p1; p1=p1-&gt;next) {
2500 02492 <font class="keywordflow">for</font> (p2=Pol2; p2; p2=p2-&gt;next) {
2501 02493 p3 = <a class="code" href="polyhedron_8c.html#a28">AddConstraints</a>(p2-&gt;Constraint[0],
2502 02494 p2-&gt;NbConstraints, p1, NbMaxRays);
2503 02495 d = <a class="code" href="polyhedron_8c.html#a30">AddPolyToDomain</a>(p3,d);
2504 02496 }
2505 02497 }
2506 02498 <font class="keywordflow">if</font> (!d)
2507 02499 <font class="keywordflow">return</font> <a class="code" href="polyhedron_8c.html#a22">Empty_Polyhedron</a>(Pol1-&gt;Dimension);
2508 02500 <font class="keywordflow">else</font>
2509 02501 <font class="keywordflow">return</font> d;
2510 02502
2511 02503 } <font class="comment">/* DomainIntersection */</font>
2512 02504
2513 02505 <font class="comment">/*</font>
2514 02506 <font class="comment"> * Given a polyhedron 'Pol', return a matrix of rays. </font>
2515 02507 <font class="comment"> */</font>
2516 <a name="l02508"></a><a class="code" href="polyhedron_8c.html#a33">02508</a> Matrix *<a class="code" href="polyhedron_8c.html#a33">Polyhedron2Rays</a>(Polyhedron *Pol) {
2517 02509
2518 02510 Matrix *Ray;
2519 02511 <font class="keywordtype">unsigned</font> NbRays, Dimension;
2520 02512
2521 02513 NbRays = Pol-&gt;NbRays;
2522 02514 Dimension = Pol-&gt;Dimension+2; <font class="comment">/* Homogeneous Dimension + Status */</font>
2523 02515 Ray = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(NbRays, Dimension);
2524 02516 <font class="keywordflow">if</font>(!Ray) {
2525 02517 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"Polyhedron2Rays"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
2526 02518 <font class="keywordflow">return</font> 0;
2527 02519 }
2528 02520 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(Pol-&gt;Ray[0], Ray-&gt;p_Init, NbRays*Dimension);
2529 02521 <font class="keywordflow">return</font> Ray;
2530 02522 } <font class="comment">/* Polyhedron2Rays */</font>
2531 02523
2532 02524 <font class="comment">/*</font>
2533 02525 <font class="comment"> * Add 'NbAddedRays' rays to polyhedron 'Pol'. Rays are pointed by 'AddedRays'</font>
2534 02526 <font class="comment"> * and the maximum allowed constraints in the new polyhedron is 'NbMaxConstrs'.</font>
2535 02527 <font class="comment"> */</font>
2536 <a name="l02528"></a><a class="code" href="polyhedron_8c.html#a34">02528</a> Polyhedron *<a class="code" href="polyhedron_8c.html#a34">AddRays</a>(<a class="code" href="arithmetique_8h.html#a93">Value</a> *AddedRays,<font class="keywordtype">unsigned</font> NbAddedRays,Polyhedron *Pol,<font class="keywordtype">unsigned</font> NbMaxConstrs) {
2537 02529
2538 02530 Polyhedron *NewPol = NULL;
2539 02531 Matrix *Mat = NULL, *Ray = NULL;
2540 02532 <a class="code" href="structSatMatrix.html">SatMatrix</a> *Sat = NULL, *SatTranspose = NULL;
2541 02533 <font class="keywordtype">unsigned</font> NbCon, NbRay,NbEle1, Dimension;
2542 02534
2543 02535 <a class="code" href="arithmetic__errors_8h.html#a4">CATCH</a>(any_exception_error) {
2544 02536 <font class="keywordflow">if</font> (NewPol) <a class="code" href="polyhedron_8c.html#a18">Polyhedron_Free</a>(NewPol);
2545 02537 <font class="keywordflow">if</font> (Mat) <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Mat);
2546 02538 <font class="keywordflow">if</font> (Ray) <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Ray);
2547 02539 <font class="keywordflow">if</font> (Sat) <a class="code" href="polyparam_8c.html#a24">SMFree</a>(&amp;Sat);
2548 02540 <font class="keywordflow">if</font> (SatTranspose) <a class="code" href="polyparam_8c.html#a24">SMFree</a>(&amp;SatTranspose);
2549 02541 <a class="code" href="arithmetic__errors_8h.html#a7">RETHROW</a>();
2550 02542 }
2551 02543 <a class="code" href="arithmetic__errors_8h.html#a6">TRY</a> {
2552 02544
2553 02545 NbCon = Pol-&gt;NbConstraints;
2554 02546 NbRay = Pol-&gt;NbRays;
2555 02547 Dimension = Pol-&gt;Dimension + 2; <font class="comment">/* Homogeneous Dimension + Status */</font>
2556 02548 NbEle1 = NbRay * Dimension;
2557 02549
2558 02550 Ray = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(NbAddedRays + NbRay, Dimension);
2559 02551 <font class="keywordflow">if</font>(!Ray) {
2560 02552 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"AddRays"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
2561 02553 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
2562 02554 <font class="keywordflow">return</font> 0;
2563 02555 }
2564 02556
2565 02557 <font class="comment">/* Copy rays of polyhedron 'Pol' to matrix 'Ray' */</font>
2566 02558 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(Pol-&gt;Ray[0], Ray-&gt;p_Init, NbEle1);
2567 02559
2568 02560 <font class="comment">/* Add the new rays pointed by 'AddedRays' to matrix 'Ray' */</font>
2569 02561 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(AddedRays, Ray-&gt;p_Init+NbEle1, NbAddedRays * Dimension);
2570 02562
2571 02563 <font class="comment">/* Allocate space for constraint matrix 'Mat' */</font>
2572 02564 Mat = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(NbMaxConstrs, Dimension);
2573 02565 <font class="keywordflow">if</font>(!Mat) {
2574 02566 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"AddRays"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
2575 02567 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
2576 02568 <font class="keywordflow">return</font> 0;
2577 02569 }
2578 02570 Mat-&gt;NbRows = NbCon;
2579 02571
2580 02572 <font class="comment">/* Copy constraints of polyhedron 'Pol' to matrix 'Mat' */</font>
2581 02573 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(Pol-&gt;Constraint[0], Mat-&gt;p_Init, NbCon*Dimension);
2582 02574
2583 02575 <font class="comment">/* Create the saturation matrix 'SatTranspose' from constraint matrix */</font>
2584 02576 <font class="comment">/* 'Mat' and ray matrix 'Ray'. Remember the saturation matrix is */</font>
2585 02577 <font class="comment">/* referenced by (constraint,ray) pair */</font>
2586 02578 SatTranspose = <a class="code" href="polyhedron_8c.html#a27">BuildSat</a>(Ray, Mat, NbRay, NbMaxConstrs);
2587 02579
2588 02580 <font class="comment">/* Create the constraint matrix 'Mat' from the ray matrix 'Ray' */</font>
2589 02581 <a class="code" href="polyhedron_8c.html#a5">Pol_status</a> = <a class="code" href="polyhedron_8c.html#a14">Chernikova</a>(Ray, Mat, SatTranspose, Pol-&gt;NbEq, NbMaxConstrs, NbRay,1);
2590 02582
2591 02583 <font class="comment">/* Transform the saturation matrix 'SatTranspose' in the standard format */</font>
2592 02584 <font class="comment">/* , that is, (ray X constraint) format. */</font>
2593 02585 Sat = <a class="code" href="polyhedron_8c.html#a12">TransformSat</a>(Mat, Ray, SatTranspose);
2594 02586 <a class="code" href="polyparam_8c.html#a24">SMFree</a>(&amp;SatTranspose), SatTranspose = NULL;
2595 02587
2596 02588 <font class="comment">/* Remove redundant rays from the ray matrix 'Ray' */</font>
2597 02589 NewPol = <a class="code" href="polyhedron_8c.html#a16">Remove_Redundants</a>(Mat, Ray, Sat, 0);
2598 02590
2599 02591 <a class="code" href="polyparam_8c.html#a24">SMFree</a>(&amp;Sat), Sat = NULL;
2600 02592 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Mat), Mat = NULL;
2601 02593 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Ray), Ray = NULL;
2602 02594 } <font class="comment">/* end of TRY */</font>
2603 02595
2604 02596 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
2605 02597 <font class="keywordflow">return</font> NewPol;
2606 02598 } <font class="comment">/* AddRays */</font>
2607 02599
2608 02600 <font class="comment">/* </font>
2609 02601 <font class="comment"> * Add rays pointed by 'Ray' to each and every polyhedron in the polyhedral </font>
2610 02602 <font class="comment"> * domain 'Pol'. 'NbMaxConstrs' is maximum allowed constraints in the </font>
2611 02603 <font class="comment"> * constraint set of a polyhedron. </font>
2612 02604 <font class="comment"> */</font>
2613 <a name="l02605"></a><a class="code" href="polyhedron_8c.html#a35">02605</a> Polyhedron *<a class="code" href="polyhedron_8c.html#a35">DomainAddRays</a>(Polyhedron *Pol,Matrix *Ray,<font class="keywordtype">unsigned</font> NbMaxConstrs) {
2614 02606
2615 02607 Polyhedron *PolA, *PolEndA, *p1, *p2, *p3;
2616 02608 <font class="keywordtype">int</font> Redundant;
2617 02609
2618 02610 <font class="keywordflow">if</font> (!Pol) <font class="keywordflow">return</font> (Polyhedron*) 0;
2619 02611 <font class="keywordflow">if</font> (!Ray ) <font class="keywordflow">return</font> Pol;
2620 02612 <font class="keywordflow">if</font> (Pol-&gt;Dimension != Ray-&gt;NbColumns-2) {
2621 02613 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(
2622 02614 <font class="stringliteral">"DomainAddRays"</font>, <font class="stringliteral">"diffdim"</font>, <font class="stringliteral">"operation on different dimensions"</font>);
2623 02615 <font class="keywordflow">return</font> (Polyhedron*) 0;
2624 02616 }
2625 02617
2626 02618 <font class="comment">/* Copy Pol to PolA */</font>
2627 02619 PolA = PolEndA = (Polyhedron *)0;
2628 02620 <font class="keywordflow">for</font> (p1=Pol; p1; p1=p1-&gt;next) {
2629 02621 p3 = <a class="code" href="polyhedron_8c.html#a34">AddRays</a>(Ray-&gt;p[0], Ray-&gt;NbRows, p1, NbMaxConstrs);
2630 02622
2631 02623 <font class="comment">/* Does any component of PolA cover 'p3' ? */</font>
2632 02624 Redundant = 0;
2633 02625 <font class="keywordflow">for</font> (p2=PolA; p2; p2=p2-&gt;next) {
2634 02626 <font class="keywordflow">if</font> (<a class="code" href="polyhedron_8c.html#a29">PolyhedronIncludes</a>(p2, p3)) { <font class="comment">/* If p2 covers p3 */</font>
2635 02627 Redundant = 1;
2636 02628 <font class="keywordflow">break</font>;
2637 02629 }
2638 02630 }
2639 02631
2640 02632 <font class="comment">/* If the new polyheron is not redundant, add it ('p3') to the list */</font>
2641 02633 <font class="keywordflow">if</font> (!Redundant) {
2642 02634 <font class="keywordflow">if</font> (!PolEndA)
2643 02635 PolEndA = PolA = p3;
2644 02636 <font class="keywordflow">else</font> {
2645 02637 PolEndA-&gt;next = p3;
2646 02638 PolEndA = PolEndA-&gt;next;
2647 02639 }
2648 02640 }
2649 02641 }
2650 02642 <font class="keywordflow">return</font> PolA;
2651 02643 } <font class="comment">/* DomainAddRays */</font>
2652 02644
2653 02645 <font class="comment">/*</font>
2654 02646 <font class="comment"> * Create a copy of the polyhedron 'Pol' </font>
2655 02647 <font class="comment"> */</font>
2656 <a name="l02648"></a><a class="code" href="polyhedron_8c.html#a36">02648</a> Polyhedron *<a class="code" href="polyhedron_8c.html#a36">Polyhedron_Copy</a>(Polyhedron *Pol) {
2657 02649
2658 02650 Polyhedron *Pol1;
2659 02651
2660 02652 <font class="keywordflow">if</font> (!Pol) <font class="keywordflow">return</font> (Polyhedron *)0;
2661 02653
2662 02654 <font class="comment">/* Allocate space for the new polyhedron */</font>
2663 02655 Pol1 = <a class="code" href="polyhedron_8c.html#a17">Polyhedron_Alloc</a>(Pol-&gt;Dimension, Pol-&gt;NbConstraints, Pol-&gt;NbRays);
2664 02656 <font class="keywordflow">if</font> (!Pol1) {
2665 02657 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"Polyhedron_Copy"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
2666 02658 <font class="keywordflow">return</font> 0;
2667 02659 }
2668 02660 <font class="keywordflow">if</font>( Pol-&gt;NbConstraints )
2669 02661 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(Pol-&gt;Constraint[0], Pol1-&gt;Constraint[0],
2670 02662 Pol-&gt;NbConstraints*(Pol-&gt;Dimension+2));
2671 02663 <font class="keywordflow">if</font>( Pol-&gt;NbRays )
2672 02664 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(Pol-&gt;Ray[0], Pol1-&gt;Ray[0],
2673 02665 Pol-&gt;NbRays*(Pol-&gt;Dimension+2));
2674 02666 Pol1-&gt;NbBid = Pol-&gt;NbBid;
2675 02667 Pol1-&gt;NbEq = Pol-&gt;NbEq;
2676 02668 <font class="keywordflow">return</font> Pol1;
2677 02669 } <font class="comment">/* Polyhedron_Copy */</font>
2678 02670
2679 02671 <font class="comment">/* </font>
2680 02672 <font class="comment"> * Create a copy of a polyhedral domain. </font>
2681 02673 <font class="comment"> */</font>
2682 <a name="l02674"></a><a class="code" href="polyhedron_8c.html#a37">02674</a> Polyhedron *<a class="code" href="polyhedron_8c.html#a37">Domain_Copy</a>(Polyhedron *Pol) {
2683 02675
2684 02676 Polyhedron *Pol1;
2685 02677
2686 02678 <font class="keywordflow">if</font> (!Pol) <font class="keywordflow">return</font> (Polyhedron *) 0;
2687 02679 Pol1 = <a class="code" href="polyhedron_8c.html#a36">Polyhedron_Copy</a>(Pol);
2688 02680 <font class="keywordflow">if</font> (Pol-&gt;next) Pol1-&gt;next = <a class="code" href="polyhedron_8c.html#a37">Domain_Copy</a>(Pol-&gt;next);
2689 02681 <font class="keywordflow">return</font> Pol1;
2690 02682 } <font class="comment">/* Domain_Copy */</font>
2691 02683
2692 02684 <font class="comment">/*</font>
2693 02685 <font class="comment"> * Given constraint number 'k' of a polyhedron, and an array 'Filter' to store</font>
2694 02686 <font class="comment"> * the non-redundant constraints of the polyhedron in bit-wise notation, and</font>
2695 02687 <font class="comment"> * a Matrix 'Sat', add the constraint 'k' in 'Filter' array. tmpR[i] stores the</font>
2696 02688 <font class="comment"> * number of constraints, other than those in 'Filter', which ray(i) saturates </font>
2697 02689 <font class="comment"> * or verifies. In case, ray(i) does not saturate or verify a constraint in</font>
2698 02690 <font class="comment"> * array 'Filter', it is assigned to -1. Similarly, tmpC[j] stores the number</font>
2699 02691 <font class="comment"> * of rays which constraint(j), if it doesn't belong to Filter, saturates or </font>
2700 02692 <font class="comment"> * verifies. If constraint(j) belongs to 'Filter', then tmpC[j] is assigned to</font>
2701 02693 <font class="comment"> * -1. 'NbConstraints' is the number of constraints in the constraint matrix of</font>
2702 02694 <font class="comment"> * the polyhedron. </font>
2703 02695 <font class="comment"> * NOTE: (1) 'Sat' is not the saturation matrix of the polyhedron. In fact, </font>
2704 02696 <font class="comment"> * entry in 'Sat' is set to 1 if ray(i) of polyhedron1 verifies or </font>
2705 02697 <font class="comment"> * saturates the constraint(j) of polyhedron2 and otherwise it is set</font>
2706 02698 <font class="comment"> * to 0. So here the difference with saturation matrix is in terms </font>
2707 02699 <font class="comment"> * definition and entries(1&lt;-&gt;0) of the matrix 'Sat'. </font>
2708 02700 <font class="comment"> * </font>
2709 02701 <font class="comment"> * ALGORITHM:-&gt;</font>
2710 02702 <font class="comment"> * (1) Include constraint(k) in array 'Filter'. </font>
2711 02703 <font class="comment"> * (2) Set tmpC[k] to -1.</font>
2712 02704 <font class="comment"> * (3) For all ray(i) {</font>
2713 02705 <font class="comment"> * If ray(i) saturates or verifies constraint(k) then --(tmpR[i])</font>
2714 02706 <font class="comment"> * Else {</font>
2715 02707 <font class="comment"> * Discard ray(i) by assigning tmpR[i] = -1</font>
2716 02708 <font class="comment"> * Decrement tmpC[j] for all constraint(j) not in array 'Filter'.</font>
2717 02709 <font class="comment"> * }</font>
2718 02710 <font class="comment"> * }</font>
2719 02711 <font class="comment"> */</font>
2720 <a name="l02712"></a><a class="code" href="polyhedron_8c.html#a38">02712</a> <font class="keyword">static</font> <font class="keywordtype">void</font> <a class="code" href="polyhedron_8c.html#a38">addToFilter</a>(<font class="keywordtype">int</font> k, <font class="keywordtype">unsigned</font> *Filter, <a class="code" href="structSatMatrix.html">SatMatrix</a> *Sat,<a class="code" href="arithmetique_8h.html#a93">Value</a> *tmpR,<a class="code" href="arithmetique_8h.html#a93">Value</a> *tmpC,<font class="keywordtype">int</font> NbRays,<font class="keywordtype">int</font> NbConstraints) {
2721 02713
2722 02714 <font class="keywordtype">int</font> kj, i,j, jx;
2723 02715 <font class="keywordtype">unsigned</font> kb, bx;
2724 02716
2725 02717 <font class="comment">/* Remove constraint k */</font>
2726 02718 kj = k/<a class="code" href="polyhedron_8c.html#a0">WSIZE</a>; kb = MSB; kb &gt;&gt;= k%<a class="code" href="polyhedron_8c.html#a0">WSIZE</a>;
2727 02719 Filter[kj]|=kb;
2728 02720 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(tmpC[k],-1);
2729 02721
2730 02722 <font class="comment">/* Remove rays excluded by constraint k */</font>
2731 02723 <font class="keywordflow">for</font>(i=0; i&lt;NbRays; i++)
2732 02724 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a65">value_posz_p</a>(tmpR[i])) {
2733 02725 <font class="keywordflow">if</font> (Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[i][kj]&amp;kb)
2734 02726 <a class="code" href="arithmetique_8h.html#a50">value_decrement</a>(tmpR[i],tmpR[i]); <font class="comment">/* adjust included ray */</font>
2735 02727 <font class="keywordflow">else</font> {
2736 02728
2737 02729 <font class="comment">/* Constraint k excludes ray i -- delete ray i */</font>
2738 02730 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(tmpR[i],-1);
2739 02731
2740 02732 <font class="comment">/* Adjust non-deleted constraints */</font>
2741 02733 jx=0; bx=MSB;
2742 02734 <font class="keywordflow">for</font>(j=0; j&lt;NbConstraints; j++) {
2743 02735 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a65">value_posz_p</a>(tmpC[j]) &amp;&amp; (Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[i][jx]&amp;bx) )
2744 02736 <a class="code" href="arithmetique_8h.html#a50">value_decrement</a>(tmpC[j],tmpC[j]);
2745 02737 NEXT(jx,bx);
2746 02738 }
2747 02739 }
2748 02740 }
2749 02741 } <font class="comment">/* addToFilter */</font>
2750 02742
2751 02743 <font class="comment">/*</font>
2752 02744 <font class="comment"> * Given polyhedra 'P1' and 'P2' such that their intersection is an empty</font>
2753 02745 <font class="comment"> * polyhedron, find the minimal set of constraints of 'P1' which contradict</font>
2754 02746 <font class="comment"> * all of the constraints of 'P2'. This is believed to be an NP-hard problem</font>
2755 02747 <font class="comment"> * and so a heuristic is employed to solve it in worst case. The heuristic is </font>
2756 02748 <font class="comment"> * to select in every turn that constraint of 'P1' which excludes most rays of</font>
2757 02749 <font class="comment"> * 'P2'. A bit in the binary format of an element of array 'Filter' is set to</font>
2758 02750 <font class="comment"> * 1 if the corresponding constraint is to be included in the minimal set of </font>
2759 02751 <font class="comment"> * constraints otherwise it is set to 0.</font>
2760 02752 <font class="comment"> */</font>
2761 <a name="l02753"></a><a class="code" href="polyhedron_8c.html#a39">02753</a> <font class="keyword">static</font> <font class="keywordtype">void</font> <a class="code" href="polyhedron_8c.html#a39">FindSimple</a>(Polyhedron *P1,Polyhedron *P2,<font class="keywordtype">unsigned</font> *Filter,<font class="keywordtype">unsigned</font> NbMaxRays) {
2762 02754
2763 02755 Matrix *Mat = NULL;
2764 02756 <a class="code" href="structSatMatrix.html">SatMatrix</a> *Sat = NULL;
2765 02757 <font class="keywordtype">int</font> i, j, k, jx, found;
2766 02758 <a class="code" href="arithmetique_8h.html#a93">Value</a> *p1, *p2, p3;
2767 02759 <font class="keywordtype">unsigned</font> Dimension, NbRays, NbConstraints, bx, nc;
2768 02760 <a class="code" href="arithmetique_8h.html#a93">Value</a> NbConstraintsLeft, tmp;
2769 02761 <a class="code" href="arithmetique_8h.html#a93">Value</a> *tmpC = NULL, *tmpR = NULL;
2770 02762 Polyhedron *Pol = NULL, *Pol2 = NULL;
2771 02763
2772 02764 <font class="comment">/* Initialize all the 'Value' variables */</font>
2773 02765 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(p3); <a class="code" href="arithmetique_8h.html#a10">value_init</a>(NbConstraintsLeft);
2774 02766 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(tmp);
2775 02767
2776 02768 <a class="code" href="arithmetic__errors_8h.html#a4">CATCH</a>(any_exception_error) {
2777 02769 <font class="keywordflow">if</font> (tmpC) free(tmpC);
2778 02770 <font class="keywordflow">if</font> (tmpR) free(tmpR);
2779 02771 <font class="keywordflow">if</font> (Mat) <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Mat);
2780 02772 <font class="keywordflow">if</font> (Sat) <a class="code" href="polyparam_8c.html#a24">SMFree</a>(&amp;Sat);
2781 02773 <font class="keywordflow">if</font> (Pol2 &amp;&amp; Pol2!=P2) <a class="code" href="polyhedron_8c.html#a18">Polyhedron_Free</a>(Pol2);
2782 02774 <font class="keywordflow">if</font> (Pol &amp;&amp; Pol!=Pol2 &amp;&amp; Pol!=P2) <a class="code" href="polyhedron_8c.html#a18">Polyhedron_Free</a>(Pol);
2783 02775
2784 02776 <font class="comment">/* Clear all the 'Value' variables */</font>
2785 02777 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(p3); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(NbConstraintsLeft);
2786 02778 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
2787 02779 <a class="code" href="arithmetic__errors_8h.html#a7">RETHROW</a>();
2788 02780 }
2789 02781 <a class="code" href="arithmetic__errors_8h.html#a6">TRY</a> {
2790 02782
2791 02783 Dimension = P1-&gt;Dimension+2; <font class="comment">/* status + homogeneous Dimension */</font>
2792 02784 Mat = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(P1-&gt;NbConstraints, Dimension);
2793 02785 <font class="keywordflow">if</font>(!Mat) {
2794 02786 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"FindSimple"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
2795 02787 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
2796 02788
2797 02789 <font class="comment">/* Clear all the 'Value' variables */</font>
2798 02790 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(p3); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(NbConstraintsLeft); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
2799 02791 <font class="keywordflow">return</font>;
2800 02792 }
2801 02793
2802 02794 <font class="comment">/* Post constraints in P1 already included by Filter */</font>
2803 02795 jx = 0; bx = MSB; Mat-&gt;NbRows=0;
2804 02796 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(NbConstraintsLeft,0);
2805 02797 <font class="keywordflow">for</font> (k=0; k&lt;P1-&gt;NbConstraints; k++) {
2806 02798 <font class="keywordflow">if</font> (Filter[jx]&amp;bx) {
2807 02799 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(P1-&gt;Constraint[k], Mat-&gt;p[Mat-&gt;NbRows], Dimension);
2808 02800 Mat-&gt;NbRows++;
2809 02801 }
2810 02802 <font class="keywordflow">else</font>
2811 02803 <a class="code" href="arithmetique_8h.html#a45">value_increment</a>(NbConstraintsLeft,NbConstraintsLeft);
2812 02804 NEXT(jx,bx);
2813 02805 }
2814 02806 Pol2 = P2;
2815 02807
2816 02808 <font class="keywordflow">for</font> (;;) {
2817 02809 <font class="keywordflow">if</font> (Mat-&gt;NbRows==0)
2818 02810 Pol = <a class="code" href="polyhedron_8c.html#a36">Polyhedron_Copy</a>(Pol2);
2819 02811 <font class="keywordflow">else</font> {
2820 02812 Pol = <a class="code" href="polyhedron_8c.html#a28">AddConstraints</a>(Mat-&gt;p_Init, Mat-&gt;NbRows, Pol2, NbMaxRays);
2821 02813 <font class="keywordflow">if</font> (Pol2 != P2) <a class="code" href="polyhedron_8c.html#a18">Polyhedron_Free</a>(Pol2), Pol2 = NULL;
2822 02814 }
2823 02815 <font class="keywordflow">if</font> (emptyQ(Pol)) {
2824 02816 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Mat), Mat = NULL;
2825 02817 <a class="code" href="polyhedron_8c.html#a18">Polyhedron_Free</a>(Pol), Pol = NULL;
2826 02818 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
2827 02819
2828 02820 <font class="comment">/* Clear all the 'Value' variables */</font>
2829 02821 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(p3); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(NbConstraintsLeft); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
2830 02822 <font class="keywordflow">return</font>;
2831 02823 }
2832 02824 Mat-&gt;NbRows = 0; <font class="comment">/* Reset Mat */</font>
2833 02825 Pol2 = Pol;
2834 02826
2835 02827 <font class="comment">/* Its not enough-- find some more constraints */</font>
2836 02828 Dimension = Pol-&gt;Dimension+1; <font class="comment">/* homogeneous Dimension */</font>
2837 02829 NbRays = Pol-&gt;NbRays;
2838 02830 NbConstraints = P1-&gt;NbConstraints;
2839 02831 tmpR = (<a class="code" href="arithmetique_8h.html#a93">Value</a> *)malloc(NbRays*<font class="keyword">sizeof</font>(<a class="code" href="arithmetique_8h.html#a93">Value</a>));
2840 02832 <font class="keywordflow">if</font>(!tmpR) {
2841 02833 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"FindSimple"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
2842 02834 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
2843 02835
2844 02836 <font class="comment">/* Clear all the 'Value' variables */</font>
2845 02837 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(p3); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(NbConstraintsLeft); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
2846 02838 <font class="keywordflow">return</font>;
2847 02839 }
2848 02840 <font class="keywordflow">for</font>(i=0;i&lt;NbRays;i++)
2849 02841 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(tmpR[i]);
2850 02842 tmpC = (<a class="code" href="arithmetique_8h.html#a93">Value</a> *)malloc(NbConstraints*<font class="keyword">sizeof</font>(<a class="code" href="arithmetique_8h.html#a93">Value</a>));
2851 02843 <font class="keywordflow">if</font>(!tmpC) {
2852 02844 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"FindSimple"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
2853 02845 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
2854 02846
2855 02847 <font class="comment">/* Clear all the 'Value' variables */</font>
2856 02848 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(p3); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(NbConstraintsLeft);
2857 02849 <font class="keywordflow">for</font>(i=0;i&lt;NbRays;i++)
2858 02850 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmpR[i]);
2859 02851 free(tmpR);
2860 02852 <font class="keywordflow">return</font>;
2861 02853 }
2862 02854 <font class="keywordflow">for</font>(i=0;i&lt;NbConstraints;i++)
2863 02855 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(tmpC[i]);
2864 02856 <a class="code" href="vector_8c.html#a9">Vector_Set</a>(tmpR,0,NbRays);
2865 02857 <a class="code" href="vector_8c.html#a9">Vector_Set</a>(tmpC,0,NbConstraints);
2866 02858
2867 02859 <font class="comment">/* Build the Sat matrix */</font>
2868 02860 nc = (NbConstraints - 1) / (<font class="keyword">sizeof</font>(int)*8) + 1;
2869 02861 Sat = <a class="code" href="polyparam_8c.html#a23">SMAlloc</a>(NbRays, nc);
2870 02862 Sat-&gt;<a class="code" href="structSatMatrix.html#m0">NbRows</a> = NbRays;
2871 02863 <a class="code" href="polyhedron_8c.html#a4">SMVector_Init</a>(Sat-&gt;<a class="code" href="structSatMatrix.html#m3">p_init</a>, nc*NbRays);
2872 02864
2873 02865 jx=0; bx=MSB;
2874 02866 <font class="keywordflow">for</font> (k=0; k&lt;NbConstraints; k++) {
2875 02867 <font class="keywordflow">if</font> (Filter[jx]&amp;bx)
2876 02868 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(tmpC[k],-1);
2877 02869 <font class="keywordflow">else</font>
2878 02870 <font class="keywordflow">for</font> (i=0; i&lt;NbRays; i++) {
2879 02871 p1 = Pol-&gt;Ray[i]+1;
2880 02872 p2 = P1-&gt;Constraint[k]+1;
2881 02873 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(p3,0);
2882 02874 <font class="keywordflow">for</font> (j=0; j&lt;Dimension; j++) {
2883 02875 <a class="code" href="arithmetique_8h.html#a47">value_multiply</a>(tmp,*p1,*p2);
2884 02876 <a class="code" href="arithmetique_8h.html#a43">value_addto</a>(p3,p3,tmp);
2885 02877 p1++; p2++;
2886 02878 }
2887 02879 <font class="keywordflow">if</font>(<a class="code" href="arithmetique_8h.html#a67">value_zero_p</a>(p3) ||
2888 02880 (<a class="code" href="arithmetique_8h.html#a63">value_pos_p</a>(p3) &amp;&amp; <a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(P1-&gt;Constraint[k][0]))) {
2889 02881 Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[i][jx]|=bx; <font class="comment">/* constraint includes ray, set flag */</font>
2890 02882 <a class="code" href="arithmetique_8h.html#a45">value_increment</a>(tmpR[i],tmpR[i]);
2891 02883 <a class="code" href="arithmetique_8h.html#a45">value_increment</a>(tmpC[k],tmpC[k]);
2892 02884 }
2893 02885 }
2894 02886 NEXT(jx, bx);
2895 02887 }
2896 02888
2897 02889 <font class="keywordflow">do</font> { <font class="comment">/* find all of the essential constraints */</font>
2898 02890 found = 0;
2899 02891 <font class="keywordflow">for</font>(i=0; i&lt;NbRays; i++)
2900 02892 <font class="keywordflow">if</font>(<a class="code" href="arithmetique_8h.html#a65">value_posz_p</a>(tmpR[i])) {
2901 02893 <a class="code" href="arithmetique_8h.html#a44">value_add_int</a>(tmp,tmpR[i],1);
2902 02894 <font class="keywordflow">if</font>(<a class="code" href="arithmetique_8h.html#a22">value_eq</a>(tmp,NbConstraintsLeft)) {
2903 02895
2904 02896 <font class="comment">/* Ray i is excluded by only one constraint... find it */</font>
2905 02897 jx = 0; bx = MSB;
2906 02898 <font class="keywordflow">for</font>(k=0; k&lt;NbConstraints; k++) {
2907 02899 <font class="keywordflow">if</font>(<a class="code" href="arithmetique_8h.html#a65">value_posz_p</a>(tmpC[k]) &amp;&amp; ((Sat-&gt;<a class="code" href="structSatMatrix.html#m2">p</a>[i][jx]&amp;bx)==0)) {
2908 02900 <a class="code" href="polyhedron_8c.html#a38">addToFilter</a>(k, Filter, Sat, tmpR, tmpC,
2909 02901 NbRays, NbConstraints);
2910 02902 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(P1-&gt;Constraint[k],
2911 02903 Mat-&gt;p[Mat-&gt;NbRows],Dimension+1);
2912 02904 Mat-&gt;NbRows++;
2913 02905 <a class="code" href="arithmetique_8h.html#a50">value_decrement</a>(NbConstraintsLeft,NbConstraintsLeft);
2914 02906 found=1;
2915 02907 <font class="keywordflow">break</font>;
2916 02908 }
2917 02909 NEXT(jx,bx);
2918 02910 }
2919 02911 <font class="keywordflow">break</font>;
2920 02912 }
2921 02913 }
2922 02914 }
2923 02915 <font class="keywordflow">while</font> (found);
2924 02916
2925 02917 <font class="keywordflow">if</font> (!Mat-&gt;NbRows) { <font class="comment">/* Well then, just use a stupid heuristic */</font>
2926 02918 <font class="comment">/* find the constraint which excludes the most */</font>
2927 02919 <a class="code" href="arithmetique_8h.html#a93">Value</a> cmax;
2928 02920 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(cmax);
2929 02921
2930 02922 <font class="preprocessor">#ifndef LINEAR_VALUE_IS_CHARS</font>
2931 02923 <font class="preprocessor"></font>
2932 02924 <font class="comment">/* the typechecking arithmetic lib does (of course) not</font>
2933 02925 <font class="comment"> recognize this one... */</font>
2934 02926 <font class="comment">//value_assign(cmax,~((Value)1&lt;&lt;(sizeof(Value)*8-1)));</font>
2935 02927 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(cmax,(NbRays * NbConstraints+1));
2936 02928 <font class="preprocessor">#else</font>
2937 02929 <font class="preprocessor"></font> <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(cmax,1);
2938 02930 <font class="preprocessor">#endif</font>
2939 02931 <font class="preprocessor"></font>
2940 02932 j = -1;
2941 02933 <font class="keywordflow">for</font>(k=0; k&lt;NbConstraints; k++)
2942 02934 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a65">value_posz_p</a>(tmpC[k])) {
2943 02935 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a24">value_gt</a>(cmax,tmpC[k])) {
2944 02936 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(cmax,tmpC[k]);
2945 02937 j = k;
2946 02938 }
2947 02939 }
2948 02940 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(cmax);
2949 02941 <font class="keywordflow">if</font> (j&lt;0) {
2950 02942 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"DomSimplify"</font>,<font class="stringliteral">"logerror"</font>,<font class="stringliteral">"logic error"</font>);
2951 02943 }
2952 02944 <font class="keywordflow">else</font> {
2953 02945 <a class="code" href="polyhedron_8c.html#a38">addToFilter</a>(j, Filter, Sat, tmpR, tmpC, NbRays, NbConstraints);
2954 02946 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(P1-&gt;Constraint[j],Mat-&gt;p[Mat-&gt;NbRows],Dimension+1);
2955 02947 Mat-&gt;NbRows++;
2956 02948 <a class="code" href="arithmetique_8h.html#a50">value_decrement</a>(NbConstraintsLeft,NbConstraintsLeft);
2957 02949 }
2958 02950 }
2959 02951 <a class="code" href="polyparam_8c.html#a24">SMFree</a>(&amp;Sat), Sat = NULL;
2960 02952 free(tmpC), tmpC = NULL;
2961 02953 free(tmpR), tmpR = NULL;
2962 02954 }
2963 02955 } <font class="comment">/* end of TRY */</font>
2964 02956
2965 02957 <font class="comment">/* Clear all the 'Value' variables */</font>
2966 02958 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(p3); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(NbConstraintsLeft);
2967 02959 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
2968 02960 <font class="keywordflow">for</font>(i=0;i&lt;NbRays;i++)
2969 02961 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmpR[i]);
2970 02962 <font class="keywordflow">for</font>(i=0;i&lt;NbRays;i++)
2971 02963 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmpC[i]);
2972 02964
2973 02965 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
2974 02966 } <font class="comment">/* FindSimple */</font>
2975 02967
2976 02968 <font class="comment">/* </font>
2977 02969 <font class="comment"> * Return 0 if the intersection of Pol1 and Pol2 is empty, otherwise return 1.</font>
2978 02970 <font class="comment"> * If the intersection is non-empty, store the non-redundant constraints in </font>
2979 02971 <font class="comment"> * 'Filter' array. If the intersection is empty then store the smallest set of</font>
2980 02972 <font class="comment"> * constraints of 'Pol1' which on intersection with 'Pol2' gives empty set, in</font>
2981 02973 <font class="comment"> * 'Filter' array. 'NbMaxRays' is the maximum allowed rays in the intersection</font>
2982 02974 <font class="comment"> * of 'Pol1' and 'Pol2'. </font>
2983 02975 <font class="comment"> */</font>
2984 <a name="l02976"></a><a class="code" href="polyhedron_8c.html#a40">02976</a> <font class="keyword">static</font> <font class="keywordtype">int</font> <a class="code" href="polyhedron_8c.html#a40">SimplifyConstraints</a>(Polyhedron *Pol1,Polyhedron *Pol2,<font class="keywordtype">unsigned</font> *Filter,<font class="keywordtype">unsigned</font> NbMaxRays) {
2985 02977
2986 02978 Polyhedron *Pol = NULL;
2987 02979 Matrix *Mat = NULL, *Ray = NULL;
2988 02980 <a class="code" href="structSatMatrix.html">SatMatrix</a> *Sat = NULL;
2989 02981 <font class="keywordtype">unsigned</font> NbRay, NbCon, NbCon1, NbCon2, NbEle1, Dimension, notempty;
2990 02982
2991 02983 <a class="code" href="arithmetic__errors_8h.html#a4">CATCH</a>(any_exception_error) {
2992 02984 <font class="keywordflow">if</font> (Pol) <a class="code" href="polyhedron_8c.html#a18">Polyhedron_Free</a>(Pol);
2993 02985 <font class="keywordflow">if</font> (Mat) <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Mat);
2994 02986 <font class="keywordflow">if</font> (Ray) <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Ray);
2995 02987 <font class="keywordflow">if</font> (Sat) <a class="code" href="polyparam_8c.html#a24">SMFree</a>(&amp;Sat);
2996 02988 <a class="code" href="arithmetic__errors_8h.html#a7">RETHROW</a>();
2997 02989 }
2998 02990 <a class="code" href="arithmetic__errors_8h.html#a6">TRY</a> {
2999 02991
3000 02992 NbRay = Pol1-&gt;NbRays;
3001 02993 NbCon1 = Pol1-&gt;NbConstraints;
3002 02994 NbCon2 = Pol2-&gt;NbConstraints;
3003 02995 NbCon = NbCon1 + NbCon2;
3004 02996 Dimension = Pol1-&gt;Dimension+2; <font class="comment">/* Homogeneous Dimension + Status */</font>
3005 02997 NbEle1 = NbCon1*Dimension;
3006 02998
3007 02999 <font class="comment">/* Allocate space for constraint matrix 'Mat' */</font>
3008 03000 Mat = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(NbCon, Dimension);
3009 03001 <font class="keywordflow">if</font>(!Mat) {
3010 03002 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"SimplifyConstraints"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
3011 03003 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
3012 03004 <font class="keywordflow">return</font> 0;
3013 03005 }
3014 03006
3015 03007 <font class="comment">/* Copy constraints of 'Pol1' to matrix 'Mat' */</font>
3016 03008 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(Pol1-&gt;Constraint[0], Mat-&gt;p_Init, NbEle1);
3017 03009
3018 03010 <font class="comment">/* Add constraints of 'Pol2' to matrix 'Mat'*/</font>
3019 03011 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(Pol2-&gt;Constraint[0], Mat-&gt;p_Init+NbEle1, NbCon2*Dimension);
3020 03012
3021 03013 <font class="comment">/* Allocate space for ray matrix 'Ray' */</font>
3022 03014 Ray = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(NbMaxRays, Dimension);
3023 03015 <font class="keywordflow">if</font>(!Ray) {
3024 03016 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"SimplifyConstraints"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
3025 03017 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
3026 03018 <font class="keywordflow">return</font> 0;
3027 03019 }
3028 03020 Ray-&gt;NbRows = NbRay;
3029 03021
3030 03022 <font class="comment">/* Copy rays of polyhedron 'Pol1' to matrix 'Ray' */</font>
3031 03023 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(Pol1-&gt;Ray[0], Ray-&gt;p_Init, NbRay*Dimension);
3032 03024
3033 03025 <font class="comment">/* Create saturation matrix from constraint matrix 'Mat' and ray matrix */</font>
3034 03026 <font class="comment">/* 'Ray'. */</font>
3035 03027 Sat = <a class="code" href="polyhedron_8c.html#a27">BuildSat</a>(Mat, Ray, NbCon1, NbMaxRays);
3036 03028
3037 03029 <font class="comment">/* Create the ray matrix 'Ray' from the constraint matrix 'Mat' */</font>
3038 03030 <a class="code" href="polyhedron_8c.html#a5">Pol_status</a> = <a class="code" href="polyhedron_8c.html#a14">Chernikova</a>(Mat, Ray, Sat, Pol1-&gt;NbBid, NbMaxRays, NbCon1,0);
3039 03031
3040 03032 <font class="comment">/* Remove redundant constraints from the constraint matrix 'Mat' */</font>
3041 03033 Pol = <a class="code" href="polyhedron_8c.html#a16">Remove_Redundants</a>(Mat, Ray, Sat, Filter);
3042 03034 notempty = 1;
3043 03035 <font class="keywordflow">if</font> (Filter &amp;&amp; emptyQ(Pol)) {
3044 03036 notempty = 0;
3045 03037 <a class="code" href="polyhedron_8c.html#a39">FindSimple</a>(Pol1, Pol2, Filter, NbMaxRays);
3046 03038 }
3047 03039 <font class="comment">/* Polyhedron_Print(stderr,"%4d",Pol1); */</font>
3048 03040
3049 03041 <a class="code" href="polyhedron_8c.html#a18">Polyhedron_Free</a>(Pol), Pol = NULL;
3050 03042 <a class="code" href="polyparam_8c.html#a24">SMFree</a>(&amp;Sat), Sat = NULL;
3051 03043 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Ray), Ray = NULL;
3052 03044 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Mat), Mat = NULL;
3053 03045
3054 03046 } <font class="comment">/* end of TRY */</font>
3055 03047
3056 03048 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
3057 03049 <font class="keywordflow">return</font> notempty;
3058 03050 } <font class="comment">/* SimplifyConstraints */</font>
3059 03051
3060 03052 <font class="comment">/* </font>
3061 03053 <font class="comment"> * Eliminate equations of Pol1 using equations of Pol2. Mark as needed, </font>
3062 03054 <font class="comment"> * equations of Pol1 that are not eliminated. Or info into Filter vector. </font>
3063 03055 <font class="comment"> */</font>
3064 <a name="l03056"></a><a class="code" href="polyhedron_8c.html#a41">03056</a> <font class="keyword">static</font> <font class="keywordtype">void</font> <a class="code" href="polyhedron_8c.html#a41">SimplifyEqualities</a>(Polyhedron *Pol1, Polyhedron *Pol2, <font class="keywordtype">unsigned</font> *Filter) {
3065 03057
3066 03058 <font class="keywordtype">int</font> i,j;
3067 03059 <font class="keywordtype">unsigned</font> ix, bx, NbEqn, NbEqn1, NbEqn2, NbEle2, Dimension;
3068 03060 Matrix *Mat;
3069 03061
3070 03062 NbEqn1 = Pol1-&gt;NbEq;
3071 03063 NbEqn2 = Pol2-&gt;NbEq;
3072 03064 NbEqn = NbEqn1 + NbEqn2;
3073 03065 Dimension = Pol1-&gt;Dimension+2; <font class="comment">/* Homogeneous Dimension + Status */</font>
3074 03066 NbEle2 = NbEqn2*Dimension;
3075 03067
3076 03068 Mat = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(NbEqn, Dimension);
3077 03069 <font class="keywordflow">if</font> (!Mat) {
3078 03070 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"SimplifyEqualities"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
3079 03071 <a class="code" href="polyhedron_8c.html#a5">Pol_status</a> = 1;
3080 03072 <font class="keywordflow">return</font>;
3081 03073 }
3082 03074
3083 03075 <font class="comment">/* Set the equalities of Pol2 */</font>
3084 03076 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(Pol2-&gt;Constraint[0], Mat-&gt;p_Init, NbEle2);
3085 03077
3086 03078 <font class="comment">/* Add the equalities of Pol1 */</font>
3087 03079 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(Pol1-&gt;Constraint[0], Mat-&gt;p_Init+NbEle2, NbEqn1*Dimension);
3088 03080
3089 03081 <a class="code" href="polyhedron_8c.html#a15">Gauss</a>(Mat, NbEqn2, Dimension-1);
3090 03082
3091 03083 ix = 0;
3092 03084 bx = MSB;
3093 03085 <font class="keywordflow">for</font> (i=NbEqn2; i&lt;NbEqn; i++) {
3094 03086 <font class="keywordflow">for</font> (j=1; j&lt;Dimension; j++) {
3095 03087 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(Mat-&gt;p[i][j])) {
3096 03088 <font class="comment">/* If any coefficient of the equation is non-zero */</font>
3097 03089 <font class="comment">/* Set the filter bit for the equation */</font>
3098 03090
3099 03091 Filter[ix] |= bx;
3100 03092 <font class="keywordflow">break</font>;
3101 03093 }
3102 03094 }
3103 03095 NEXT(ix,bx);
3104 03096 }
3105 03097 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Mat);
3106 03098 <font class="keywordflow">return</font>;
3107 03099 } <font class="comment">/* SimplifyEqualities */</font>
3108 03100
3109 03101
3110 03102 <font class="comment">/* </font>
3111 03103 <font class="comment"> * Given two polyhedral domains 'Pol1' and 'Pol2', find the largest domain</font>
3112 03104 <font class="comment"> * set (or the smallest list of non-redundant constraints), that when </font>
3113 03105 <font class="comment"> * intersected with polyhedral domain 'Pol2' equals (Pol1)intersect(Pol2).</font>
3114 03106 <font class="comment"> * The output is a polyhedral domain with the "redundant" constraints removed.</font>
3115 03107 <font class="comment"> * 'NbMaxRays' is the maximium allowed rays in the new polyhedra. </font>
3116 03108 <font class="comment"> */</font>
3117 <a name="l03109"></a><a class="code" href="polyhedron_8c.html#a42">03109</a> Polyhedron *<a class="code" href="polyhedron_8c.html#a42">DomainSimplify</a>(Polyhedron *Pol1, Polyhedron *Pol2, <font class="keywordtype">unsigned</font> NbMaxRays) {
3118 03110
3119 03111 Polyhedron *p1, *p2, *p3, *d;
3120 03112 <font class="keywordtype">unsigned</font> k, jx, bx, nbentries, NbConstraints, Dimension, NbCon, empty;
3121 03113 <font class="keywordtype">unsigned</font> *Filter;
3122 03114 Matrix *Constraints;
3123 03115
3124 03116
3125 03117 <font class="keywordflow">if</font> (!Pol1 || !Pol2) <font class="keywordflow">return</font> Pol1;
3126 03118 <font class="keywordflow">if</font> (Pol1-&gt;Dimension != Pol2-&gt;Dimension) {
3127 03119 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"DomSimplify"</font>,<font class="stringliteral">"diffdim"</font>,<font class="stringliteral">"operation on different dimensions"</font>);
3128 03120 <a class="code" href="polyhedron_8c.html#a5">Pol_status</a> = 1;
3129 03121 <font class="keywordflow">return</font> 0;
3130 03122 }
3131 03123 <font class="keywordflow">if</font> (emptyQ(Pol1)||emptyQ(Pol2))
3132 03124 <font class="keywordflow">return</font> <a class="code" href="polyhedron_8c.html#a22">Empty_Polyhedron</a>(Pol1-&gt;Dimension);
3133 03125
3134 03126 <font class="comment">/* Find the maximum number of constraints over all polyhedron in the */</font>
3135 03127 <font class="comment">/* polyhedral domain 'Pol2' and store in 'NbCon'. */</font>
3136 03128 NbCon = 0;
3137 03129 <font class="keywordflow">for</font> (p2=Pol2; p2; p2=p2-&gt;next)
3138 03130 <font class="keywordflow">if</font> (p2-&gt;NbConstraints &gt; NbCon)
3139 03131 NbCon = p2-&gt;NbConstraints;
3140 03132
3141 03133 Dimension = Pol1-&gt;Dimension+2; <font class="comment">/* Homogenous Dimension + Status */</font>
3142 03134 d = (Polyhedron *)0;
3143 03135 <font class="keywordflow">for</font> (p1=Pol1; p1; p1=p1-&gt;next) {
3144 03136
3145 03137 <font class="comment">/* Filter is an array of integers, each bit in an element of Filter */</font>
3146 03138 <font class="comment">/* array corresponds to a constraint. The bit is marked 1 if the */</font>
3147 03139 <font class="comment">/* corresponding constraint is non-redundant and is 0 if it is */</font>
3148 03140 <font class="comment">/* redundant. */</font>
3149 03141
3150 03142 NbConstraints = p1-&gt;NbConstraints;
3151 03143 nbentries = (NbConstraints + NbCon - 1) / (<font class="keyword">sizeof</font>(int)*8) + 1;
3152 03144
3153 03145 <font class="comment">/* Allocate space for array 'Filter' */</font>
3154 03146 Filter = (<font class="keywordtype">unsigned</font> *)malloc(nbentries * <font class="keyword">sizeof</font>(<font class="keywordtype">int</font>));
3155 03147 <font class="keywordflow">if</font> (!Filter) {
3156 03148 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"DomSimplify"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space\n"</font>);
3157 03149 <a class="code" href="polyhedron_8c.html#a5">Pol_status</a> = 1;
3158 03150 <font class="keywordflow">return</font> 0;
3159 03151 }
3160 03152
3161 03153 <font class="comment">/* Initialize 'Filter' with zeros */</font>
3162 03154 <a class="code" href="polyhedron_8c.html#a4">SMVector_Init</a>(Filter, nbentries);
3163 03155
3164 03156 <font class="comment">/* Filter the constraints of p1 in context of polyhedra p2(s) */</font>
3165 03157 empty = 1;
3166 03158 <font class="keywordflow">for</font> (p2=Pol2; p2; p2=p2-&gt;next) {
3167 03159
3168 03160 <font class="comment">/* Store the non-redundant constraints in array 'Filter'. With */</font>
3169 03161 <font class="comment">/* successive loops, the array 'Filter' holds the union of all */</font>
3170 03162 <font class="comment">/* non-redundant constraints. 'empty' is set to zero if the */</font>
3171 03163 <font class="comment">/* intersection of two polyhedra is non-empty and Filter is !Null */</font>
3172 03164
3173 03165 <a class="code" href="polyhedron_8c.html#a41">SimplifyEqualities</a>(p1, p2, Filter);
3174 03166 <font class="keywordflow">if</font> (<a class="code" href="polyhedron_8c.html#a40">SimplifyConstraints</a>(p1, p2, Filter, NbMaxRays))
3175 03167 empty=0;
3176 03168
3177 03169 <font class="comment">/* takes the union of all non redundant constraints */</font>
3178 03170 }
3179 03171
3180 03172 <font class="keywordflow">if</font> (!empty) {
3181 03173
3182 03174 <font class="comment">/* Copy all non-redundant constraints to matrix 'Constraints' */</font>
3183 03175 Constraints = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(NbConstraints, Dimension);
3184 03176 <font class="keywordflow">if</font> (!Constraints) {
3185 03177 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"DomSimplify"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space\n"</font>);
3186 03178 <a class="code" href="polyhedron_8c.html#a5">Pol_status</a> = 1;
3187 03179 <font class="keywordflow">return</font> 0;
3188 03180 }
3189 03181 Constraints-&gt;NbRows = 0;
3190 03182 <font class="keywordflow">for</font> (k=0, jx=0, bx=MSB; k&lt;NbConstraints; k++) {
3191 03183
3192 03184 <font class="comment">/* If a bit entry in Filter[jx] is marked 1, copy the correspond- */</font>
3193 03185 <font class="comment">/* ing constraint in matrix 'Constraints'. */</font>
3194 03186 <font class="keywordflow">if</font> (Filter[jx]&amp;bx) {
3195 03187 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(p1-&gt;Constraint[k],
3196 03188 Constraints-&gt;p[Constraints-&gt;NbRows],
3197 03189 Dimension);
3198 03190 Constraints-&gt;NbRows++;
3199 03191 }
3200 03192 NEXT(jx,bx);
3201 03193 }
3202 03194
3203 03195 <font class="comment">/* Create the polyhedron 'p3' corresponding to the constraints in */</font>
3204 03196 <font class="comment">/* matrix 'Constraints'. */</font>
3205 03197 p3 = <a class="code" href="polyhedron_8c.html#a24">Constraints2Polyhedron</a>(Constraints,NbMaxRays);
3206 03198 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Constraints);
3207 03199
3208 03200 <font class="comment">/* Add polyhedron 'p3' in the domain 'd'. */</font>
3209 03201 d = <a class="code" href="polyhedron_8c.html#a30">AddPolyToDomain</a> (p3, d);
3210 03202 p3 = NULL;
3211 03203 }
3212 03204 free(Filter);
3213 03205 }
3214 03206 <font class="keywordflow">if</font> (!d)
3215 03207 <font class="keywordflow">return</font> <a class="code" href="polyhedron_8c.html#a22">Empty_Polyhedron</a>(Pol1-&gt;Dimension);
3216 03208 <font class="keywordflow">else</font> <font class="keywordflow">return</font> d;
3217 03209
3218 03210 } <font class="comment">/* DomainSimplify */</font>
3219 03211
3220 03212 <font class="comment">/*</font>
3221 03213 <font class="comment"> * Domain Simplify as defined in Strasborg Polylib version. </font>
3222 03214 <font class="comment"> */</font>
3223 <a name="l03215"></a><a class="code" href="polyhedron_8c.html#a43">03215</a> Polyhedron *<a class="code" href="polyhedron_8c.html#a43">Stras_DomainSimplify</a>(Polyhedron *Pol1,Polyhedron *Pol2,<font class="keywordtype">unsigned</font> NbMaxRays) {
3224 03216
3225 03217 Polyhedron *p1, *p2, *p3 = NULL, *d = NULL;
3226 03218 <font class="keywordtype">unsigned</font> k, jx, bx, nbentries, NbConstraints, Dimension, NbCon, empty;
3227 03219 <font class="keywordtype">unsigned</font> *Filter = NULL;
3228 03220 Matrix *Constraints = NULL;
3229 03221
3230 03222 <a class="code" href="arithmetic__errors_8h.html#a4">CATCH</a>(any_exception_error) {
3231 03223 <font class="keywordflow">if</font> (Constraints) <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Constraints);
3232 03224 <font class="keywordflow">if</font> (Filter) free(Filter);
3233 03225 <font class="keywordflow">if</font> (d) <a class="code" href="polyhedron_8c.html#a18">Polyhedron_Free</a>(d);
3234 03226 <font class="keywordflow">if</font> (p2) <a class="code" href="polyhedron_8c.html#a18">Polyhedron_Free</a>(p3);
3235 03227 <a class="code" href="arithmetic__errors_8h.html#a7">RETHROW</a>();
3236 03228 }
3237 03229 <a class="code" href="arithmetic__errors_8h.html#a6">TRY</a> {
3238 03230 <font class="keywordflow">if</font> (!Pol1 || !Pol2) {
3239 03231 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
3240 03232 <font class="keywordflow">return</font> Pol1;
3241 03233 }
3242 03234 <font class="keywordflow">if</font> (Pol1-&gt;Dimension != Pol2-&gt;Dimension) {
3243 03235 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"DomainSimplify"</font>,<font class="stringliteral">"diffdim"</font>,<font class="stringliteral">"operation on different dimensions"</font>);
3244 03236 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
3245 03237 <font class="keywordflow">return</font> 0;
3246 03238 }
3247 03239 <font class="keywordflow">if</font> (emptyQ(Pol1)||emptyQ(Pol2)) {
3248 03240 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
3249 03241 <font class="keywordflow">return</font> <a class="code" href="polyhedron_8c.html#a22">Empty_Polyhedron</a>(Pol1-&gt;Dimension);
3250 03242 }
3251 03243
3252 03244 <font class="comment">/* Find the maximum number of constraints over all polyhedron in the */</font>
3253 03245 <font class="comment">/* polyhedral domain 'Pol2' and store in 'NbCon'. */</font>
3254 03246 NbCon = 0;
3255 03247 <font class="keywordflow">for</font> (p2=Pol2; p2; p2=p2-&gt;next)
3256 03248 <font class="keywordflow">if</font> (p2-&gt;NbConstraints &gt; NbCon)
3257 03249 NbCon = p2-&gt;NbConstraints;
3258 03250
3259 03251 Dimension = Pol1-&gt;Dimension+2; <font class="comment">/* Homogenous Dimension + Status */</font>
3260 03252 d = (Polyhedron *)0;
3261 03253 <font class="keywordflow">for</font> (p1=Pol1; p1; p1=p1-&gt;next) {
3262 03254
3263 03255 <font class="comment">/* Filter is an array of integers, each bit in an element of Filter */</font>
3264 03256 <font class="comment">/* array corresponds to a constraint. The bit is marked 1 if the */</font>
3265 03257 <font class="comment">/* corresponding constraint is non-redundant and is 0 if it is */</font>
3266 03258 <font class="comment">/* redundant. */</font>
3267 03259
3268 03260 NbConstraints = p1-&gt;NbConstraints;
3269 03261 nbentries = (NbConstraints + NbCon - 1)/(<font class="keyword">sizeof</font>(int)*8) + 1;
3270 03262
3271 03263 <font class="comment">/* Allocate space for array 'Filter' */</font>
3272 03264 Filter = (<font class="keywordtype">unsigned</font> *)malloc(nbentries * <font class="keyword">sizeof</font>(<font class="keywordtype">int</font>));
3273 03265 <font class="keywordflow">if</font>(!Filter) {
3274 03266 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"DomainSimplify"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
3275 03267 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
3276 03268 <font class="keywordflow">return</font> 0;
3277 03269 }
3278 03270
3279 03271 <font class="comment">/* Initialize 'Filter' with zeros */</font>
3280 03272 <a class="code" href="polyhedron_8c.html#a4">SMVector_Init</a>(Filter, nbentries);
3281 03273
3282 03274 <font class="comment">/* Filter the constraints of p1 in context to the polyhedra p2(s) */</font>
3283 03275 empty = 1;
3284 03276 <font class="keywordflow">for</font> (p2=Pol2; p2; p2=p2-&gt;next) {
3285 03277
3286 03278 <font class="comment">/* Store the non-redundant constraints in array 'Filter'. With */</font>
3287 03279 <font class="comment">/* successive loops, the array 'Filter' holds the union of all */</font>
3288 03280 <font class="comment">/* non-redundant constraints. 'empty' is set to zero if the */</font>
3289 03281 <font class="comment">/* intersection of two polyhedra is non-empty and Filter is !Null */</font>
3290 03282
3291 03283 <font class="keywordflow">if</font> (<a class="code" href="polyhedron_8c.html#a40">SimplifyConstraints</a>(p1, p2, Filter, NbMaxRays))
3292 03284 empty=0;
3293 03285 }
3294 03286
3295 03287 <font class="keywordflow">if</font> (!empty) {
3296 03288
3297 03289 <font class="comment">/* Copy all non-redundant constraints to matrix 'Constraints' */</font>
3298 03290 Constraints = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(NbConstraints,Dimension);
3299 03291 <font class="keywordflow">if</font>(!Constraints) {
3300 03292 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"DomainSimplify"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
3301 03293 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
3302 03294 <font class="keywordflow">return</font> 0;
3303 03295 }
3304 03296 Constraints-&gt;NbRows = 0;
3305 03297 <font class="keywordflow">for</font> (k=0, jx=0, bx=MSB; k&lt;NbConstraints; k++) {
3306 03298
3307 03299 <font class="comment">/* If a bit entry in Filter[jx] is marked 1, copy the correspond- */</font>
3308 03300 <font class="comment">/* ing constraint in matrix 'Constraints'. */</font>
3309 03301 <font class="keywordflow">if</font> (Filter[jx]&amp;bx) {
3310 03302 <a class="code" href="vector_8c.html#a11">Vector_Copy</a>(p1-&gt;Constraint[k],
3311 03303 Constraints-&gt;p[Constraints-&gt;NbRows],
3312 03304 Dimension);
3313 03305 Constraints-&gt;NbRows++;
3314 03306 }
3315 03307 NEXT(jx,bx);
3316 03308 }
3317 03309
3318 03310 <font class="comment">/* Create the polyhedron 'p3' corresponding to the constraints in */</font>
3319 03311 <font class="comment">/* matrix 'Constraints'. */</font>
3320 03312 p3 = <a class="code" href="polyhedron_8c.html#a24">Constraints2Polyhedron</a>(Constraints,NbMaxRays);
3321 03313 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Constraints), Constraints = NULL;
3322 03314
3323 03315 <font class="comment">/* Add polyhedron 'p3' in the domain 'd'. */</font>
3324 03316 d = <a class="code" href="polyhedron_8c.html#a30">AddPolyToDomain</a> (p3, d);
3325 03317 p3 = NULL;
3326 03318 }
3327 03319 free(Filter), Filter = NULL;
3328 03320 }
3329 03321 } <font class="comment">/* end of TRY */</font>
3330 03322
3331 03323 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
3332 03324 <font class="keywordflow">if</font> (!d)
3333 03325 <font class="keywordflow">return</font> <a class="code" href="polyhedron_8c.html#a22">Empty_Polyhedron</a>(Pol1-&gt;Dimension);
3334 03326 <font class="keywordflow">else</font>
3335 03327 <font class="keywordflow">return</font> d;
3336 03328 } <font class="comment">/* DomainSimplify */</font>
3337 03329
3338 03330 <font class="comment">/*</font>
3339 03331 <font class="comment"> * Return the Union of two polyhedral domains 'Pol1' and Pol2'. The result is</font>
3340 03332 <font class="comment"> * a new polyhedral domain.</font>
3341 03333 <font class="comment"> */</font>
3342 <a name="l03334"></a><a class="code" href="polyhedron_8c.html#a44">03334</a> Polyhedron *<a class="code" href="polyhedron_8c.html#a44">DomainUnion</a>(Polyhedron *Pol1,Polyhedron *Pol2,<font class="keywordtype">unsigned</font> NbMaxRays) {
3343 03335
3344 03336 Polyhedron *PolA, *PolEndA, *PolB, *PolEndB, *p1, *p2;
3345 03337 <font class="keywordtype">int</font> Redundant;
3346 03338
3347 03339 <font class="keywordflow">if</font> (!Pol1 || !Pol2) <font class="keywordflow">return</font> (Polyhedron *) 0;
3348 03340 <font class="keywordflow">if</font> (Pol1-&gt;Dimension != Pol2-&gt;Dimension) {
3349 03341 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"DomainUnion"</font>,<font class="stringliteral">"diffdim"</font>,<font class="stringliteral">"operation on different dimensions"</font>);
3350 03342 <font class="keywordflow">return</font> (Polyhedron*) 0;
3351 03343 }
3352 03344
3353 03345
3354 03346
3355 03347
3356 03348
3357 03349
3358 03350 <font class="comment">/* Copy 'Pol1' to 'PolA' */</font>
3359 03351 PolA = PolEndA = (Polyhedron *)0;
3360 03352 <font class="keywordflow">for</font> (p1=Pol1; p1; p1=p1-&gt;next) {
3361 03353
3362 03354 <font class="comment">/* Does any component of 'Pol2' cover 'p1' ? */</font>
3363 03355 Redundant = 0;
3364 03356 <font class="keywordflow">for</font> (p2=Pol2; p2; p2=p2-&gt;next) {
3365 03357 <font class="keywordflow">if</font> (<a class="code" href="polyhedron_8c.html#a29">PolyhedronIncludes</a>(p2, p1) ) { <font class="comment">/* p2 covers p1 */</font>
3366 03358 Redundant = 1;
3367 03359
3368 03360
3369 03361 <font class="keywordflow">break</font>;
3370 03362
3371 03363 }
3372 03364 }
3373 03365 <font class="keywordflow">if</font> (!Redundant) {
3374 03366
3375 03367 <font class="comment">/* Add 'p1' to 'PolA' */</font>
3376 03368 <font class="keywordflow">if</font> (!PolEndA)
3377 03369 PolEndA = PolA = <a class="code" href="polyhedron_8c.html#a36">Polyhedron_Copy</a>(p1);
3378 03370 <font class="keywordflow">else</font> {
3379 03371 PolEndA-&gt;next = <a class="code" href="polyhedron_8c.html#a36">Polyhedron_Copy</a>(p1);
3380 03372 PolEndA = PolEndA-&gt;next;
3381 03373 }
3382 03374
3383 03375 }
3384 03376 }
3385 03377
3386 03378 <font class="comment">/* Copy 'Pol2' to PolB */</font>
3387 03379 PolB = PolEndB = (Polyhedron *)0;
3388 03380 <font class="keywordflow">for</font> (p2=Pol2; p2; p2=p2-&gt;next) {
3389 03381
3390 03382 <font class="comment">/* Does any component of PolA cover 'p2' ? */</font>
3391 03383 Redundant = 0;
3392 03384 <font class="keywordflow">for</font> (p1=PolA; p1; p1=p1-&gt;next) {
3393 03385 <font class="keywordflow">if</font> (<a class="code" href="polyhedron_8c.html#a29">PolyhedronIncludes</a>(p1, p2)) { <font class="comment">/* p1 covers p2 */</font>
3394 03386 Redundant = 1;
3395 03387 <font class="keywordflow">break</font>;
3396 03388 }
3397 03389 }
3398 03390 <font class="keywordflow">if</font> (!Redundant) {
3399 03391
3400 03392 <font class="comment">/* Add 'p2' to 'PolB' */</font>
3401 03393 <font class="keywordflow">if</font> (!PolEndB)
3402 03394 PolEndB = PolB = <a class="code" href="polyhedron_8c.html#a36">Polyhedron_Copy</a>(p2);
3403 03395 <font class="keywordflow">else</font> {
3404 03396 PolEndB-&gt;next = <a class="code" href="polyhedron_8c.html#a36">Polyhedron_Copy</a>(p2);
3405 03397 PolEndB = PolEndB-&gt;next;
3406 03398 }
3407 03399
3408 03400
3409 03401 }
3410 03402 }
3411 03403
3412 03404 <font class="keywordflow">if</font> (!PolA) <font class="keywordflow">return</font> PolB;
3413 03405 PolEndA-&gt;next = PolB;
3414 03406 <font class="keywordflow">return</font> PolA;
3415 03407 } <font class="comment">/* DomainUnion */</font>
3416 03408
3417 03409 <font class="comment">/* </font>
3418 03410 <font class="comment"> * Given a polyhedral domain 'Pol', concatenate the lists of rays and lines </font>
3419 03411 <font class="comment"> * of the two (or more) polyhedra in the domain into one combined list, and </font>
3420 03412 <font class="comment"> * find the set of constraints which tightly bound all of those objects. </font>
3421 03413 <font class="comment"> * 'NbMaxConstrs' is the maximum allowed constraints in the new polyhedron. </font>
3422 03414 <font class="comment"> */</font>
3423 <a name="l03415"></a><a class="code" href="polyhedron_8c.html#a45">03415</a> Polyhedron *<a class="code" href="polyhedron_8c.html#a45">DomainConvex</a>(Polyhedron *Pol,<font class="keywordtype">unsigned</font> NbMaxConstrs) {
3424 03416
3425 03417 Polyhedron *p, *q, *NewPol = NULL;
3426 03418
3427 03419 <a class="code" href="arithmetic__errors_8h.html#a4">CATCH</a>(any_exception_error) {
3428 03420 <font class="keywordflow">if</font> (NewPol) <a class="code" href="polyhedron_8c.html#a18">Polyhedron_Free</a>(NewPol);
3429 03421 <a class="code" href="arithmetic__errors_8h.html#a7">RETHROW</a>();
3430 03422 }
3431 03423 <a class="code" href="arithmetic__errors_8h.html#a6">TRY</a> {
3432 03424
3433 03425 <font class="keywordflow">if</font> (!Pol) {
3434 03426 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
3435 03427 <font class="keywordflow">return</font> (Polyhedron*) 0;
3436 03428 }
3437 03429
3438 03430 NewPol = <a class="code" href="polyhedron_8c.html#a36">Polyhedron_Copy</a>(Pol);
3439 03431 <font class="keywordflow">for</font> (p=Pol-&gt;next; p; p=p-&gt;next) {
3440 03432 q = <a class="code" href="polyhedron_8c.html#a34">AddRays</a>(p-&gt;Ray[0], p-&gt;NbRays, NewPol, NbMaxConstrs);
3441 03433 <a class="code" href="polyhedron_8c.html#a18">Polyhedron_Free</a>(NewPol);
3442 03434 NewPol = q;
3443 03435 }
3444 03436 } <font class="comment">/* end of TRY */</font>
3445 03437
3446 03438 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
3447 03439
3448 03440 <font class="keywordflow">return</font> NewPol;
3449 03441 } <font class="comment">/* DomainConvex */</font>
3450 03442
3451 03443 <font class="comment">/*</font>
3452 03444 <font class="comment"> * Given polyhedral domains 'Pol1' and 'Pol2', create a new polyhedral </font>
3453 03445 <font class="comment"> * domain which is mathematically the differnce of the two domains. </font>
3454 03446 <font class="comment"> */</font>
3455 <a name="l03447"></a><a class="code" href="polyhedron_8c.html#a46">03447</a> Polyhedron *<a class="code" href="polyhedron_8c.html#a46">DomainDifference</a>(Polyhedron *Pol1,Polyhedron *Pol2,<font class="keywordtype">unsigned</font> NbMaxRays) {
3456 03448
3457 03449 Polyhedron *p1, *p2, *p3, *d;
3458 03450 <font class="keywordtype">int</font> i;
3459 03451
3460 03452 <font class="keywordflow">if</font> (!Pol1 || !Pol2) <font class="keywordflow">return</font> (Polyhedron*) 0;
3461 03453 <font class="keywordflow">if</font> (Pol1-&gt;Dimension != Pol2-&gt;Dimension) {
3462 03454 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"DomainDifference"</font>,
3463 03455 <font class="stringliteral">"diffdim"</font>, <font class="stringliteral">"operation on different dimensions"</font>);
3464 03456 <font class="keywordflow">return</font> (Polyhedron*) 0;
3465 03457 }
3466 03458 <font class="keywordflow">if</font> (emptyQ(Pol2))
3467 03459 <font class="keywordflow">return</font> (<a class="code" href="polyhedron_8c.html#a37">Domain_Copy</a>(Pol1));
3468 03460 d = (Polyhedron *)0;
3469 03461 <font class="keywordflow">for</font> (p2=Pol2; p2; p2=p2-&gt;next) {
3470 03462 <font class="keywordflow">for</font> (p1=Pol1; p1; p1=p1-&gt;next) {
3471 03463 <font class="keywordflow">for</font> (i=0; i&lt;p2-&gt;NbConstraints; i++) {
3472 03464
3473 03465 <font class="comment">/* Add the constraint ( -p2-&gt;constraint[i] -1) &gt;= 0 in 'p1' */</font>
3474 03466 <font class="comment">/* and create the new polyhedron 'p3'. */</font>
3475 03467 p3 = <a class="code" href="polyhedron_8c.html#a31">SubConstraint</a>(p2-&gt;Constraint[i], p1, NbMaxRays,0);
3476 03468
3477 03469 <font class="comment">/* Add 'p3' in the new domain 'd' */</font>
3478 03470 d = <a class="code" href="polyhedron_8c.html#a30">AddPolyToDomain</a> (p3, d);
3479 03471
3480 03472 <font class="comment">/* If the constraint p2-&gt;constraint[i][0] is an equality, then */</font>
3481 03473 <font class="comment">/* add the constraint ( +p2-&gt;constraint[i] -1) &gt;= 0 in 'p1' and*/</font>
3482 03474 <font class="comment">/* create the new polyhedron 'p3'. */</font>
3483 03475
3484 03476 <font class="keywordflow">if</font>( <a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(p2-&gt;Constraint[i][0]) ) <font class="comment">/* Inequality */</font>
3485 03477 <font class="keywordflow">continue</font>;
3486 03478 p3 = <a class="code" href="polyhedron_8c.html#a31">SubConstraint</a>(p2-&gt;Constraint[i], p1, NbMaxRays,1);
3487 03479
3488 03480 <font class="comment">/* Add 'p3' in the new domain 'd' */</font>
3489 03481 d = <a class="code" href="polyhedron_8c.html#a30">AddPolyToDomain</a> (p3, d);
3490 03482 }
3491 03483 }
3492 03484 Pol1 = d;
3493 03485 d = (Polyhedron *)0;
3494 03486 }
3495 03487 <font class="keywordflow">if</font> (!Pol1)
3496 03488 <font class="keywordflow">return</font> <a class="code" href="polyhedron_8c.html#a22">Empty_Polyhedron</a>(Pol2-&gt;Dimension);
3497 03489 <font class="keywordflow">else</font>
3498 03490 <font class="keywordflow">return</font> Pol1;
3499 03491 } <font class="comment">/* DomainDifference */</font>
3500 03492
3501 03493 <font class="comment">/*</font>
3502 03494 <font class="comment"> * Given a polyhedral domain 'Pol', convert it to a new polyhedral domain </font>
3503 03495 <font class="comment"> * with dimension expanded to 'align_dimension'. 'NbMaxRays' is the maximum</font>
3504 03496 <font class="comment"> * allowed rays in the new polyhedra.</font>
3505 03497 <font class="comment"> */</font>
3506 <a name="l03498"></a><a class="code" href="polyhedron_8c.html#a47">03498</a> Polyhedron *<a class="code" href="polyhedron_8c.html#a47">align_context</a>(Polyhedron *Pol,<font class="keywordtype">int</font> align_dimension,<font class="keywordtype">int</font> NbMaxRays) {
3507 03499
3508 03500 <font class="keywordtype">int</font> i, j, k;
3509 03501 Polyhedron *p = NULL, *q, *result = NULL;
3510 03502 Matrix *Mat = NULL;
3511 03503
3512 03504 <a class="code" href="arithmetic__errors_8h.html#a4">CATCH</a>(any_exception_error) {
3513 03505 <font class="keywordflow">if</font> (Mat) <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Mat);
3514 03506 <font class="keywordflow">if</font> (result) <a class="code" href="polyhedron_8c.html#a18">Polyhedron_Free</a>(result);
3515 03507 <a class="code" href="arithmetic__errors_8h.html#a7">RETHROW</a>();
3516 03508 }
3517 03509 <a class="code" href="arithmetic__errors_8h.html#a6">TRY</a> {
3518 03510
3519 03511 <font class="keywordflow">if</font> (!Pol) <font class="keywordflow">return</font> Pol;
3520 03512 <font class="keywordflow">if</font> (align_dimension &lt; Pol-&gt;Dimension) {
3521 03513 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"align_context"</font>, <font class="stringliteral">"diffdim"</font>, <font class="stringliteral">"context dimension exceeds data"</font>);
3522 03514 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
3523 03515 <font class="keywordflow">return</font> Pol;
3524 03516 }
3525 03517 <font class="keywordflow">if</font> (align_dimension == Pol-&gt;Dimension) {
3526 03518 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
3527 03519 <font class="keywordflow">return</font> Pol;
3528 03520 }
3529 03521
3530 03522 <font class="comment">/* 'k' is the dimension increment */</font>
3531 03523 k = align_dimension - Pol-&gt;Dimension;
3532 03524 result = NULL;
3533 03525 p = NULL;
3534 03526
3535 03527 <font class="comment">/* Expand the dimension of all polyhedron in the polyhedral domain 'Pol' */</font>
3536 03528 <font class="keywordflow">for</font> (; Pol; Pol=Pol-&gt;next) {
3537 03529 q = p;
3538 03530
3539 03531 <font class="comment">/* Allocate space for the new constraint matrix with dimension expanded*/</font>
3540 03532 <font class="comment">/* to align_dimension. */</font>
3541 03533 Mat = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(Pol-&gt;NbConstraints, align_dimension + 2);
3542 03534 <font class="keywordflow">if</font>(!Mat) {
3543 03535 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"align_context"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
3544 03536 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
3545 03537 <font class="keywordflow">return</font> 0;
3546 03538 }
3547 03539
3548 03540 <font class="comment">/* Initialize the constraint matrix 'Mat' with zeros. */</font>
3549 03541 <a class="code" href="vector_8c.html#a9">Vector_Set</a>(Mat-&gt;p[0],0,(Pol-&gt;NbConstraints) * (align_dimension + 2));
3550 03542
3551 03543 <font class="comment">/* Each constraint in 'Pol' is mapped to k-zeros followed by the */</font>
3552 03544 <font class="comment">/* constraint and is stored in constraint matrix 'Mat'. */</font>
3553 03545 <font class="keywordflow">for</font> (i=0; i&lt;Pol-&gt;NbConstraints; i++) {
3554 03546 <font class="keywordflow">for</font> (j=1; j&lt;=Pol-&gt;Dimension+1;j++) {
3555 03547 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(Mat-&gt;p[i][k+j], Pol-&gt;Constraint[i][j]);
3556 03548 }
3557 03549 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(Mat-&gt;p[i][0], Pol-&gt;Constraint[i][0]); <font class="comment">/* Status bit */</font>
3558 03550 }
3559 03551
3560 03552 <font class="comment">/* Convert the constraint matrix 'Mat' into an equivalent polyhedron. */</font>
3561 03553 p = <a class="code" href="polyhedron_8c.html#a24">Constraints2Polyhedron</a>(Mat, NbMaxRays);
3562 03554 <font class="keywordflow">if</font> (q) q-&gt;next = p; <font class="keywordflow">else</font> result = p;
3563 03555 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Mat), Mat = NULL;
3564 03556 }
3565 03557 } <font class="comment">/* end of TRY */</font>
3566 03558
3567 03559 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
3568 03560 <font class="keywordflow">return</font> result;
3569 03561 } <font class="comment">/* align_context */</font>
3570 03562
3571 03563 <font class="comment">/*----------------------------------------------------------------------*/</font>
3572 03564 <font class="comment">/* Polyhedron *Polyhedron_Scan(D, C, NbMaxRays) */</font>
3573 03565 <font class="comment">/* D : Domain to be scanned (single polyhedron only) */</font>
3574 03566 <font class="comment">/* C : Context domain */</font>
3575 03567 <font class="comment">/* NbMaxRays : Workspace size */</font>
3576 03568 <font class="comment">/* Returns a linked list of scan domains, outer loop first */</font>
3577 03569 <font class="comment">/*----------------------------------------------------------------------*/</font>
3578 <a name="l03570"></a><a class="code" href="polyhedron_8c.html#a48">03570</a> Polyhedron *<a class="code" href="polyhedron_8c.html#a48">Polyhedron_Scan</a>(Polyhedron *D, Polyhedron *C,<font class="keywordtype">unsigned</font> NbMaxRays) {
3579 03571
3580 03572 <font class="keywordtype">int</font> i, j, dim ;
3581 03573 Matrix *Mat;
3582 03574 Polyhedron *C1, *C2, *D1, *D2;
3583 03575 Polyhedron *res, *last, *tmp;
3584 03576
3585 03577 dim = D-&gt;Dimension - C-&gt;Dimension;
3586 03578 res = last = (Polyhedron *) 0;
3587 03579 <font class="keywordflow">if</font> (dim==0) <font class="keywordflow">return</font> (Polyhedron *)0;
3588 03580
3589 03581 <font class="comment">/* Allocate space for constraint matrix. */</font>
3590 03582 Mat = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(D-&gt;Dimension, D-&gt;Dimension+2);
3591 03583 <font class="keywordflow">if</font>(!Mat) {
3592 03584 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"Polyhedron_Scan"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space"</font>);
3593 03585 <font class="keywordflow">return</font> 0;
3594 03586 }
3595 03587 C1 = <a class="code" href="polyhedron_8c.html#a47">align_context</a>(C,D-&gt;Dimension,NbMaxRays);
3596 03588 <font class="keywordflow">if</font>(!C1) {
3597 03589 <font class="keywordflow">return</font> 0;
3598 03590 }
3599 03591 <font class="comment">/* Vin100, aug 16, 2001: The context is intersected with D */</font>
3600 03592 D2 = <a class="code" href="polyhedron_8c.html#a32">DomainIntersection</a>( C1, D, NbMaxRays);
3601 03593
3602 03594 <font class="keywordflow">for</font> (i=0; i&lt;dim; i++)
3603 03595 {
3604 03596 <a class="code" href="vector_8c.html#a9">Vector_Set</a>(Mat-&gt;p_Init,0,D2-&gt;Dimension*(D2-&gt;Dimension + 2));
3605 03597 <font class="keywordflow">for</font> (j=i+1; j&lt;dim; j++) {
3606 03598 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Mat-&gt;p[j-i-1][j+1],1);
3607 03599 }
3608 03600 Mat-&gt;NbRows = dim-i-1;
3609 03601 D1 = Mat-&gt;NbRows ? <a class="code" href="polyhedron_8c.html#a35">DomainAddRays</a>(D2, Mat, NbMaxRays) : D2;
3610 03602 tmp = <a class="code" href="polyhedron_8c.html#a42">DomainSimplify</a>(D1, C1, NbMaxRays);
3611 03603 <font class="keywordflow">if</font> (!last) res = last = tmp;
3612 03604 <font class="keywordflow">else</font> { last-&gt;next = tmp; last = tmp; }
3613 03605 C2 = <a class="code" href="polyhedron_8c.html#a32">DomainIntersection</a>(C1, D1, NbMaxRays);
3614 03606 <a class="code" href="polyhedron_8c.html#a19">Domain_Free</a>(C1);
3615 03607 C1 = C2;
3616 03608 <font class="keywordflow">if</font> (Mat-&gt;NbRows) <a class="code" href="polyhedron_8c.html#a19">Domain_Free</a>(D1);
3617 03609 }
3618 03610 <a class="code" href="polyhedron_8c.html#a19">Domain_Free</a>(D2);
3619 03611 <a class="code" href="polyhedron_8c.html#a19">Domain_Free</a>(C1);
3620 03612 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Mat);
3621 03613 <font class="keywordflow">return</font> res;
3622 03614 } <font class="comment">/* Polyhedron_Scan */</font>
3623 03615
3624 03616 <font class="comment">/*---------------------------------------------------------------------*/</font>
3625 03617 <font class="comment">/* int lower_upper_bounds(pos,P,context,LBp,UBp) */</font>
3626 03618 <font class="comment">/* pos : index position of current loop index (1..hdim-1) */</font>
3627 03619 <font class="comment">/* P: loop domain */</font>
3628 03620 <font class="comment">/* context : context values for fixed indices */</font>
3629 03621 <font class="comment">/* notice that context[hdim] must be 1 */</font>
3630 03622 <font class="comment">/* LBp, UBp : pointers to resulting bounds */</font>
3631 03623 <font class="comment">/* returns the flag = (UB_INFINITY, LB_INFINITY) */</font>
3632 03624 <font class="comment">/*---------------------------------------------------------------------*/</font>
3633 <a name="l03625"></a><a class="code" href="polyhedron_8c.html#a49">03625</a> <font class="keywordtype">int</font> <a class="code" href="polyhedron_8c.html#a49">lower_upper_bounds</a>(<font class="keywordtype">int</font> pos,Polyhedron *P,<a class="code" href="arithmetique_8h.html#a93">Value</a> *context,<a class="code" href="arithmetique_8h.html#a93">Value</a> *LBp,<a class="code" href="arithmetique_8h.html#a93">Value</a> *UBp) {
3634 03626
3635 03627 <a class="code" href="arithmetique_8h.html#a93">Value</a> LB, UB;
3636 03628 <font class="keywordtype">int</font> flag, i;
3637 03629 <a class="code" href="arithmetique_8h.html#a93">Value</a> n, n1, d, tmp;
3638 03630
3639 03631 <font class="comment">/* Initialize all the 'Value' variables */</font>
3640 03632 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(LB); <a class="code" href="arithmetique_8h.html#a10">value_init</a>(UB); <a class="code" href="arithmetique_8h.html#a10">value_init</a>(tmp);
3641 03633 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(n); <a class="code" href="arithmetique_8h.html#a10">value_init</a>(n1); <a class="code" href="arithmetique_8h.html#a10">value_init</a>(d);
3642 03634
3643 03635 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(LB,0);
3644 03636 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(UB,0);
3645 03637
3646 03638 <font class="comment">/* Compute Upper Bound and Lower Bound for current loop */</font>
3647 03639 flag = LB_INFINITY | UB_INFINITY;
3648 03640 <font class="keywordflow">for</font> (i=0; i&lt;P-&gt;NbConstraints; i++) {
3649 03641 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(d,P-&gt;Constraint[i][pos]);
3650 03642 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a67">value_zero_p</a>(d)) <font class="keywordflow">continue</font>;
3651 03643 <a class="code" href="vector_8c.html#a17">Inner_Product</a>(&amp;context[1],&amp;(P-&gt;Constraint[i][1]),P-&gt;Dimension+1,&amp;n);
3652 03644 <a class="code" href="arithmetique_8h.html#a54">value_oppose</a>(n,n);
3653 03645
3654 03646 <font class="comment">/*---------------------------------------------------*/</font>
3655 03647 <font class="comment">/* Compute n/d n/d&lt;0 n/d&gt;0 */</font>
3656 03648 <font class="comment">/*---------------------------------------------------*/</font>
3657 03649 <font class="comment">/* n%d == 0 floor = n/d floor = n/d */</font>
3658 03650 <font class="comment">/* ceiling = n/d ceiling = n/d */</font>
3659 03651 <font class="comment">/*---------------------------------------------------*/</font>
3660 03652 <font class="comment">/* n%d != 0 floor = n/d - 1 floor = n/d */</font>
3661 03653 <font class="comment">/* ceiling = n/d ceiling = n/d + 1 */</font>
3662 03654 <font class="comment">/*---------------------------------------------------*/</font>
3663 03655
3664 03656 <font class="comment">/* Check to see if constraint is inequality */</font>
3665 03657 <font class="comment">/* if constraint is equality, both upper and lower bounds are fixed */</font>
3666 03658 <font class="keywordflow">if</font>(<a class="code" href="arithmetique_8h.html#a67">value_zero_p</a>(P-&gt;Constraint[i][0])) { <font class="comment">/* Equality */</font>
3667 03659 <a class="code" href="arithmetique_8h.html#a52">value_modulus</a>(tmp,n,d);
3668 03660
3669 03661 <font class="comment">/* if not integer, return 0; */</font>
3670 03662 <font class="keywordflow">if</font>(<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(tmp)) {
3671 03663 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(*LBp,1);
3672 03664 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(*UBp,0); <font class="comment">/* empty loop */</font>
3673 03665
3674 03666 <font class="comment">/* Clear all the 'Value' variables */</font>
3675 03667 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(LB); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(UB); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
3676 03668 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(n); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(n1); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(d);
3677 03669 <font class="keywordflow">return</font> 0;
3678 03670 }
3679 03671 <a class="code" href="arithmetique_8h.html#a51">value_division</a>(n1,n,d);
3680 03672
3681 03673 <font class="comment">/* Upper and Lower bounds found */</font>
3682 03674 <font class="keywordflow">if</font>((flag&amp;LB_INFINITY) || <a class="code" href="arithmetique_8h.html#a24">value_gt</a>(n1,LB))
3683 03675 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(LB,n1);
3684 03676 <font class="keywordflow">if</font>((flag&amp;UB_INFINITY) || <a class="code" href="arithmetique_8h.html#a26">value_lt</a>(n1,UB))
3685 03677 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(UB,n1);
3686 03678 flag = 0;
3687 03679 }
3688 03680
3689 03681 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a63">value_pos_p</a>(d)) { <font class="comment">/* Lower Bound */</font>
3690 03682 <a class="code" href="arithmetique_8h.html#a52">value_modulus</a>(tmp,n,d);
3691 03683
3692 03684 <font class="comment">/* n1 = ceiling(n/d) */</font>
3693 03685 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a63">value_pos_p</a>(n) &amp;&amp; <a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(tmp)) {
3694 03686 <a class="code" href="arithmetique_8h.html#a51">value_division</a>(n1,n,d);
3695 03687 <a class="code" href="arithmetique_8h.html#a44">value_add_int</a>(n1,n1,1);
3696 03688 }
3697 03689 <font class="keywordflow">else</font>
3698 03690 <a class="code" href="arithmetique_8h.html#a51">value_division</a>(n1,n,d);
3699 03691 <font class="keywordflow">if</font> (flag&amp;LB_INFINITY) {
3700 03692 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(LB,n1);
3701 03693 flag^=LB_INFINITY;
3702 03694 }
3703 03695 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(<a class="code" href="arithmetique_8h.html#a24">value_gt</a>(n1,LB))
3704 03696 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(LB,n1);
3705 03697 }
3706 03698
3707 03699 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a64">value_neg_p</a>(d)) { <font class="comment">/* Upper Bound */</font>
3708 03700 <a class="code" href="arithmetique_8h.html#a52">value_modulus</a>(tmp,n,d);
3709 03701
3710 03702 <font class="comment">/* n1 = floor(n/d) */</font>
3711 03703 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a63">value_pos_p</a>(n) &amp;&amp; <a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(tmp)) {
3712 03704 <a class="code" href="arithmetique_8h.html#a51">value_division</a>(n1,n,d);
3713 03705 <a class="code" href="arithmetique_8h.html#a49">value_sub_int</a>(n1,n1,1);
3714 03706 }
3715 03707 <font class="keywordflow">else</font>
3716 03708 <a class="code" href="arithmetique_8h.html#a51">value_division</a>(n1,n,d);
3717 03709
3718 03710 <font class="keywordflow">if</font> (flag&amp;UB_INFINITY) {
3719 03711 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(UB,n1);
3720 03712 flag^=UB_INFINITY;
3721 03713 }
3722 03714 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a26">value_lt</a>(n1,UB))
3723 03715 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(UB, n1);
3724 03716 }
3725 03717 }
3726 03718 <font class="keywordflow">if</font> ((flag &amp; LB_INFINITY)==0) <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(*LBp,LB);
3727 03719 <font class="keywordflow">if</font> ((flag &amp; UB_INFINITY)==0) <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(*UBp,UB);
3728 03720
3729 03721 <font class="comment">/* Clear all the 'Value' variables */</font>
3730 03722 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(LB); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(UB); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
3731 03723 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(n); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(n1); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(d);
3732 03724 <font class="keywordflow">return</font> flag;
3733 03725 } <font class="comment">/* lower_upper_bounds */</font>
3734 03726
3735 03727 <font class="comment">/*</font>
3736 03728 <font class="comment"> * Given a polyhedron 'Pol' and a transformation matrix 'Func', return the </font>
3737 03729 <font class="comment"> * polyhedron which when transformed by mapping function 'Func' gives 'Pol'. </font>
3738 03730 <font class="comment"> * 'NbMaxRays' is the maximum number of rays that can be in the ray matrix </font>
3739 03731 <font class="comment"> * of the resulting polyhedron.</font>
3740 03732 <font class="comment"> */</font>
3741 <a name="l03733"></a><a class="code" href="polyhedron_8c.html#a50">03733</a> Polyhedron *<a class="code" href="polyhedron_8c.html#a50">Polyhedron_Preimage</a>(Polyhedron *Pol,Matrix *Func,<font class="keywordtype">unsigned</font> NbMaxRays) {
3742 03734
3743 03735 Matrix *Constraints = NULL;
3744 03736 Polyhedron *NewPol = NULL;
3745 03737 <font class="keywordtype">unsigned</font> NbConstraints, Dimension1, Dimension2;
3746 03738 <font class="keywordtype">int</font> i, j, k;
3747 03739 <a class="code" href="arithmetique_8h.html#a93">Value</a> Sum,tmp;
3748 03740
3749 03741 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(Sum); <a class="code" href="arithmetique_8h.html#a10">value_init</a>(tmp);
3750 03742
3751 03743 <a class="code" href="arithmetic__errors_8h.html#a4">CATCH</a>(any_exception_error) {
3752 03744 <font class="keywordflow">if</font> (Constraints) <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Constraints);
3753 03745 <font class="keywordflow">if</font> (NewPol) <a class="code" href="polyhedron_8c.html#a18">Polyhedron_Free</a>(NewPol);
3754 03746 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(Sum); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
3755 03747 <a class="code" href="arithmetic__errors_8h.html#a7">RETHROW</a>();
3756 03748 }
3757 03749 <a class="code" href="arithmetic__errors_8h.html#a6">TRY</a> {
3758 03750
3759 03751 NbConstraints = Pol-&gt;NbConstraints;
3760 03752 Dimension1 = Pol-&gt;Dimension+1; <font class="comment">/* Homogeneous Dimension */</font>
3761 03753 Dimension2 = Func-&gt;NbColumns; <font class="comment">/* Homogeneous Dimension */</font>
3762 03754 <font class="keywordflow">if</font> (Dimension1!=(Func-&gt;NbRows)) {
3763 03755 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"Polyhedron_Preimage"</font>, <font class="stringliteral">"dimincomp"</font>, <font class="stringliteral">"incompatable dimensions"</font>);
3764 03756 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
3765 03757 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(Sum); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
3766 03758 <font class="keywordflow">return</font> <a class="code" href="polyhedron_8c.html#a22">Empty_Polyhedron</a>(Dimension2-1);
3767 03759 }
3768 03760
3769 03761 <font class="comment">/* Dim1 Dim2 Dim2</font>
3770 03762 <font class="comment"> __k__ __j__ __j__ </font>
3771 03763 <font class="comment"> NbCon | | X Dim1| | = NbCon | |</font>
3772 03764 <font class="comment"> i |___| k |___| i |___|</font>
3773 03765 <font class="comment"> Pol-&gt;Constraints Function Constraints</font>
3774 03766 <font class="comment"> */</font>
3775 03767
3776 03768 <font class="comment">/* Allocate space for the resultant constraint matrix */</font>
3777 03769 Constraints = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(NbConstraints, Dimension2+1);
3778 03770 <font class="keywordflow">if</font> (!Constraints) {
3779 03771 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"Polyhedron_Preimage"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space\n"</font>);
3780 03772 <a class="code" href="polyhedron_8c.html#a5">Pol_status</a> = 1;
3781 03773 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
3782 03774 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(Sum); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
3783 03775 <font class="keywordflow">return</font> 0;
3784 03776 }
3785 03777
3786 03778 <font class="comment">/* The new constraint matrix is the product of constraint matrix of the */</font>
3787 03779 <font class="comment">/* polyhedron and the function matrix. */</font>
3788 03780 <font class="keywordflow">for</font> (i=0; i&lt;NbConstraints; i++) {
3789 03781 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(Constraints-&gt;p[i][0],Pol-&gt;Constraint[i][0]);
3790 03782 <font class="keywordflow">for</font> (j=0; j&lt;Dimension2; j++) {
3791 03783 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Sum,0);
3792 03784 <font class="keywordflow">for</font> (k=0; k&lt;Dimension1; k++) {
3793 03785
3794 03786 <font class="comment">/* Sum+=Pol-&gt;Constraint[i][k+1] * Func-&gt;p[k][j]; */</font>
3795 03787 <a class="code" href="arithmetique_8h.html#a47">value_multiply</a>(tmp,Pol-&gt;Constraint[i][k+1],Func-&gt;p[k][j]);
3796 03788 <a class="code" href="arithmetique_8h.html#a43">value_addto</a>(Sum,Sum,tmp);
3797 03789 }
3798 03790 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(Constraints-&gt;p[i][j+1],Sum);
3799 03791 }
3800 03792 }
3801 03793 NewPol = <a class="code" href="polyhedron_8c.html#a24">Constraints2Polyhedron</a>(Constraints, NbMaxRays);
3802 03794 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Constraints), Constraints = NULL;
3803 03795
3804 03796 } <font class="comment">/* end of TRY */</font>
3805 03797
3806 03798 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(Sum); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
3807 03799 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
3808 03800
3809 03801 <font class="keywordflow">return</font> NewPol;
3810 03802 } <font class="comment">/* Polyhedron_Preimage */</font>
3811 03803
3812 03804 <font class="comment">/*</font>
3813 03805 <font class="comment"> * Given a polyhedral domain 'Pol' and a transformation matrix 'Func', return </font>
3814 03806 <font class="comment"> * the polyhedral domain which when transformed by mapping function 'Func' </font>
3815 03807 <font class="comment"> * gives 'Pol'. 'NbMaxRays' is the maximum number of rays that can be in the </font>
3816 03808 <font class="comment"> * ray matrix of the resulting domain.</font>
3817 03809 <font class="comment"> */</font>
3818 <a name="l03810"></a><a class="code" href="polyhedron_8c.html#a51">03810</a> Polyhedron *<a class="code" href="polyhedron_8c.html#a51">DomainPreimage</a>(Polyhedron *Pol,Matrix *Func,<font class="keywordtype">unsigned</font> NbMaxRays) {
3819 03811
3820 03812 Polyhedron *p, *q, *d = NULL;
3821 03813
3822 03814 <a class="code" href="arithmetic__errors_8h.html#a4">CATCH</a>(any_exception_error) {
3823 03815 <font class="keywordflow">if</font> (d) <a class="code" href="polyhedron_8c.html#a18">Polyhedron_Free</a>(d);
3824 03816 <a class="code" href="arithmetic__errors_8h.html#a7">RETHROW</a>();
3825 03817 }
3826 03818 <a class="code" href="arithmetic__errors_8h.html#a6">TRY</a> {
3827 03819 <font class="keywordflow">if</font> (!Pol || !Func) {
3828 03820 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
3829 03821 <font class="keywordflow">return</font> (Polyhedron *) 0;
3830 03822 }
3831 03823 d = (Polyhedron *) 0;
3832 03824 <font class="keywordflow">for</font> (p=Pol; p; p=p-&gt;next) {
3833 03825 q = <a class="code" href="polyhedron_8c.html#a50">Polyhedron_Preimage</a>(p, Func, NbMaxRays);
3834 03826 d = <a class="code" href="polyhedron_8c.html#a30">AddPolyToDomain</a> (q, d);
3835 03827 }
3836 03828 } <font class="comment">/* end of TRY */</font>
3837 03829 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
3838 03830 <font class="keywordflow">return</font> d;
3839 03831 } <font class="comment">/* DomainPreimage */</font>
3840 03832
3841 03833 <font class="comment">/*</font>
3842 03834 <font class="comment"> * Transform a polyhedron 'Pol' into another polyhedron according to a given</font>
3843 03835 <font class="comment"> * affine mapping function 'Func'. 'NbMaxConstrs' is the maximum number of </font>
3844 03836 <font class="comment"> * constraints that can be in the constraint matrix of the new polyhedron. </font>
3845 03837 <font class="comment"> */</font>
3846 <a name="l03838"></a><a class="code" href="polyhedron_8c.html#a52">03838</a> Polyhedron *<a class="code" href="polyhedron_8c.html#a52">Polyhedron_Image</a>(Polyhedron *Pol, Matrix *Func,<font class="keywordtype">unsigned</font> NbMaxConstrs) {
3847 03839
3848 03840 Matrix *Rays = NULL;
3849 03841 Polyhedron *NewPol = NULL;
3850 03842 <font class="keywordtype">unsigned</font> NbRays, Dimension1, Dimension2;
3851 03843 <font class="keywordtype">int</font> i, j, k;
3852 03844 <a class="code" href="arithmetique_8h.html#a93">Value</a> Sum, tmp;
3853 03845
3854 03846 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(Sum); <a class="code" href="arithmetique_8h.html#a10">value_init</a>(tmp);
3855 03847
3856 03848 <a class="code" href="arithmetic__errors_8h.html#a4">CATCH</a>(any_exception_error) {
3857 03849 <font class="keywordflow">if</font> (Rays) <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Rays);
3858 03850 <font class="keywordflow">if</font> (NewPol) <a class="code" href="polyhedron_8c.html#a18">Polyhedron_Free</a>(NewPol);
3859 03851 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(Sum); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
3860 03852 <a class="code" href="arithmetic__errors_8h.html#a7">RETHROW</a>();
3861 03853 }
3862 03854 <a class="code" href="arithmetic__errors_8h.html#a6">TRY</a> {
3863 03855
3864 03856 NbRays = Pol-&gt;NbRays;
3865 03857 Dimension1 = Pol-&gt;Dimension+1; <font class="comment">/* Homogeneous Dimension */</font>
3866 03858 Dimension2 = Func-&gt;NbRows; <font class="comment">/* Homogeneous Dimension */</font>
3867 03859 <font class="keywordflow">if</font> (Dimension1!=Func-&gt;NbColumns) {
3868 03860 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"Polyhedron_Image"</font>, <font class="stringliteral">"dimincomp"</font>, <font class="stringliteral">"incompatable dimensions"</font>);
3869 03861 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
3870 03862 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(Sum); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
3871 03863 <font class="keywordflow">return</font> <a class="code" href="polyhedron_8c.html#a22">Empty_Polyhedron</a>(Dimension2-1);
3872 03864 }
3873 03865
3874 03866 <font class="comment">/* </font>
3875 03867 <font class="comment"> Dim1 / Dim1 \Transpose Dim2</font>
3876 03868 <font class="comment"> __k__ | __k__ | __j__</font>
3877 03869 <font class="comment"> NbRays| | X | Dim2 | | | = NbRays| |</font>
3878 03870 <font class="comment"> i |___| | j |___| | i |___|</font>
3879 03871 <font class="comment"> Pol-&gt;Rays \ Func / Rays</font>
3880 03872 <font class="comment"></font>
3881 03873 <font class="comment"> */</font>
3882 03874
3883 03875
3884 03876 <font class="comment">/* Allocate space for the resultant ray matrix */</font>
3885 03877 Rays = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(NbRays, Dimension2+1);
3886 03878 <font class="keywordflow">if</font> (!Rays) {
3887 03879 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"Polyhedron_Image"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space\n"</font>);
3888 03880 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
3889 03881 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(Sum); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
3890 03882 <font class="keywordflow">return</font> 0;
3891 03883 }
3892 03884
3893 03885 <font class="comment">/* The new ray space is the product of ray matrix of the polyhedron and */</font>
3894 03886 <font class="comment">/* the transpose matrix of the mapping function. */</font>
3895 03887 <font class="keywordflow">for</font> (i=0; i&lt;NbRays; i++) {
3896 03888 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(Rays-&gt;p[i][0],Pol-&gt;Ray[i][0]);
3897 03889 <font class="keywordflow">for</font> (j=0; j&lt;Dimension2; j++) {
3898 03890 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Sum,0);
3899 03891 <font class="keywordflow">for</font> (k=0; k&lt;Dimension1; k++) {
3900 03892
3901 03893 <font class="comment">/* Sum+=Pol-&gt;Ray[i][k+1] * Func-&gt;p[j][k]; */</font>
3902 03894 <a class="code" href="arithmetique_8h.html#a47">value_multiply</a>(tmp,Pol-&gt;Ray[i][k+1],Func-&gt;p[j][k]);
3903 03895 <a class="code" href="arithmetique_8h.html#a43">value_addto</a>(Sum,Sum,tmp);
3904 03896 }
3905 03897 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(Rays-&gt;p[i][j+1],Sum);
3906 03898 }
3907 03899 }
3908 03900 NewPol = <a class="code" href="polyhedron_8c.html#a26">Rays2Polyhedron</a>(Rays, NbMaxConstrs);
3909 03901 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Rays), Rays = NULL;
3910 03902
3911 03903 } <font class="comment">/* end of TRY */</font>
3912 03904
3913 03905 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
3914 03906 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(Sum); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
3915 03907 <font class="keywordflow">return</font> NewPol;
3916 03908 } <font class="comment">/* Polyhedron_Image */</font>
3917 03909
3918 03910 <font class="comment">/* </font>
3919 03911 <font class="comment"> *Transform a polyhedral domain 'Pol' into another domain according to a given</font>
3920 03912 <font class="comment"> * affine mapping function 'Func'. 'NbMaxConstrs' is the maximum number of </font>
3921 03913 <font class="comment"> * constraints that can be in the constraint matrix of the resulting domain. </font>
3922 03914 <font class="comment"> */</font>
3923 <a name="l03915"></a><a class="code" href="polyhedron_8c.html#a53">03915</a> Polyhedron *<a class="code" href="polyhedron_8c.html#a53">DomainImage</a>(Polyhedron *Pol,Matrix *Func,<font class="keywordtype">unsigned</font> NbMaxConstrs) {
3924 03916
3925 03917 Polyhedron *p, *q, *d = NULL;
3926 03918
3927 03919 <a class="code" href="arithmetic__errors_8h.html#a4">CATCH</a>(any_exception_error) {
3928 03920 <font class="keywordflow">if</font> (d) <a class="code" href="polyhedron_8c.html#a18">Polyhedron_Free</a>(d);
3929 03921 <a class="code" href="arithmetic__errors_8h.html#a7">RETHROW</a>();
3930 03922 }
3931 03923 <a class="code" href="arithmetic__errors_8h.html#a6">TRY</a> {
3932 03924
3933 03925 <font class="keywordflow">if</font> (!Pol || !Func) {
3934 03926 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
3935 03927 <font class="keywordflow">return</font> (Polyhedron *) 0;
3936 03928 }
3937 03929 d = (Polyhedron *) 0;
3938 03930 <font class="keywordflow">for</font> (p=Pol; p; p=p-&gt;next) {
3939 03931 q = <a class="code" href="polyhedron_8c.html#a52">Polyhedron_Image</a>(p, Func, NbMaxConstrs);
3940 03932 d = <a class="code" href="polyhedron_8c.html#a30">AddPolyToDomain</a> (q, d);
3941 03933 }
3942 03934 } <font class="comment">/* end of TRY */</font>
3943 03935
3944 03936 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
3945 03937
3946 03938 <font class="keywordflow">return</font> d;
3947 03939 } <font class="comment">/* DomainImage */</font>
3948 03940
3949 03941 <font class="comment">/* </font>
3950 03942 <font class="comment"> * Given a polyhedron 'Pol' and an affine cost function 'Cost', compute the </font>
3951 03943 <font class="comment"> * maximum and minimum value of the function over set of points representing</font>
3952 03944 <font class="comment"> * polyhedron. </font>
3953 03945 <font class="comment"> * Note: If Polyhedron 'Pol' is empty, then there is no feasible solution. </font>
3954 03946 <font class="comment"> * Otherwise, if there is a bidirectional ray with Sum[cost(i)*ray(i)] != 0 or</font>
3955 03947 <font class="comment"> * a unidirectional ray with Sum[cost(i)*ray(i)] &gt;0, then the maximum is un-</font>
3956 03948 <font class="comment"> * bounded else the finite optimal solution occurs at one of the vertices of</font>
3957 03949 <font class="comment"> * the polyhderon. </font>
3958 03950 <font class="comment"> */</font>
3959 <a name="l03951"></a><a class="code" href="polyhedron_8c.html#a54">03951</a> Interval *<a class="code" href="polyhedron_8c.html#a54">DomainCost</a>(Polyhedron *Pol,<a class="code" href="arithmetique_8h.html#a93">Value</a> *Cost) {
3960 03952
3961 03953 <font class="keywordtype">int</font> i, j, NbRay, Dim;
3962 03954 <a class="code" href="arithmetique_8h.html#a93">Value</a> *p1, *p2, p3, d, status;
3963 03955 <a class="code" href="arithmetique_8h.html#a93">Value</a> tmp1, tmp2, tmp3;
3964 03956 <a class="code" href="arithmetique_8h.html#a93">Value</a> **Ray;
3965 03957 Interval *I = NULL;
3966 03958
3967 03959 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(p3); <a class="code" href="arithmetique_8h.html#a10">value_init</a>(d); <a class="code" href="arithmetique_8h.html#a10">value_init</a>(status);
3968 03960 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(tmp1); <a class="code" href="arithmetique_8h.html#a10">value_init</a>(tmp2); <a class="code" href="arithmetique_8h.html#a10">value_init</a>(tmp3);
3969 03961
3970 03962 <a class="code" href="arithmetic__errors_8h.html#a4">CATCH</a>(any_exception_error) {
3971 03963 <font class="keywordflow">if</font> (I) free(I);
3972 03964 <a class="code" href="arithmetic__errors_8h.html#a7">RETHROW</a>();
3973 03965 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(p3); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(d); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(status);
3974 03966 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp1); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp2); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp3);
3975 03967 }
3976 03968 <a class="code" href="arithmetic__errors_8h.html#a6">TRY</a> {
3977 03969
3978 03970 Ray = Pol-&gt;Ray;
3979 03971 NbRay = Pol-&gt;NbRays;
3980 03972 Dim = Pol-&gt;Dimension+1; <font class="comment">/* Homogenous Dimension */</font>
3981 03973 I = (Interval *) malloc (<font class="keyword">sizeof</font>(Interval));
3982 03974 <font class="keywordflow">if</font> (!I) {
3983 03975 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"DomainCost"</font>, <font class="stringliteral">"outofmem"</font>, <font class="stringliteral">"out of memory space\n"</font>);
3984 03976 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
3985 03977 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(p3); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(d); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(status);
3986 03978 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp1); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp2); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp3);
3987 03979 <font class="keywordflow">return</font> 0;
3988 03980 }
3989 03981
3990 03982 <font class="comment">/* The maximum and minimum values of the cost function over polyhedral */</font>
3991 03983 <font class="comment">/* domain is stored in 'I'. I-&gt;MaxN and I-&gt;MaxD store the numerator and */</font>
3992 03984 <font class="comment">/* denominator of the maximum value. Likewise,I-&gt;MinN and I-&gt;MinD store */</font>
3993 03985 <font class="comment">/* the numerator and denominator of the minimum value. I-&gt;MaxI and */</font>
3994 03986 <font class="comment">/* I-&gt;MinI store the ray indices corresponding to the max and min values*/</font>
3995 03987 <font class="comment">/* of the function. */</font>
3996 03988
3997 03989 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(I-&gt;MaxN,-1);
3998 03990 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(I-&gt;MaxD,0); <font class="comment">/* Actual cost is MaxN/MaxD */</font>
3999 03991 I-&gt;MaxI = -1;
4000 03992 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(I-&gt;MinN,1);
4001 03993 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(I-&gt;MinD,0);
4002 03994 I-&gt;MinI = -1;
4003 03995
4004 03996 <font class="comment">/* Compute the cost of each ray[i] */</font>
4005 03997 <font class="keywordflow">for</font> (i=0; i&lt;NbRay; i++) {
4006 03998 p1 = Ray[i];
4007 03999 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(status, *p1);
4008 04000 p1++;
4009 04001 p2 = Cost;
4010 04002
4011 04003 <font class="comment">/* p3 = *p1++ * *p2++; */</font>
4012 04004 <a class="code" href="arithmetique_8h.html#a47">value_multiply</a>(p3,*p1,*p2);
4013 04005 p1++; p2++;
4014 04006 <font class="keywordflow">for</font> (j=1; j&lt;Dim; j++) {
4015 04007 <a class="code" href="arithmetique_8h.html#a47">value_multiply</a>(tmp1,*p1,*p2);
4016 04008
4017 04009 <font class="comment">/* p3 += *p1++ * *p2++; */</font>
4018 04010 <a class="code" href="arithmetique_8h.html#a43">value_addto</a>(p3,p3,tmp1);
4019 04011 p1++; p2++;
4020 04012 }
4021 04013
4022 04014 <font class="comment">/* d = *--p1; */</font>
4023 04015 p1--;
4024 04016 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(d,*p1); <font class="comment">/* d == 0 for lines and ray, non-zero for vertex */</font>
4025 04017 <a class="code" href="arithmetique_8h.html#a47">value_multiply</a>(tmp1,p3,I-&gt;MaxD);
4026 04018 <a class="code" href="arithmetique_8h.html#a47">value_multiply</a>(tmp2,I-&gt;MaxN,d);
4027 04019 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(tmp3,1);
4028 04020
4029 04021 <font class="comment">/* Compare p3/d with MaxN/MaxD to assign new maximum cost value */</font>
4030 04022 <font class="keywordflow">if</font> (I-&gt;MaxI==-1 ||
4031 04023 <a class="code" href="arithmetique_8h.html#a24">value_gt</a>(tmp1,tmp2) ||
4032 04024 (<a class="code" href="arithmetique_8h.html#a22">value_eq</a>(tmp1,tmp2) &amp;&amp;
4033 04025 <a class="code" href="arithmetique_8h.html#a22">value_eq</a>(d,tmp3) &amp;&amp; <a class="code" href="arithmetique_8h.html#a23">value_ne</a>(I-&gt;MaxD,tmp3))) {
4034 04026 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(I-&gt;MaxN,p3);
4035 04027 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(I-&gt;MaxD,d);
4036 04028 I-&gt;MaxI = i;
4037 04029 }
4038 04030 <a class="code" href="arithmetique_8h.html#a47">value_multiply</a>(tmp1,p3,I-&gt;MinD);
4039 04031 <a class="code" href="arithmetique_8h.html#a47">value_multiply</a>(tmp2,I-&gt;MinN,d);
4040 04032 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(tmp3,1);
4041 04033
4042 04034 <font class="comment">/* Compare p3/d with MinN/MinD to assign new minimum cost value */</font>
4043 04035 <font class="keywordflow">if</font> (I-&gt;MinI==-1 ||
4044 04036 <a class="code" href="arithmetique_8h.html#a26">value_lt</a>(tmp1,tmp2) ||
4045 04037 (<a class="code" href="arithmetique_8h.html#a22">value_eq</a>(tmp1,tmp2) &amp;&amp;
4046 04038 <a class="code" href="arithmetique_8h.html#a22">value_eq</a>(d,tmp3) &amp;&amp; <a class="code" href="arithmetique_8h.html#a23">value_ne</a>(I-&gt;MinD,tmp3))) {
4047 04039 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(I-&gt;MinN, p3);
4048 04040 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(I-&gt;MinD, d);
4049 04041 I-&gt;MinI = i;
4050 04042 }
4051 04043 <a class="code" href="arithmetique_8h.html#a47">value_multiply</a>(tmp1,p3,I-&gt;MaxD);
4052 04044 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(tmp2,0);
4053 04045
4054 04046 <font class="comment">/* If there is a line, assign max to +infinity and min to -infinity */</font>
4055 04047 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a67">value_zero_p</a>(status)) { <font class="comment">/* line , d is 0 */</font>
4056 04048 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a26">value_lt</a>(tmp1,tmp2)) {
4057 04049 <a class="code" href="arithmetique_8h.html#a54">value_oppose</a>(I-&gt;MaxN,p3);
4058 04050 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(I-&gt;MaxD,0);
4059 04051 I-&gt;MaxI = i;
4060 04052 }
4061 04053 <a class="code" href="arithmetique_8h.html#a47">value_multiply</a>(tmp1,p3,I-&gt;MinD);
4062 04054 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(tmp2,0);
4063 04055
4064 04056 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a24">value_gt</a>(tmp1,tmp2)) {
4065 04057 <a class="code" href="arithmetique_8h.html#a54">value_oppose</a>(I-&gt;MinN,p3);
4066 04058 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(I-&gt;MinD,0);
4067 04059 I-&gt;MinI = i;
4068 04060 }
4069 04061 }
4070 04062 }
4071 04063 } <font class="comment">/* end of TRY */</font>
4072 04064
4073 04065 <a class="code" href="arithmetic__errors_8h.html#a5">UNCATCH</a>(any_exception_error);
4074 04066 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(p3); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(d); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(status);
4075 04067 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp1); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp2); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp3);
4076 04068 <font class="keywordflow">return</font> I;
4077 04069 } <font class="comment">/* DomainCost */</font>
4078 04070
4079 04071 <font class="comment">/* </font>
4080 04072 <font class="comment"> * Add constraints pointed by 'Mat' to each and every polyhedron in the </font>
4081 04073 <font class="comment"> * polyhedral domain 'Pol'. 'NbMaxRays' is maximum allowed rays in the ray </font>
4082 04074 <font class="comment"> * matrix of a polyhedron.</font>
4083 04075 <font class="comment"> */</font>
4084 <a name="l04076"></a><a class="code" href="polyhedron_8c.html#a55">04076</a> Polyhedron *<a class="code" href="polyhedron_8c.html#a55">DomainAddConstraints</a>(Polyhedron *Pol,Matrix *Mat,<font class="keywordtype">unsigned</font> NbMaxRays) {
4085 04077
4086 04078 Polyhedron *PolA, *PolEndA, *p1, *p2, *p3;
4087 04079 <font class="keywordtype">int</font> Redundant;
4088 04080
4089 04081 <font class="keywordflow">if</font> (!Pol) <font class="keywordflow">return</font> (Polyhedron*) 0;
4090 04082 <font class="keywordflow">if</font> (!Mat) <font class="keywordflow">return</font> Pol;
4091 04083 <font class="keywordflow">if</font> (Pol-&gt;Dimension != Mat-&gt;NbColumns-2) {
4092 04084 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"DomainAddConstraints"</font>,
4093 04085 <font class="stringliteral">"diffdim"</font>, <font class="stringliteral">"operation on different dimensions"</font>);
4094 04086 <font class="keywordflow">return</font> (Polyhedron*) 0;
4095 04087 }
4096 04088
4097 04089 <font class="comment">/* Copy 'Pol' to 'PolA' */</font>
4098 04090 PolA = PolEndA = (Polyhedron *)0;
4099 04091 <font class="keywordflow">for</font> (p1=Pol; p1; p1=p1-&gt;next) {
4100 04092 p3 = <a class="code" href="polyhedron_8c.html#a28">AddConstraints</a>(Mat-&gt;p_Init, Mat-&gt;NbRows, p1, NbMaxRays);
4101 04093
4102 04094 <font class="comment">/* Does any component of 'PolA' cover 'p3' */</font>
4103 04095 Redundant = 0;
4104 04096 <font class="keywordflow">for</font> (p2=PolA; p2; p2=p2-&gt;next) {
4105 04097 <font class="keywordflow">if</font> (<a class="code" href="polyhedron_8c.html#a29">PolyhedronIncludes</a>(p2, p3)) { <font class="comment">/* 'p2' covers 'p3' */</font>
4106 04098 Redundant = 1;
4107 04099 <font class="keywordflow">break</font>;
4108 04100 }
4109 04101 }
4110 04102
4111 04103 <font class="comment">/* If the new polyhedron 'p3' is not redundant, add it to the domain */</font>
4112 04104 <font class="keywordflow">if</font> (!Redundant) {
4113 04105
4114 04106 <font class="comment">/* Add 'p3' to 'PolA' */</font>
4115 04107 <font class="keywordflow">if</font> (!PolEndA)
4116 04108 PolEndA = PolA = p3;
4117 04109 <font class="keywordflow">else</font> {
4118 04110 PolEndA-&gt;next = p3;
4119 04111 PolEndA = PolEndA-&gt;next;
4120 04112 }
4121 04113 }
4122 04114 }
4123 04115 <font class="keywordflow">return</font> PolA;
4124 04116 } <font class="comment">/* DomainAddConstraints */</font>
4125 04117
4126 04118
4127 04119 <font class="comment">/* </font>
4128 04120 <font class="comment"> * Computes the disjoint union of a union of polyhedra.</font>
4129 04121 <font class="comment"> * If flag = 0 the result is such that there are no intersections</font>
4130 04122 <font class="comment"> * between the resulting polyhedra,</font>
4131 04123 <font class="comment"> * if flag = 1 it computes a joint union, the resulting polyhedra are</font>
4132 04124 <font class="comment"> * adjacent (they have their facets in common).</font>
4133 04125 <font class="comment"> *</font>
4134 04126 <font class="comment"> * WARNING: if all polyhedra are not of same geometrical dimension</font>
4135 04127 <font class="comment"> * duplicates may appear.</font>
4136 04128 <font class="comment"> */</font>
4137 <a name="l04129"></a><a class="code" href="polyhedron_8c.html#a56">04129</a> Polyhedron *<a class="code" href="polyhedron_8c.html#a56">Disjoint_Domain</a>( Polyhedron *P, <font class="keywordtype">int</font> flag, <font class="keywordtype">unsigned</font> NbMaxRays )
4138 04130 {
4139 04131 Polyhedron *lP, *tmp, *Result, *lR, *prec, *reste;
4140 04132 Polyhedron *p1, *p2, *p3, *Pol1, *dx, *d1, *d2, *pi, *newpi;
4141 04133 <font class="keywordtype">int</font> i;
4142 04134
4143 04135 <font class="keywordflow">if</font>( flag!=0 &amp;&amp; flag!=1 )
4144 04136 {
4145 04137 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>(<font class="stringliteral">"Disjoint_Domain"</font>,
4146 04138 <font class="stringliteral">"invalidarg"</font>, <font class="stringliteral">"flag should be equal to 0 or 1"</font>);
4147 04139 <font class="keywordflow">return</font> (Polyhedron*) 0;
4148 04140 }
4149 04141 <font class="keywordflow">if</font>(!P) <font class="keywordflow">return</font> (Polyhedron*) 0;
4150 04142 <font class="keywordflow">if</font>(!P-&gt;next) <font class="keywordflow">return</font> <a class="code" href="polyhedron_8c.html#a36">Polyhedron_Copy</a>(P);
4151 04143
4152 04144 Result = (Polyhedron *)0;
4153 04145
4154 04146 <font class="keywordflow">for</font>(lP=P;lP;lP=lP-&gt;next)
4155 04147 {
4156 04148 reste = <a class="code" href="polyhedron_8c.html#a36">Polyhedron_Copy</a>(lP);
4157 04149 prec = (Polyhedron *)0; <font class="comment">/* preceeding lR */</font>
4158 04150 <font class="comment">/* Intersection with each polyhedron of the current Result */</font>
4159 04151 lR=Result;
4160 04152 <font class="keywordflow">while</font>( lR &amp;&amp; reste )
4161 04153 {
4162 04154 <font class="comment">/* dx = DomainIntersection(reste,lR-&gt;P,WS); */</font>
4163 04155 dx = (Polyhedron *)0;
4164 04156 <font class="keywordflow">for</font>( p1=reste; p1; p1=p1-&gt;next )
4165 04157 {
4166 04158 p3 = <a class="code" href="polyhedron_8c.html#a28">AddConstraints</a>(lR-&gt;Constraint[0], lR-&gt;NbConstraints, p1,
4167 04159 NbMaxRays);
4168 04160 dx = <a class="code" href="polyhedron_8c.html#a30">AddPolyToDomain</a>(p3,dx);
4169 04161 }
4170 04162
4171 04163 <font class="comment">/* if empty intersection, continue */</font>
4172 04164 <font class="keywordflow">if</font>(!dx)
4173 04165 { prec = lR;
4174 04166 lR=lR-&gt;next;
4175 04167 <font class="keywordflow">continue</font>;
4176 04168 }
4177 04169 <font class="keywordflow">if</font> (emptyQ(dx)) {
4178 04170 <a class="code" href="polyhedron_8c.html#a19">Domain_Free</a>(dx);
4179 04171 prec = lR;
4180 04172 lR=lR-&gt;next;
4181 04173 <font class="keywordflow">continue</font>;
4182 04174 }
4183 04175
4184 04176 <font class="comment">/* intersection is not empty, we need to compute the differences */</font>
4185 04177 <font class="comment">/* between the intersection and the two polyhedra, such that the */</font>
4186 04178 <font class="comment">/* results are disjoint unions (according to flag) */</font>
4187 04179 <font class="comment">/* d1 = reste \ P = DomainDifference(reste,lR-&gt;P,WS); */</font>
4188 04180 <font class="comment">/* d2 = P \ reste = DomainDifference(lR-&gt;P,reste,WS); */</font>
4189 04181
4190 04182 <font class="comment">/* compute d1 */</font>
4191 04183 d1 = (Polyhedron *)0;
4192 04184 <font class="keywordflow">for</font> (p1=reste; p1; p1=p1-&gt;next)
4193 04185 {
4194 04186 pi = p1;
4195 04187 <font class="keywordflow">for</font> (i=0; i&lt;P-&gt;NbConstraints &amp;&amp; pi ; i++)
4196 04188 {
4197 04189
4198 04190 <font class="comment">/* Add the constraint ( -P-&gt;constraint[i] [-1 if flag=0]) &gt;= 0 in 'p1' */</font>
4199 04191 <font class="comment">/* and create the new polyhedron 'p3'. */</font>
4200 04192 p3 = <a class="code" href="polyhedron_8c.html#a31">SubConstraint</a>(P-&gt;Constraint[i], pi, NbMaxRays,2*flag);
4201 04193 <font class="comment">/* Add 'p3' in the new domain 'd1' */</font>
4202 04194 d1 = <a class="code" href="polyhedron_8c.html#a30">AddPolyToDomain</a> (p3, d1);
4203 04195
4204 04196 <font class="comment">/* If the constraint P-&gt;constraint[i][0] is an equality, then add */</font>
4205 04197 <font class="comment">/* the constraint ( +P-&gt;constraint[i] [-1 if flag=0]) &gt;= 0 in 'pi' */</font>
4206 04198 <font class="comment">/* and create the new polyhedron 'p3'. */</font>
4207 04199 <font class="keywordflow">if</font>( <a class="code" href="arithmetique_8h.html#a67">value_zero_p</a>(P-&gt;Constraint[i][0]) ) <font class="comment">/* Inequality */</font>
4208 04200 {
4209 04201 p3 = <a class="code" href="polyhedron_8c.html#a31">SubConstraint</a>(P-&gt;Constraint[i], pi, NbMaxRays,1+2*flag);
4210 04202 <font class="comment">/* Add 'p3' in the new domain 'd1' */</font>
4211 04203 d1 = <a class="code" href="polyhedron_8c.html#a30">AddPolyToDomain</a> (p3, d1);
4212 04204
4213 04205 <font class="comment">/* newpi : add constraint P-&gt;constraint[i]==0 to pi */</font>
4214 04206 newpi = <a class="code" href="polyhedron_8c.html#a28">AddConstraints</a>( P-&gt;Constraint[i], 1, pi, NbMaxRays);
4215 04207 }
4216 04208 <font class="keywordflow">else</font>
4217 04209 {
4218 04210 <font class="comment">/* newpi : add constraint +P-&gt;constraint[i] &gt;= 0 in pi */</font>
4219 04211 newpi = <a class="code" href="polyhedron_8c.html#a31">SubConstraint</a>(P-&gt;Constraint[i], pi, NbMaxRays,3);
4220 04212 }
4221 04213 <font class="keywordflow">if</font>( newpi &amp;&amp; emptyQ( newpi ) )
4222 04214 {
4223 04215 <a class="code" href="polyhedron_8c.html#a19">Domain_Free</a>( newpi );
4224 04216 newpi = (Polyhedron *)0;
4225 04217 }
4226 04218 <font class="keywordflow">if</font>( pi != p1 )
4227 04219 <a class="code" href="polyhedron_8c.html#a19">Domain_Free</a>( pi );
4228 04220 pi = newpi;
4229 04221 }
4230 04222 <font class="keywordflow">if</font>( pi != p1 )
4231 04223 <a class="code" href="polyhedron_8c.html#a19">Domain_Free</a>( pi );
4232 04224 }
4233 04225
4234 04226 <font class="comment">/* and now d2 */</font>
4235 04227 Pol1 = <a class="code" href="polyhedron_8c.html#a36">Polyhedron_Copy</a>( lR );
4236 04228 <font class="keywordflow">for</font> (p2=reste; p2; p2=p2-&gt;next)
4237 04229 {
4238 04230 d2 = (Polyhedron *)0;
4239 04231 <font class="keywordflow">for</font> (p1=Pol1; p1; p1=p1-&gt;next)
4240 04232 {
4241 04233 pi = p1;
4242 04234 <font class="keywordflow">for</font> (i=0; i&lt;p2-&gt;NbConstraints &amp;&amp; pi ; i++)
4243 04235 {
4244 04236
4245 04237 <font class="comment">/* Add the constraint ( -p2-&gt;constraint[i] [-1 if flag=0]) &gt;= 0 in 'pi' */</font>
4246 04238 <font class="comment">/* and create the new polyhedron 'p3'. */</font>
4247 04239 p3 = <a class="code" href="polyhedron_8c.html#a31">SubConstraint</a>(p2-&gt;Constraint[i], pi, NbMaxRays,2*flag);
4248 04240 <font class="comment">/* Add 'p3' in the new domain 'd2' */</font>
4249 04241 d2 = <a class="code" href="polyhedron_8c.html#a30">AddPolyToDomain</a> (p3, d2);
4250 04242
4251 04243 <font class="comment">/* If the constraint p2-&gt;constraint[i][0] is an equality, then add */</font>
4252 04244 <font class="comment">/* the constraint ( +p2-&gt;constraint[i] [-1 if flag=0]) &gt;= 0 in 'pi' */</font>
4253 04245 <font class="comment">/* and create the new polyhedron 'p3'. */</font>
4254 04246 <font class="keywordflow">if</font>( <a class="code" href="arithmetique_8h.html#a67">value_zero_p</a>(p2-&gt;Constraint[i][0]) ) <font class="comment">/* Inequality */</font>
4255 04247 {
4256 04248 p3 = <a class="code" href="polyhedron_8c.html#a31">SubConstraint</a>(p2-&gt;Constraint[i], pi, NbMaxRays,1+2*flag);
4257 04249 <font class="comment">/* Add 'p3' in the new domain 'd2' */</font>
4258 04250 d2 = <a class="code" href="polyhedron_8c.html#a30">AddPolyToDomain</a> (p3, d2);
4259 04251
4260 04252 <font class="comment">/* newpi : add constraint p2-&gt;constraint[i]==0 to pi */</font>
4261 04253 newpi = <a class="code" href="polyhedron_8c.html#a28">AddConstraints</a>( p2-&gt;Constraint[i], 1, pi, NbMaxRays);
4262 04254 }
4263 04255 <font class="keywordflow">else</font>
4264 04256 {
4265 04257 <font class="comment">/* newpi : add constraint +p2-&gt;constraint[i] &gt;= 0 in pi */</font>
4266 04258 newpi = <a class="code" href="polyhedron_8c.html#a31">SubConstraint</a>(p2-&gt;Constraint[i], pi, NbMaxRays,3);
4267 04259 }
4268 04260 <font class="keywordflow">if</font>( newpi &amp;&amp; emptyQ( newpi ) )
4269 04261 {
4270 04262 <a class="code" href="polyhedron_8c.html#a19">Domain_Free</a>( newpi );
4271 04263 newpi = (Polyhedron *)0;
4272 04264 }
4273 04265 <font class="keywordflow">if</font>( pi != p1 )
4274 04266 <a class="code" href="polyhedron_8c.html#a19">Domain_Free</a>( pi );
4275 04267 pi = newpi;
4276 04268 }
4277 04269 <font class="keywordflow">if</font>( pi &amp;&amp; pi!=p1 )
4278 04270 <a class="code" href="polyhedron_8c.html#a19">Domain_Free</a>( pi );
4279 04271 }
4280 04272 <font class="keywordflow">if</font>( Pol1 )
4281 04273 <a class="code" href="polyhedron_8c.html#a19">Domain_Free</a>( Pol1 );
4282 04274 Pol1 = d2;
4283 04275 }
4284 04276 <font class="comment">/* ok, d1 and d2 are computed */</font>
4285 04277
4286 04278 <font class="comment">/* now, replace lR by d2+dx (at least dx is nonempty) and set reste to d1 */</font>
4287 04279 <font class="keywordflow">if</font>( d1 &amp;&amp; emptyQ(d1) )
4288 04280 {
4289 04281 <a class="code" href="polyhedron_8c.html#a19">Domain_Free</a>( d1 );
4290 04282 d1 = NULL;
4291 04283 }
4292 04284 <font class="keywordflow">if</font>( d2 &amp;&amp; emptyQ(d2) )
4293 04285 {
4294 04286 <a class="code" href="polyhedron_8c.html#a19">Domain_Free</a>( d2 );
4295 04287 d2 = NULL;
4296 04288 }
4297 04289
4298 04290 <font class="comment">/* set reste */</font>
4299 04291 <a class="code" href="polyhedron_8c.html#a19">Domain_Free</a>( reste );
4300 04292 reste = d1;
4301 04293
4302 04294 <font class="comment">/* add d2 at beginning of Result */</font>
4303 04295 <font class="keywordflow">if</font>( d2 )
4304 04296 {
4305 04297 <font class="keywordflow">for</font>( tmp=d2 ; tmp-&gt;next ; tmp=tmp-&gt;next )
4306 04298 ;
4307 04299 tmp-&gt;next = Result;
4308 04300 Result = d2;
4309 04301 <font class="keywordflow">if</font>( !prec )
4310 04302 prec = tmp;
4311 04303 }
4312 04304
4313 04305 <font class="comment">/* add dx at beginning of Result */</font>
4314 04306 <font class="comment">// if( dx )</font>
4315 04307 {
4316 04308 <font class="keywordflow">for</font>( tmp=dx ; tmp-&gt;next ; tmp=tmp-&gt;next )
4317 04309 ;
4318 04310 tmp-&gt;next = Result;
4319 04311 Result = dx;
4320 04312 <font class="keywordflow">if</font>( !prec )
4321 04313 prec = tmp;
4322 04314 }
4323 04315
4324 04316 <font class="comment">/* suppress current lR */</font>
4325 04317 <font class="keywordflow">if</font>( !prec )
4326 04318 <a class="code" href="errormsg_8c.html#a1">errormsg1</a>( <font class="stringliteral">"Disjoint_Domain"</font>,<font class="stringliteral">"internalerror"</font>,<font class="stringliteral">"internal error"</font>);
4327 04319 prec-&gt;next = lR-&gt;next;
4328 04320 <a class="code" href="polyhedron_8c.html#a18">Polyhedron_Free</a>( lR );
4329 04321 lR = prec-&gt;next;
4330 04322 } <font class="comment">/* end for result */</font>
4331 04323
4332 04324 <font class="comment">/* if there is something left, add it to Result : */</font>
4333 04325 <font class="keywordflow">if</font>(reste)
4334 04326 {
4335 04327 <font class="keywordflow">if</font>(emptyQ(reste))
4336 04328 {
4337 04329 <a class="code" href="polyhedron_8c.html#a19">Domain_Free</a>( reste );
4338 04330 reste = NULL;
4339 04331 }
4340 04332 <font class="keywordflow">else</font>
4341 04333 {
4342 04334 Polyhedron *tnext;
4343 04335 <font class="keywordflow">for</font>( tmp=reste ; tmp ; tmp=tnext )
4344 04336 {
4345 04337 tnext = tmp-&gt;next;
4346 04338 tmp-&gt;next = NULL;
4347 04339 Result = <a class="code" href="polyhedron_8c.html#a30">AddPolyToDomain</a>(tmp, Result);
4348 04340 }
4349 04341 }
4350 04342 }
4351 04343 }
4352 04344
4353 04345 <font class="keywordflow">return</font>( Result );
4354 04346 }
4355 04347
4356 04348
4357 04349
4358 04350 <font class="comment">/* Procedure to print constraint matrix of a polyhedron */</font>
4359 <a name="l04351"></a><a class="code" href="polyhedron_8c.html#a57">04351</a> <font class="keywordtype">void</font> <a class="code" href="polyhedron_8c.html#a57">Polyhedron_PrintConstraints</a>(FILE *Dst,<font class="keywordtype">char</font> *Format,Polyhedron *Pol)
4360 04352 {
4361 04353 <font class="keywordtype">int</font> i,j;
4362 04354
4363 04355 fprintf( Dst, <font class="stringliteral">"%d %d\n"</font>, Pol-&gt;NbConstraints, Pol-&gt;Dimension+2 );
4364 04356 <font class="keywordflow">for</font>( i=0 ; i&lt;Pol-&gt;NbConstraints ; i++ )
4365 04357 {
4366 04358 <font class="keywordflow">for</font>( j=0 ; j&lt;Pol-&gt;Dimension+2 ; j++ )
4367 04359 <a class="code" href="arithmetique_8h.html#a16">value_print</a>( stdout, Format, Pol-&gt;Constraint[i][j] );
4368 04360 fprintf( Dst, <font class="stringliteral">"\n"</font> );
4369 04361 }
4370 04362
4371 04363 }
4372 04364
4373 04365
4374 </pre></div><hr><address align="right"><small>Generated on Fri Nov 8 12:10:06 2002 for Polylib by
4375 <a href="http://www.doxygen.org/index.html">
4376 <img src="doxygen.png" alt="doxygen" align="middle" border=0
4377 width=110 height=53></a>1.2.15 </small></address>
4378 </body>
4379 </html>