exQHV
Compute Exclusive 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 "Extending
8  * quick hypervolume. Luís M. S. Russo, Alexandre P. Francisco:
9  * J. Heuristics 22(3): 245-271 (2016)".
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 
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 
48 #ifndef D
49 #define D 6
50 #endif /* D */
51 
52 #ifndef Eps
53 #define Eps 0.0000000001
54 #endif /* Eps */
55 
56 /*** typedefs(not structures) and defined constants *******/
58 struct point{
59 #if (D & 1)
60  double x[D+1];
61 #else /* (D & 1) */
62  double x[D];
63 #endif /* (D & 1) */
64 };
66 typedef struct point __attribute__ ((aligned (16))) point;
67 
68 /*** enums ************************************************/
69 
70 /*** structures declarations (and typedefs of )************/
71 
72 /*** global variables defined in .c file ******************/
73 
74 extern point cZero;
75 extern point cOne;
77 /*** declarations of public functions *********************/
78 
87 #define equal(A, B, I) (fabs((A)->x[I] - (B)->x[I]) < Eps)
88 
96 #define objective(Z, A, O) HV(Z, A)
97 //#define objective(Z, A, O) minCoord(Z, A, O)
98 
105 void parsePoint(char* S, point* p, double max);
106 
112 void randomPoint(point* p);
113 
114 static sureInline(void) projectZero(point* res, point* pvt, unsigned int oct, point* zero)
115 {
116  unsigned int B;
117  int i;
118 
119  i = 0;
120  B = 1;
121 
122  while(i < D)
123  {
124  if(B & oct)
125  res->x[i] = pvt->x[i];
126  else
127  res->x[i] = zero->x[i];
128  i++;
129  B <<= 1;
130  }
131 }
132 
133 static sureInline(void) projectOne(point* res, point* pvt, unsigned int oct, point* one)
134 {
135  unsigned int B;
136  int i;
137 
138  i = 0;
139  B = 1;
140 
141  while(i < D)
142  {
143  if(B & oct)
144  res->x[i] = one->x[i];
145  else
146  res->x[i] = pvt->x[i];
147  i++;
148  B <<= 1;
149  }
150 }
151 
158 static sureInline(int) classify(point* pvt, point* a)
159 {
160  unsigned int res;
161  unsigned int B;
162  int i;
163 
164  res = 0;
165  i = 0;
166  B = 1;
167 
168  while(i < D)
169  {
170  if(a->x[i] > pvt->x[i])
171  res |= B;
172 
173  i++;
174  B <<= 1;
175  }
176 
177  return res;
178 }
179 
187 static sureInline(double) HV(point* zero, point* one)
188 {
189  __m128d c;
190  __m128d* o;
191  __m128d* z;
192  double* V;
193 
194  int d;
195 
196 #if (D & 1)
197  one->x[D] = 1;
198  zero->x[D] = 0;
199 #endif /* (D & 1) */
200 
201  z = (__m128d*)&(zero->x[0]);
202  o = (__m128d*)&(one->x[0]);
203  c = _mm_set1_pd(1);
204 
205  d = 0;
206  while(d < ((D+1) >> 1))
207  {
208  c = _mm_mul_pd(c, _mm_sub_pd(z[d], o[d]));
209  d++;
210  }
211 
212  V = (double*) &c;
213  V[0] *= V[1];
214 
215  return V[0];
216 }
217 
218 
225 static sureInline(double) minCoord(point* zero, point* pt, point* one)
226 {
227  __m128d t; /* Temporary */
228  __m128d s; /* Scaling */
229  __m128d c;
230  __m128d* o;
231  __m128d* p;
232  __m128d* z;
233  double* V;
234 
235  int d;
236 
237 #if (D & 1)
238  one->x[D] = one->x[D-1];
239  pt->x[D] = pt->x[D-1];
240  zero->x[D] = zero->x[D-1];
241 #endif /* (D & 1) */
242 
243  z = (__m128d*)&(zero->x[0]);
244  p = (__m128d*)&(pt->x[0]);
245  o = (__m128d*)&(one->x[0]);
246  c = _mm_set1_pd(DBL_MAX);
247 
248  d = 0;
249  while(d < ((D+1) >> 1))
250  {
251  s = _mm_sub_pd(o[d], z[d]);
252  t = _mm_sub_pd(p[d], z[d]);
253  t = _mm_div_pd(t, s);
254 
255  c = _mm_min_pd(c, t);
256 
257  /* printf("Coordinate %f in [%f, %f], scaled value %f\n", */
258  /* ((double*)&(p[d]))[0], */
259  /* ((double*)&(z[d]))[0], */
260  /* ((double*)&(o[d]))[0], */
261  /* ((double*)&t)[0]); */
262  /* printf("Coordinate %f in [%f, %f], scaled value %f\n", */
263  /* ((double*)&(p[d]))[1], */
264  /* ((double*)&(z[d]))[1], */
265  /* ((double*)&(o[d]))[1], */
266  /* ((double*)&t)[1]); */
267  d++;
268  }
269 
270  V = (double*) &c;
271  if(V[1] < V[0])
272  V[0] = V[1];
273 
274  return V[0];
275 }
276 
277 
286 static sureInline(void) intercept(point* res, point* A, point* B)
287 /* static void intercept(point* res, point* A, point* B) */
288 {
289  __m128d* a;
290  __m128d* b;
291  __m128d* r;
292 
293  int d;
294 
295  a = (__m128d*)&(A->x[0]);
296  b = (__m128d*)&(B->x[0]);
297  r = (__m128d*)&(res->x[0]);
298 
299  d = 0;
300  while(d < ((D+1) >> 1))
301  {
302  r[d] = _mm_min_pd(a[d], b[d]);
303  d++;
304  }
305 }
306 
314 static sureInline(void) swap(int* idx, int n, int j)
315 {
316  int t;
317 
318  t = idx[n];
319  idx[n] = idx[j];
320  idx[j] = t;
321 }
322 
323 
324 /*** inline functions *************************************/
325 
326 #endif /* POINT_H */
point cZero
Definition: point.c:44
void randomPoint(point *p)
Definition: point.c:74
double * V
A volume value for every dimension + 1.
Definition: point.h:192
struct point __attribute__((aligned(16))) point
All points must be aligned for SSE2.
#define D
Definition: point.h:49
void parsePoint(char *S, point *p, double max)
Definition: point.c:57
Point is an array of coordinates, in a struct for simple and fast copy.
Definition: point.h:58
point cOne
Definition: point.c:45