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">
6 <!-- Generated by Doxygen 1.2.15 -->
8 <a class=
"qindex" href=
"main.html">Main Page
</a> <a class=
"qindex" href=
"annotated.html">Compound List
</a> <a class=
"qindex" href=
"files.html">File List
</a> <a class=
"qindex" href=
"functions.html">Compound Members
</a> <a class=
"qindex" href=
"globals.html">File Members
</a> </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>
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>
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>
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>
49 00041 <font class=
"preprocessor">#include
<stdio.h
></font>
50 00042 <font class=
"preprocessor">#include
<stdlib.h
></font>
51 00043 <font class=
"preprocessor">#include
<string.h
></font>
52 00044 <font class=
"preprocessor">#include
<<a class=
"code" href=
"assert_8h.html">assert.h
</a>></font>
53 00045 <font class=
"preprocessor">#include
<polylib/polylib.h
></font>
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>
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);
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>
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>
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>;
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) {
102 00094 <font class=
"keywordtype">int
</font> **q, *p, i;
103 00095 <a class=
"code" href=
"structSatMatrix.html">SatMatrix
</a> *result;
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;
110 00102 result-
><a class=
"code" href=
"structSatMatrix.html#m0">NbRows
</a> = rows;
111 00103 result-
><a class=
"code" href=
"structSatMatrix.html#m1">NbColumns
</a> = cols;
112 00104 <font class=
"keywordflow">if
</font>(rows ==
0 || cols ==
0) {
113 00105 result-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a> = NULL;
114 00106 <font class=
"keywordflow">return
</font> result;
116 00108 result-
><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-
><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;
121 00113 result-
><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-
><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;
126 00118 <font class=
"keywordflow">for
</font> (i=
0; i
<rows; i++) {
130 00122 <font class=
"keywordflow">return
</font> result;
131 00123 }
<font class=
"comment">/* SMAlloc */
</font>
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) {
138 00130 <font class=
"keywordflow">if
</font> (matrix[
0]){
139 00131 free ((
<font class=
"keywordtype">char
</font> *) matrix[
0]-
>p_init);
140 00132 free ((
<font class=
"keywordtype">char
</font> *) matrix[
0]-
>p);
141 00133 free ((
<font class=
"keywordtype">char
</font> *) matrix[
0]);
142 00134 matrix[
0]=NULL;}
143 00135 }
<font class=
"comment">/* SMFree */
</font>
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) {
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;
155 00147 fprintf(stderr,
<font class=
"stringliteral">"%d %d\n"</font>,NbRows=matrix-
><a class=
"code" href=
"structSatMatrix.html#m0">NbRows
</a>, NbColumns=matrix-
><a class=
"code" href=
"structSatMatrix.html#m1">NbColumns
</a>);
156 00148 <font class=
"keywordflow">for
</font> (i=
0;i
<NbRows;i++) {
157 00149 p = *(matrix-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>+i);
158 00150 <font class=
"keywordflow">for
</font> (j=
0;j
<NbColumns;j++)
159 00151 fprintf(stderr,
<font class=
"stringliteral">" %10X "</font>, *p++);
160 00152 fprintf(stderr,
<font class=
"stringliteral">"\n"</font>);
162 00154 }
<font class=
"comment">/* SMPrint */
</font>
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) {
169 00161 <font class=
"keywordtype">int
</font> *cp1, *cp2, *cp3;
170 00162 <font class=
"keywordtype">int
</font> i;
175 00167 <font class=
"keywordflow">for
</font> (i=
0;i
<length;i++) {
176 00168 *cp3 = *cp1 | *cp2;
181 00173 }
<font class=
"comment">/* SatVector_OR */
</font>
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>
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) {
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;
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);
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]);
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]);
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);
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);
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,
&gcd);
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);
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);
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);
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);
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);
245 00237 <font class=
"keywordflow">return
</font>;
246 00238 }
<font class=
"comment">/* Combine */
</font>
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) {
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;
259 00251 <font class=
"keywordflow">if
</font> (Mat-
>NbRows !=
0)
260 00252 sat_nbcolumns = (Mat-
>NbRows-
1) /(
<font class=
"keyword">sizeof
</font>(int)*
8) +
1;
261 00253 <font class=
"keywordflow">else
</font>
262 00254 sat_nbcolumns =
0;
264 00256 result =
<a class=
"code" href=
"polyparam_8c.html#a23">SMAlloc
</a>(Ray-
>NbRows, sat_nbcolumns);
265 00257 <a class=
"code" href=
"polyhedron_8c.html#a4">SMVector_Init
</a>(result-
><a class=
"code" href=
"structSatMatrix.html#m3">p_init
</a>, Ray-
>NbRows * sat_nbcolumns);
267 00259 <font class=
"keywordflow">for
</font>(i=
0,jx1=
0,bx1=MSB; i
<Ray-
>NbRows; i++) {
268 00260 <font class=
"keywordflow">for
</font>(j=
0,jx2=
0,bx2=MSB; j
<Mat-
>NbRows; j++) {
269 00261 <font class=
"keywordflow">if
</font> (Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[j][jx1]
& bx1)
270 00262 result-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[i][jx2] |= bx2;
273 00265 NEXT(jx1, bx1);
275 00267 <font class=
"keywordflow">return
</font> result;
276 00268 }
<font class=
"comment">/* TransformSat */
</font>
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
<= i
< equal_bound : saturates the constraint
</font>
281 00273 <font class=
"comment"> * equal_bound
<= i
< sup_bound : verifies the constraint
</font>
282 00274 <font class=
"comment"> * sup_bound
<= i
< 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-
>p[i][
0] =
0 -
> ray(i) saturates the constraint
</font>
289 00281 <font class=
"comment"> * Ray-
>p[i][
0]
> 0 -
> ray(i) verifies the constraint
</font>
290 00282 <font class=
"comment"> * Ray-
>p[i][
0]
< 0 -
> 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) {
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;
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>
307 00299 *sup_bound = *equal_bound = NbBid;
308 00300 uni_sup = uni_eq = Ray-
>p+NbBid;
309 00301 inc_sup = inc_eq = Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>+NbBid;
310 00302 inf_bound = NbRay;
311 00303 uni_inf = Ray-
>p+NbRay;
312 00304 inc_inf = Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>+NbRay;
314 00306 <font class=
"keywordflow">while
</font> (inf_bound
>*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++;
321 00313 <font class=
"keywordflow">else
</font> {
322 00314 *((*inc_sup)+jx)|=bx;
324 00316 <font class=
"comment">/* if (**uni_sup
<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);
330 00322 <font class=
"keywordflow">else
</font> {
<font class=
"comment">/* status == verify */
</font>
331 00323 (*sup_bound)++; uni_sup++; inc_sup++;
335 00327 }
<font class=
"comment">/* RaySort */
</font>
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) {
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;
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-
>NbRows;
370 00362 NbRay = Ray-
>NbRows;
371 00363 Dimension = Mat-
>NbColumns-
1;
<font class=
"comment">/* Homogeneous Dimension */
</font>
372 00364 sat_nbcolumns=Sat-
><a class=
"code" href=
"structSatMatrix.html#m1">NbColumns
</a>;
374 00366 RowSize1=(Dimension+
1);
375 00367 RowSize2=sat_nbcolumns *
<font class=
"keyword">sizeof
</font>(int);
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;
383 00375 <a class=
"code" href=
"arithmetic__errors_8h.html#a4">CATCH
</a>(any_exception_error) {
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);
391 00383 <a class=
"code" href=
"arithmetic__errors_8h.html#a7">RETHROW
</a>();
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
>>= FirstConstraint%
<a class=
"code" href=
"polyhedron_8c.html#a0">WSIZE
</a>;
396 00388 <font class=
"keywordflow">for
</font> (k=FirstConstraint; k
<NbConstraints; k++) {
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>
403 00395 index_non_zero = NbRay;
404 00396 <font class=
"keywordflow">for
</font> (i=
0; i
<NbRay; i++) {
405 00397 p1 = Ray-
>p[i]+
1;
406 00398 p2 = Mat-
>p[k]+
1;
407 00399 p3 = Ray-
>p[i];
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);
412 00404 <font class=
"keywordflow">for
</font> (j=
1; j
<Dimension; j++) {
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);
419 00411 <font class=
"keywordflow">if
</font> (
<a class=
"code" href=
"arithmetique_8h.html#a68">value_notzero_p
</a>(*p3)
&& (i
<index_non_zero))
420 00412 index_non_zero=i;
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
<> 0 */
</font>
433 00425 <font class=
"keywordflow">if
</font> (index_non_zero
<NbBid) {
435 00427 <font class=
"comment">/* Discard index_non_zero bidirectional ray */
</font>
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-
>p[index_non_zero],Ray-
>p[NbBid],RowSize1);
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
<RowSize1;i++) {
443 00435 <a class=
"code" href=
"arithmetique_8h.html#a16">value_print
</a>(stderr,P_VALUE_FMT,Ray-
>p[index_non_zero][i]);
445 00437 fprintf(stderr,
<font class=
"stringliteral">"\n******\n"</font>);
446 00438 <font class=
"keywordflow">for
</font>(i=
0;i
<RowSize1;i++) {
447 00439 <a class=
"code" href=
"arithmetique_8h.html#a16">value_print
</a>(stderr,P_VALUE_FMT,Ray-
>p[NbBid][i]);
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
<NbBid; i++)
454 00446 <font class=
"keywordflow">if
</font> (
<a class=
"code" href=
"arithmetique_8h.html#a68">value_notzero_p
</a>(Ray-
>p[i][
0]))
455 00447 <a class=
"code" href=
"polyhedron_8c.html#a11">Combine
</a>(Ray-
>p[i],Ray-
>p[NbBid],Ray-
>p[i],
0,Dimension);
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>
460 00452 <font class=
"keywordflow">if
</font> (
<a class=
"code" href=
"arithmetique_8h.html#a64">value_neg_p
</a>(Ray-
>p[NbBid][
0])) {
461 00453 p1=Ray-
>p[NbBid];
462 00454 <font class=
"keywordflow">for
</font> (j=
0;j
<Dimension+
1; j++) {
464 00456 <font class=
"comment">/* *p1 = - *p1 */
</font>
465 00457 <a class=
"code" href=
"arithmetique_8h.html#a54">value_oppose
</a>(*p1,*p1);
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-
>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
<NbRay; i++)
482 00474 <font class=
"keywordflow">if
</font> (
<a class=
"code" href=
"arithmetique_8h.html#a68">value_notzero_p
</a>(Ray-
>p[i][
0]))
483 00475 <a class=
"code" href=
"polyhedron_8c.html#a11">Combine
</a>(Ray-
>p[i],Ray-
>p[NbBid],Ray-
>p[i],
0,Dimension);
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-
>p[k][
0])) {
<font class=
"comment">/* Constraint is an inequality */
</font>
487 00479 <font class=
"keywordflow">for
</font> (j=
0;j
<sat_nbcolumns;j++) {
488 00480 Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[NbBid][j] =
0;
<font class=
"comment">/* Saturation vec for new ray */
</font>
490 00482 <font class=
"comment">/* The new ray saturates everything except last inequality */
</font>
491 00483 Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[NbBid][jx] |= bx;
493 00485 <font class=
"keywordflow">else
</font> {
<font class=
"comment">/* Constraint is an equality */
</font>
495 00487 <a class=
"code" href=
"vector_8c.html#a11">Vector_Copy
</a>(Ray-
>p[NbRay],Ray-
>p[NbBid],Dimension+
1);
496 00488 <a class=
"code" href=
"polyhedron_8c.html#a3">SMVector_Copy
</a>(Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[NbRay],Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[NbBid],sat_nbcolumns);
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-
>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>
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,
&equal_bound,
&sup_bound,
512 00504 RowSize1, RowSize2,bx,jx);
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-
> bound-
> ________
</font>
517 00509 <font class=
"comment"> | R- | R- ==
> ray.eq
< 0 (outside domain)
</font>
518 00510 <font class=
"comment"> sup-
> |------|
</font>
519 00511 <font class=
"comment"> | R+ | R+ ==
> ray.eq
> 0 (inside domain)
</font>
520 00512 <font class=
"comment"> equal-
> |------|
</font>
521 00513 <font class=
"comment"> | R0 | R0 ==
> ray.eq =
0 (on face of domain)
</font>
522 00514 <font class=
"comment"> NbBid-
> |______|
</font>
523 00515 <font class=
"comment"> */
</font>
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-
>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>
537 00529 <font class=
"keywordflow">for
</font> (i=equal_bound; i
<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
<bound; j++) {
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>
545 00537 nbcommonconstraints =
0;
546 00538 <font class=
"keywordflow">for
</font> (l=
0; l
<jx; l++) {
547 00539 aux = Temp[l] = Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[i][l] | Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[j][l];
548 00540 <font class=
"keywordflow">for
</font> (m=MSB; m!=
0; m
>>=
1)
549 00541 <font class=
"keywordflow">if
</font> (!(aux
&m))
550 00542 nbcommonconstraints++;
552 00544 aux = Temp[jx] = Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[i][jx] | Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[j][jx];
553 00545 <font class=
"keywordflow">for
</font> (m=MSB; m!=bx; m
>>=
1)
554 00546 <font class=
"keywordflow">if
</font> (!(aux
&m))
555 00547 nbcommonconstraints++;
556 00548 rayonly = (
<a class=
"code" href=
"arithmetique_8h.html#a67">value_zero_p
</a>(Ray-
>p[i][Dimension])
&&
557 00549 <a class=
"code" href=
"arithmetique_8h.html#a67">value_zero_p
</a>(Ray-
>p[j][Dimension])
&&
559 00551 <font class=
"keywordflow">if
</font>(rayonly)
560 00552 nbcommonconstraints++;
<font class=
"comment">/* account for pos constr */
</font>
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>
566 00558 <font class=
"keywordflow">if
</font> (nbcommonconstraints+NbBid
>=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>
569 00561 <font class=
"keywordflow">for
</font> (m=NbBid; m
<bound; m++)
570 00562 <font class=
"keywordflow">if
</font> ((m!=i)
&&(m!=j)) {
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>
576 00568 <font class=
"keywordflow">if
</font> (rayonly
&& <a class=
"code" href=
"arithmetique_8h.html#a68">value_notzero_p
</a>(Ray-
>p[m][Dimension]))
577 00569 <font class=
"keywordflow">continue
</font>;
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>
583 00575 ip2 = Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[m];
584 00576 <font class=
"keywordflow">for
</font> (l=
0; l
<=jx; l++,ip2++,ip1++)
585 00577 <font class=
"keywordflow">if
</font> (*ip2
& ~*ip1)
586 00578 <font class=
"keywordflow">break
</font>;
587 00579 <font class=
"keywordflow">if
</font> (l
>jx) {
589 00581 <font class=
"keywordflow">break
</font>;
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-
>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>
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;
615 00607 <font class=
"comment">/* Compute the new ray */
</font>
616 00608 <a class=
"code" href=
"polyhedron_8c.html#a11">Combine
</a>(Ray-
>p[j],Ray-
>p[i],Ray-
>p[NbRay],
0,Dimension);
617 00609 <a class=
"code" href=
"polyhedron_8c.html#a10">SatVector_OR
</a>(Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[j],Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[i],Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[NbRay],sat_nbcolumns);
618 00610 Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[NbRay][jx]
&= ~bx;
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-
>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-
>p[k][
0]) ? */
</font>
643 00635 j = (
<a class=
"code" href=
"arithmetique_8h.html#a68">value_notzero_p
</a>(Mat-
>p[k][
0])) ?
644 00636 sup_bound : equal_bound;
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
<bound)
&&(i
>bound)) {
652 00644 <a class=
"code" href=
"vector_8c.html#a11">Vector_Copy
</a>(Ray-
>p[i],Ray-
>p[j],Dimension+
1);
653 00645 <a class=
"code" href=
"polyhedron_8c.html#a3">SMVector_Copy
</a>(Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[i],Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[j],sat_nbcolumns);
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-
>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)
675 00667 <font class=
"keywordflow">else
</font>
680 00672 Ray-
>NbRows=NbRay;
681 00673 Sat-
><a class=
"code" href=
"structSatMatrix.html#m0">NbRows
</a>=NbRay;
683 00675 }
<font class=
"comment">/* End of TRY */
</font>
685 00677 <a class=
"code" href=
"arithmetic__errors_8h.html#a5">UNCATCH
</a>(any_exception_error);
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>
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) {
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;
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;
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>();
733 00725 <a class=
"code" href=
"arithmetic__errors_8h.html#a6">TRY
</a> {
735 00727 <font class=
"keywordflow">for
</font> (j=
1; j
<=Dimension; j++) {
<font class=
"comment">/* for each column (except status) */
</font>
736 00728 <font class=
"keywordflow">for
</font> (i=Rank; i
<NbEq; i++)
<font class=
"comment">/* starting at diagonal, look down */
</font>
738 00730 <font class=
"comment">/* if (Mat-
>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-
>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-
>p[Rank]+
1,Mat-
>p[i]+
1,Dimension);
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-
>p[Rank]+
1,Dimension) */
</font>
747 00739 <a class=
"code" href=
"vector_8c.html#a23">Vector_Gcd
</a>(Mat-
>p[Rank]+
1,Dimension,
&gcd);
749 00741 <font class=
"comment">/* if (gcd
>=
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 =
&Mat-
>p[Rank][
1];
753 00745 <font class=
"keywordflow">for
</font> (k=
0; k
<Dimension; k++) {
754 00746 <a class=
"code" href=
"arithmetique_8h.html#a51">value_division
</a> (*cp,*cp,gcd);
<font class=
"comment">/* *cp /= gcd */
</font>
759 00751 <font class=
"comment">/* if (Mat-
>p[Rank][j]
< 0) */
</font>
760 00752 <font class=
"keywordflow">if
</font> (
<a class=
"code" href=
"arithmetique_8h.html#a64">value_neg_p
</a>(Mat-
>p[Rank][j])) {
761 00753 cp = Mat-
>p[Rank]+
1;
762 00754 <font class=
"keywordflow">for
</font> (k=
0; k
<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>
768 00760 <font class=
"comment">/* End of normalize */
</font>
771 00763 <font class=
"keywordflow">for
</font> (i=pivot+
1; i
<NbEq; i++) {
<font class=
"comment">/* Zero out the rest of the column */
</font>
773 00765 <font class=
"comment">/* if (Mat-
>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-
>p[i][j]))
775 00767 <a class=
"code" href=
"polyhedron_8c.html#a11">Combine
</a>(Mat-
>p[i],Mat-
>p[Rank],Mat-
>p[i],j,Dimension);
778 00770 <font class=
"comment">/* For each row with non-zero entry Mat-
>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>
782 00774 column_index[Rank]=j;
785 00777 }
<font class=
"comment">/* end of Gaussian elimination forward step */
</font>
787 00779 <font class=
"comment">/* Back Substitution -- normalize the system of equations */
</font>
788 00780 <font class=
"keywordflow">for
</font> (k=Rank-
1; k
>=
0; k--) {
789 00781 j = column_index[k];
791 00783 <font class=
"comment">/* Normalize the equations */
</font>
792 00784 <font class=
"keywordflow">for
</font> (i=
0; i
<k; i++) {
794 00786 <font class=
"comment">/* if (Mat-
>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-
>p[i][j]))
796 00788 <a class=
"code" href=
"polyhedron_8c.html#a11">Combine
</a>(Mat-
>p[i],Mat-
>p[k],Mat-
>p[i],j,Dimension);
799 00791 <font class=
"comment">/* Normalize the inequalities */
</font>
800 00792 <font class=
"keywordflow">for
</font> (i=NbEq;i
<Mat-
>NbRows;i++) {
802 00794 <font class=
"comment">/* if (Mat-
>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-
>p[i][j]))
804 00796 <a class=
"code" href=
"polyhedron_8c.html#a11">Combine
</a>(Mat-
>p[i],Mat-
>p[k],Mat-
>p[i],j,Dimension);
807 00799 }
<font class=
"comment">/* end of TRY */
</font>
809 00801 <a class=
"code" href=
"arithmetic__errors_8h.html#a5">UNCATCH
</a>(any_exception_error);
810 00802 free(column_index), column_index = NULL;
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>
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) {
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;
846 00838 Dimension = Mat-
>NbColumns-
1;
<font class=
"comment">/* Homogeneous Dimension */
</font>
847 00839 NbRay = Ray-
>NbRows;
848 00840 sat_nbcolumns = Sat-
><a class=
"code" href=
"structSatMatrix.html#m1">NbColumns
</a>;
849 00841 NbConstraints = Mat-
>NbRows;
850 00842 RowSize1=(Dimension+
1);
851 00843 RowSize2=sat_nbcolumns *
<font class=
"keyword">sizeof
</font>(int);
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;
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);
863 00855 <font class=
"keywordflow">for
</font>(i=
0;i
<RowSize1;i++)
864 00856 <a class=
"code" href=
"arithmetique_8h.html#a10">value_init
</a>(temp1[i]);
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>);
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
<RowSize1;i++)
874 00866 <a class=
"code" href=
"arithmetique_8h.html#a14">value_clear
</a>(temp1[i]);
876 00868 <font class=
"keywordflow">return
</font> 0;
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>);
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
<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;
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>);
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
<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;
905 00897 <a class=
"code" href=
"arithmetic__errors_8h.html#a4">CATCH
</a>(any_exception_error) {
907 00899 <font class=
"keywordflow">if
</font> (temp1) {
908 00900 <font class=
"keywordflow">for
</font>(i=
0;i
<RowSize1;i++)
909 00901 <a class=
"code" href=
"arithmetique_8h.html#a14">value_clear
</a>(temp1[i]);
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);
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);
922 00914 <a class=
"code" href=
"arithmetic__errors_8h.html#a7">RETHROW
</a>();
924 00916 <a class=
"code" href=
"arithmetic__errors_8h.html#a6">TRY
</a> {
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] -
> floor[j/(
8*sizeof(int))] */
</font>
929 00921 <font class=
"comment">/* (
2) bx[j] -
> bin(
00.
.10.
.0) where position of
1 = j%(
8*sizeof(int)) */
</font>
933 00925 <font class=
"keywordflow">for
</font> (j=
0; j
<NbConstraints; j++) {
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>
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>
948 00940 <font class=
"keywordflow">for
</font> (i=
0; i
<NbRay; i++) {
950 00942 <font class=
"comment">/* Ray-
>p[i][
0] =
0 */
</font>
951 00943 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(Ray-
>p[i][
0],
0);
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-
>p[i][Dimension]))
958 00950 <font class=
"comment">/* If no vertices, return an empty polyhedron. */
</font>
959 00951 <font class=
"keywordflow">if
</font> (!aux) {
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
<RowSize1;i++)
965 00957 <a class=
"code" href=
"arithmetique_8h.html#a14">value_clear
</a>(temp1[i]);
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);
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>
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
<NbConstraints; j++) {
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
&& <a class=
"code" href=
"arithmetique_8h.html#a67">value_zero_p
</a>(Mat-
>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-
>p[j][
0],
0);
1015 01007 <font class=
"comment">/* Identify and remove the positivity constraint
1>=
0 */
</font>
1016 01008 <font class=
"keywordflow">for
</font> (i=
1, p =
&Mat-
>p[j][
1]; i
<Dimension; i++) {
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)) {
1021 01013 <font class=
"keywordflow">break
</font>;
1023 01015 <font class=
"keywordflow">else
</font>
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 >=
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>
1037 01029 <font class=
"keywordflow">if
</font> (i==Dimension) {
1038 01030 <font class=
"keywordflow">for
</font> (i=
0; i
<NbRay; i++)
1039 01031 <font class=
"keywordflow">if
</font> (!(Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[i][jx[j]]
&bx[j])) {
1041 01033 <font class=
"comment">/* Mat-
>p[j][
0]++ */
</font>
1042 01034 <a class=
"code" href=
"arithmetique_8h.html#a45">value_increment
</a>(Mat-
>p[j][
0],Mat-
>p[j][
0]);
1045 01037 <font class=
"comment">/* if ((Mat-
>p[j][
0] == NbRay)
&& : it is an equality
</font>
1046 01038 <font class=
"comment"> (Mat-
>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-
>p[j][
0],tmp1))
&&
1049 01041 (
<a class=
"code" href=
"arithmetique_8h.html#a68">value_notzero_p
</a>(Mat-
>p[j][Dimension]))) {
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
<RowSize1;i++)
1055 01047 <a class=
"code" href=
"arithmetique_8h.html#a14">value_clear
</a>(temp1[i]);
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);
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-
>p[j], Mat-
>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>;
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
<NbRay; i++)
1075 01067 <font class=
"keywordflow">if
</font> (!(Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[i][jx[j]]
&bx[j])) {
1077 01069 <font class=
"comment">/* Mat-
>p[j][
0]++ */
</font>
1078 01070 <a class=
"code" href=
"arithmetique_8h.html#a45">value_increment
</a>(Mat-
>p[j][
0],Mat-
>p[j][
0]);
1080 01072 <font class=
"comment">/* Ray-
>p[i][
0]++ */
</font>
1081 01073 <a class=
"code" href=
"arithmetique_8h.html#a45">value_increment
</a> (Ray-
>p[i][
0],Ray-
>p[i][
0]);
1084 01076 <font class=
"comment">/* if (Mat-
>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-
>p[j][
0],tmp1))
1087 01079 NbEq++;
<font class=
"comment">/* all vertices/rays are saturated */
</font>
1089 01081 Mat-
>NbRows = NbConstraints;
1092 01084 <font class=
"keywordflow">for
</font> (i=
0; i
<NbRay; i++) {
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-
>p[i][Dimension]))
1097 01089 <font class=
"comment">/* Ray-
>p[i][
0]++ */
</font>
1098 01090 <a class=
"code" href=
"arithmetique_8h.html#a45">value_increment
</a>(Ray-
>p[i][
0],Ray-
>p[i][
0]);
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>
1104 01096 <font class=
"comment">/* if (Ray-
>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-
>p[i][
0],tmp1))
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
>=
3; y
<=
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>
1124 01116 <font class=
"keywordflow">for
</font> (i=
0; i
<NbEq; i++) {
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-
>p[i][
0],tmp1)) {
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-
>p[k][
0],tmp1)
&& k
<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>;
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-
>p[k], temp1,RowSize1);
1140 01132 <font class=
"keywordflow">for
</font> (;k
>i;k--) {
1141 01133 <a class=
"code" href=
"vector_8c.html#a11">Vector_Copy
</a>(Mat-
>p[k-
1],Mat-
>p[k],RowSize1);
1142 01134 jx[k] = jx[k-
1];
1143 01135 bx[k] = bx[k-
1];
1145 01137 <a class=
"code" href=
"vector_8c.html#a11">Vector_Copy
</a>(temp1,Mat-
>p[i],RowSize1);
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
<NbEq; i++) {
1155 01147 <font class=
"comment">/* Detect implicit constraints such as y
>=
3 and y
<=
3 */
</font>
1156 01148 Redundant =
0;
1157 01149 <font class=
"keywordflow">for
</font> (j=i+
1; j
<NbEq; j++) {
1158 01150 <font class=
"keywordflow">for
</font> (k=
0, p=
&Mat-
>p[i][
1], q=
&Mat-
>p[j][
1]; k
<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>;
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
&& (temp2[jx[j]]
& bx[j])) {
1168 01160 <font class=
"keywordflow">break
</font>;
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>
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>
1191 01183 NbEq2 =
<a class=
"code" href=
"polyhedron_8c.html#a15">Gauss
</a>(Mat,NbEq,Dimension);
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>
1196 01188 <font class=
"keywordflow">if
</font> (NbEq2
>=Dimension) {
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
<RowSize1;i++)
1202 01194 <a class=
"code" href=
"arithmetique_8h.html#a14">value_clear
</a>(temp1[i]);
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);
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>=
0.
</font>
1221 01213 <font class=
"comment"> */
</font>
1224 01216 <font class=
"keywordflow">for
</font> (i=
0, k=NbRay; i
<NbBid
&& k
>i; i++) {
1225 01217 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(tmp1,(NbConstraints+
1));
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-
>p[i][
0],tmp1)) {
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
>i
&& <a class=
"code" href=
"arithmetique_8h.html#a23">value_ne
</a>(Ray-
>p[k][
0],tmp1)) ;
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-
>p[i], Ray-
>p[k], RowSize1);
1237 01229 <a class=
"code" href=
"polyhedron_8c.html#a1">bexchange
</a>(Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[i], Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[k], RowSize2);
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>
1255 01247 NbBid2 =
<a class=
"code" href=
"polyhedron_8c.html#a15">Gauss
</a>(Ray, NbBid, Dimension);
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
>=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>);
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
<RowSize1;i++)
1271 01263 <a class=
"code" href=
"arithmetique_8h.html#a14">value_clear
</a>(temp1[i]);
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);
1278 01270 <font class=
"comment">/* Compute dimension of non-homogenous ray space */
</font>
1279 01271 Dim_RaySpace = Dimension-
1-NbEq2-NbBid2;
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>
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);
1298 01290 <font class=
"keywordflow">for
</font> (j=
0; j
<NbConstraints; j++) {
1300 01292 <font class=
"comment">/* Identify and remove the positivity constraint
1>=
0 */
</font>
1301 01293 <font class=
"keywordflow">for
</font> (i=
1, p =
&Mat-
>p[j][
1]; i
<Dimension; i++)
1302 01294 <font class=
"keywordflow">if
</font> (
<a class=
"code" href=
"arithmetique_8h.html#a68">value_notzero_p
</a> (*p)) {
1304 01296 <font class=
"keywordflow">break
</font>;
1306 01298 <font class=
"keywordflow">else
</font>
1309 01301 <font class=
"comment">/* Check if constraint(j) is a positivity constraint,
1>=
0, or if it */
</font>
1310 01302 <font class=
"comment">/* is
1==
0. */
</font>
1311 01303 <font class=
"keywordflow">if
</font> (i==Dimension) {
1313 01305 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(tmp1,NbRay);
1315 01307 <font class=
"comment">/* if ((Mat-
>p[j][
0]==NbRay)
&& : it is an equality
</font>
1316 01308 <font class=
"comment"> (Mat-
>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-
>p[j][
0],tmp1))
&&
1318 01310 (
<a class=
"code" href=
"arithmetique_8h.html#a68">value_notzero_p
</a>(Mat-
>p[j][Dimension]))) {
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
<RowSize1;i++)
1324 01316 <a class=
"code" href=
"arithmetique_8h.html#a14">value_clear
</a>(temp1[i]);
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);
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-
>p[j][
0],
2);
1335 01327 <font class=
"keywordflow">continue
</font>;
1338 01330 <font class=
"comment">/* Status = Mat-
>p[j][
0] */
</font>
1339 01331 <a class=
"code" href=
"arithmetique_8h.html#a11">value_assign
</a>(Status, Mat-
>p[j][
0]);
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))
1344 01336 <font class=
"comment">/* Mat-
>p[j][
0]=
2 : redundant */
</font>
1345 01337 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(Mat-
>p[j][
0],
2);
1347 01339 <font class=
"comment">/* else if (Status
<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))
1350 01342 <font class=
"comment">/* Mat-
>p[j][
0]=
2 : redundant */
</font>
1351 01343 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(Mat-
>p[j][
0],
2);
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))
1356 01348 <font class=
"comment">/* Mat-
>p[j][
0]=
0 : equality */
</font>
1357 01349 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(Mat-
>p[j][
0],
0);
1359 01351 <font class=
"comment">/* else constraint is an irredundant inequality */
</font>
1360 01352 <font class=
"keywordflow">else
</font> {
1363 01355 <font class=
"comment">/* Mat-
>p[j][
0]=
1 : inequality */
</font>
1364 01356 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(Mat-
>p[j][
0],
1);
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>
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));
1383 01375 <font class=
"keywordflow">for
</font> (j=
0; j
<NbRay; j++) {
1385 01377 <font class=
"comment">/* Status = Ray-
>p[j][
0] */
</font>
1386 01378 <a class=
"code" href=
"arithmetique_8h.html#a11">value_assign
</a>(Status, Ray-
>p[j][
0]);
1388 01380 <font class=
"comment">/* if (Status
< 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))
1391 01383 <font class=
"comment">/* Ray-
>p[j][
0]=
2 : redundant */
</font>
1392 01384 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(Ray-
>p[j][
0],
2);
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))
1397 01389 <font class=
"comment">/* Ray-
>p[j][
0]=
0 : line */
</font>
1398 01390 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(Ray-
>p[j][
0],
0);
1400 01392 <font class=
"comment">/* else ray is an irredundant unidirectional ray. */
</font>
1401 01393 <font class=
"keywordflow">else
</font> {
1404 01396 <font class=
"comment">/* Ray-
>p[j][
0]=
1 : ray */
</font>
1405 01397 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(Ray-
>p[j][
0],
1);
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>
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>);
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
<RowSize1;i++)
1425 01417 <a class=
"code" href=
"arithmetique_8h.html#a14">value_clear
</a>(temp1[i]);
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;
1431 01423 Pol-
>NbBid = NbBid2;
1432 01424 Pol-
>NbEq = NbEq2;
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-
>p[
0], Pol-
>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-
>p[
0], Pol-
>Constraint[
0], (Dimension+
1)*NbEq2);
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>=
0,
</font>
1449 01441 <font class=
"comment"> * (
2) Redundant inequalities such as y
>=
4 given y
>=
3, or x
>=
1 given x=
2.
</font>
1450 01442 <font class=
"comment"> * (
3) Redundant inequalities such as x+y
>=
5 given x
>=
3 and y
>=
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>
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>);
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
<RowSize1;i++)
1466 01458 <a class=
"code" href=
"arithmetique_8h.html#a14">value_clear
</a>(temp1[i]);
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;
1473 01465 <font class=
"comment">/* NbEq NbConstraints
</font>
1474 01466 <font class=
"comment"> |-----------
></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>
1495 01487 <font class=
"keywordflow">for
</font> (j=NbEq; j
<NbConstraints; j++) {
1497 01489 <font class=
"comment">/* if (Mat-
>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-
>p[j][
0])) {
1499 01491 <font class=
"keywordflow">for
</font> (k=
0; k
<sat_nbcolumns; k++) Trace[k]=
0;
<font class=
"comment">/* init Trace */
</font>
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
<NbRay; i++)
1505 01497 <font class=
"comment">/* if (Ray-
>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-
>p[i][
0])) {
1507 01499 <font class=
"keywordflow">if
</font> (!(Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[i][jx[j]]
&bx[j]))
1508 01500 <font class=
"keywordflow">for
</font> (k=
0; k
<sat_nbcolumns; k++) Trace[k] |= Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[i][k];
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>
1515 01507 <font class=
"keywordflow">for
</font> (i=NbEq; i
<NbConstraints; i++) {
1517 01509 <font class=
"comment">/* if ((Mat-
>p[i][
0] ==
1)
&& (i!=j)
&& !(Trace[jx[i]]
& bx[i]) ) */
</font>
1518 01510 <font class=
"keywordflow">if
</font> (
<a class=
"code" href=
"arithmetique_8h.html#a69">value_one_p
</a>(Mat-
>p[i][
0])
&& (i!=j)
&& !(Trace[jx[i]]
& bx[i])) {
1520 01512 <font class=
"keywordflow">break
</font>;
1523 01515 <font class=
"keywordflow">if
</font> (Redundant) {
1524 01516 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(Mat-
>p[j][
0],
2);
1526 01518 <font class=
"keywordflow">else
</font> {
1527 01519 <a class=
"code" href=
"vector_8c.html#a11">Vector_Copy
</a>(Mat-
>p[j], Pol-
>Constraint[NbEq2+NbIneq2], Dimension+
1);
1528 01520 <font class=
"keywordflow">if
</font> (Filter) Filter[jx[j]] |= bx[j];
<font class=
"comment">/* for SIMPLIFY */
</font>
1533 01525 free(Trace), Trace = NULL;
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>
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>
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>);
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
<RowSize1;i++)
1559 01551 <a class=
"code" href=
"arithmetique_8h.html#a14">value_clear
</a>(temp1[i]);
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;
1566 01558 <font class=
"comment">/* NbEq NbConstraints
</font>
1567 01559 <font class=
"comment"> |----------
></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|-------|------
>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>
1585 01577 <font class=
"comment">/* Let 'aux' be the number of rays not vertices */
</font>
1587 01579 <font class=
"keywordflow">for
</font> (i=NbBid; i
<NbRay; i++) {
1589 01581 <font class=
"comment">/* if (Ray-
>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-
>p[i][
0])) {
1592 01584 <font class=
"comment">/* if (Ray-
>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-
>p[i][Dimension]))
1594 01586 <font class=
"keywordflow">for
</font> (k=NbBid; k
<NbRay; k++) Trace[k]=
0;
<font class=
"comment">/* init Trace */
</font>
1595 01587 <font class=
"keywordflow">else
</font> <font class=
"comment">/* for ray */
</font>
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>
1600 01592 <font class=
"keywordflow">for
</font> (k=NbBid; k
<NbRay; k++)
1602 01594 <font class=
"comment">/* Trace[k]=(Ray-
>p[k][Dimension]!=
0); */
</font>
1603 01595 Trace[k] = (
<a class=
"code" href=
"arithmetique_8h.html#a68">value_notzero_p
</a> (Ray-
>p[k][Dimension]));
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
<NbConstraints; j++)
1609 01601 <font class=
"comment">/* if (Mat-
>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-
>p[j][
0])) {
1611 01603 <font class=
"keywordflow">if
</font> (!(Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[i][jx[j]]
&bx[j]))
1612 01604 <font class=
"keywordflow">for
</font> (k=NbBid; k
<NbRay; k++) Trace[k] |= Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[k][jx[j]]
&bx[j];
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>
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>
1623 01615 Redundant =
0;
1624 01616 <font class=
"keywordflow">for
</font> (j=NbBid; j
<NbRay; j++) {
1626 01618 <font class=
"comment">/* if ( (Ray-
>p[j][
0]==
1)
&& (i!=j)
&& !Trace[j] ) */
</font>
1627 01619 <font class=
"keywordflow">if
</font> (
<a class=
"code" href=
"arithmetique_8h.html#a69">value_one_p
</a> (Ray-
>p[j][
0])
&& (i!=j)
&& !Trace[j]) {
1629 01621 <font class=
"keywordflow">break
</font>;
1632 01624 <font class=
"keywordflow">if
</font> (Redundant)
1633 01625 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(Ray-
>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-
>p[i], Pol-
>Ray[NbBid2+NbUni2], Dimension+
1);
1636 01628 NbUni2++;
<font class=
"comment">/* Increment number of uni-directional rays */
</font>
1638 01630 <font class=
"comment">/* if (Ray-
>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-
>p[i][Dimension]))
1640 01632 aux++;
<font class=
"comment">/* Increment number of rays which are not vertices */
</font>
1645 01637 <font class=
"comment">/* Include the positivity constraint */
</font>
1646 01638 <font class=
"keywordflow">if
</font> (aux
>=Dim_RaySpace) {
1647 01639 <a class=
"code" href=
"vector_8c.html#a9">Vector_Set
</a>(Pol-
>Constraint[NbEq2+NbIneq2],
0,Dimension+
1);
1648 01640 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(Pol-
>Constraint[NbEq2+NbIneq2][
0],
1);
1649 01641 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(Pol-
>Constraint[NbEq2+NbIneq2][Dimension],
1);
1652 01644 }
<font class=
"comment">/* end of TRY */
</font>
1654 01646 <a class=
"code" href=
"arithmetic__errors_8h.html#a5">UNCATCH
</a>(any_exception_error);
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>
1668 01660 Pol-
>NbConstraints = NbEq2 + NbIneq2;
1669 01661 Pol-
>NbRays = NbBid2 + NbUni2;
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
<RowSize1;i++)
1675 01667 <a class=
"code" href=
"arithmetique_8h.html#a14">value_clear
</a>(temp1[i]);
1677 01669 <font class=
"keywordflow">return
</font> Pol;
1678 01670 }
<font class=
"comment">/* Remove_Redundants */
</font>
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) {
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;
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;
1696 01688 Pol-
>next = (Polyhedron *)
0;
1697 01689 Pol-
>Dimension = Dimension;
1698 01690 Pol-
>NbConstraints = NbConstraints;
1699 01691 Pol-
>NbRays = NbRays;
1700 01692 Pol-
>NbEq =
0;
1701 01693 Pol-
>NbBid =
0;
1702 01694 NbRows = NbConstraints + NbRays;
1703 01695 NbColumns = Dimension +
2;
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;
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) {
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;
1716 01708 Pol-
>Constraint = q;
1717 01709 Pol-
>Ray = q + NbConstraints;
1718 01710 Pol-
>p_Init = p;
1719 01711 <font class=
"keywordflow">for
</font> (i=
0;i
<NbRows;i++) {
1721 01713 <font class=
"keywordflow">for
</font>(j=
0;j
<NbColumns;j++)
1722 01714 <a class=
"code" href=
"arithmetique_8h.html#a10">value_init
</a>(*(p+j));
1723 01715 p += NbColumns;
1725 01717 Pol-
>p_Init_size = NbRows*NbColumns;
1726 01718 <font class=
"keywordflow">return
</font> Pol;
1727 01719 }
<font class=
"comment">/* Polyhedron_Alloc */
</font>
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) {
1734 01726 <font class=
"keywordtype">int
</font> i,size;
1735 01727 <a class=
"code" href=
"arithmetique_8h.html#a93">Value
</a> *p;
1737 01729 <font class=
"keywordflow">if
</font>(!Pol)
1738 01730 <font class=
"keywordflow">return
</font>;
1739 01731 size = Pol-
>p_Init_size;
1740 01732 p = Pol-
>p_Init;
1741 01733 <font class=
"keywordflow">for
</font>(i=
0;i
<size;i++)
1742 01734 <a class=
"code" href=
"arithmetique_8h.html#a14">value_clear
</a>(p[i]);
1743 01735 free(Pol-
>p_Init);
1744 01736 free(Pol-
>Constraint);
1746 01738 <font class=
"keywordflow">return
</font>;
1747 01739 }
<font class=
"comment">/* Polyhedron_Free */
</font>
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) {
1754 01746 <font class=
"keywordtype">int
</font> i,size;
1755 01747 <a class=
"code" href=
"arithmetique_8h.html#a93">Value
</a> *p;
1757 01749 <font class=
"keywordflow">if
</font>(!Pol)
1758 01750 <font class=
"keywordflow">return
</font>;
1759 01751 <font class=
"keywordflow">if
</font> (Pol-
>next)
1760 01752 <a class=
"code" href=
"polyhedron_8c.html#a19">Domain_Free
</a>(Pol-
>next);
1762 01754 size = Pol-
>p_Init_size;
1763 01755 p = Pol-
>p_Init;
1764 01756 <font class=
"keywordflow">for
</font>(i=
0;i
<size;i++)
1765 01757 <a class=
"code" href=
"arithmetique_8h.html#a14">value_clear
</a>(p[i]);
1766 01758 free(Pol-
>p_Init);
1767 01759 free(Pol-
>Constraint);
1769 01761 <font class=
"keywordflow">return
</font>;
1770 01762 }
<font class=
"comment">/* Domain_Free */
</font>
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) {
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;
1781 01773 <font class=
"keywordflow">if
</font> (!Pol) {
1782 01774 fprintf(Dst,
<font class=
"stringliteral">"<null polyhedron>\n"</font>);
1783 01775 <font class=
"keywordflow">return
</font>;
1786 01778 Dimension = Pol-
>Dimension +
2;
<font class=
"comment">/* Homogenous Dimension + status */
</font>
1787 01779 NbConstraints = Pol-
>NbConstraints;
1788 01780 NbRays = Pol-
>NbRays;
1789 01781 fprintf(Dst,
<font class=
"stringliteral">"POLYHEDRON Dimension:%d\n"</font>, Pol-
>Dimension);
1790 01782 fprintf(Dst,
<font class=
"stringliteral">" Constraints:%d Equations:%d Rays:%d Lines:%d\n"</font>,
1791 01783 Pol-
>NbConstraints, Pol-
>NbEq, Pol-
>NbRays, Pol-
>NbBid);
1792 01784 fprintf(Dst,
<font class=
"stringliteral">"Constraints %d %d\n"</font>, NbConstraints, Dimension);
1794 01786 <font class=
"keywordflow">for
</font> (i=
0;i
<NbConstraints;i++) {
1795 01787 p=Pol-
>Constraint[i];
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>);
1803 01795 <font class=
"keywordflow">for
</font> (j=
1;j
<Dimension;j++) {
1804 01796 <a class=
"code" href=
"arithmetique_8h.html#a16">value_print
</a>(Dst,Format,*p++);
1806 01798 (void)fprintf(Dst,
<font class=
"stringliteral">" ]\n"</font>);
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
<NbRays;i++) {
1811 01803 p=Pol-
>Ray[i];
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)) {
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>);
1823 01815 <font class=
"keywordflow">else
</font> {
1825 01817 fprintf(Dst,
<font class=
"stringliteral">"Line: ["</font>);
1827 01819 <font class=
"keywordflow">for
</font> (j=
1; j
< Dimension-
1; j++) {
1828 01820 <a class=
"code" href=
"arithmetique_8h.html#a16">value_print
</a>(Dst,Format,*p++);
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> );
1837 01829 <font class=
"keywordflow">else
</font>
1838 01830 fprintf(Dst,
<font class=
"stringliteral">" ]\n"</font>);
1840 01832 <font class=
"keywordflow">if
</font> (Pol-
>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-
>next);
1844 01836 }
<font class=
"comment">/* Polyhedron_Print */
</font>
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>
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) {
1862 01854 Polyhedron *Pol;
1863 01855 <font class=
"keywordtype">int
</font> i;
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;
1870 01862 <a class=
"code" href=
"vector_8c.html#a9">Vector_Set
</a>(Pol-
>Constraint[
0],
0,(Dimension+
1)*(Dimension+
2));
1871 01863 <font class=
"keywordflow">for
</font> (i=
0; i
<=Dimension; i++) {
1873 01865 <font class=
"comment">/* Pol-
>Constraint[i][i+
1]=
1 */
</font>
1874 01866 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(Pol-
>Constraint[i][i+
1],
1);
1876 01868 Pol-
>NbEq = Dimension+
1;
1877 01869 Pol-
>NbBid =
0;
1878 01870 <font class=
"keywordflow">return
</font> Pol;
1879 01871 }
<font class=
"comment">/* Empty_Polyhedron */
</font>
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 >=
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) {
1893 01885 Polyhedron *Pol;
1894 01886 <font class=
"keywordtype">int
</font> i;
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;
1901 01893 <a class=
"code" href=
"vector_8c.html#a9">Vector_Set
</a>(Pol-
>Constraint[
0],
0,(Dimension+
2));
1903 01895 <font class=
"comment">/* Pol-
>Constraint[
0][
0] =
1 */
</font>
1904 01896 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(Pol-
>Constraint[
0][
0],
1);
1906 01898 <font class=
"comment">/* Pol-
>Constraint[
0][Dimension+
1] =
1 */
</font>
1907 01899 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(Pol-
>Constraint[
0][Dimension+
1],
1);
1908 01900 <a class=
"code" href=
"vector_8c.html#a9">Vector_Set
</a>(Pol-
>Ray[
0],
0,(Dimension+
1)*(Dimension+
2));
1909 01901 <font class=
"keywordflow">for
</font> (i=
0;i
<=Dimension;i++) {
1911 01903 <font class=
"comment">/* Pol-
>Ray[i][i+
1]=
1 */
</font>
1912 01904 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(Pol-
>Ray[i][i+
1],
1);
1915 01907 <font class=
"comment">/* Pol-
>Ray[Dimension][
0] =
1 : vertex status */
</font>
1916 01908 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(Pol-
>Ray[Dimension][
0],
1);
1917 01909 Pol-
>NbEq =
0;
1918 01910 Pol-
>NbBid = Dimension;
1919 01911 <font class=
"keywordflow">return
</font> Pol;
1920 01912 }
<font class=
"comment">/* Universe_Polyhedron */
</font>
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) {
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;
1935 01927 Dimension = Constraints-
>NbColumns -
1;
<font class=
"comment">/* Homogeneous Dimension */
</font>
1936 01928 <font class=
"keywordflow">if
</font> (Dimension
< 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;
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-
>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;
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>
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;
1963 01955 <a class=
"code" href=
"vector_8c.html#a9">Vector_Set
</a>(Ray-
>p_Init,
0, NbMaxRays * (Dimension+
1));
1964 01956 <font class=
"keywordflow">for
</font> (i=
0; i
<Dimension; i++) {
1966 01958 <font class=
"comment">/* Ray-
>p[i][i+
1] =
1 */
</font>
1967 01959 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(Ray-
>p[i][i+
1],
1);
1970 01962 <font class=
"comment">/* Ray-
>p[Dimension-
1][
0] =
1 : mark for ray */
</font>
1971 01963 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(Ray-
>p[Dimension-
1][
0],
1);
1972 01964 Ray-
>NbRows = Dimension;
1974 01966 <font class=
"comment">/* Initialize the Sat Matrix */
</font>
1975 01967 nbcolumns = (Constraints-
>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-
><a class=
"code" href=
"structSatMatrix.html#m3">p_init
</a>,Dimension*nbcolumns);
1978 01970 Sat-
><a class=
"code" href=
"structSatMatrix.html#m0">NbRows
</a> = Dimension;
1980 01972 <a class=
"code" href=
"arithmetic__errors_8h.html#a4">CATCH
</a>(any_exception_error) {
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>(
&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>();
1988 01980 <a class=
"code" href=
"arithmetic__errors_8h.html#a6">TRY
</a> {
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);
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>
2006 01998 <a class=
"code" href=
"arithmetic__errors_8h.html#a5">UNCATCH
</a>(any_exception_error);
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>(
&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>
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) {
2026 02018 <font class=
"keywordtype">unsigned
</font> NbConstraints,Dimension;
2028 02020 NbConstraints = Pol-
>NbConstraints;
2029 02021 Dimension = Pol-
>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;
2035 02027 <a class=
"code" href=
"vector_8c.html#a11">Vector_Copy
</a>(Pol-
>Constraint[
0],Mat-
>p_Init,NbConstraints * Dimension);
2036 02028 <font class=
"keywordflow">return
</font> Mat;
2037 02029 }
<font class=
"comment">/* Polyhedron2Constraints */
</font>
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) {
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;
2052 02044 Dimension = Ray-
><a class=
"code" href=
"structSatMatrix.html#m1">NbColumns
</a>-
1;
<font class=
"comment">/* Homogeneous Dimension */
</font>
2054 02046 SatTranspose = NULL;
2057 02049 <font class=
"keywordflow">if
</font> (Ray-
>NbRows==
0) {
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);
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;
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-
>p_Init,
0,NbMaxConstrs * (Dimension+
1));
2073 02065 <font class=
"keywordflow">for
</font> (i=
0; i
<Dimension; i++) {
2075 02067 <font class=
"comment">/* Mat-
>p[i][i+
1]=
1 */
</font>
2076 02068 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(Mat-
>p[i][i+
1],
1);
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-
>NbRows = Dimension;
2082 02074 nbcolumns = (Ray-
>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-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[
0],Dimension * nbcolumns);
2085 02077 SatTranspose-
><a class=
"code" href=
"structSatMatrix.html#m0">NbRows
</a> = Dimension;
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) {
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>(
&SatTranspose);
2102 02094 <font class=
"keywordflow">if
</font> (Sat)
<a class=
"code" href=
"polyparam_8c.html#a24">SMFree
</a>(
&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>();
2107 02099 <a class=
"code" href=
"arithmetic__errors_8h.html#a6">TRY
</a> {
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);
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);
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>(
&SatTranspose), SatTranspose = NULL;
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>
2136 02128 <a class=
"code" href=
"arithmetic__errors_8h.html#a5">UNCATCH
</a>(any_exception_error);
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>(
&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>
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) {
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;
2163 02155 <a class=
"code" href=
"arithmetique_8h.html#a10">value_init
</a>(tmp);
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>(
&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>();
2171 02163 <a class=
"code" href=
"arithmetic__errors_8h.html#a6">TRY
</a> {
2172 02164 NbRay = Ray-
>NbRows;
2173 02165 Dimension = Mat-
>NbColumns-
1;
<font class=
"comment">/* Homogeneous Dimension */
</font>
2175 02167 <font class=
"comment">/* Build the Sat matrix */
</font>
2176 02168 nbcolumns = (Mat-
>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-
><a class=
"code" href=
"structSatMatrix.html#m0">NbRows
</a> = NbRay;
2179 02171 <a class=
"code" href=
"polyhedron_8c.html#a4">SMVector_Init
</a>(Sat-
><a class=
"code" href=
"structSatMatrix.html#m3">p_init
</a>, nbcolumns * NbRay);
2181 02173 <font class=
"keywordflow">for
</font> (k=
0; k
<NbConstraints; k++) {
2182 02174 <font class=
"keywordflow">for
</font> (i=
0; i
<NbRay; i++) {
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-
>p[i]+
1;
2187 02179 p2 = Mat-
>p[k]+
1;
2188 02180 p3 = Ray-
>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
<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);
2196 02188 <font class=
"keywordflow">for
</font> (j=
0; j
<NbRay; j++) {
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-
>p[j][
0]))
2201 02193 Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[j][jx]|=bx;
2205 02197 }
<font class=
"comment">/* end of TRY */
</font>
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>
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) {
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;
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>(
&Sat);
2229 02221 <a class=
"code" href=
"arithmetic__errors_8h.html#a7">RETHROW
</a>();
2231 02223 <a class=
"code" href=
"arithmetic__errors_8h.html#a6">TRY
</a> {
2232 02224 NbRay = Pol-
>NbRays;
2233 02225 NbCon = Pol-
>NbConstraints + NbConstraints;
2234 02226 Dimension = Pol-
>Dimension +
2;
<font class=
"comment">/* Homogeneous Dimension + Status */
</font>
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;
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-
>Constraint[
0], Mat-
>p[
0], Pol-
>NbConstraints * Dimension);
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-
>p[Pol-
>NbConstraints], NbConstraints * Dimension);
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;
2256 02248 Ray-
>NbRows = NbRay;
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-
>Ray[
0], Ray-
>p[
0], NbRay * Dimension);
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-
>NbConstraints, NbMaxRays);
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-
>NbBid, NbMaxRays, Pol-
>NbConstraints,
0);
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);
2271 02263 }
<font class=
"comment">/* end of TRY */
</font>
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>(
&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>
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) {
2288 02280 <font class=
"keywordtype">int
</font> Dimension = Pol1-
>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;
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
<Pol1-
>NbConstraints; k++) {
2294 02286 <font class=
"keywordflow">for
</font> (i=
0;i
<Pol2-
>NbRays;i++) {
2296 02288 <font class=
"comment">/* Compute the dot product of ray(i) and constraint(k) and store in p3 */
</font>
2297 02289 p1 = Pol2-
>Ray[i]+
1;
2298 02290 p2 = Pol1-
>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
<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);
2306 02298 <font class=
"comment">/* If (p3
< 0) or (p3
> 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 && (
<a class=
"code" href=
"arithmetique_8h.html#a67">value_zero_p
</a>(Pol1-
>Constraint[k][
0]) || (
<a class=
"code" href=
"arithmetique_8h.html#a67">value_zero_p
</a>(Pol2-
>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;
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>
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) {
2328 02320 Polyhedron *p, *pnext, *p_domain_end = (Polyhedron *)
0;
2329 02321 <font class=
"keywordtype">int
</font> Redundant;
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;
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;
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;
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) {
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))
2355 02347 <font class=
"comment">/* free p */
</font>
2356 02348 pnext = p-
>next;
2357 02349 <a class=
"code" href=
"polyhedron_8c.html#a18">Polyhedron_Free
</a>( p );
2358 02350 <font class=
"keywordflow">continue
</font>;
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-
>next = p;
2363 02355 p_domain_end = p;
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>;
2370 02362 pnext = p-
>next;
2372 02364 <font class=
"keywordflow">if
</font> (!Redundant) {
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-
>next = Pol;
2378 02370 <font class=
"keywordflow">else
</font> {
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);
2383 02375 <font class=
"keywordflow">return
</font> PolDomain;
2384 02376 }
<font class=
"comment">/* AddPolyToDomain */
</font>
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)
>=
0</font>
2392 02384 <font class=
"comment"> * If Pass ==
1, add ( +constraint -
1)
>=
0</font>
2393 02385 <font class=
"comment"> * If Pass ==
2, add ( -constraint )
>=
0</font>
2394 02386 <font class=
"comment"> * If Pass ==
3, add ( +constraint )
>=
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) {
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;
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>(
&Sat);
2409 02401 <a class=
"code" href=
"arithmetic__errors_8h.html#a7">RETHROW
</a>();
2411 02403 <a class=
"code" href=
"arithmetic__errors_8h.html#a6">TRY
</a> {
2413 02405 <font class=
"comment">/* If 'Con' is the positivity constraint, return Null */
</font>
2414 02406 Dimension = Pol-
>Dimension+
1;
<font class=
"comment">/* Homogeneous Dimension */
</font>
2415 02407 <font class=
"keywordflow">for
</font> (i=
1; i
<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;
2422 02414 NbRay = Pol-
>NbRays;
2423 02415 NbCon = Pol-
>NbConstraints;
2424 02416 Dimension = Pol-
>Dimension+
2;
<font class=
"comment">/* Homogeneous Dimension + Status */
</font>
2425 02417 NbEle1 = NbCon * Dimension;
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;
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-
>Constraint[
0], Mat-
>p[
0], NbEle1);
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-
>p[NbCon][
0],
1);
2439 02431 <font class=
"keywordflow">if
</font> (!(Pass
&1))
2440 02432 <font class=
"keywordflow">for
</font>(i=
1; i
<Dimension; i++)
2441 02433 <a class=
"code" href=
"arithmetique_8h.html#a54">value_oppose
</a>(Mat-
>p[NbCon][i],Con[i]);
2442 02434 <font class=
"keywordflow">else
</font>
2443 02435 <font class=
"keywordflow">for
</font>(i=
1; i
<Dimension; i++)
2444 02436 <a class=
"code" href=
"arithmetique_8h.html#a11">value_assign
</a>(Mat-
>p[NbCon][i],Con[i]);
2445 02437 <font class=
"keywordflow">if
</font> (!(Pass
&2))
2446 02438 <a class=
"code" href=
"arithmetique_8h.html#a50">value_decrement
</a>(Mat-
>p[NbCon][Dimension-
1],Mat-
>p[NbCon][Dimension-
1]);
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;
2456 02448 <font class=
"comment">/* Initialize the ray matrix with the rays of polyhedron 'Pol' */
</font>
2457 02449 Ray-
>NbRows = NbRay;
2458 02450 <a class=
"code" href=
"vector_8c.html#a11">Vector_Copy
</a>(Pol-
>Ray[
0], Ray-
>p[
0], NbRay * Dimension);
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);
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-
>NbBid, NbMaxRays, NbCon,
0);
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);
2470 02462 }
<font class=
"comment">/* end of TRY */
</font>
2472 02464 <a class=
"code" href=
"arithmetic__errors_8h.html#a5">UNCATCH
</a>(any_exception_error);
2474 02466 <a class=
"code" href=
"polyparam_8c.html#a24">SMFree
</a>(
&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>
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) {
2486 02478 Polyhedron *p1, *p2, *p3, *d;
2488 02480 <font class=
"keywordflow">if
</font> (!Pol1 || !Pol2)
<font class=
"keywordflow">return
</font> (Polyhedron*)
0;
2489 02481 <font class=
"keywordflow">if
</font> (Pol1-
>Dimension != Pol2-
>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;
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-
>next) {
2500 02492 <font class=
"keywordflow">for
</font> (p2=Pol2; p2; p2=p2-
>next) {
2501 02493 p3 =
<a class=
"code" href=
"polyhedron_8c.html#a28">AddConstraints
</a>(p2-
>Constraint[
0],
2502 02494 p2-
>NbConstraints, p1, NbMaxRays);
2503 02495 d =
<a class=
"code" href=
"polyhedron_8c.html#a30">AddPolyToDomain
</a>(p3,d);
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-
>Dimension);
2508 02500 <font class=
"keywordflow">else
</font>
2509 02501 <font class=
"keywordflow">return
</font> d;
2511 02503 }
<font class=
"comment">/* DomainIntersection */
</font>
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) {
2519 02511 <font class=
"keywordtype">unsigned
</font> NbRays, Dimension;
2521 02513 NbRays = Pol-
>NbRays;
2522 02514 Dimension = Pol-
>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;
2528 02520 <a class=
"code" href=
"vector_8c.html#a11">Vector_Copy
</a>(Pol-
>Ray[
0], Ray-
>p_Init, NbRays*Dimension);
2529 02521 <font class=
"keywordflow">return
</font> Ray;
2530 02522 }
<font class=
"comment">/* Polyhedron2Rays */
</font>
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) {
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;
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>(
&Sat);
2548 02540 <font class=
"keywordflow">if
</font> (SatTranspose)
<a class=
"code" href=
"polyparam_8c.html#a24">SMFree
</a>(
&SatTranspose);
2549 02541 <a class=
"code" href=
"arithmetic__errors_8h.html#a7">RETHROW
</a>();
2551 02543 <a class=
"code" href=
"arithmetic__errors_8h.html#a6">TRY
</a> {
2553 02545 NbCon = Pol-
>NbConstraints;
2554 02546 NbRay = Pol-
>NbRays;
2555 02547 Dimension = Pol-
>Dimension +
2;
<font class=
"comment">/* Homogeneous Dimension + Status */
</font>
2556 02548 NbEle1 = NbRay * Dimension;
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;
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-
>Ray[
0], Ray-
>p_Init, NbEle1);
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-
>p_Init+NbEle1, NbAddedRays * Dimension);
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;
2578 02570 Mat-
>NbRows = NbCon;
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-
>Constraint[
0], Mat-
>p_Init, NbCon*Dimension);
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);
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-
>NbEq, NbMaxConstrs, NbRay,
1);
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>(
&SatTranspose), SatTranspose = NULL;
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);
2599 02591 <a class=
"code" href=
"polyparam_8c.html#a24">SMFree
</a>(
&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>
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>
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) {
2615 02607 Polyhedron *PolA, *PolEndA, *p1, *p2, *p3;
2616 02608 <font class=
"keywordtype">int
</font> Redundant;
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-
>Dimension != Ray-
>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;
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-
>next) {
2629 02621 p3 =
<a class=
"code" href=
"polyhedron_8c.html#a34">AddRays
</a>(Ray-
>p[
0], Ray-
>NbRows, p1, NbMaxConstrs);
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-
>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>;
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-
>next = p3;
2646 02638 PolEndA = PolEndA-
>next;
2650 02642 <font class=
"keywordflow">return
</font> PolA;
2651 02643 }
<font class=
"comment">/* DomainAddRays */
</font>
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) {
2658 02650 Polyhedron *Pol1;
2660 02652 <font class=
"keywordflow">if
</font> (!Pol)
<font class=
"keywordflow">return
</font> (Polyhedron *)
0;
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-
>Dimension, Pol-
>NbConstraints, Pol-
>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;
2668 02660 <font class=
"keywordflow">if
</font>( Pol-
>NbConstraints )
2669 02661 <a class=
"code" href=
"vector_8c.html#a11">Vector_Copy
</a>(Pol-
>Constraint[
0], Pol1-
>Constraint[
0],
2670 02662 Pol-
>NbConstraints*(Pol-
>Dimension+
2));
2671 02663 <font class=
"keywordflow">if
</font>( Pol-
>NbRays )
2672 02664 <a class=
"code" href=
"vector_8c.html#a11">Vector_Copy
</a>(Pol-
>Ray[
0], Pol1-
>Ray[
0],
2673 02665 Pol-
>NbRays*(Pol-
>Dimension+
2));
2674 02666 Pol1-
>NbBid = Pol-
>NbBid;
2675 02667 Pol1-
>NbEq = Pol-
>NbEq;
2676 02668 <font class=
"keywordflow">return
</font> Pol1;
2677 02669 }
<font class=
"comment">/* Polyhedron_Copy */
</font>
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) {
2684 02676 Polyhedron *Pol1;
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-
>next) Pol1-
>next =
<a class=
"code" href=
"polyhedron_8c.html#a37">Domain_Copy
</a>(Pol-
>next);
2689 02681 <font class=
"keywordflow">return
</font> Pol1;
2690 02682 }
<font class=
"comment">/* Domain_Copy */
</font>
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<-
>0) of the matrix 'Sat'.
</font>
2708 02700 <font class=
"comment"> *
</font>
2709 02701 <font class=
"comment"> * ALGORITHM:-
></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) {
2722 02714 <font class=
"keywordtype">int
</font> kj, i,j, jx;
2723 02715 <font class=
"keywordtype">unsigned
</font> kb, bx;
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
>>= 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);
2730 02722 <font class=
"comment">/* Remove rays excluded by constraint k */
</font>
2731 02723 <font class=
"keywordflow">for
</font>(i=
0; i
<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-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[i][kj]
&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> {
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);
2740 02732 <font class=
"comment">/* Adjust non-deleted constraints */
</font>
2742 02734 <font class=
"keywordflow">for
</font>(j=
0; j
<NbConstraints; j++) {
2743 02735 <font class=
"keywordflow">if
</font> (
<a class=
"code" href=
"arithmetique_8h.html#a65">value_posz_p
</a>(tmpC[j])
&& (Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[i][jx]
&bx) )
2744 02736 <a class=
"code" href=
"arithmetique_8h.html#a50">value_decrement
</a>(tmpC[j],tmpC[j]);
2749 02741 }
<font class=
"comment">/* addToFilter */
</font>
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) {
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;
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);
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>(
&Sat);
2781 02773 <font class=
"keywordflow">if
</font> (Pol2
&& Pol2!=P2)
<a class=
"code" href=
"polyhedron_8c.html#a18">Polyhedron_Free
</a>(Pol2);
2782 02774 <font class=
"keywordflow">if
</font> (Pol
&& Pol!=Pol2
&& Pol!=P2)
<a class=
"code" href=
"polyhedron_8c.html#a18">Polyhedron_Free
</a>(Pol);
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>();
2789 02781 <a class=
"code" href=
"arithmetic__errors_8h.html#a6">TRY
</a> {
2791 02783 Dimension = P1-
>Dimension+
2;
<font class=
"comment">/* status + homogeneous Dimension */
</font>
2792 02784 Mat =
<a class=
"code" href=
"matrix_8c.html#a0">Matrix_Alloc
</a>(P1-
>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);
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>;
2802 02794 <font class=
"comment">/* Post constraints in P1 already included by Filter */
</font>
2803 02795 jx =
0; bx = MSB; Mat-
>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
<P1-
>NbConstraints; k++) {
2806 02798 <font class=
"keywordflow">if
</font> (Filter[jx]
&bx) {
2807 02799 <a class=
"code" href=
"vector_8c.html#a11">Vector_Copy
</a>(P1-
>Constraint[k], Mat-
>p[Mat-
>NbRows], Dimension);
2808 02800 Mat-
>NbRows++;
2810 02802 <font class=
"keywordflow">else
</font>
2811 02803 <a class=
"code" href=
"arithmetique_8h.html#a45">value_increment
</a>(NbConstraintsLeft,NbConstraintsLeft);
2816 02808 <font class=
"keywordflow">for
</font> (;;) {
2817 02809 <font class=
"keywordflow">if
</font> (Mat-
>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-
>p_Init, Mat-
>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;
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);
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>;
2832 02824 Mat-
>NbRows =
0;
<font class=
"comment">/* Reset Mat */
</font>
2835 02827 <font class=
"comment">/* Its not enough-- find some more constraints */
</font>
2836 02828 Dimension = Pol-
>Dimension+
1;
<font class=
"comment">/* homogeneous Dimension */
</font>
2837 02829 NbRays = Pol-
>NbRays;
2838 02830 NbConstraints = P1-
>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);
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>;
2848 02840 <font class=
"keywordflow">for
</font>(i=
0;i
<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);
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
<NbRays;i++)
2858 02850 <a class=
"code" href=
"arithmetique_8h.html#a14">value_clear
</a>(tmpR[i]);
2860 02852 <font class=
"keywordflow">return
</font>;
2862 02854 <font class=
"keywordflow">for
</font>(i=
0;i
<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);
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-
><a class=
"code" href=
"structSatMatrix.html#m0">NbRows
</a> = NbRays;
2871 02863 <a class=
"code" href=
"polyhedron_8c.html#a4">SMVector_Init
</a>(Sat-
><a class=
"code" href=
"structSatMatrix.html#m3">p_init
</a>, nc*NbRays);
2874 02866 <font class=
"keywordflow">for
</font> (k=
0; k
<NbConstraints; k++) {
2875 02867 <font class=
"keywordflow">if
</font> (Filter[jx]
&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
<NbRays; i++) {
2879 02871 p1 = Pol-
>Ray[i]+
1;
2880 02872 p2 = P1-
>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
<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);
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)
&& <a class=
"code" href=
"arithmetique_8h.html#a68">value_notzero_p
</a>(P1-
>Constraint[k][
0]))) {
2889 02881 Sat-
><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]);
2897 02889 <font class=
"keywordflow">do
</font> {
<font class=
"comment">/* find all of the essential constraints */
</font>
2899 02891 <font class=
"keywordflow">for
</font>(i=
0; i
<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)) {
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
<NbConstraints; k++) {
2907 02899 <font class=
"keywordflow">if
</font>(
<a class=
"code" href=
"arithmetique_8h.html#a65">value_posz_p
</a>(tmpC[k])
&& ((Sat-
><a class=
"code" href=
"structSatMatrix.html#m2">p
</a>[i][jx]
&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-
>Constraint[k],
2911 02903 Mat-
>p[Mat-
>NbRows],Dimension+
1);
2912 02904 Mat-
>NbRows++;
2913 02905 <a class=
"code" href=
"arithmetique_8h.html#a50">value_decrement
</a>(NbConstraintsLeft,NbConstraintsLeft);
2915 02907 <font class=
"keywordflow">break
</font>;
2919 02911 <font class=
"keywordflow">break
</font>;
2923 02915 <font class=
"keywordflow">while
</font> (found);
2925 02917 <font class=
"keywordflow">if
</font> (!Mat-
>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);
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<<(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>
2941 02933 <font class=
"keywordflow">for
</font>(k=
0; k
<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]);
2948 02940 <a class=
"code" href=
"arithmetique_8h.html#a14">value_clear
</a>(cmax);
2949 02941 <font class=
"keywordflow">if
</font> (j
<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>);
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-
>Constraint[j],Mat-
>p[Mat-
>NbRows],Dimension+
1);
2955 02947 Mat-
>NbRows++;
2956 02948 <a class=
"code" href=
"arithmetique_8h.html#a50">value_decrement
</a>(NbConstraintsLeft,NbConstraintsLeft);
2959 02951 <a class=
"code" href=
"polyparam_8c.html#a24">SMFree
</a>(
&Sat), Sat = NULL;
2960 02952 free(tmpC), tmpC = NULL;
2961 02953 free(tmpR), tmpR = NULL;
2963 02955 }
<font class=
"comment">/* end of TRY */
</font>
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
<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
<NbRays;i++)
2971 02963 <a class=
"code" href=
"arithmetique_8h.html#a14">value_clear
</a>(tmpC[i]);
2973 02965 <a class=
"code" href=
"arithmetic__errors_8h.html#a5">UNCATCH
</a>(any_exception_error);
2974 02966 }
<font class=
"comment">/* FindSimple */
</font>
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) {
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;
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>(
&Sat);
2996 02988 <a class=
"code" href=
"arithmetic__errors_8h.html#a7">RETHROW
</a>();
2998 02990 <a class=
"code" href=
"arithmetic__errors_8h.html#a6">TRY
</a> {
3000 02992 NbRay = Pol1-
>NbRays;
3001 02993 NbCon1 = Pol1-
>NbConstraints;
3002 02994 NbCon2 = Pol2-
>NbConstraints;
3003 02995 NbCon = NbCon1 + NbCon2;
3004 02996 Dimension = Pol1-
>Dimension+
2;
<font class=
"comment">/* Homogeneous Dimension + Status */
</font>
3005 02997 NbEle1 = NbCon1*Dimension;
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;
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-
>Constraint[
0], Mat-
>p_Init, NbEle1);
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-
>Constraint[
0], Mat-
>p_Init+NbEle1, NbCon2*Dimension);
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;
3028 03020 Ray-
>NbRows = NbRay;
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-
>Ray[
0], Ray-
>p_Init, NbRay*Dimension);
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);
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-
>NbBid, NbMaxRays, NbCon1,
0);
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);
3043 03035 <font class=
"keywordflow">if
</font> (Filter
&& emptyQ(Pol)) {
3045 03037 <a class=
"code" href=
"polyhedron_8c.html#a39">FindSimple
</a>(Pol1, Pol2, Filter, NbMaxRays);
3047 03039 <font class=
"comment">/* Polyhedron_Print(stderr,
"%4d",Pol1); */
</font>
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>(
&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;
3054 03046 }
<font class=
"comment">/* end of TRY */
</font>
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>
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) {
3066 03058 <font class=
"keywordtype">int
</font> i,j;
3067 03059 <font class=
"keywordtype">unsigned
</font> ix, bx, NbEqn, NbEqn1, NbEqn2, NbEle2, Dimension;
3070 03062 NbEqn1 = Pol1-
>NbEq;
3071 03063 NbEqn2 = Pol2-
>NbEq;
3072 03064 NbEqn = NbEqn1 + NbEqn2;
3073 03065 Dimension = Pol1-
>Dimension+
2;
<font class=
"comment">/* Homogeneous Dimension + Status */
</font>
3074 03066 NbEle2 = NbEqn2*Dimension;
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>;
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-
>Constraint[
0], Mat-
>p_Init, NbEle2);
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-
>Constraint[
0], Mat-
>p_Init+NbEle2, NbEqn1*Dimension);
3089 03081 <a class=
"code" href=
"polyhedron_8c.html#a15">Gauss
</a>(Mat, NbEqn2, Dimension-
1);
3093 03085 <font class=
"keywordflow">for
</font> (i=NbEqn2; i
<NbEqn; i++) {
3094 03086 <font class=
"keywordflow">for
</font> (j=
1; j
<Dimension; j++) {
3095 03087 <font class=
"keywordflow">if
</font> (
<a class=
"code" href=
"arithmetique_8h.html#a68">value_notzero_p
</a>(Mat-
>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>
3099 03091 Filter[ix] |= bx;
3100 03092 <font class=
"keywordflow">break
</font>;
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>
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) {
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;
3125 03117 <font class=
"keywordflow">if
</font> (!Pol1 || !Pol2)
<font class=
"keywordflow">return
</font> Pol1;
3126 03118 <font class=
"keywordflow">if
</font> (Pol1-
>Dimension != Pol2-
>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;
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-
>Dimension);
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>
3137 03129 <font class=
"keywordflow">for
</font> (p2=Pol2; p2; p2=p2-
>next)
3138 03130 <font class=
"keywordflow">if
</font> (p2-
>NbConstraints
> NbCon)
3139 03131 NbCon = p2-
>NbConstraints;
3141 03133 Dimension = Pol1-
>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-
>next) {
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>
3150 03142 NbConstraints = p1-
>NbConstraints;
3151 03143 nbentries = (NbConstraints + NbCon -
1) / (
<font class=
"keyword">sizeof
</font>(int)*
8) +
1;
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;
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);
3164 03156 <font class=
"comment">/* Filter the constraints of p1 in context of polyhedra p2(s) */
</font>
3166 03158 <font class=
"keywordflow">for
</font> (p2=Pol2; p2; p2=p2-
>next) {
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>
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))
3177 03169 <font class=
"comment">/* takes the union of all non redundant constraints */
</font>
3180 03172 <font class=
"keywordflow">if
</font> (!empty) {
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;
3189 03181 Constraints-
>NbRows =
0;
3190 03182 <font class=
"keywordflow">for
</font> (k=
0, jx=
0, bx=MSB; k
<NbConstraints; k++) {
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]
&bx) {
3195 03187 <a class=
"code" href=
"vector_8c.html#a11">Vector_Copy
</a>(p1-
>Constraint[k],
3196 03188 Constraints-
>p[Constraints-
>NbRows],
3198 03190 Constraints-
>NbRows++;
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);
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);
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-
>Dimension);
3216 03208 <font class=
"keywordflow">else
</font> <font class=
"keywordflow">return
</font> d;
3218 03210 }
<font class=
"comment">/* DomainSimplify */
</font>
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) {
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;
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>();
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;
3242 03234 <font class=
"keywordflow">if
</font> (Pol1-
>Dimension != Pol2-
>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;
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-
>Dimension);
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>
3255 03247 <font class=
"keywordflow">for
</font> (p2=Pol2; p2; p2=p2-
>next)
3256 03248 <font class=
"keywordflow">if
</font> (p2-
>NbConstraints
> NbCon)
3257 03249 NbCon = p2-
>NbConstraints;
3259 03251 Dimension = Pol1-
>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-
>next) {
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>
3268 03260 NbConstraints = p1-
>NbConstraints;
3269 03261 nbentries = (NbConstraints + NbCon -
1)/(
<font class=
"keyword">sizeof
</font>(int)*
8) +
1;
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;
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);
3282 03274 <font class=
"comment">/* Filter the constraints of p1 in context to the polyhedra p2(s) */
</font>
3284 03276 <font class=
"keywordflow">for
</font> (p2=Pol2; p2; p2=p2-
>next) {
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>
3291 03283 <font class=
"keywordflow">if
</font> (
<a class=
"code" href=
"polyhedron_8c.html#a40">SimplifyConstraints
</a>(p1, p2, Filter, NbMaxRays))
3295 03287 <font class=
"keywordflow">if
</font> (!empty) {
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;
3304 03296 Constraints-
>NbRows =
0;
3305 03297 <font class=
"keywordflow">for
</font> (k=
0, jx=
0, bx=MSB; k
<NbConstraints; k++) {
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]
&bx) {
3310 03302 <a class=
"code" href=
"vector_8c.html#a11">Vector_Copy
</a>(p1-
>Constraint[k],
3311 03303 Constraints-
>p[Constraints-
>NbRows],
3313 03305 Constraints-
>NbRows++;
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;
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);
3327 03319 free(Filter), Filter = NULL;
3329 03321 }
<font class=
"comment">/* end of TRY */
</font>
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-
>Dimension);
3334 03326 <font class=
"keywordflow">else
</font>
3335 03327 <font class=
"keywordflow">return
</font> d;
3336 03328 }
<font class=
"comment">/* DomainSimplify */
</font>
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) {
3344 03336 Polyhedron *PolA, *PolEndA, *PolB, *PolEndB, *p1, *p2;
3345 03337 <font class=
"keywordtype">int
</font> Redundant;
3347 03339 <font class=
"keywordflow">if
</font> (!Pol1 || !Pol2)
<font class=
"keywordflow">return
</font> (Polyhedron *)
0;
3348 03340 <font class=
"keywordflow">if
</font> (Pol1-
>Dimension != Pol2-
>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;
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-
>next) {
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-
>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;
3369 03361 <font class=
"keywordflow">break
</font>;
3373 03365 <font class=
"keywordflow">if
</font> (!Redundant) {
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-
>next =
<a class=
"code" href=
"polyhedron_8c.html#a36">Polyhedron_Copy
</a>(p1);
3380 03372 PolEndA = PolEndA-
>next;
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-
>next) {
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-
>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>;
3398 03390 <font class=
"keywordflow">if
</font> (!Redundant) {
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-
>next =
<a class=
"code" href=
"polyhedron_8c.html#a36">Polyhedron_Copy
</a>(p2);
3405 03397 PolEndB = PolEndB-
>next;
3412 03404 <font class=
"keywordflow">if
</font> (!PolA)
<font class=
"keywordflow">return
</font> PolB;
3413 03405 PolEndA-
>next = PolB;
3414 03406 <font class=
"keywordflow">return
</font> PolA;
3415 03407 }
<font class=
"comment">/* DomainUnion */
</font>
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) {
3425 03417 Polyhedron *p, *q, *NewPol = NULL;
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>();
3431 03423 <a class=
"code" href=
"arithmetic__errors_8h.html#a6">TRY
</a> {
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;
3438 03430 NewPol =
<a class=
"code" href=
"polyhedron_8c.html#a36">Polyhedron_Copy
</a>(Pol);
3439 03431 <font class=
"keywordflow">for
</font> (p=Pol-
>next; p; p=p-
>next) {
3440 03432 q =
<a class=
"code" href=
"polyhedron_8c.html#a34">AddRays
</a>(p-
>Ray[
0], p-
>NbRays, NewPol, NbMaxConstrs);
3441 03433 <a class=
"code" href=
"polyhedron_8c.html#a18">Polyhedron_Free
</a>(NewPol);
3444 03436 }
<font class=
"comment">/* end of TRY */
</font>
3446 03438 <a class=
"code" href=
"arithmetic__errors_8h.html#a5">UNCATCH
</a>(any_exception_error);
3448 03440 <font class=
"keywordflow">return
</font> NewPol;
3449 03441 }
<font class=
"comment">/* DomainConvex */
</font>
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) {
3457 03449 Polyhedron *p1, *p2, *p3, *d;
3458 03450 <font class=
"keywordtype">int
</font> i;
3460 03452 <font class=
"keywordflow">if
</font> (!Pol1 || !Pol2)
<font class=
"keywordflow">return
</font> (Polyhedron*)
0;
3461 03453 <font class=
"keywordflow">if
</font> (Pol1-
>Dimension != Pol2-
>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;
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-
>next) {
3470 03462 <font class=
"keywordflow">for
</font> (p1=Pol1; p1; p1=p1-
>next) {
3471 03463 <font class=
"keywordflow">for
</font> (i=
0; i
<p2-
>NbConstraints; i++) {
3473 03465 <font class=
"comment">/* Add the constraint ( -p2-
>constraint[i] -
1)
>=
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-
>Constraint[i], p1, NbMaxRays,
0);
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);
3480 03472 <font class=
"comment">/* If the constraint p2-
>constraint[i][
0] is an equality, then */
</font>
3481 03473 <font class=
"comment">/* add the constraint ( +p2-
>constraint[i] -
1)
>=
0 in 'p1' and*/
</font>
3482 03474 <font class=
"comment">/* create the new polyhedron 'p3'. */
</font>
3484 03476 <font class=
"keywordflow">if
</font>(
<a class=
"code" href=
"arithmetique_8h.html#a68">value_notzero_p
</a>(p2-
>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-
>Constraint[i], p1, NbMaxRays,
1);
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);
3493 03485 d = (Polyhedron *)
0;
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-
>Dimension);
3497 03489 <font class=
"keywordflow">else
</font>
3498 03490 <font class=
"keywordflow">return
</font> Pol1;
3499 03491 }
<font class=
"comment">/* DomainDifference */
</font>
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) {
3508 03500 <font class=
"keywordtype">int
</font> i, j, k;
3509 03501 Polyhedron *p = NULL, *q, *result = NULL;
3510 03502 Matrix *Mat = NULL;
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>();
3517 03509 <a class=
"code" href=
"arithmetic__errors_8h.html#a6">TRY
</a> {
3519 03511 <font class=
"keywordflow">if
</font> (!Pol)
<font class=
"keywordflow">return
</font> Pol;
3520 03512 <font class=
"keywordflow">if
</font> (align_dimension
< Pol-
>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;
3525 03517 <font class=
"keywordflow">if
</font> (align_dimension == Pol-
>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;
3530 03522 <font class=
"comment">/* 'k' is the dimension increment */
</font>
3531 03523 k = align_dimension - Pol-
>Dimension;
3532 03524 result = NULL;
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-
>next) {
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-
>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;
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-
>p[
0],
0,(Pol-
>NbConstraints) * (align_dimension +
2));
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
<Pol-
>NbConstraints; i++) {
3554 03546 <font class=
"keywordflow">for
</font> (j=
1; j
<=Pol-
>Dimension+
1;j++) {
3555 03547 <a class=
"code" href=
"arithmetique_8h.html#a11">value_assign
</a>(Mat-
>p[i][k+j], Pol-
>Constraint[i][j]);
3557 03549 <a class=
"code" href=
"arithmetique_8h.html#a11">value_assign
</a>(Mat-
>p[i][
0], Pol-
>Constraint[i][
0]);
<font class=
"comment">/* Status bit */
</font>
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-
>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;
3565 03557 }
<font class=
"comment">/* end of TRY */
</font>
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>
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) {
3580 03572 <font class=
"keywordtype">int
</font> i, j, dim ;
3582 03574 Polyhedron *C1, *C2, *D1, *D2;
3583 03575 Polyhedron *res, *last, *tmp;
3585 03577 dim = D-
>Dimension - C-
>Dimension;
3586 03578 res = last = (Polyhedron *)
0;
3587 03579 <font class=
"keywordflow">if
</font> (dim==
0)
<font class=
"keywordflow">return
</font> (Polyhedron *)
0;
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-
>Dimension, D-
>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;
3595 03587 C1 =
<a class=
"code" href=
"polyhedron_8c.html#a47">align_context
</a>(C,D-
>Dimension,NbMaxRays);
3596 03588 <font class=
"keywordflow">if
</font>(!C1) {
3597 03589 <font class=
"keywordflow">return
</font> 0;
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);
3602 03594 <font class=
"keywordflow">for
</font> (i=
0; i
<dim; i++)
3604 03596 <a class=
"code" href=
"vector_8c.html#a9">Vector_Set
</a>(Mat-
>p_Init,
0,D2-
>Dimension*(D2-
>Dimension +
2));
3605 03597 <font class=
"keywordflow">for
</font> (j=i+
1; j
<dim; j++) {
3606 03598 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(Mat-
>p[j-i-
1][j+
1],
1);
3608 03600 Mat-
>NbRows = dim-i-
1;
3609 03601 D1 = Mat-
>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-
>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);
3616 03608 <font class=
"keywordflow">if
</font> (Mat-
>NbRows)
<a class=
"code" href=
"polyhedron_8c.html#a19">Domain_Free
</a>(D1);
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>
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) {
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;
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);
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);
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
<P-
>NbConstraints; i++) {
3649 03641 <a class=
"code" href=
"arithmetique_8h.html#a11">value_assign
</a>(d,P-
>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>(
&context[
1],
&(P-
>Constraint[i][
1]),P-
>Dimension+
1,
&n);
3652 03644 <a class=
"code" href=
"arithmetique_8h.html#a54">value_oppose
</a>(n,n);
3654 03646 <font class=
"comment">/*---------------------------------------------------*/
</font>
3655 03647 <font class=
"comment">/* Compute n/d n/d
<0 n/d
>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>
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-
>Constraint[i][
0])) {
<font class=
"comment">/* Equality */
</font>
3667 03659 <a class=
"code" href=
"arithmetique_8h.html#a52">value_modulus
</a>(tmp,n,d);
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>
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;
3679 03671 <a class=
"code" href=
"arithmetique_8h.html#a51">value_division
</a>(n1,n,d);
3681 03673 <font class=
"comment">/* Upper and Lower bounds found */
</font>
3682 03674 <font class=
"keywordflow">if
</font>((flag
&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
&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);
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);
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)
&& <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);
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
&LB_INFINITY) {
3700 03692 <a class=
"code" href=
"arithmetique_8h.html#a11">value_assign
</a>(LB,n1);
3701 03693 flag^=LB_INFINITY;
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);
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);
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)
&& <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);
3715 03707 <font class=
"keywordflow">else
</font>
3716 03708 <a class=
"code" href=
"arithmetique_8h.html#a51">value_division
</a>(n1,n,d);
3718 03710 <font class=
"keywordflow">if
</font> (flag
&UB_INFINITY) {
3719 03711 <a class=
"code" href=
"arithmetique_8h.html#a11">value_assign
</a>(UB,n1);
3720 03712 flag^=UB_INFINITY;
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);
3726 03718 <font class=
"keywordflow">if
</font> ((flag
& LB_INFINITY)==
0)
<a class=
"code" href=
"arithmetique_8h.html#a11">value_assign
</a>(*LBp,LB);
3727 03719 <font class=
"keywordflow">if
</font> ((flag
& UB_INFINITY)==
0)
<a class=
"code" href=
"arithmetique_8h.html#a11">value_assign
</a>(*UBp,UB);
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>
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) {
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;
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);
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>();
3757 03749 <a class=
"code" href=
"arithmetic__errors_8h.html#a6">TRY
</a> {
3759 03751 NbConstraints = Pol-
>NbConstraints;
3760 03752 Dimension1 = Pol-
>Dimension+
1;
<font class=
"comment">/* Homogeneous Dimension */
</font>
3761 03753 Dimension2 = Func-
>NbColumns;
<font class=
"comment">/* Homogeneous Dimension */
</font>
3762 03754 <font class=
"keywordflow">if
</font> (Dimension1!=(Func-
>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);
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-
>Constraints Function Constraints
</font>
3774 03766 <font class=
"comment"> */
</font>
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;
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
<NbConstraints; i++) {
3789 03781 <a class=
"code" href=
"arithmetique_8h.html#a11">value_assign
</a>(Constraints-
>p[i][
0],Pol-
>Constraint[i][
0]);
3790 03782 <font class=
"keywordflow">for
</font> (j=
0; j
<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
<Dimension1; k++) {
3794 03786 <font class=
"comment">/* Sum+=Pol-
>Constraint[i][k+
1] * Func-
>p[k][j]; */
</font>
3795 03787 <a class=
"code" href=
"arithmetique_8h.html#a47">value_multiply
</a>(tmp,Pol-
>Constraint[i][k+
1],Func-
>p[k][j]);
3796 03788 <a class=
"code" href=
"arithmetique_8h.html#a43">value_addto
</a>(Sum,Sum,tmp);
3798 03790 <a class=
"code" href=
"arithmetique_8h.html#a11">value_assign
</a>(Constraints-
>p[i][j+
1],Sum);
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;
3804 03796 }
<font class=
"comment">/* end of TRY */
</font>
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);
3809 03801 <font class=
"keywordflow">return
</font> NewPol;
3810 03802 }
<font class=
"comment">/* Polyhedron_Preimage */
</font>
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) {
3820 03812 Polyhedron *p, *q, *d = NULL;
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>();
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;
3831 03823 d = (Polyhedron *)
0;
3832 03824 <font class=
"keywordflow">for
</font> (p=Pol; p; p=p-
>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);
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>
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) {
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;
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);
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>();
3862 03854 <a class=
"code" href=
"arithmetic__errors_8h.html#a6">TRY
</a> {
3864 03856 NbRays = Pol-
>NbRays;
3865 03857 Dimension1 = Pol-
>Dimension+
1;
<font class=
"comment">/* Homogeneous Dimension */
</font>
3866 03858 Dimension2 = Func-
>NbRows;
<font class=
"comment">/* Homogeneous Dimension */
</font>
3867 03859 <font class=
"keywordflow">if
</font> (Dimension1!=Func-
>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);
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-
>Rays \ Func / Rays
</font>
3880 03872 <font class=
"comment"></font>
3881 03873 <font class=
"comment"> */
</font>
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;
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
<NbRays; i++) {
3896 03888 <a class=
"code" href=
"arithmetique_8h.html#a11">value_assign
</a>(Rays-
>p[i][
0],Pol-
>Ray[i][
0]);
3897 03889 <font class=
"keywordflow">for
</font> (j=
0; j
<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
<Dimension1; k++) {
3901 03893 <font class=
"comment">/* Sum+=Pol-
>Ray[i][k+
1] * Func-
>p[j][k]; */
</font>
3902 03894 <a class=
"code" href=
"arithmetique_8h.html#a47">value_multiply
</a>(tmp,Pol-
>Ray[i][k+
1],Func-
>p[j][k]);
3903 03895 <a class=
"code" href=
"arithmetique_8h.html#a43">value_addto
</a>(Sum,Sum,tmp);
3905 03897 <a class=
"code" href=
"arithmetique_8h.html#a11">value_assign
</a>(Rays-
>p[i][j+
1],Sum);
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;
3911 03903 }
<font class=
"comment">/* end of TRY */
</font>
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>
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) {
3925 03917 Polyhedron *p, *q, *d = NULL;
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>();
3931 03923 <a class=
"code" href=
"arithmetic__errors_8h.html#a6">TRY
</a> {
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;
3937 03929 d = (Polyhedron *)
0;
3938 03930 <font class=
"keywordflow">for
</font> (p=Pol; p; p=p-
>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);
3942 03934 }
<font class=
"comment">/* end of TRY */
</font>
3944 03936 <a class=
"code" href=
"arithmetic__errors_8h.html#a5">UNCATCH
</a>(any_exception_error);
3946 03938 <font class=
"keywordflow">return
</font> d;
3947 03939 }
<font class=
"comment">/* DomainImage */
</font>
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)]
>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) {
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;
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);
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);
3976 03968 <a class=
"code" href=
"arithmetic__errors_8h.html#a6">TRY
</a> {
3978 03970 Ray = Pol-
>Ray;
3979 03971 NbRay = Pol-
>NbRays;
3980 03972 Dim = Pol-
>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;
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-
>MaxN and I-
>MaxD store the numerator and */
</font>
3992 03984 <font class=
"comment">/* denominator of the maximum value. Likewise,I-
>MinN and I-
>MinD store */
</font>
3993 03985 <font class=
"comment">/* the numerator and denominator of the minimum value. I-
>MaxI and */
</font>
3994 03986 <font class=
"comment">/* I-
>MinI store the ray indices corresponding to the max and min values*/
</font>
3995 03987 <font class=
"comment">/* of the function. */
</font>
3997 03989 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(I-
>MaxN,-
1);
3998 03990 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(I-
>MaxD,
0);
<font class=
"comment">/* Actual cost is MaxN/MaxD */
</font>
3999 03991 I-
>MaxI = -
1;
4000 03992 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(I-
>MinN,
1);
4001 03993 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(I-
>MinD,
0);
4002 03994 I-
>MinI = -
1;
4004 03996 <font class=
"comment">/* Compute the cost of each ray[i] */
</font>
4005 03997 <font class=
"keywordflow">for
</font> (i=
0; i
<NbRay; i++) {
4007 03999 <a class=
"code" href=
"arithmetique_8h.html#a11">value_assign
</a>(status, *p1);
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);
4014 04006 <font class=
"keywordflow">for
</font> (j=
1; j
<Dim; j++) {
4015 04007 <a class=
"code" href=
"arithmetique_8h.html#a47">value_multiply
</a>(tmp1,*p1,*p2);
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);
4022 04014 <font class=
"comment">/* d = *--p1; */
</font>
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-
>MaxD);
4026 04018 <a class=
"code" href=
"arithmetique_8h.html#a47">value_multiply
</a>(tmp2,I-
>MaxN,d);
4027 04019 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(tmp3,
1);
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-
>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)
&&
4033 04025 <a class=
"code" href=
"arithmetique_8h.html#a22">value_eq
</a>(d,tmp3)
&& <a class=
"code" href=
"arithmetique_8h.html#a23">value_ne
</a>(I-
>MaxD,tmp3))) {
4034 04026 <a class=
"code" href=
"arithmetique_8h.html#a11">value_assign
</a>(I-
>MaxN,p3);
4035 04027 <a class=
"code" href=
"arithmetique_8h.html#a11">value_assign
</a>(I-
>MaxD,d);
4036 04028 I-
>MaxI = i;
4038 04030 <a class=
"code" href=
"arithmetique_8h.html#a47">value_multiply
</a>(tmp1,p3,I-
>MinD);
4039 04031 <a class=
"code" href=
"arithmetique_8h.html#a47">value_multiply
</a>(tmp2,I-
>MinN,d);
4040 04032 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(tmp3,
1);
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-
>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)
&&
4046 04038 <a class=
"code" href=
"arithmetique_8h.html#a22">value_eq
</a>(d,tmp3)
&& <a class=
"code" href=
"arithmetique_8h.html#a23">value_ne
</a>(I-
>MinD,tmp3))) {
4047 04039 <a class=
"code" href=
"arithmetique_8h.html#a11">value_assign
</a>(I-
>MinN, p3);
4048 04040 <a class=
"code" href=
"arithmetique_8h.html#a11">value_assign
</a>(I-
>MinD, d);
4049 04041 I-
>MinI = i;
4051 04043 <a class=
"code" href=
"arithmetique_8h.html#a47">value_multiply
</a>(tmp1,p3,I-
>MaxD);
4052 04044 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(tmp2,
0);
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-
>MaxN,p3);
4058 04050 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(I-
>MaxD,
0);
4059 04051 I-
>MaxI = i;
4061 04053 <a class=
"code" href=
"arithmetique_8h.html#a47">value_multiply
</a>(tmp1,p3,I-
>MinD);
4062 04054 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(tmp2,
0);
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-
>MinN,p3);
4066 04058 <a class=
"code" href=
"arithmetique_8h.html#a12">value_set_si
</a>(I-
>MinD,
0);
4067 04059 I-
>MinI = i;
4071 04063 }
<font class=
"comment">/* end of TRY */
</font>
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>
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) {
4086 04078 Polyhedron *PolA, *PolEndA, *p1, *p2, *p3;
4087 04079 <font class=
"keywordtype">int
</font> Redundant;
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-
>Dimension != Mat-
>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;
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-
>next) {
4100 04092 p3 =
<a class=
"code" href=
"polyhedron_8c.html#a28">AddConstraints
</a>(Mat-
>p_Init, Mat-
>NbRows, p1, NbMaxRays);
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-
>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>;
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) {
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-
>next = p3;
4119 04111 PolEndA = PolEndA-
>next;
4123 04115 <font class=
"keywordflow">return
</font> PolA;
4124 04116 }
<font class=
"comment">/* DomainAddConstraints */
</font>
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 )
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;
4143 04135 <font class=
"keywordflow">if
</font>( flag!=
0 && flag!=
1 )
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;
4149 04141 <font class=
"keywordflow">if
</font>(!P)
<font class=
"keywordflow">return
</font> (Polyhedron*)
0;
4150 04142 <font class=
"keywordflow">if
</font>(!P-
>next)
<font class=
"keywordflow">return
</font> <a class=
"code" href=
"polyhedron_8c.html#a36">Polyhedron_Copy
</a>(P);
4152 04144 Result = (Polyhedron *)
0;
4154 04146 <font class=
"keywordflow">for
</font>(lP=P;lP;lP=lP-
>next)
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>
4160 04152 <font class=
"keywordflow">while
</font>( lR
&& reste )
4162 04154 <font class=
"comment">/* dx = DomainIntersection(reste,lR-
>P,WS); */
</font>
4163 04155 dx = (Polyhedron *)
0;
4164 04156 <font class=
"keywordflow">for
</font>( p1=reste; p1; p1=p1-
>next )
4166 04158 p3 =
<a class=
"code" href=
"polyhedron_8c.html#a28">AddConstraints
</a>(lR-
>Constraint[
0], lR-
>NbConstraints, p1,
4168 04160 dx =
<a class=
"code" href=
"polyhedron_8c.html#a30">AddPolyToDomain
</a>(p3,dx);
4171 04163 <font class=
"comment">/* if empty intersection, continue */
</font>
4172 04164 <font class=
"keywordflow">if
</font>(!dx)
4174 04166 lR=lR-
>next;
4175 04167 <font class=
"keywordflow">continue
</font>;
4177 04169 <font class=
"keywordflow">if
</font> (emptyQ(dx)) {
4178 04170 <a class=
"code" href=
"polyhedron_8c.html#a19">Domain_Free
</a>(dx);
4180 04172 lR=lR-
>next;
4181 04173 <font class=
"keywordflow">continue
</font>;
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-
>P,WS); */
</font>
4188 04180 <font class=
"comment">/* d2 = P \ reste = DomainDifference(lR-
>P,reste,WS); */
</font>
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-
>next)
4195 04187 <font class=
"keywordflow">for
</font> (i=
0; i
<P-
>NbConstraints
&& pi ; i++)
4198 04190 <font class=
"comment">/* Add the constraint ( -P-
>constraint[i] [-
1 if flag=
0])
>=
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-
>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);
4204 04196 <font class=
"comment">/* If the constraint P-
>constraint[i][
0] is an equality, then add */
</font>
4205 04197 <font class=
"comment">/* the constraint ( +P-
>constraint[i] [-
1 if flag=
0])
>=
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-
>Constraint[i][
0]) )
<font class=
"comment">/* Inequality */
</font>
4209 04201 p3 =
<a class=
"code" href=
"polyhedron_8c.html#a31">SubConstraint
</a>(P-
>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);
4213 04205 <font class=
"comment">/* newpi : add constraint P-
>constraint[i]==
0 to pi */
</font>
4214 04206 newpi =
<a class=
"code" href=
"polyhedron_8c.html#a28">AddConstraints
</a>( P-
>Constraint[i],
1, pi, NbMaxRays);
4216 04208 <font class=
"keywordflow">else
</font>
4218 04210 <font class=
"comment">/* newpi : add constraint +P-
>constraint[i]
>=
0 in pi */
</font>
4219 04211 newpi =
<a class=
"code" href=
"polyhedron_8c.html#a31">SubConstraint
</a>(P-
>Constraint[i], pi, NbMaxRays,
3);
4221 04213 <font class=
"keywordflow">if
</font>( newpi
&& emptyQ( newpi ) )
4223 04215 <a class=
"code" href=
"polyhedron_8c.html#a19">Domain_Free
</a>( newpi );
4224 04216 newpi = (Polyhedron *)
0;
4226 04218 <font class=
"keywordflow">if
</font>( pi != p1 )
4227 04219 <a class=
"code" href=
"polyhedron_8c.html#a19">Domain_Free
</a>( pi );
4230 04222 <font class=
"keywordflow">if
</font>( pi != p1 )
4231 04223 <a class=
"code" href=
"polyhedron_8c.html#a19">Domain_Free
</a>( pi );
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-
>next)
4238 04230 d2 = (Polyhedron *)
0;
4239 04231 <font class=
"keywordflow">for
</font> (p1=Pol1; p1; p1=p1-
>next)
4242 04234 <font class=
"keywordflow">for
</font> (i=
0; i
<p2-
>NbConstraints
&& pi ; i++)
4245 04237 <font class=
"comment">/* Add the constraint ( -p2-
>constraint[i] [-
1 if flag=
0])
>=
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-
>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);
4251 04243 <font class=
"comment">/* If the constraint p2-
>constraint[i][
0] is an equality, then add */
</font>
4252 04244 <font class=
"comment">/* the constraint ( +p2-
>constraint[i] [-
1 if flag=
0])
>=
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-
>Constraint[i][
0]) )
<font class=
"comment">/* Inequality */
</font>
4256 04248 p3 =
<a class=
"code" href=
"polyhedron_8c.html#a31">SubConstraint
</a>(p2-
>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);
4260 04252 <font class=
"comment">/* newpi : add constraint p2-
>constraint[i]==
0 to pi */
</font>
4261 04253 newpi =
<a class=
"code" href=
"polyhedron_8c.html#a28">AddConstraints
</a>( p2-
>Constraint[i],
1, pi, NbMaxRays);
4263 04255 <font class=
"keywordflow">else
</font>
4265 04257 <font class=
"comment">/* newpi : add constraint +p2-
>constraint[i]
>=
0 in pi */
</font>
4266 04258 newpi =
<a class=
"code" href=
"polyhedron_8c.html#a31">SubConstraint
</a>(p2-
>Constraint[i], pi, NbMaxRays,
3);
4268 04260 <font class=
"keywordflow">if
</font>( newpi
&& emptyQ( newpi ) )
4270 04262 <a class=
"code" href=
"polyhedron_8c.html#a19">Domain_Free
</a>( newpi );
4271 04263 newpi = (Polyhedron *)
0;
4273 04265 <font class=
"keywordflow">if
</font>( pi != p1 )
4274 04266 <a class=
"code" href=
"polyhedron_8c.html#a19">Domain_Free
</a>( pi );
4277 04269 <font class=
"keywordflow">if
</font>( pi
&& pi!=p1 )
4278 04270 <a class=
"code" href=
"polyhedron_8c.html#a19">Domain_Free
</a>( pi );
4280 04272 <font class=
"keywordflow">if
</font>( Pol1 )
4281 04273 <a class=
"code" href=
"polyhedron_8c.html#a19">Domain_Free
</a>( Pol1 );
4284 04276 <font class=
"comment">/* ok, d1 and d2 are computed */
</font>
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
&& emptyQ(d1) )
4289 04281 <a class=
"code" href=
"polyhedron_8c.html#a19">Domain_Free
</a>( d1 );
4292 04284 <font class=
"keywordflow">if
</font>( d2
&& emptyQ(d2) )
4294 04286 <a class=
"code" href=
"polyhedron_8c.html#a19">Domain_Free
</a>( d2 );
4298 04290 <font class=
"comment">/* set reste */
</font>
4299 04291 <a class=
"code" href=
"polyhedron_8c.html#a19">Domain_Free
</a>( reste );
4302 04294 <font class=
"comment">/* add d2 at beginning of Result */
</font>
4303 04295 <font class=
"keywordflow">if
</font>( d2 )
4305 04297 <font class=
"keywordflow">for
</font>( tmp=d2 ; tmp-
>next ; tmp=tmp-
>next )
4307 04299 tmp-
>next = Result;
4309 04301 <font class=
"keywordflow">if
</font>( !prec )
4313 04305 <font class=
"comment">/* add dx at beginning of Result */
</font>
4314 04306 <font class=
"comment">// if( dx )
</font>
4316 04308 <font class=
"keywordflow">for
</font>( tmp=dx ; tmp-
>next ; tmp=tmp-
>next )
4318 04310 tmp-
>next = Result;
4320 04312 <font class=
"keywordflow">if
</font>( !prec )
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-
>next = lR-
>next;
4328 04320 <a class=
"code" href=
"polyhedron_8c.html#a18">Polyhedron_Free
</a>( lR );
4329 04321 lR = prec-
>next;
4330 04322 }
<font class=
"comment">/* end for result */
</font>
4332 04324 <font class=
"comment">/* if there is something left, add it to Result : */
</font>
4333 04325 <font class=
"keywordflow">if
</font>(reste)
4335 04327 <font class=
"keywordflow">if
</font>(emptyQ(reste))
4337 04329 <a class=
"code" href=
"polyhedron_8c.html#a19">Domain_Free
</a>( reste );
4340 04332 <font class=
"keywordflow">else
</font>
4342 04334 Polyhedron *tnext;
4343 04335 <font class=
"keywordflow">for
</font>( tmp=reste ; tmp ; tmp=tnext )
4345 04337 tnext = tmp-
>next;
4346 04338 tmp-
>next = NULL;
4347 04339 Result =
<a class=
"code" href=
"polyhedron_8c.html#a30">AddPolyToDomain
</a>(tmp, Result);
4353 04345 <font class=
"keywordflow">return
</font>( Result );
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)
4361 04353 <font class=
"keywordtype">int
</font> i,j;
4363 04355 fprintf( Dst,
<font class=
"stringliteral">"%d %d\n"</font>, Pol-
>NbConstraints, Pol-
>Dimension+
2 );
4364 04356 <font class=
"keywordflow">for
</font>( i=
0 ; i
<Pol-
>NbConstraints ; i++ )
4366 04358 <font class=
"keywordflow">for
</font>( j=
0 ; j
<Pol-
>Dimension+
2 ; j++ )
4367 04359 <a class=
"code" href=
"arithmetique_8h.html#a16">value_print
</a>( stdout, Format, Pol-
>Constraint[i][j] );
4368 04360 fprintf( Dst,
<font class=
"stringliteral">"\n"</font> );
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>