QHV
Compute HyperVolumes sequentially
 All Data Structures Files Functions Variables Macros
point.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) Year(s), 2013, Luis M. S. Russo and Alexandre
4  * P. Francisco / KDBIO / INESC-ID, <qhv@kdbio.inesc-id.pt>
5  *
6  * Any published media that is related with to use of the distributed
7  * software, or derived software, must contain a reference to "Quick
8  * HyperVolume, Luís M. S. Russo, Alexandre P. Francisco IEEE Trans.
9  * Evolutionary Computation 18(4): 481-502(2014)".
10  *
11  * Permission to use, copy, modify, and/or distribute this software for
12  * any purpose with or without fee is hereby granted, provided that the
13  * above copyright notice and this permission notice appear in all
14  * copies.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
17  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
19  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
20  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
21  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
22  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
23  * PERFORMANCE OF THIS SOFTWARE.
24  *
25  */
26 
27 
38 #ifndef POINT_H
39 #define POINT_H
40 
41 #include <stdio.h>
42 #include <math.h>
43 #include <float.h>
44 #include "emmintrin.h"
45 #include "macros.h"
46 
47 #ifndef Eps
48 #define Eps 0.0000000001
49 #endif /* Eps */
50 
51 /*** typedefs(not structures) and defined constants *******/
52 
53 #include "pointStruct.h"
54 
55 /*** enums ************************************************/
56 
57 /*** structures declarations (and typedefs of )************/
58 
59 /*** global variables defined in .c file ******************/
60 
61 extern point cZero;
62 extern point cOne;
64 /*** declarations of public functions *********************/
65 
74 #define equal(A, B, I) (fabs((A)->x[I] - (B)->x[I]) < Eps)
75 
83 #define objective(Z, A, O) HV(Z, A)
84 //#define objective(Z, A, O) minCoord(Z, A, O)
85 
92 void parsePoint(char* S, point* p, double max);
93 
99 void randomPoint(point* p);
100 
101 static sureInline(void) projectZero(point* res, point* pvt, unsigned int oct, point* zero)
102 {
103  unsigned int B;
104  int i;
105 
106  i = 0;
107  B = 1;
108 
109  while(i < D)
110  {
111  if(B & oct)
112  res->x[i] = pvt->x[i];
113  else
114  res->x[i] = zero->x[i];
115  i++;
116  B <<= 1;
117  }
118 }
119 
120 static sureInline(void) projectOne(point* res, point* pvt, unsigned int oct, point* one)
121 {
122  unsigned int B;
123  int i;
124 
125  i = 0;
126  B = 1;
127 
128  while(i < D)
129  {
130  if(B & oct)
131  res->x[i] = one->x[i];
132  else
133  res->x[i] = pvt->x[i];
134  i++;
135  B <<= 1;
136  }
137 }
138 
145 static sureInline(int) classify(point* pvt, point* a)
146 {
147  unsigned int res;
148  unsigned int B;
149  int i;
150 
151  res = 0;
152  i = 0;
153  B = 1;
154 
155  while(i < D)
156  {
157  if(a->x[i] > pvt->x[i])
158  res |= B;
159 
160  i++;
161  B <<= 1;
162  }
163 
164  return res;
165 }
166 
174 static sureInline(double) HV(point* zero, point* one)
175 {
176  __m128d c;
177  __m128d* o;
178  __m128d* z;
179  double* V;
180 
181  int d;
182 
183 #if (D & 1)
184  one->x[D] = 1;
185  zero->x[D] = 0;
186 #endif /* (D & 1) */
187 
188  z = (__m128d*)&(zero->x[0]);
189  o = (__m128d*)&(one->x[0]);
190  c = _mm_set1_pd(1);
191 
192  d = 0;
193  while(d < ((D+1) >> 1))
194  {
195  c = _mm_mul_pd(c, _mm_sub_pd(z[d], o[d]));
196  d++;
197  }
198 
199  V = (double*) &c;
200  V[0] *= V[1];
201 
202  return V[0];
203 }
204 
205 
212 static sureInline(double) minCoord(point* zero, point* pt, point* one)
213 {
214  __m128d t; /* Temporary */
215  __m128d s; /* Scaling */
216  __m128d c;
217  __m128d* o;
218  __m128d* p;
219  __m128d* z;
220  double* V;
221 
222  int d;
223 
224 #if (D & 1)
225  one->x[D] = one->x[D-1];
226  pt->x[D] = pt->x[D-1];
227  zero->x[D] = zero->x[D-1];
228 #endif /* (D & 1) */
229 
230  z = (__m128d*)&(zero->x[0]);
231  p = (__m128d*)&(pt->x[0]);
232  o = (__m128d*)&(one->x[0]);
233  c = _mm_set1_pd(DBL_MAX);
234 
235  d = 0;
236  while(d < ((D+1) >> 1))
237  {
238  s = _mm_sub_pd(o[d], z[d]);
239  t = _mm_sub_pd(p[d], z[d]);
240  t = _mm_div_pd(t, s);
241 
242  c = _mm_min_pd(c, t);
243 
244  /* printf("Coordinate %f in [%f, %f], scaled value %f\n", */
245  /* ((double*)&(p[d]))[0], */
246  /* ((double*)&(z[d]))[0], */
247  /* ((double*)&(o[d]))[0], */
248  /* ((double*)&t)[0]); */
249  /* printf("Coordinate %f in [%f, %f], scaled value %f\n", */
250  /* ((double*)&(p[d]))[1], */
251  /* ((double*)&(z[d]))[1], */
252  /* ((double*)&(o[d]))[1], */
253  /* ((double*)&t)[1]); */
254  d++;
255  }
256 
257  V = (double*) &c;
258  if(V[1] < V[0])
259  V[0] = V[1];
260 
261  return V[0];
262 }
263 
264 
273 static sureInline(void) intercept(point* res, point* A, point* B)
274 /* static void intercept(point* res, point* A, point* B) */
275 {
276  __m128d* a;
277  __m128d* b;
278  __m128d* r;
279 
280  int d;
281 
282  a = (__m128d*)&(A->x[0]);
283  b = (__m128d*)&(B->x[0]);
284  r = (__m128d*)&(res->x[0]);
285 
286  d = 0;
287  while(d < ((D+1) >> 1))
288  {
289  r[d] = _mm_min_pd(a[d], b[d]);
290  d++;
291  }
292 }
293 
294 /*** inline functions *************************************/
295 
296 #endif /* POINT_H */
point cZero
Definition: point.c:45
#define D
D is the number of dimensions.
Definition: pointStruct.h:43
void randomPoint(point *p)
Definition: point.c:75
double * V
A volume value for every dimension + 1.
Definition: point.h:179
void parsePoint(char *S, point *p, double max)
Definition: point.c:58
Point is an array of coordinates, in a struct for simple and fast copy.
Definition: pointStruct.h:47
The definition of a point stucture.
point cOne
Definition: point.c:46