parExQHV
Compute Exclusive HyperVolumes using threads
 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 <string.h>
45 #include "emmintrin.h"
46 #include "macros.h"
47 
48 #ifndef Eps
49 #define Eps 0.0000000001
50 #endif /* Eps */
51 
52 /*** typedefs(not structures) and defined constants *******/
53 
54 #include "pointStruct.h"
55 
56 /*** enums ************************************************/
57 
58 /*** structures declarations (and typedefs of )************/
59 
60 /*** global variables defined in .c file ******************/
61 
62 extern point cZero;
63 extern point cOne;
65 /*** declarations of public functions *********************/
66 
75 #define equal(A, B, I) (fabs((A)->x[I] - (B)->x[I]) < Eps)
76 
84 #define objective(Z, A, O) HV(Z, A)
85 //#define objective(Z, A, O) minCoord(Z, A, O)
86 
93 void parsePoint(char* S, point* p, double max);
94 
100 void randomPoint(point* p);
101 
102 static sureInline(void) projectZero(point* res, point* pvt, unsigned int oct, point* zero)
103 {
104  unsigned int B;
105  int i;
106 
107  i = 0;
108  B = 1;
109 
110  while(i < D)
111  {
112  if(B & oct)
113  res->x[i] = pvt->x[i];
114  else
115  res->x[i] = zero->x[i];
116  i++;
117  B <<= 1;
118  }
119 }
120 
121 static sureInline(void) projectOne(point* res, point* pvt, unsigned int oct, point* one)
122 {
123  unsigned int B;
124  int i;
125 
126  i = 0;
127  B = 1;
128 
129  while(i < D)
130  {
131  if(B & oct)
132  res->x[i] = one->x[i];
133  else
134  res->x[i] = pvt->x[i];
135  i++;
136  B <<= 1;
137  }
138 }
139 
146 static sureInline(int) classify(point* pvt, point* a)
147 {
148  unsigned int res;
149  unsigned int B;
150  int i;
151 
152  res = 0;
153  i = 0;
154  B = 1;
155 
156  while(i < D)
157  {
158  if(a->x[i] > pvt->x[i])
159  res |= B;
160 
161  i++;
162  B <<= 1;
163  }
164 
165  return res;
166 }
167 
169 #define SSED ((D+1)/2)
170 
178 static sureInline(double) HV(point* zero, point* one)
179 {
180  __m128d c;
181  __m128d o[SSED];
182  __m128d z[SSED];
183  double* V;
184 
185  int d;
186 
187 #if (D & 1)
188  one->x[D] = 1;
189  zero->x[D] = 0;
190 #endif /* (D & 1) */
191 
192  memcpy(z, &(zero->x[0]), SSED*sizeof(__m128d));
193  memcpy(o, &(one->x[0]), SSED*sizeof(__m128d));
194 
195  /* z = (__m128d*)&(zero->x[0]); */
196  /* o = (__m128d*)&(one->x[0]); */
197  c = _mm_set1_pd(1);
198 
199  d = 0;
200  while(d < ((D+1) >> 1))
201  {
202  c = _mm_mul_pd(c, _mm_sub_pd(z[d], o[d]));
203  d++;
204  }
205 
206  V = (double*) &c;
207  V[0] *= V[1];
208 
209  return V[0];
210 }
211 
212 
219 static sureInline(double) minCoord(point* zero, point* pt, point* one)
220 {
221  __m128d t; /* Temporary */
222  __m128d s; /* Scaling */
223  __m128d c;
224  __m128d o[SSED];
225  __m128d p[SSED];
226  __m128d z[SSED];
227  double* V;
228 
229  int d;
230 
231 #if (D & 1)
232  one->x[D] = one->x[D-1];
233  pt->x[D] = pt->x[D-1];
234  zero->x[D] = zero->x[D-1];
235 #endif /* (D & 1) */
236 
237  /* z = (__m128d*)&(zero->x[0]); */
238  /* p = (__m128d*)&(pt->x[0]); */
239  /* o = (__m128d*)&(one->x[0]); */
240 
241  memcpy(z, &(zero->x[0]), SSED*sizeof(__m128d));
242  memcpy(o, &(one->x[0]), SSED*sizeof(__m128d));
243  memcpy(p, &(pt->x[0]), SSED*sizeof(__m128d));
244 
245  c = _mm_set1_pd(DBL_MAX);
246 
247  d = 0;
248  while(d < ((D+1) >> 1))
249  {
250  s = _mm_sub_pd(o[d], z[d]);
251  t = _mm_sub_pd(p[d], z[d]);
252  t = _mm_div_pd(t, s);
253 
254  c = _mm_min_pd(c, t);
255 
256  /* printf("Coordinate %f in [%f, %f], scaled value %f\n", */
257  /* ((double*)&(p[d]))[0], */
258  /* ((double*)&(z[d]))[0], */
259  /* ((double*)&(o[d]))[0], */
260  /* ((double*)&t)[0]); */
261  /* printf("Coordinate %f in [%f, %f], scaled value %f\n", */
262  /* ((double*)&(p[d]))[1], */
263  /* ((double*)&(z[d]))[1], */
264  /* ((double*)&(o[d]))[1], */
265  /* ((double*)&t)[1]); */
266  d++;
267  }
268 
269  V = (double*) &c;
270  if(V[1] < V[0])
271  V[0] = V[1];
272 
273  return V[0];
274 }
275 
276 
285 static sureInline(void) intercept(point* res, point* A, point* B)
286 /* static void intercept(point* res, point* A, point* B) */
287 {
288  __m128d a[SSED];
289  __m128d b[SSED];
290  __m128d r[SSED];
291 
292  int d;
293 
294  memcpy(a, &(A->x[0]), SSED*sizeof(__m128d));
295  memcpy(b, &(B->x[0]), SSED*sizeof(__m128d));
296 
297  /* a = (__m128d*)&(A->x[0]); */
298  /* b = (__m128d*)&(B->x[0]); */
299  /* r = (__m128d*)&(res->x[0]); */
300 
301  d = 0;
302  while(d < ((D+1) >> 1))
303  {
304  r[d] = _mm_min_pd(a[d], b[d]);
305  d++;
306  }
307 
308  memcpy(&(res->x[0]), r, SSED*sizeof(__m128d));
309 }
310 
318 static sureInline(void) swap(int* idx, int n, int j)
319 {
320  int t;
321 
322  t = idx[n];
323  idx[n] = idx[j];
324  idx[j] = t;
325 }
326 
327 /*** inline functions *************************************/
328 
329 #endif /* POINT_H */
point cZero
Definition: point.c:44
#define D
D is the number of dimensions.
Definition: pointStruct.h:43
void randomPoint(point *p)
Definition: point.c:74
double * V
A volume value for every dimension + 1.
Definition: point.h:183
#define SSED
Used to guarantee aligned points.
Definition: point.h:169
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: pointStruct.h:47
The definition of a point stucture.
point cOne
Definition: point.c:45